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 6641281cf3SAxel Dörfler const float kHPad = 8.0f; 675e625eadSJohn Scipione const float kVPad = 2.0f; 6841281cf3SAxel Dörfler const float kLabelOffset = 8.0f; 6915eb397eSJohn Scipione const float kIconPadding = 8.0f; 7041281cf3SAxel Dörfler 7141281cf3SAxel Dörfler 72072c2dcdSJohn Scipione // #pragma mark - TTeamMenuItem 73072c2dcdSJohn Scipione 74072c2dcdSJohn Scipione 75c9363f78SJohn Scipione TTeamMenuItem::TTeamMenuItem(BList* team, BBitmap* icon, char* name, 76c9363f78SJohn Scipione char* signature, float width, float height) 7701f35d10SJohn Scipione : 78c9363f78SJohn Scipione TTruncatableMenuItem(new TWindowMenu(team, signature)) 7941281cf3SAxel Dörfler { 80e9982f68SJohn Scipione _Init(team, icon, name, signature, width, height); 8141281cf3SAxel Dörfler } 8241281cf3SAxel Dörfler 8341281cf3SAxel Dörfler 8418bcf77aSJohn Scipione TTeamMenuItem::TTeamMenuItem(float width, float height) 8501f35d10SJohn Scipione : 86c9363f78SJohn Scipione TTruncatableMenuItem("", NULL) 8741281cf3SAxel Dörfler { 88e9982f68SJohn Scipione _Init(NULL, NULL, strdup(""), strdup(""), width, height); 8941281cf3SAxel Dörfler } 9041281cf3SAxel Dörfler 9141281cf3SAxel Dörfler 9241281cf3SAxel Dörfler TTeamMenuItem::~TTeamMenuItem() 9341281cf3SAxel Dörfler { 9441281cf3SAxel Dörfler delete fTeam; 9541281cf3SAxel Dörfler delete fIcon; 96c9363f78SJohn Scipione free(fSignature); 975e625eadSJohn Scipione } 985e625eadSJohn Scipione 995e625eadSJohn Scipione 10041281cf3SAxel Dörfler status_t 10141281cf3SAxel Dörfler TTeamMenuItem::Invoke(BMessage* message) 10241281cf3SAxel Dörfler { 1036a27de89SMurai Takashi if (fBarView != NULL) { 1041dccb7aaSJohn Scipione if (fBarView->InvokeItem(Signature())) { 10541281cf3SAxel Dörfler // handles drop on application 10641281cf3SAxel Dörfler return B_OK; 1071dccb7aaSJohn Scipione } 10841281cf3SAxel Dörfler 10941281cf3SAxel Dörfler // if the app could not handle the drag message 11041281cf3SAxel Dörfler // and we were dragging, then kill the drag 11141281cf3SAxel Dörfler // should never get here, disabled item will not invoke 1126a27de89SMurai Takashi if (fBarView->Dragging()) 1131dccb7aaSJohn Scipione fBarView->DragStop(); 1146a27de89SMurai Takashi } 11541281cf3SAxel Dörfler 11641281cf3SAxel Dörfler // bring to front or minimize shortcuts 11741281cf3SAxel Dörfler uint32 mods = modifiers(); 1181687edd0SFredrik Holmqvist if (mods & B_CONTROL_KEY) { 11941281cf3SAxel Dörfler TShowHideMenuItem::TeamShowHideCommon((mods & B_SHIFT_KEY) 12041281cf3SAxel Dörfler ? B_MINIMIZE_WINDOW : B_BRING_TO_FRONT, Teams()); 1211687edd0SFredrik Holmqvist } 12241281cf3SAxel Dörfler 12341281cf3SAxel Dörfler return BMenuItem::Invoke(message); 12441281cf3SAxel Dörfler } 12541281cf3SAxel Dörfler 12641281cf3SAxel Dörfler 12741281cf3SAxel Dörfler void 128249a4a18SStephan Aßmus TTeamMenuItem::SetOverrideSelected(bool selected) 129249a4a18SStephan Aßmus { 130249a4a18SStephan Aßmus fOverriddenSelected = selected; 131249a4a18SStephan Aßmus Highlight(selected); 132249a4a18SStephan Aßmus } 133249a4a18SStephan Aßmus 134249a4a18SStephan Aßmus 1351dccb7aaSJohn Scipione void 136c9d2a320SJohn Scipione TTeamMenuItem::SetIcon(BBitmap* icon) { 137c9d2a320SJohn Scipione delete fIcon; 138c9d2a320SJohn Scipione fIcon = icon; 1392ce9bab8SJohn Scipione } 1402ce9bab8SJohn Scipione 1412ce9bab8SJohn Scipione 14241281cf3SAxel Dörfler void 14341281cf3SAxel Dörfler TTeamMenuItem::GetContentSize(float* width, float* height) 14441281cf3SAxel Dörfler { 14541281cf3SAxel Dörfler BMenuItem::GetContentSize(width, height); 14641281cf3SAxel Dörfler 14741281cf3SAxel Dörfler if (fOverrideWidth != -1.0f) 14841281cf3SAxel Dörfler *width = fOverrideWidth; 1492ce9bab8SJohn Scipione else { 15015eb397eSJohn Scipione bool hideLabels = static_cast<TBarApp*>(be_app)->Settings()->hideLabels; 15115eb397eSJohn Scipione float iconSize = static_cast<TBarApp*>(be_app)->IconSize(); 15215eb397eSJohn Scipione float iconOnlyWidth = kIconPadding + iconSize + kIconPadding; 15315eb397eSJohn Scipione 15415eb397eSJohn Scipione if (fBarView->MiniState()) { 15515eb397eSJohn Scipione if (hideLabels) 15615eb397eSJohn Scipione *width = iconOnlyWidth; 15715eb397eSJohn Scipione else 15815eb397eSJohn Scipione *width = gMinimumWindowWidth - (kDragRegionWidth + kGutter) * 2; 15915eb397eSJohn Scipione } else if (!fBarView->Vertical()) { 160*0d2645e4SJohn Scipione TExpandoMenuBar* menu = static_cast<TExpandoMenuBar*>(Menu()); 161*0d2645e4SJohn Scipione *width = menu->MaxHorizontalItemWidth(); 16215eb397eSJohn Scipione } else 16315eb397eSJohn Scipione *width = static_cast<TBarApp*>(be_app)->Settings()->width; 16418bcf77aSJohn Scipione } 16541281cf3SAxel Dörfler 16641281cf3SAxel Dörfler if (fOverrideHeight != -1.0f) 16741281cf3SAxel Dörfler *height = fOverrideHeight; 16815eb397eSJohn Scipione else 16915eb397eSJohn Scipione *height = fBarView->TeamMenuItemHeight(); 17041281cf3SAxel Dörfler } 17141281cf3SAxel Dörfler 17241281cf3SAxel Dörfler 17341281cf3SAxel Dörfler void 17441281cf3SAxel Dörfler TTeamMenuItem::Draw() 17541281cf3SAxel Dörfler { 1766b65d934SJohn Scipione BRect frame = Frame(); 17741281cf3SAxel Dörfler BMenu* menu = Menu(); 178fe624b39SJohn Scipione 17941281cf3SAxel Dörfler menu->PushState(); 1805b0fd10dSJohn Scipione 18116c10517Slooncraz rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 1821dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 1831dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 184cb6afcb1SStephan Aßmus uint32 flags = 0; 185cb6afcb1SStephan Aßmus if (_IsSelected() && canHandle) 186cb6afcb1SStephan Aßmus flags |= BControlLook::B_ACTIVATED; 187cb6afcb1SStephan Aßmus 188cb6afcb1SStephan Aßmus uint32 borders = BControlLook::B_TOP_BORDER; 18918bcf77aSJohn Scipione if (fBarView->Vertical()) { 190cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_1_TINT)); 191cb6afcb1SStephan Aßmus borders |= BControlLook::B_LEFT_BORDER 192cb6afcb1SStephan Aßmus | BControlLook::B_RIGHT_BORDER; 193cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftBottom(), frame.RightBottom()); 194cb6afcb1SStephan Aßmus frame.bottom--; 195cb6afcb1SStephan Aßmus 196cb6afcb1SStephan Aßmus be_control_look->DrawMenuBarBackground(menu, frame, frame, 197cb6afcb1SStephan Aßmus menuColor, flags, borders); 198cb6afcb1SStephan Aßmus } else { 199cb6afcb1SStephan Aßmus if (flags & BControlLook::B_ACTIVATED) 200cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_3_TINT)); 201cb6afcb1SStephan Aßmus else 202cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, 1.22)); 203cb6afcb1SStephan Aßmus borders |= BControlLook::B_BOTTOM_BORDER; 204cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); 205cb6afcb1SStephan Aßmus frame.left++; 206cb6afcb1SStephan Aßmus 207cb6afcb1SStephan Aßmus be_control_look->DrawButtonBackground(menu, frame, frame, 208cb6afcb1SStephan Aßmus menuColor, flags, borders); 209cb6afcb1SStephan Aßmus } 210cb6afcb1SStephan Aßmus 211cb6afcb1SStephan Aßmus menu->MovePenTo(ContentLocation()); 212cb6afcb1SStephan Aßmus DrawContent(); 213fe624b39SJohn Scipione 214cb6afcb1SStephan Aßmus menu->PopState(); 21541281cf3SAxel Dörfler } 21641281cf3SAxel Dörfler 21741281cf3SAxel Dörfler 21841281cf3SAxel Dörfler void 21941281cf3SAxel Dörfler TTeamMenuItem::DrawContent() 22041281cf3SAxel Dörfler { 22141281cf3SAxel Dörfler BMenu* menu = Menu(); 22215eb397eSJohn Scipione BRect frame = Frame(); 22315eb397eSJohn Scipione 2242ce9bab8SJohn Scipione if (fIcon != NULL) { 22559deaf10SStephan Aßmus if (fIcon->ColorSpace() == B_RGBA32) { 22659deaf10SStephan Aßmus menu->SetDrawingMode(B_OP_ALPHA); 22759deaf10SStephan Aßmus menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); 2281687edd0SFredrik Holmqvist } else 22941281cf3SAxel Dörfler menu->SetDrawingMode(B_OP_OVER); 23041281cf3SAxel Dörfler 23115eb397eSJohn Scipione BRect iconBounds = fIcon != NULL ? fIcon->Bounds() 23215eb397eSJohn Scipione : BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1); 2336b65d934SJohn Scipione BRect updateRect = iconBounds; 234c9363f78SJohn Scipione BPoint contentLocation = ContentLocation(); 235c9363f78SJohn Scipione BPoint drawLocation = contentLocation + BPoint(kHPad, kVPad); 2361687edd0SFredrik Holmqvist 23718bcf77aSJohn Scipione if (static_cast<TBarApp*>(be_app)->Settings()->hideLabels 23818bcf77aSJohn Scipione || (fBarView->Vertical() && iconBounds.Width() > 32)) { 23915eb397eSJohn Scipione // determine icon location (centered horizontally) 240c9363f78SJohn Scipione float offsetx = contentLocation.x 24115eb397eSJohn Scipione + floorf((frame.Width() - iconBounds.Width()) / 2); 24215eb397eSJohn Scipione float offsety = contentLocation.y + kVPad + kGutter; 2432ce9bab8SJohn Scipione 24415eb397eSJohn Scipione // draw icon 2456b65d934SJohn Scipione updateRect.OffsetTo(BPoint(offsetx, offsety)); 2466b65d934SJohn Scipione menu->DrawBitmapAsync(fIcon, updateRect); 2472ce9bab8SJohn Scipione 24815eb397eSJohn Scipione // determine label position (below icon) 24915eb397eSJohn Scipione drawLocation.x = floorf((frame.Width() - fLabelWidth) / 2); 25015eb397eSJohn Scipione drawLocation.y = frame.top + kVPad + iconBounds.Height() + kVPad; 2512ce9bab8SJohn Scipione } else { 25215eb397eSJohn Scipione // determine icon location (centered vertically) 253c9363f78SJohn Scipione float offsetx = contentLocation.x + kHPad; 254c9363f78SJohn Scipione float offsety = contentLocation.y + 25515eb397eSJohn Scipione floorf((frame.Height() - iconBounds.Height()) / 2); 2562ce9bab8SJohn Scipione 25715eb397eSJohn Scipione // draw icon 2586b65d934SJohn Scipione updateRect.OffsetTo(BPoint(offsetx, offsety)); 2596b65d934SJohn Scipione menu->DrawBitmapAsync(fIcon, updateRect); 26041281cf3SAxel Dörfler 26115eb397eSJohn Scipione // determine label position (centered vertically) 262c9363f78SJohn Scipione drawLocation.x += iconBounds.Width() + kLabelOffset; 26315eb397eSJohn Scipione drawLocation.y = frame.top 26415eb397eSJohn Scipione + ceilf((frame.Height() - fLabelHeight) / 2); 2652ce9bab8SJohn Scipione } 2662ce9bab8SJohn Scipione 267c9363f78SJohn Scipione menu->MovePenTo(drawLocation); 26841281cf3SAxel Dörfler } 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 27315eb397eSJohn Scipione menu->SetDrawingMode(B_OP_OVER); 27415eb397eSJohn Scipione menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 27541281cf3SAxel Dörfler 2761dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 2771dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 278249a4a18SStephan Aßmus if (_IsSelected() && IsEnabled() && canHandle) 27916c10517Slooncraz menu->SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 28041281cf3SAxel Dörfler B_HIGHLIGHT_BACKGROUND_TINT)); 28141281cf3SAxel Dörfler else 28216c10517Slooncraz menu->SetLowColor(ui_color(B_MENU_BACKGROUND_COLOR)); 28341281cf3SAxel Dörfler 284859c3781SJohn Scipione if (IsSelected()) 285859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR)); 286859c3781SJohn Scipione else 287859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 288859c3781SJohn Scipione 28915eb397eSJohn Scipione menu->MovePenBy(0, fLabelAscent); 29015eb397eSJohn Scipione 29115eb397eSJohn Scipione // draw label 292c9363f78SJohn Scipione if (!static_cast<TBarApp*>(be_app)->Settings()->hideLabels) { 293c9363f78SJohn Scipione float labelWidth = menu->StringWidth(Label()); 294c9363f78SJohn Scipione BPoint penLocation = menu->PenLocation(); 29515eb397eSJohn Scipione // truncate to max width 29615eb397eSJohn Scipione float offset = penLocation.x - frame.left; 297c9363f78SJohn Scipione menu->DrawString(Label(labelWidth + offset)); 298c9363f78SJohn Scipione } 29941281cf3SAxel Dörfler 30015eb397eSJohn Scipione // draw expander arrow 3015e625eadSJohn Scipione if (fBarView->Vertical() 3025e625eadSJohn Scipione && static_cast<TBarApp*>(be_app)->Settings()->superExpando 3035e625eadSJohn Scipione && fBarView->ExpandoState()) { 3045e625eadSJohn Scipione DrawExpanderArrow(); 3055e625eadSJohn Scipione } 3065e625eadSJohn Scipione } 3075e625eadSJohn Scipione 30841281cf3SAxel Dörfler 3095b0fd10dSJohn Scipione void 3101dccb7aaSJohn Scipione TTeamMenuItem::DrawExpanderArrow() 3115b0fd10dSJohn Scipione { 3126b65d934SJohn Scipione BRect frame = Frame(); 313c9363f78SJohn Scipione BRect rect(0.0f, 0.0f, kSwitchWidth, kHPad + 2.0f); 3145b0fd10dSJohn Scipione rect.OffsetTo(BPoint(frame.right - rect.Width(), 3155b0fd10dSJohn Scipione ContentLocation().y + ((frame.Height() - rect.Height()) / 2))); 3169a9f4ef5SMikael Konradsson 3179a9f4ef5SMikael Konradsson float colorTint = B_DARKEN_3_TINT; 3189a9f4ef5SMikael Konradsson rgb_color bgColor = ui_color(B_MENU_BACKGROUND_COLOR); 31915eb397eSJohn Scipione if (bgColor.red + bgColor.green + bgColor.blue <= 128 * 3) 3209a9f4ef5SMikael Konradsson colorTint = B_LIGHTEN_2_TINT; 3219a9f4ef5SMikael Konradsson 32215eb397eSJohn Scipione be_control_look->DrawArrowShape(Menu(), rect, Menu()->Frame(), 32315eb397eSJohn Scipione bgColor, fArrowDirection, 0, colorTint); 32441281cf3SAxel Dörfler } 32541281cf3SAxel Dörfler 32641281cf3SAxel Dörfler 32741281cf3SAxel Dörfler void 32841281cf3SAxel Dörfler TTeamMenuItem::ToggleExpandState(bool resizeWindow) 32941281cf3SAxel Dörfler { 33041281cf3SAxel Dörfler fExpanded = !fExpanded; 3311dccb7aaSJohn Scipione fArrowDirection = fExpanded ? BControlLook::B_DOWN_ARROW 3321dccb7aaSJohn Scipione : BControlLook::B_RIGHT_ARROW; 33341281cf3SAxel Dörfler 33441281cf3SAxel Dörfler if (fExpanded) { 33541281cf3SAxel Dörfler // Populate Menu() with the stuff from SubMenu(). 33641281cf3SAxel Dörfler TWindowMenu* sub = (static_cast<TWindowMenu*>(Submenu())); 3375b0fd10dSJohn Scipione if (sub != NULL) { 33841281cf3SAxel Dörfler // force the menu to update it's contents. 339bdfed6c0SAxel Dörfler bool locked = sub->LockLooper(); 340bdfed6c0SAxel Dörfler // if locking the looper failed, the menu is just not visible 341bdfed6c0SAxel Dörfler sub->AttachedToWindow(); 342bdfed6c0SAxel Dörfler if (locked) 343bdfed6c0SAxel Dörfler sub->UnlockLooper(); 344bdfed6c0SAxel Dörfler 34541281cf3SAxel Dörfler if (sub->CountItems() > 1) { 34641281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 34741281cf3SAxel Dörfler int myindex = parent->IndexOf(this) + 1; 34841281cf3SAxel Dörfler 34941281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 350deaae5fcSJohn Scipione int32 childIndex = 0; 351deaae5fcSJohn Scipione int32 totalChildren = sub->CountItems() - 4; 35271bd3ba5SJonas Sundström // hide, show, close, separator. 35341281cf3SAxel Dörfler for (; childIndex < totalChildren; childIndex++) { 35471bd3ba5SJonas Sundström windowItem = static_cast<TWindowMenuItem*> 35571bd3ba5SJonas Sundström (sub->RemoveItem((int32)0)); 35641281cf3SAxel Dörfler parent->AddItem(windowItem, myindex + childIndex); 3575e625eadSJohn Scipione windowItem->SetExpanded(true); 35841281cf3SAxel Dörfler } 35941281cf3SAxel Dörfler sub->SetExpanded(true, myindex + childIndex); 36041281cf3SAxel Dörfler 36141281cf3SAxel Dörfler if (resizeWindow) 362afa1c291SJohn Scipione parent->SizeWindow(-1); 363c0107fb2SJonas Sundström } 36441281cf3SAxel Dörfler } 36541281cf3SAxel Dörfler } else { 36641281cf3SAxel Dörfler // Remove the goodies from the Menu() that should be in the SubMenu(); 36741281cf3SAxel Dörfler TWindowMenu* sub = static_cast<TWindowMenu*>(Submenu()); 3685b0fd10dSJohn Scipione if (sub != NULL) { 36941281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 37041281cf3SAxel Dörfler 37141281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 372deaae5fcSJohn Scipione int32 childIndex = parent->IndexOf(this) + 1; 373deaae5fcSJohn Scipione while (parent->SubmenuAt(childIndex) == NULL 374deaae5fcSJohn Scipione && childIndex < parent->CountItems()) { 37515eb397eSJohn Scipione windowItem = static_cast<TWindowMenuItem*>( 37615eb397eSJohn Scipione parent->RemoveItem(childIndex)); 37741281cf3SAxel Dörfler sub->AddItem(windowItem, 0); 3785e625eadSJohn Scipione windowItem->SetExpanded(false); 37941281cf3SAxel Dörfler } 38041281cf3SAxel Dörfler sub->SetExpanded(false, 0); 38141281cf3SAxel Dörfler 38241281cf3SAxel Dörfler if (resizeWindow) 38349ff476dSJohn Scipione parent->SizeWindow(1); 384c0107fb2SJonas Sundström } 38541281cf3SAxel Dörfler } 38641281cf3SAxel Dörfler } 38741281cf3SAxel Dörfler 38841281cf3SAxel Dörfler 38941281cf3SAxel Dörfler TWindowMenuItem* 39041281cf3SAxel Dörfler TTeamMenuItem::ExpandedWindowItem(int32 id) 39141281cf3SAxel Dörfler { 3921687edd0SFredrik Holmqvist if (!fExpanded) { 3931687edd0SFredrik Holmqvist // Paranoia 39441281cf3SAxel Dörfler return NULL; 3951687edd0SFredrik Holmqvist } 39641281cf3SAxel Dörfler 39741281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 39841281cf3SAxel Dörfler int childIndex = parent->IndexOf(this) + 1; 39941281cf3SAxel Dörfler 40071bd3ba5SJonas Sundström while (!parent->SubmenuAt(childIndex) 40171bd3ba5SJonas Sundström && childIndex < parent->CountItems()) { 40271bd3ba5SJonas Sundström TWindowMenuItem* item 40371bd3ba5SJonas Sundström = static_cast<TWindowMenuItem*>(parent->ItemAt(childIndex)); 40441281cf3SAxel Dörfler if (item->ID() == id) 40541281cf3SAxel Dörfler return item; 40641281cf3SAxel Dörfler 40741281cf3SAxel Dörfler childIndex++; 40841281cf3SAxel Dörfler } 40941281cf3SAxel Dörfler return NULL; 41041281cf3SAxel Dörfler } 41141281cf3SAxel Dörfler 41241281cf3SAxel Dörfler 41341281cf3SAxel Dörfler BRect 41441281cf3SAxel Dörfler TTeamMenuItem::ExpanderBounds() const 41541281cf3SAxel Dörfler { 41641281cf3SAxel Dörfler BRect bounds(Frame()); 41741281cf3SAxel Dörfler bounds.left = bounds.right - kSwitchWidth; 41841281cf3SAxel Dörfler return bounds; 41941281cf3SAxel Dörfler } 42041281cf3SAxel Dörfler 421249a4a18SStephan Aßmus 4225b0fd10dSJohn Scipione // #pragma mark - Private methods 4235b0fd10dSJohn Scipione 4245b0fd10dSJohn Scipione 4255b0fd10dSJohn Scipione void 426e9982f68SJohn Scipione TTeamMenuItem::_Init(BList* team, BBitmap* icon, char* name, char* signature, 42718bcf77aSJohn Scipione float width, float height) 4285b0fd10dSJohn Scipione { 4295b0fd10dSJohn Scipione fTeam = team; 4305b0fd10dSJohn Scipione fIcon = icon; 431c9363f78SJohn Scipione fSignature = signature; 432c38afcd6SJohn Scipione 433c38afcd6SJohn Scipione if (name == NULL) { 4345b0fd10dSJohn Scipione char temp[32]; 4355b0fd10dSJohn Scipione snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0)); 436c38afcd6SJohn Scipione name = strdup(temp); 4375b0fd10dSJohn Scipione } 438c9363f78SJohn Scipione 439c38afcd6SJohn Scipione SetLabel(name); 440c9363f78SJohn Scipione 4411dccb7aaSJohn Scipione fOverrideWidth = width; 4421dccb7aaSJohn Scipione fOverrideHeight = height; 4435b0fd10dSJohn Scipione 4441dccb7aaSJohn Scipione fBarView = static_cast<TBarApp*>(be_app)->BarView(); 4455b0fd10dSJohn Scipione 446c38afcd6SJohn Scipione BFont font(be_plain_font); 447c38afcd6SJohn Scipione fLabelWidth = ceilf(font.StringWidth(name)); 448c38afcd6SJohn Scipione font_height fontHeight; 449c38afcd6SJohn Scipione font.GetHeight(&fontHeight); 450c38afcd6SJohn Scipione fLabelAscent = ceilf(fontHeight.ascent); 451c38afcd6SJohn Scipione fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading); 45215eb397eSJohn Scipione fLabelHeight = fLabelAscent + fLabelDescent; 453c38afcd6SJohn Scipione 4545b0fd10dSJohn Scipione fOverriddenSelected = false; 4555b0fd10dSJohn Scipione 4565b0fd10dSJohn Scipione fExpanded = false; 4571dccb7aaSJohn Scipione fArrowDirection = BControlLook::B_RIGHT_ARROW; 4585b0fd10dSJohn Scipione } 4595b0fd10dSJohn Scipione 4605b0fd10dSJohn Scipione 461249a4a18SStephan Aßmus bool 462249a4a18SStephan Aßmus TTeamMenuItem::_IsSelected() const 463249a4a18SStephan Aßmus { 464249a4a18SStephan Aßmus return IsSelected() || fOverriddenSelected; 465249a4a18SStephan Aßmus } 466