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 4341281cf3SAxel Dörfler #include <Bitmap.h> 44cb6afcb1SStephan Aßmus #include <ControlLook.h> 451cd61330SJohn Scipione #include <Debug.h> 4641281cf3SAxel Dörfler #include <Font.h> 4741281cf3SAxel Dörfler #include <Region.h> 4841281cf3SAxel Dörfler #include <Roster.h> 4941281cf3SAxel Dörfler #include <Resources.h> 5041281cf3SAxel Dörfler 5141281cf3SAxel Dörfler #include "BarApp.h" 5241281cf3SAxel Dörfler #include "BarMenuBar.h" 534ae3e542SJohn Scipione #include "BarView.h" 5441281cf3SAxel Dörfler #include "ExpandoMenuBar.h" 5541281cf3SAxel Dörfler #include "ResourceSet.h" 5641281cf3SAxel Dörfler #include "ShowHideMenuItem.h" 5741281cf3SAxel Dörfler #include "TeamMenu.h" 5841281cf3SAxel Dörfler #include "WindowMenu.h" 5941281cf3SAxel Dörfler #include "WindowMenuItem.h" 6041281cf3SAxel Dörfler 6141281cf3SAxel Dörfler 6241281cf3SAxel Dörfler const float kHPad = 8.0f; 635e625eadSJohn Scipione const float kVPad = 2.0f; 6441281cf3SAxel Dörfler const float kLabelOffset = 8.0f; 65a7c02e02SJohn Scipione const float kSwitchWidth = 12.0f; 6641281cf3SAxel Dörfler 6741281cf3SAxel Dörfler 68072c2dcdSJohn Scipione // #pragma mark - TTeamMenuItem 69072c2dcdSJohn Scipione 70072c2dcdSJohn Scipione 71c9363f78SJohn Scipione TTeamMenuItem::TTeamMenuItem(BList* team, BBitmap* icon, char* name, 72c9363f78SJohn Scipione char* signature, float width, float height) 7301f35d10SJohn Scipione : 74c9363f78SJohn Scipione TTruncatableMenuItem(new TWindowMenu(team, signature)) 7541281cf3SAxel Dörfler { 76c9363f78SJohn Scipione _InitData(team, icon, name, signature, width, height); 7741281cf3SAxel Dörfler } 7841281cf3SAxel Dörfler 7941281cf3SAxel Dörfler 8018bcf77aSJohn Scipione TTeamMenuItem::TTeamMenuItem(float width, float height) 8101f35d10SJohn Scipione : 82c9363f78SJohn Scipione TTruncatableMenuItem("", NULL) 8341281cf3SAxel Dörfler { 8418bcf77aSJohn Scipione _InitData(NULL, NULL, strdup(""), strdup(""), width, height); 8541281cf3SAxel Dörfler } 8641281cf3SAxel Dörfler 8741281cf3SAxel Dörfler 8841281cf3SAxel Dörfler TTeamMenuItem::~TTeamMenuItem() 8941281cf3SAxel Dörfler { 9041281cf3SAxel Dörfler delete fTeam; 9141281cf3SAxel Dörfler delete fIcon; 9241281cf3SAxel Dörfler free(fName); 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 { 1001dccb7aaSJohn Scipione if (fBarView->InvokeItem(Signature())) { 10141281cf3SAxel Dörfler // handles drop on application 10241281cf3SAxel Dörfler return B_OK; 1031dccb7aaSJohn Scipione } 10441281cf3SAxel Dörfler 10541281cf3SAxel Dörfler // if the app could not handle the drag message 10641281cf3SAxel Dörfler // and we were dragging, then kill the drag 10741281cf3SAxel Dörfler // should never get here, disabled item will not invoke 1081dccb7aaSJohn Scipione if (fBarView != NULL && fBarView->Dragging()) 1091dccb7aaSJohn Scipione fBarView->DragStop(); 11041281cf3SAxel Dörfler 11141281cf3SAxel Dörfler // bring to front or minimize shortcuts 11241281cf3SAxel Dörfler uint32 mods = modifiers(); 1131687edd0SFredrik Holmqvist if (mods & B_CONTROL_KEY) { 11441281cf3SAxel Dörfler TShowHideMenuItem::TeamShowHideCommon((mods & B_SHIFT_KEY) 11541281cf3SAxel Dörfler ? B_MINIMIZE_WINDOW : B_BRING_TO_FRONT, Teams()); 1161687edd0SFredrik Holmqvist } 11741281cf3SAxel Dörfler 11841281cf3SAxel Dörfler return BMenuItem::Invoke(message); 11941281cf3SAxel Dörfler } 12041281cf3SAxel Dörfler 12141281cf3SAxel Dörfler 12241281cf3SAxel Dörfler void 123249a4a18SStephan Aßmus TTeamMenuItem::SetOverrideSelected(bool selected) 124249a4a18SStephan Aßmus { 125249a4a18SStephan Aßmus fOverriddenSelected = selected; 126249a4a18SStephan Aßmus Highlight(selected); 127249a4a18SStephan Aßmus } 128249a4a18SStephan Aßmus 129249a4a18SStephan Aßmus 1301dccb7aaSJohn Scipione void 131c9d2a320SJohn Scipione TTeamMenuItem::SetIcon(BBitmap* icon) { 132c9d2a320SJohn Scipione delete fIcon; 133c9d2a320SJohn Scipione fIcon = icon; 1342ce9bab8SJohn Scipione } 1352ce9bab8SJohn Scipione 1362ce9bab8SJohn Scipione 13741281cf3SAxel Dörfler void 13841281cf3SAxel Dörfler TTeamMenuItem::GetContentSize(float* width, float* height) 13941281cf3SAxel Dörfler { 14041281cf3SAxel Dörfler BRect iconBounds; 14141281cf3SAxel Dörfler 14201f35d10SJohn Scipione if (fIcon != NULL) 14341281cf3SAxel Dörfler iconBounds = fIcon->Bounds(); 14441281cf3SAxel Dörfler else 1452ce9bab8SJohn Scipione iconBounds = BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1); 14641281cf3SAxel Dörfler 14741281cf3SAxel Dörfler BMenuItem::GetContentSize(width, height); 14841281cf3SAxel Dörfler 14941281cf3SAxel Dörfler if (fOverrideWidth != -1.0f) 15041281cf3SAxel Dörfler *width = fOverrideWidth; 1512ce9bab8SJohn Scipione else { 1522ce9bab8SJohn Scipione *width = kHPad + iconBounds.Width() + kHPad; 15318bcf77aSJohn Scipione if (iconBounds.Width() <= 32 15418bcf77aSJohn Scipione && !static_cast<TBarApp*>(be_app)->Settings()->hideLabels) { 1552ce9bab8SJohn Scipione *width += LabelWidth() + kHPad; 1562ce9bab8SJohn Scipione } 15718bcf77aSJohn Scipione } 15841281cf3SAxel Dörfler 15941281cf3SAxel Dörfler if (fOverrideHeight != -1.0f) 16041281cf3SAxel Dörfler *height = fOverrideHeight; 16141281cf3SAxel Dörfler else { 16218bcf77aSJohn Scipione if (fBarView->Vertical()) { 1635e625eadSJohn Scipione *height = iconBounds.Height() + kVPad * 2; 16418bcf77aSJohn Scipione if (!static_cast<TBarApp*>(be_app)->Settings()->hideLabels 16518bcf77aSJohn Scipione && iconBounds.Width() > 32) { 1662ce9bab8SJohn Scipione *height += fLabelAscent + fLabelDescent; 16718bcf77aSJohn Scipione } 1682ce9bab8SJohn Scipione } else { 1695e625eadSJohn Scipione *height = iconBounds.Height() + kVPad * 2; 1702ce9bab8SJohn Scipione } 17141281cf3SAxel Dörfler } 17241281cf3SAxel Dörfler *height += 2; 17341281cf3SAxel Dörfler } 17441281cf3SAxel Dörfler 17541281cf3SAxel Dörfler 17641281cf3SAxel Dörfler void 17741281cf3SAxel Dörfler TTeamMenuItem::Draw() 17841281cf3SAxel Dörfler { 179*6b65d934SJohn Scipione BRect frame = Frame(); 18041281cf3SAxel Dörfler BMenu* menu = Menu(); 181fe624b39SJohn Scipione 18241281cf3SAxel Dörfler menu->PushState(); 1835b0fd10dSJohn Scipione 184cb6afcb1SStephan Aßmus rgb_color menuColor = menu->LowColor(); 1851dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 1861dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 187cb6afcb1SStephan Aßmus uint32 flags = 0; 188cb6afcb1SStephan Aßmus if (_IsSelected() && canHandle) 189cb6afcb1SStephan Aßmus flags |= BControlLook::B_ACTIVATED; 190cb6afcb1SStephan Aßmus 191cb6afcb1SStephan Aßmus uint32 borders = BControlLook::B_TOP_BORDER; 19218bcf77aSJohn Scipione if (fBarView->Vertical()) { 193cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_1_TINT)); 194cb6afcb1SStephan Aßmus borders |= BControlLook::B_LEFT_BORDER 195cb6afcb1SStephan Aßmus | BControlLook::B_RIGHT_BORDER; 196cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftBottom(), frame.RightBottom()); 197cb6afcb1SStephan Aßmus frame.bottom--; 198cb6afcb1SStephan Aßmus 199cb6afcb1SStephan Aßmus be_control_look->DrawMenuBarBackground(menu, frame, frame, 200cb6afcb1SStephan Aßmus menuColor, flags, borders); 201cb6afcb1SStephan Aßmus } else { 202cb6afcb1SStephan Aßmus if (flags & BControlLook::B_ACTIVATED) 203cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_3_TINT)); 204cb6afcb1SStephan Aßmus else 205cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, 1.22)); 206cb6afcb1SStephan Aßmus borders |= BControlLook::B_BOTTOM_BORDER; 207cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); 208cb6afcb1SStephan Aßmus frame.left++; 209cb6afcb1SStephan Aßmus 210cb6afcb1SStephan Aßmus be_control_look->DrawButtonBackground(menu, frame, frame, 211cb6afcb1SStephan Aßmus menuColor, flags, borders); 212cb6afcb1SStephan Aßmus } 213cb6afcb1SStephan Aßmus 214cb6afcb1SStephan Aßmus menu->MovePenTo(ContentLocation()); 215cb6afcb1SStephan Aßmus DrawContent(); 216fe624b39SJohn Scipione 217cb6afcb1SStephan Aßmus menu->PopState(); 21841281cf3SAxel Dörfler } 21941281cf3SAxel Dörfler 22041281cf3SAxel Dörfler 22141281cf3SAxel Dörfler void 22241281cf3SAxel Dörfler TTeamMenuItem::DrawContent() 22341281cf3SAxel Dörfler { 22441281cf3SAxel Dörfler BMenu* menu = Menu(); 2252ce9bab8SJohn Scipione if (fIcon != NULL) { 22659deaf10SStephan Aßmus if (fIcon->ColorSpace() == B_RGBA32) { 22759deaf10SStephan Aßmus menu->SetDrawingMode(B_OP_ALPHA); 22859deaf10SStephan Aßmus menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); 2291687edd0SFredrik Holmqvist } else 23041281cf3SAxel Dörfler menu->SetDrawingMode(B_OP_OVER); 23141281cf3SAxel Dörfler 232*6b65d934SJohn Scipione BRect frame = Frame(); 233*6b65d934SJohn Scipione BRect iconBounds = fIcon->Bounds(); 234*6b65d934SJohn Scipione BRect updateRect = iconBounds; 23518bcf77aSJohn Scipione float extra = fBarView->Vertical() ? 0.0f : -1.0f; 236c9363f78SJohn Scipione BPoint contentLocation = ContentLocation(); 237c9363f78SJohn Scipione BPoint drawLocation = contentLocation + BPoint(kHPad, kVPad); 2381687edd0SFredrik Holmqvist 23918bcf77aSJohn Scipione if (static_cast<TBarApp*>(be_app)->Settings()->hideLabels 24018bcf77aSJohn Scipione || (fBarView->Vertical() && iconBounds.Width() > 32)) { 241c9363f78SJohn Scipione float offsetx = contentLocation.x 2422ce9bab8SJohn Scipione + ((frame.Width() - iconBounds.Width()) / 2) + extra; 243c9363f78SJohn Scipione float offsety = contentLocation.y + 3.0f + extra; 2442ce9bab8SJohn Scipione 245*6b65d934SJohn Scipione updateRect.OffsetTo(BPoint(offsetx, offsety)); 246*6b65d934SJohn Scipione menu->DrawBitmapAsync(fIcon, updateRect); 2472ce9bab8SJohn Scipione 248c9363f78SJohn Scipione drawLocation.x = ((frame.Width() - LabelWidth()) / 2); 249c9363f78SJohn Scipione drawLocation.y = frame.top + iconBounds.Height() + kVPad * 2; 2502ce9bab8SJohn Scipione } else { 251c9363f78SJohn Scipione float offsetx = contentLocation.x + kHPad; 252c9363f78SJohn Scipione float offsety = contentLocation.y + 2532ce9bab8SJohn Scipione ((frame.Height() - iconBounds.Height()) / 2) + extra; 2542ce9bab8SJohn Scipione 255*6b65d934SJohn Scipione updateRect.OffsetTo(BPoint(offsetx, offsety)); 256*6b65d934SJohn Scipione menu->DrawBitmapAsync(fIcon, updateRect); 25741281cf3SAxel Dörfler 25841281cf3SAxel Dörfler float labelHeight = fLabelAscent + fLabelDescent; 259c9363f78SJohn Scipione drawLocation.x += iconBounds.Width() + kLabelOffset; 260c9363f78SJohn Scipione drawLocation.y = frame.top + ((frame.Height() - labelHeight) / 2) 26118bcf77aSJohn Scipione + extra; 2622ce9bab8SJohn Scipione } 2632ce9bab8SJohn Scipione 264c9363f78SJohn Scipione menu->MovePenTo(drawLocation); 26541281cf3SAxel Dörfler } 26641281cf3SAxel Dörfler 267cb6afcb1SStephan Aßmus menu->SetDrawingMode(B_OP_OVER); 268e19488b2SRyan Leavengood menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 26941281cf3SAxel Dörfler 27041281cf3SAxel Dörfler // override the drawing of the content when the item is disabled 27141281cf3SAxel Dörfler // the wrong lowcolor is used when the item is disabled since the 27241281cf3SAxel Dörfler // text color does not change 27341281cf3SAxel Dörfler menu->MovePenBy(0, fLabelAscent); 27441281cf3SAxel Dörfler 2751dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 2761dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 277249a4a18SStephan Aßmus if (_IsSelected() && IsEnabled() && canHandle) 278ab4e79c3SRyan Leavengood menu->SetLowColor(tint_color(menu->LowColor(), 27941281cf3SAxel Dörfler B_HIGHLIGHT_BACKGROUND_TINT)); 28041281cf3SAxel Dörfler else 281ab4e79c3SRyan Leavengood menu->SetLowColor(menu->LowColor()); 28241281cf3SAxel Dörfler 283859c3781SJohn Scipione if (IsSelected()) 284859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR)); 285859c3781SJohn Scipione else 286859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 287859c3781SJohn Scipione 288c9363f78SJohn Scipione if (!static_cast<TBarApp*>(be_app)->Settings()->hideLabels) { 289c9363f78SJohn Scipione float labelWidth = menu->StringWidth(Label()); 290c9363f78SJohn Scipione BPoint penLocation = menu->PenLocation(); 291c9363f78SJohn Scipione float offset = penLocation.x - Frame().left; 292c9363f78SJohn Scipione menu->DrawString(Label(labelWidth + offset)); 293c9363f78SJohn Scipione } 29441281cf3SAxel Dörfler 2955e625eadSJohn Scipione if (fBarView->Vertical() 2965e625eadSJohn Scipione && static_cast<TBarApp*>(be_app)->Settings()->superExpando 2975e625eadSJohn Scipione && fBarView->ExpandoState()) { 2985e625eadSJohn Scipione DrawExpanderArrow(); 2995e625eadSJohn Scipione } 3005e625eadSJohn Scipione } 3015e625eadSJohn Scipione 30241281cf3SAxel Dörfler 3035b0fd10dSJohn Scipione void 3041dccb7aaSJohn Scipione TTeamMenuItem::DrawExpanderArrow() 3055b0fd10dSJohn Scipione { 3065b0fd10dSJohn Scipione BMenu* menu = Menu(); 307*6b65d934SJohn Scipione BRect frame = Frame(); 308c9363f78SJohn Scipione BRect rect(0.0f, 0.0f, kSwitchWidth, kHPad + 2.0f); 3092b8d4131SJohn Scipione 3105b0fd10dSJohn Scipione rect.OffsetTo(BPoint(frame.right - rect.Width(), 3115b0fd10dSJohn Scipione ContentLocation().y + ((frame.Height() - rect.Height()) / 2))); 3125b0fd10dSJohn Scipione be_control_look->DrawArrowShape(menu, rect, rect, menu->LowColor(), 3131dccb7aaSJohn Scipione fArrowDirection, 0, B_DARKEN_3_TINT); 31441281cf3SAxel Dörfler } 31541281cf3SAxel Dörfler 31641281cf3SAxel Dörfler 31741281cf3SAxel Dörfler void 31841281cf3SAxel Dörfler TTeamMenuItem::ToggleExpandState(bool resizeWindow) 31941281cf3SAxel Dörfler { 32041281cf3SAxel Dörfler fExpanded = !fExpanded; 3211dccb7aaSJohn Scipione fArrowDirection = fExpanded ? BControlLook::B_DOWN_ARROW 3221dccb7aaSJohn Scipione : BControlLook::B_RIGHT_ARROW; 32341281cf3SAxel Dörfler 32441281cf3SAxel Dörfler if (fExpanded) { 32541281cf3SAxel Dörfler // Populate Menu() with the stuff from SubMenu(). 32641281cf3SAxel Dörfler TWindowMenu* sub = (static_cast<TWindowMenu*>(Submenu())); 3275b0fd10dSJohn Scipione if (sub != NULL) { 32841281cf3SAxel Dörfler // force the menu to update it's contents. 329bdfed6c0SAxel Dörfler bool locked = sub->LockLooper(); 330bdfed6c0SAxel Dörfler // if locking the looper failed, the menu is just not visible 331bdfed6c0SAxel Dörfler sub->AttachedToWindow(); 332bdfed6c0SAxel Dörfler if (locked) 333bdfed6c0SAxel Dörfler sub->UnlockLooper(); 334bdfed6c0SAxel Dörfler 33541281cf3SAxel Dörfler if (sub->CountItems() > 1) { 33641281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 33741281cf3SAxel Dörfler int myindex = parent->IndexOf(this) + 1; 33841281cf3SAxel Dörfler 33941281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 340deaae5fcSJohn Scipione int32 childIndex = 0; 341deaae5fcSJohn Scipione int32 totalChildren = sub->CountItems() - 4; 34271bd3ba5SJonas Sundström // hide, show, close, separator. 34341281cf3SAxel Dörfler for (; childIndex < totalChildren; childIndex++) { 34471bd3ba5SJonas Sundström windowItem = static_cast<TWindowMenuItem*> 34571bd3ba5SJonas Sundström (sub->RemoveItem((int32)0)); 34641281cf3SAxel Dörfler parent->AddItem(windowItem, myindex + childIndex); 3475e625eadSJohn Scipione windowItem->SetExpanded(true); 34841281cf3SAxel Dörfler } 34941281cf3SAxel Dörfler sub->SetExpanded(true, myindex + childIndex); 35041281cf3SAxel Dörfler 35141281cf3SAxel Dörfler if (resizeWindow) 352afa1c291SJohn Scipione parent->SizeWindow(-1); 353c0107fb2SJonas Sundström } 35441281cf3SAxel Dörfler } 35541281cf3SAxel Dörfler } else { 35641281cf3SAxel Dörfler // Remove the goodies from the Menu() that should be in the SubMenu(); 35741281cf3SAxel Dörfler TWindowMenu* sub = static_cast<TWindowMenu*>(Submenu()); 3585b0fd10dSJohn Scipione if (sub != NULL) { 35941281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 36041281cf3SAxel Dörfler 36141281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 362deaae5fcSJohn Scipione int32 childIndex = parent->IndexOf(this) + 1; 363deaae5fcSJohn Scipione while (parent->SubmenuAt(childIndex) == NULL 364deaae5fcSJohn Scipione && childIndex < parent->CountItems()) { 365deaae5fcSJohn Scipione windowItem 366deaae5fcSJohn Scipione = static_cast<TWindowMenuItem*>(parent->RemoveItem(childIndex)); 36741281cf3SAxel Dörfler sub->AddItem(windowItem, 0); 3685e625eadSJohn Scipione windowItem->SetExpanded(false); 36941281cf3SAxel Dörfler } 37041281cf3SAxel Dörfler sub->SetExpanded(false, 0); 37141281cf3SAxel Dörfler 37241281cf3SAxel Dörfler if (resizeWindow) 37349ff476dSJohn Scipione parent->SizeWindow(1); 374c0107fb2SJonas Sundström } 37541281cf3SAxel Dörfler } 37641281cf3SAxel Dörfler } 37741281cf3SAxel Dörfler 37841281cf3SAxel Dörfler 37941281cf3SAxel Dörfler TWindowMenuItem* 38041281cf3SAxel Dörfler TTeamMenuItem::ExpandedWindowItem(int32 id) 38141281cf3SAxel Dörfler { 3821687edd0SFredrik Holmqvist if (!fExpanded) { 3831687edd0SFredrik Holmqvist // Paranoia 38441281cf3SAxel Dörfler return NULL; 3851687edd0SFredrik Holmqvist } 38641281cf3SAxel Dörfler 38741281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 38841281cf3SAxel Dörfler int childIndex = parent->IndexOf(this) + 1; 38941281cf3SAxel Dörfler 39071bd3ba5SJonas Sundström while (!parent->SubmenuAt(childIndex) 39171bd3ba5SJonas Sundström && childIndex < parent->CountItems()) { 39271bd3ba5SJonas Sundström TWindowMenuItem* item 39371bd3ba5SJonas Sundström = static_cast<TWindowMenuItem*>(parent->ItemAt(childIndex)); 39441281cf3SAxel Dörfler if (item->ID() == id) 39541281cf3SAxel Dörfler return item; 39641281cf3SAxel Dörfler 39741281cf3SAxel Dörfler childIndex++; 39841281cf3SAxel Dörfler } 39941281cf3SAxel Dörfler return NULL; 40041281cf3SAxel Dörfler } 40141281cf3SAxel Dörfler 40241281cf3SAxel Dörfler 40341281cf3SAxel Dörfler BRect 40441281cf3SAxel Dörfler TTeamMenuItem::ExpanderBounds() const 40541281cf3SAxel Dörfler { 40641281cf3SAxel Dörfler BRect bounds(Frame()); 40741281cf3SAxel Dörfler bounds.left = bounds.right - kSwitchWidth; 40841281cf3SAxel Dörfler return bounds; 40941281cf3SAxel Dörfler } 41041281cf3SAxel Dörfler 411249a4a18SStephan Aßmus 4125b0fd10dSJohn Scipione // #pragma mark - Private methods 4135b0fd10dSJohn Scipione 4145b0fd10dSJohn Scipione 4155b0fd10dSJohn Scipione void 416c9363f78SJohn Scipione TTeamMenuItem::_InitData(BList* team, BBitmap* icon, char* name, char* signature, 41718bcf77aSJohn Scipione float width, float height) 4185b0fd10dSJohn Scipione { 4195b0fd10dSJohn Scipione fTeam = team; 4205b0fd10dSJohn Scipione fIcon = icon; 4215b0fd10dSJohn Scipione fName = name; 422c9363f78SJohn Scipione fSignature = signature; 4235b0fd10dSJohn Scipione if (fName == NULL) { 4245b0fd10dSJohn Scipione char temp[32]; 4255b0fd10dSJohn Scipione snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0)); 4265b0fd10dSJohn Scipione fName = strdup(temp); 4275b0fd10dSJohn Scipione } 428c9363f78SJohn Scipione BFont font(be_plain_font); 429c9363f78SJohn Scipione fLabelWidth = ceilf(font.StringWidth(fName)); 430c9363f78SJohn Scipione font_height fontHeight; 431c9363f78SJohn Scipione font.GetHeight(&fontHeight); 432c9363f78SJohn Scipione fLabelAscent = ceilf(fontHeight.ascent); 433c9363f78SJohn Scipione fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading); 434c9363f78SJohn Scipione 4355b0fd10dSJohn Scipione SetLabel(fName); 436c9363f78SJohn Scipione 4371dccb7aaSJohn Scipione fOverrideWidth = width; 4381dccb7aaSJohn Scipione fOverrideHeight = height; 4395b0fd10dSJohn Scipione 4401dccb7aaSJohn Scipione fBarView = static_cast<TBarApp*>(be_app)->BarView(); 4415b0fd10dSJohn Scipione 4425b0fd10dSJohn Scipione fOverriddenSelected = false; 4435b0fd10dSJohn Scipione 4445b0fd10dSJohn Scipione fExpanded = false; 4451dccb7aaSJohn Scipione fArrowDirection = BControlLook::B_RIGHT_ARROW; 4465b0fd10dSJohn Scipione } 4475b0fd10dSJohn Scipione 4485b0fd10dSJohn Scipione 449249a4a18SStephan Aßmus bool 450249a4a18SStephan Aßmus TTeamMenuItem::_IsSelected() const 451249a4a18SStephan Aßmus { 452249a4a18SStephan Aßmus return IsSelected() || fOverriddenSelected; 453249a4a18SStephan Aßmus } 454