141281cf3SAxel Dörfler /* 241281cf3SAxel Dörfler Open Tracker License 341281cf3SAxel Dörfler 441281cf3SAxel Dörfler Terms and Conditions 541281cf3SAxel Dörfler 641281cf3SAxel Dörfler Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 741281cf3SAxel Dörfler 841281cf3SAxel Dörfler Permission is hereby granted, free of charge, to any person obtaining a copy of 941281cf3SAxel Dörfler this software and associated documentation files (the "Software"), to deal in 1041281cf3SAxel Dörfler the Software without restriction, including without limitation the rights to 1141281cf3SAxel Dörfler use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 1241281cf3SAxel Dörfler of the Software, and to permit persons to whom the Software is furnished to do 1341281cf3SAxel Dörfler so, subject to the following conditions: 1441281cf3SAxel Dörfler 1541281cf3SAxel Dörfler The above copyright notice and this permission notice applies to all licensees 1641281cf3SAxel Dörfler and shall be included in all copies or substantial portions of the Software. 1741281cf3SAxel Dörfler 1841281cf3SAxel Dörfler THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1941281cf3SAxel Dörfler IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 2041281cf3SAxel Dörfler FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2141281cf3SAxel Dörfler BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2241281cf3SAxel Dörfler AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 2341281cf3SAxel Dörfler WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2441281cf3SAxel Dörfler 2541281cf3SAxel Dörfler Except as contained in this notice, the name of Be Incorporated shall not be 2641281cf3SAxel Dörfler used in advertising or otherwise to promote the sale, use or other dealings in 2741281cf3SAxel Dörfler this Software without prior written authorization from Be Incorporated. 2841281cf3SAxel Dörfler 291687edd0SFredrik Holmqvist Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered 301687edd0SFredrik Holmqvist trademarks of Be Incorporated in the United States and other countries. Other 311687edd0SFredrik Holmqvist brand product names are registered trademarks or trademarks of their respective 321687edd0SFredrik Holmqvist holders. 3341281cf3SAxel Dörfler All rights reserved. 3441281cf3SAxel Dörfler */ 3541281cf3SAxel Dörfler 36136d40a8SStefano Ceccherini 37cb6afcb1SStephan Aßmus #include "TeamMenuItem.h" 38cb6afcb1SStephan Aßmus 3941281cf3SAxel Dörfler #include <string.h> 4041281cf3SAxel Dörfler #include <stdio.h> 41136d40a8SStefano Ceccherini #include <stdlib.h> 42136d40a8SStefano Ceccherini 4315eb397eSJohn Scipione #include <algorithm> 4415eb397eSJohn Scipione 4541281cf3SAxel Dörfler #include <Bitmap.h> 46cb6afcb1SStephan Aßmus #include <ControlLook.h> 471cd61330SJohn Scipione #include <Debug.h> 4841281cf3SAxel Dörfler #include <Font.h> 4915eb397eSJohn Scipione #include <Mime.h> 5041281cf3SAxel Dörfler #include <Region.h> 5141281cf3SAxel Dörfler #include <Roster.h> 5241281cf3SAxel Dörfler #include <Resources.h> 5341281cf3SAxel Dörfler 5441281cf3SAxel Dörfler #include "BarApp.h" 5541281cf3SAxel Dörfler #include "BarMenuBar.h" 564ae3e542SJohn Scipione #include "BarView.h" 5741281cf3SAxel Dörfler #include "ExpandoMenuBar.h" 5841281cf3SAxel Dörfler #include "ResourceSet.h" 5941281cf3SAxel Dörfler #include "ShowHideMenuItem.h" 6015eb397eSJohn Scipione #include "StatusView.h" 6141281cf3SAxel Dörfler #include "TeamMenu.h" 6241281cf3SAxel Dörfler #include "WindowMenu.h" 6341281cf3SAxel Dörfler #include "WindowMenuItem.h" 6441281cf3SAxel Dörfler 6541281cf3SAxel Dörfler 661e0308a8SAugustin Cavalier static float sHPad, sVPad, sLabelOffset = 0.0f; 6741281cf3SAxel Dörfler 6841281cf3SAxel Dörfler 69072c2dcdSJohn Scipione // #pragma mark - TTeamMenuItem 70072c2dcdSJohn Scipione 71072c2dcdSJohn Scipione 72c9363f78SJohn Scipione TTeamMenuItem::TTeamMenuItem(BList* team, BBitmap* icon, char* name, 73c9363f78SJohn Scipione char* signature, float width, float height) 7401f35d10SJohn Scipione : 75c9363f78SJohn Scipione TTruncatableMenuItem(new TWindowMenu(team, signature)) 7641281cf3SAxel Dörfler { 77e9982f68SJohn Scipione _Init(team, icon, name, signature, width, height); 7841281cf3SAxel Dörfler } 7941281cf3SAxel Dörfler 8041281cf3SAxel Dörfler 8118bcf77aSJohn Scipione TTeamMenuItem::TTeamMenuItem(float width, float height) 8201f35d10SJohn Scipione : 83c9363f78SJohn Scipione TTruncatableMenuItem("", NULL) 8441281cf3SAxel Dörfler { 85e9982f68SJohn Scipione _Init(NULL, NULL, strdup(""), strdup(""), width, height); 8641281cf3SAxel Dörfler } 8741281cf3SAxel Dörfler 8841281cf3SAxel Dörfler 8941281cf3SAxel Dörfler TTeamMenuItem::~TTeamMenuItem() 9041281cf3SAxel Dörfler { 9141281cf3SAxel Dörfler delete fTeam; 9241281cf3SAxel Dörfler delete fIcon; 93c9363f78SJohn Scipione free(fSignature); 945e625eadSJohn Scipione } 955e625eadSJohn Scipione 965e625eadSJohn Scipione 9741281cf3SAxel Dörfler status_t 9841281cf3SAxel Dörfler TTeamMenuItem::Invoke(BMessage* message) 9941281cf3SAxel Dörfler { 1006a27de89SMurai Takashi if (fBarView != NULL) { 1011dccb7aaSJohn Scipione if (fBarView->InvokeItem(Signature())) { 10241281cf3SAxel Dörfler // handles drop on application 10341281cf3SAxel Dörfler return B_OK; 1041dccb7aaSJohn Scipione } 10541281cf3SAxel Dörfler 10641281cf3SAxel Dörfler // if the app could not handle the drag message 10741281cf3SAxel Dörfler // and we were dragging, then kill the drag 10841281cf3SAxel Dörfler // should never get here, disabled item will not invoke 1096a27de89SMurai Takashi if (fBarView->Dragging()) 1101dccb7aaSJohn Scipione fBarView->DragStop(); 1116a27de89SMurai Takashi } 11241281cf3SAxel Dörfler 11341281cf3SAxel Dörfler // bring to front or minimize shortcuts 11441281cf3SAxel Dörfler uint32 mods = modifiers(); 1151687edd0SFredrik Holmqvist if (mods & B_CONTROL_KEY) { 11641281cf3SAxel Dörfler TShowHideMenuItem::TeamShowHideCommon((mods & B_SHIFT_KEY) 11741281cf3SAxel Dörfler ? B_MINIMIZE_WINDOW : B_BRING_TO_FRONT, Teams()); 1181687edd0SFredrik Holmqvist } 11941281cf3SAxel Dörfler 12041281cf3SAxel Dörfler return BMenuItem::Invoke(message); 12141281cf3SAxel Dörfler } 12241281cf3SAxel Dörfler 12341281cf3SAxel Dörfler 12441281cf3SAxel Dörfler void 125249a4a18SStephan Aßmus TTeamMenuItem::SetOverrideSelected(bool selected) 126249a4a18SStephan Aßmus { 127249a4a18SStephan Aßmus fOverriddenSelected = selected; 128249a4a18SStephan Aßmus Highlight(selected); 129249a4a18SStephan Aßmus } 130249a4a18SStephan Aßmus 131249a4a18SStephan Aßmus 1321dccb7aaSJohn Scipione void 133c9d2a320SJohn Scipione TTeamMenuItem::SetIcon(BBitmap* icon) { 134c9d2a320SJohn Scipione delete fIcon; 135c9d2a320SJohn Scipione fIcon = icon; 1362ce9bab8SJohn Scipione } 1372ce9bab8SJohn Scipione 1382ce9bab8SJohn Scipione 13941281cf3SAxel Dörfler void 14041281cf3SAxel Dörfler TTeamMenuItem::GetContentSize(float* width, float* height) 14141281cf3SAxel Dörfler { 14241281cf3SAxel Dörfler BMenuItem::GetContentSize(width, height); 14341281cf3SAxel Dörfler 14441281cf3SAxel Dörfler if (fOverrideWidth != -1.0f) 14541281cf3SAxel Dörfler *width = fOverrideWidth; 1462ce9bab8SJohn Scipione else { 14715eb397eSJohn Scipione bool hideLabels = static_cast<TBarApp*>(be_app)->Settings()->hideLabels; 14815eb397eSJohn Scipione float iconSize = static_cast<TBarApp*>(be_app)->IconSize(); 1491e0308a8SAugustin Cavalier float iconOnlyWidth = (be_control_look->ComposeSpacing(kIconPadding) * 2) + iconSize; 15015eb397eSJohn Scipione 15115eb397eSJohn Scipione if (fBarView->MiniState()) { 15215eb397eSJohn Scipione if (hideLabels) 15315eb397eSJohn Scipione *width = iconOnlyWidth; 15415eb397eSJohn Scipione else 155*9f4bb0f5SAugustin Cavalier *width = gMinimumWindowWidth - (gDragRegionWidth + kGutter) * 2; 15615eb397eSJohn Scipione } else if (!fBarView->Vertical()) { 1570d2645e4SJohn Scipione TExpandoMenuBar* menu = static_cast<TExpandoMenuBar*>(Menu()); 1580d2645e4SJohn Scipione *width = menu->MaxHorizontalItemWidth(); 15915eb397eSJohn Scipione } else 16015eb397eSJohn Scipione *width = static_cast<TBarApp*>(be_app)->Settings()->width; 16118bcf77aSJohn Scipione } 16241281cf3SAxel Dörfler 16341281cf3SAxel Dörfler if (fOverrideHeight != -1.0f) 16441281cf3SAxel Dörfler *height = fOverrideHeight; 16515eb397eSJohn Scipione else 16615eb397eSJohn Scipione *height = fBarView->TeamMenuItemHeight(); 16741281cf3SAxel Dörfler } 16841281cf3SAxel Dörfler 16941281cf3SAxel Dörfler 17041281cf3SAxel Dörfler void 17141281cf3SAxel Dörfler TTeamMenuItem::Draw() 17241281cf3SAxel Dörfler { 1736b65d934SJohn Scipione BRect frame = Frame(); 17441281cf3SAxel Dörfler BMenu* menu = Menu(); 175fe624b39SJohn Scipione 17641281cf3SAxel Dörfler menu->PushState(); 1775b0fd10dSJohn Scipione 17816c10517Slooncraz rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 1791dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 1801dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 181cb6afcb1SStephan Aßmus uint32 flags = 0; 182cb6afcb1SStephan Aßmus if (_IsSelected() && canHandle) 183cb6afcb1SStephan Aßmus flags |= BControlLook::B_ACTIVATED; 184cb6afcb1SStephan Aßmus 185cb6afcb1SStephan Aßmus uint32 borders = BControlLook::B_TOP_BORDER; 18618bcf77aSJohn Scipione if (fBarView->Vertical()) { 187cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_1_TINT)); 188cb6afcb1SStephan Aßmus borders |= BControlLook::B_LEFT_BORDER 189cb6afcb1SStephan Aßmus | BControlLook::B_RIGHT_BORDER; 190cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftBottom(), frame.RightBottom()); 191cb6afcb1SStephan Aßmus frame.bottom--; 192cb6afcb1SStephan Aßmus 193cb6afcb1SStephan Aßmus be_control_look->DrawMenuBarBackground(menu, frame, frame, 194cb6afcb1SStephan Aßmus menuColor, flags, borders); 195cb6afcb1SStephan Aßmus } else { 196cb6afcb1SStephan Aßmus if (flags & BControlLook::B_ACTIVATED) 197cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_3_TINT)); 198cb6afcb1SStephan Aßmus else 199cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, 1.22)); 200cb6afcb1SStephan Aßmus borders |= BControlLook::B_BOTTOM_BORDER; 201cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); 202cb6afcb1SStephan Aßmus frame.left++; 203cb6afcb1SStephan Aßmus 204cb6afcb1SStephan Aßmus be_control_look->DrawButtonBackground(menu, frame, frame, 205cb6afcb1SStephan Aßmus menuColor, flags, borders); 206cb6afcb1SStephan Aßmus } 207cb6afcb1SStephan Aßmus 208cb6afcb1SStephan Aßmus menu->MovePenTo(ContentLocation()); 209cb6afcb1SStephan Aßmus DrawContent(); 210fe624b39SJohn Scipione 211cb6afcb1SStephan Aßmus menu->PopState(); 21241281cf3SAxel Dörfler } 21341281cf3SAxel Dörfler 21441281cf3SAxel Dörfler 21541281cf3SAxel Dörfler void 21641281cf3SAxel Dörfler TTeamMenuItem::DrawContent() 21741281cf3SAxel Dörfler { 21841281cf3SAxel Dörfler BMenu* menu = Menu(); 21915eb397eSJohn Scipione BRect frame = Frame(); 22015eb397eSJohn Scipione 2212ce9bab8SJohn Scipione if (fIcon != NULL) { 22259deaf10SStephan Aßmus if (fIcon->ColorSpace() == B_RGBA32) { 22359deaf10SStephan Aßmus menu->SetDrawingMode(B_OP_ALPHA); 22459deaf10SStephan Aßmus menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); 2251687edd0SFredrik Holmqvist } else 22641281cf3SAxel Dörfler menu->SetDrawingMode(B_OP_OVER); 22741281cf3SAxel Dörfler 22815eb397eSJohn Scipione BRect iconBounds = fIcon != NULL ? fIcon->Bounds() 22915eb397eSJohn Scipione : BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1); 2306b65d934SJohn Scipione BRect updateRect = iconBounds; 231c9363f78SJohn Scipione BPoint contentLocation = ContentLocation(); 2321e0308a8SAugustin Cavalier BPoint drawLocation = contentLocation + BPoint(sHPad, sVPad); 2331687edd0SFredrik Holmqvist 23418bcf77aSJohn Scipione if (static_cast<TBarApp*>(be_app)->Settings()->hideLabels 23518bcf77aSJohn Scipione || (fBarView->Vertical() && iconBounds.Width() > 32)) { 23615eb397eSJohn Scipione // determine icon location (centered horizontally) 237c9363f78SJohn Scipione float offsetx = contentLocation.x 23815eb397eSJohn Scipione + floorf((frame.Width() - iconBounds.Width()) / 2); 2391e0308a8SAugustin Cavalier float offsety = contentLocation.y + sVPad + kGutter; 2402ce9bab8SJohn Scipione 24115eb397eSJohn Scipione // draw icon 2426b65d934SJohn Scipione updateRect.OffsetTo(BPoint(offsetx, offsety)); 2436b65d934SJohn Scipione menu->DrawBitmapAsync(fIcon, updateRect); 2442ce9bab8SJohn Scipione 24515eb397eSJohn Scipione // determine label position (below icon) 24615eb397eSJohn Scipione drawLocation.x = floorf((frame.Width() - fLabelWidth) / 2); 2471e0308a8SAugustin Cavalier drawLocation.y = frame.top + sVPad + iconBounds.Height() + sVPad; 2482ce9bab8SJohn Scipione } else { 24915eb397eSJohn Scipione // determine icon location (centered vertically) 2501e0308a8SAugustin Cavalier float offsetx = contentLocation.x + sHPad; 251c9363f78SJohn Scipione float offsety = contentLocation.y + 25215eb397eSJohn Scipione floorf((frame.Height() - iconBounds.Height()) / 2); 2532ce9bab8SJohn Scipione 25415eb397eSJohn Scipione // draw icon 2556b65d934SJohn Scipione updateRect.OffsetTo(BPoint(offsetx, offsety)); 2566b65d934SJohn Scipione menu->DrawBitmapAsync(fIcon, updateRect); 25741281cf3SAxel Dörfler 25815eb397eSJohn Scipione // determine label position (centered vertically) 2591e0308a8SAugustin Cavalier drawLocation.x += iconBounds.Width() + sLabelOffset; 26015eb397eSJohn Scipione drawLocation.y = frame.top 26115eb397eSJohn Scipione + ceilf((frame.Height() - fLabelHeight) / 2); 2622ce9bab8SJohn Scipione } 2632ce9bab8SJohn Scipione 264c9363f78SJohn Scipione menu->MovePenTo(drawLocation); 26541281cf3SAxel Dörfler } 26641281cf3SAxel Dörfler 26741281cf3SAxel Dörfler // override the drawing of the content when the item is disabled 26841281cf3SAxel Dörfler // the wrong lowcolor is used when the item is disabled since the 26941281cf3SAxel Dörfler // text color does not change 27015eb397eSJohn Scipione menu->SetDrawingMode(B_OP_OVER); 27115eb397eSJohn Scipione menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 27241281cf3SAxel Dörfler 2731dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 2741dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 275249a4a18SStephan Aßmus if (_IsSelected() && IsEnabled() && canHandle) 27616c10517Slooncraz menu->SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 27741281cf3SAxel Dörfler B_HIGHLIGHT_BACKGROUND_TINT)); 27841281cf3SAxel Dörfler else 27916c10517Slooncraz menu->SetLowColor(ui_color(B_MENU_BACKGROUND_COLOR)); 28041281cf3SAxel Dörfler 281859c3781SJohn Scipione if (IsSelected()) 282859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR)); 283859c3781SJohn Scipione else 284859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 285859c3781SJohn Scipione 28615eb397eSJohn Scipione menu->MovePenBy(0, fLabelAscent); 28715eb397eSJohn Scipione 28815eb397eSJohn Scipione // draw label 289c9363f78SJohn Scipione if (!static_cast<TBarApp*>(be_app)->Settings()->hideLabels) { 290c9363f78SJohn Scipione float labelWidth = menu->StringWidth(Label()); 291c9363f78SJohn Scipione BPoint penLocation = menu->PenLocation(); 29215eb397eSJohn Scipione // truncate to max width 29315eb397eSJohn Scipione float offset = penLocation.x - frame.left; 294c9363f78SJohn Scipione menu->DrawString(Label(labelWidth + offset)); 295c9363f78SJohn Scipione } 29641281cf3SAxel Dörfler 29715eb397eSJohn Scipione // draw expander arrow 2985e625eadSJohn Scipione if (fBarView->Vertical() 2995e625eadSJohn Scipione && static_cast<TBarApp*>(be_app)->Settings()->superExpando 3005e625eadSJohn Scipione && fBarView->ExpandoState()) { 3015e625eadSJohn Scipione DrawExpanderArrow(); 3025e625eadSJohn Scipione } 3035e625eadSJohn Scipione } 3045e625eadSJohn Scipione 30541281cf3SAxel Dörfler 3065b0fd10dSJohn Scipione void 3071dccb7aaSJohn Scipione TTeamMenuItem::DrawExpanderArrow() 3085b0fd10dSJohn Scipione { 3096b65d934SJohn Scipione BRect frame = Frame(); 3101e0308a8SAugustin Cavalier BRect rect(0.0f, 0.0f, kSwitchWidth, sHPad + 2.0f); 3115b0fd10dSJohn Scipione rect.OffsetTo(BPoint(frame.right - rect.Width(), 3125b0fd10dSJohn Scipione ContentLocation().y + ((frame.Height() - rect.Height()) / 2))); 3139a9f4ef5SMikael Konradsson 3149a9f4ef5SMikael Konradsson float colorTint = B_DARKEN_3_TINT; 3159a9f4ef5SMikael Konradsson rgb_color bgColor = ui_color(B_MENU_BACKGROUND_COLOR); 31615eb397eSJohn Scipione if (bgColor.red + bgColor.green + bgColor.blue <= 128 * 3) 3179a9f4ef5SMikael Konradsson colorTint = B_LIGHTEN_2_TINT; 3189a9f4ef5SMikael Konradsson 31915eb397eSJohn Scipione be_control_look->DrawArrowShape(Menu(), rect, Menu()->Frame(), 32015eb397eSJohn Scipione bgColor, fArrowDirection, 0, colorTint); 32141281cf3SAxel Dörfler } 32241281cf3SAxel Dörfler 32341281cf3SAxel Dörfler 32441281cf3SAxel Dörfler void 32541281cf3SAxel Dörfler TTeamMenuItem::ToggleExpandState(bool resizeWindow) 32641281cf3SAxel Dörfler { 32741281cf3SAxel Dörfler fExpanded = !fExpanded; 3281dccb7aaSJohn Scipione fArrowDirection = fExpanded ? BControlLook::B_DOWN_ARROW 3291dccb7aaSJohn Scipione : BControlLook::B_RIGHT_ARROW; 33041281cf3SAxel Dörfler 33141281cf3SAxel Dörfler if (fExpanded) { 33241281cf3SAxel Dörfler // Populate Menu() with the stuff from SubMenu(). 33341281cf3SAxel Dörfler TWindowMenu* sub = (static_cast<TWindowMenu*>(Submenu())); 3345b0fd10dSJohn Scipione if (sub != NULL) { 33541281cf3SAxel Dörfler // force the menu to update it's contents. 336bdfed6c0SAxel Dörfler bool locked = sub->LockLooper(); 337bdfed6c0SAxel Dörfler // if locking the looper failed, the menu is just not visible 338bdfed6c0SAxel Dörfler sub->AttachedToWindow(); 339bdfed6c0SAxel Dörfler if (locked) 340bdfed6c0SAxel Dörfler sub->UnlockLooper(); 341bdfed6c0SAxel Dörfler 34241281cf3SAxel Dörfler if (sub->CountItems() > 1) { 34341281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 34441281cf3SAxel Dörfler int myindex = parent->IndexOf(this) + 1; 34541281cf3SAxel Dörfler 34641281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 347deaae5fcSJohn Scipione int32 childIndex = 0; 348deaae5fcSJohn Scipione int32 totalChildren = sub->CountItems() - 4; 34971bd3ba5SJonas Sundström // hide, show, close, separator. 35041281cf3SAxel Dörfler for (; childIndex < totalChildren; childIndex++) { 35171bd3ba5SJonas Sundström windowItem = static_cast<TWindowMenuItem*> 35271bd3ba5SJonas Sundström (sub->RemoveItem((int32)0)); 35341281cf3SAxel Dörfler parent->AddItem(windowItem, myindex + childIndex); 3545e625eadSJohn Scipione windowItem->SetExpanded(true); 35541281cf3SAxel Dörfler } 35641281cf3SAxel Dörfler sub->SetExpanded(true, myindex + childIndex); 35741281cf3SAxel Dörfler 35841281cf3SAxel Dörfler if (resizeWindow) 359afa1c291SJohn Scipione parent->SizeWindow(-1); 360c0107fb2SJonas Sundström } 36141281cf3SAxel Dörfler } 36241281cf3SAxel Dörfler } else { 36341281cf3SAxel Dörfler // Remove the goodies from the Menu() that should be in the SubMenu(); 36441281cf3SAxel Dörfler TWindowMenu* sub = static_cast<TWindowMenu*>(Submenu()); 3655b0fd10dSJohn Scipione if (sub != NULL) { 36641281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 36741281cf3SAxel Dörfler 36841281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 369deaae5fcSJohn Scipione int32 childIndex = parent->IndexOf(this) + 1; 370deaae5fcSJohn Scipione while (parent->SubmenuAt(childIndex) == NULL 371deaae5fcSJohn Scipione && childIndex < parent->CountItems()) { 37215eb397eSJohn Scipione windowItem = static_cast<TWindowMenuItem*>( 37315eb397eSJohn Scipione parent->RemoveItem(childIndex)); 37441281cf3SAxel Dörfler sub->AddItem(windowItem, 0); 3755e625eadSJohn Scipione windowItem->SetExpanded(false); 37641281cf3SAxel Dörfler } 37741281cf3SAxel Dörfler sub->SetExpanded(false, 0); 37841281cf3SAxel Dörfler 37941281cf3SAxel Dörfler if (resizeWindow) 38049ff476dSJohn Scipione parent->SizeWindow(1); 381c0107fb2SJonas Sundström } 38241281cf3SAxel Dörfler } 38341281cf3SAxel Dörfler } 38441281cf3SAxel Dörfler 38541281cf3SAxel Dörfler 38641281cf3SAxel Dörfler TWindowMenuItem* 38741281cf3SAxel Dörfler TTeamMenuItem::ExpandedWindowItem(int32 id) 38841281cf3SAxel Dörfler { 3891687edd0SFredrik Holmqvist if (!fExpanded) { 3901687edd0SFredrik Holmqvist // Paranoia 39141281cf3SAxel Dörfler return NULL; 3921687edd0SFredrik Holmqvist } 39341281cf3SAxel Dörfler 39441281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 39541281cf3SAxel Dörfler int childIndex = parent->IndexOf(this) + 1; 39641281cf3SAxel Dörfler 39771bd3ba5SJonas Sundström while (!parent->SubmenuAt(childIndex) 39871bd3ba5SJonas Sundström && childIndex < parent->CountItems()) { 39971bd3ba5SJonas Sundström TWindowMenuItem* item 40071bd3ba5SJonas Sundström = static_cast<TWindowMenuItem*>(parent->ItemAt(childIndex)); 40141281cf3SAxel Dörfler if (item->ID() == id) 40241281cf3SAxel Dörfler return item; 40341281cf3SAxel Dörfler 40441281cf3SAxel Dörfler childIndex++; 40541281cf3SAxel Dörfler } 40641281cf3SAxel Dörfler return NULL; 40741281cf3SAxel Dörfler } 40841281cf3SAxel Dörfler 40941281cf3SAxel Dörfler 41041281cf3SAxel Dörfler BRect 41141281cf3SAxel Dörfler TTeamMenuItem::ExpanderBounds() const 41241281cf3SAxel Dörfler { 41341281cf3SAxel Dörfler BRect bounds(Frame()); 41441281cf3SAxel Dörfler bounds.left = bounds.right - kSwitchWidth; 41541281cf3SAxel Dörfler return bounds; 41641281cf3SAxel Dörfler } 41741281cf3SAxel Dörfler 418249a4a18SStephan Aßmus 4195b0fd10dSJohn Scipione // #pragma mark - Private methods 4205b0fd10dSJohn Scipione 4215b0fd10dSJohn Scipione 4225b0fd10dSJohn Scipione void 423e9982f68SJohn Scipione TTeamMenuItem::_Init(BList* team, BBitmap* icon, char* name, char* signature, 42418bcf77aSJohn Scipione float width, float height) 4255b0fd10dSJohn Scipione { 4261e0308a8SAugustin Cavalier if (sHPad == 0.0f) { 4271e0308a8SAugustin Cavalier // Initialize the padding values. 4281e0308a8SAugustin Cavalier sHPad = be_control_look->ComposeSpacing(B_USE_SMALL_SPACING); 4291e0308a8SAugustin Cavalier sVPad = ceilf(be_control_look->ComposeSpacing(B_USE_SMALL_SPACING) / 4.0f); 4301e0308a8SAugustin Cavalier sLabelOffset = ceilf((be_control_look->DefaultLabelSpacing() / 3.0f) * 4.0f); 4311e0308a8SAugustin Cavalier } 4321e0308a8SAugustin Cavalier 4335b0fd10dSJohn Scipione fTeam = team; 4345b0fd10dSJohn Scipione fIcon = icon; 435c9363f78SJohn Scipione fSignature = signature; 436c38afcd6SJohn Scipione 437c38afcd6SJohn Scipione if (name == NULL) { 4385b0fd10dSJohn Scipione char temp[32]; 4395b0fd10dSJohn Scipione snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0)); 440c38afcd6SJohn Scipione name = strdup(temp); 4415b0fd10dSJohn Scipione } 442c9363f78SJohn Scipione 443c38afcd6SJohn Scipione SetLabel(name); 444c9363f78SJohn Scipione 4451dccb7aaSJohn Scipione fOverrideWidth = width; 4461dccb7aaSJohn Scipione fOverrideHeight = height; 4475b0fd10dSJohn Scipione 4481dccb7aaSJohn Scipione fBarView = static_cast<TBarApp*>(be_app)->BarView(); 4495b0fd10dSJohn Scipione 450c38afcd6SJohn Scipione BFont font(be_plain_font); 451c38afcd6SJohn Scipione fLabelWidth = ceilf(font.StringWidth(name)); 452c38afcd6SJohn Scipione font_height fontHeight; 453c38afcd6SJohn Scipione font.GetHeight(&fontHeight); 454c38afcd6SJohn Scipione fLabelAscent = ceilf(fontHeight.ascent); 455c38afcd6SJohn Scipione fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading); 45615eb397eSJohn Scipione fLabelHeight = fLabelAscent + fLabelDescent; 457c38afcd6SJohn Scipione 4585b0fd10dSJohn Scipione fOverriddenSelected = false; 4595b0fd10dSJohn Scipione 4605b0fd10dSJohn Scipione fExpanded = false; 4611dccb7aaSJohn Scipione fArrowDirection = BControlLook::B_RIGHT_ARROW; 4625b0fd10dSJohn Scipione } 4635b0fd10dSJohn Scipione 4645b0fd10dSJohn Scipione 465249a4a18SStephan Aßmus bool 466249a4a18SStephan Aßmus TTeamMenuItem::_IsSelected() const 467249a4a18SStephan Aßmus { 468249a4a18SStephan Aßmus return IsSelected() || fOverriddenSelected; 469249a4a18SStephan Aßmus } 470