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; 6341281cf3SAxel Dörfler const float kVPad = 1.0f; 6441281cf3SAxel Dörfler const float kLabelOffset = 8.0f; 65*a7c02e02SJohn Scipione const float kSwitchWidth = 12.0f; 6641281cf3SAxel Dörfler 6741281cf3SAxel Dörfler 6841281cf3SAxel Dörfler TTeamMenuItem::TTeamMenuItem(BList* team, BBitmap* icon, char* name, char* sig, 6941281cf3SAxel Dörfler float width, float height, bool drawLabel, bool vertical) 7001f35d10SJohn Scipione : 7101f35d10SJohn Scipione BMenuItem(new TWindowMenu(team, sig)) 7241281cf3SAxel Dörfler { 735b0fd10dSJohn Scipione _InitData(team, icon, name, sig, width, height, drawLabel, vertical); 7441281cf3SAxel Dörfler } 7541281cf3SAxel Dörfler 7641281cf3SAxel Dörfler 7741281cf3SAxel Dörfler TTeamMenuItem::TTeamMenuItem(float width, float height, bool vertical) 7801f35d10SJohn Scipione : 7901f35d10SJohn Scipione BMenuItem("", NULL) 8041281cf3SAxel Dörfler { 815b0fd10dSJohn Scipione _InitData(NULL, NULL, strdup(""), strdup(""), width, height, false, 821687edd0SFredrik Holmqvist vertical); 8341281cf3SAxel Dörfler } 8441281cf3SAxel Dörfler 8541281cf3SAxel Dörfler 8641281cf3SAxel Dörfler TTeamMenuItem::~TTeamMenuItem() 8741281cf3SAxel Dörfler { 8841281cf3SAxel Dörfler delete fTeam; 8941281cf3SAxel Dörfler delete fIcon; 9041281cf3SAxel Dörfler free(fName); 9141281cf3SAxel Dörfler free(fSig); 9241281cf3SAxel Dörfler } 9341281cf3SAxel Dörfler 9441281cf3SAxel Dörfler 9541281cf3SAxel Dörfler status_t 9641281cf3SAxel Dörfler TTeamMenuItem::Invoke(BMessage* message) 9741281cf3SAxel Dörfler { 981dccb7aaSJohn Scipione if (fBarView->InvokeItem(Signature())) { 9941281cf3SAxel Dörfler // handles drop on application 10041281cf3SAxel Dörfler return B_OK; 1011dccb7aaSJohn Scipione } 10241281cf3SAxel Dörfler 10341281cf3SAxel Dörfler // if the app could not handle the drag message 10441281cf3SAxel Dörfler // and we were dragging, then kill the drag 10541281cf3SAxel Dörfler // should never get here, disabled item will not invoke 1061dccb7aaSJohn Scipione if (fBarView != NULL && fBarView->Dragging()) 1071dccb7aaSJohn Scipione fBarView->DragStop(); 10841281cf3SAxel Dörfler 10941281cf3SAxel Dörfler // bring to front or minimize shortcuts 11041281cf3SAxel Dörfler uint32 mods = modifiers(); 1111687edd0SFredrik Holmqvist if (mods & B_CONTROL_KEY) { 11241281cf3SAxel Dörfler TShowHideMenuItem::TeamShowHideCommon((mods & B_SHIFT_KEY) 11341281cf3SAxel Dörfler ? B_MINIMIZE_WINDOW : B_BRING_TO_FRONT, Teams()); 1141687edd0SFredrik Holmqvist } 11541281cf3SAxel Dörfler 11641281cf3SAxel Dörfler return BMenuItem::Invoke(message); 11741281cf3SAxel Dörfler } 11841281cf3SAxel Dörfler 11941281cf3SAxel Dörfler 12041281cf3SAxel Dörfler void 12141281cf3SAxel Dörfler TTeamMenuItem::SetOverrideWidth(float width) 12241281cf3SAxel Dörfler { 12341281cf3SAxel Dörfler fOverrideWidth = width; 12441281cf3SAxel Dörfler } 12541281cf3SAxel Dörfler 12641281cf3SAxel Dörfler 12741281cf3SAxel Dörfler void 12841281cf3SAxel Dörfler TTeamMenuItem::SetOverrideHeight(float height) 12941281cf3SAxel Dörfler { 13041281cf3SAxel Dörfler fOverrideHeight = height; 13141281cf3SAxel Dörfler } 13241281cf3SAxel Dörfler 13341281cf3SAxel Dörfler 134249a4a18SStephan Aßmus void 135249a4a18SStephan Aßmus TTeamMenuItem::SetOverrideSelected(bool selected) 136249a4a18SStephan Aßmus { 137249a4a18SStephan Aßmus fOverriddenSelected = selected; 138249a4a18SStephan Aßmus Highlight(selected); 139249a4a18SStephan Aßmus } 140249a4a18SStephan Aßmus 141249a4a18SStephan Aßmus 1421dccb7aaSJohn Scipione void 1431dccb7aaSJohn Scipione TTeamMenuItem::SetArrowDirection(int32 direction) 1441f0c9f18SJohn Scipione { 1451dccb7aaSJohn Scipione fArrowDirection = direction; 1461f0c9f18SJohn Scipione } 1471f0c9f18SJohn Scipione 1481f0c9f18SJohn Scipione 1492ce9bab8SJohn Scipione void 150dc05c262SJohn Scipione TTeamMenuItem::SetHasLabel(bool drawLabel) 1512ce9bab8SJohn Scipione { 1522ce9bab8SJohn Scipione fDrawLabel = drawLabel; 1532ce9bab8SJohn Scipione } 1542ce9bab8SJohn Scipione 1552ce9bab8SJohn Scipione 15641281cf3SAxel Dörfler void 15741281cf3SAxel Dörfler TTeamMenuItem::GetContentSize(float* width, float* height) 15841281cf3SAxel Dörfler { 15941281cf3SAxel Dörfler BRect iconBounds; 16041281cf3SAxel Dörfler 16101f35d10SJohn Scipione if (fIcon != NULL) 16241281cf3SAxel Dörfler iconBounds = fIcon->Bounds(); 16341281cf3SAxel Dörfler else 1642ce9bab8SJohn Scipione iconBounds = BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1); 16541281cf3SAxel Dörfler 16641281cf3SAxel Dörfler BMenuItem::GetContentSize(width, height); 16741281cf3SAxel Dörfler 16841281cf3SAxel Dörfler if (fOverrideWidth != -1.0f) 16941281cf3SAxel Dörfler *width = fOverrideWidth; 1702ce9bab8SJohn Scipione else { 1712ce9bab8SJohn Scipione *width = kHPad + iconBounds.Width() + kHPad; 1722ce9bab8SJohn Scipione if (iconBounds.Width() <= 32 && fDrawLabel) 1732ce9bab8SJohn Scipione *width += LabelWidth() + kHPad; 1742ce9bab8SJohn Scipione } 17541281cf3SAxel Dörfler 17641281cf3SAxel Dörfler if (fOverrideHeight != -1.0f) 17741281cf3SAxel Dörfler *height = fOverrideHeight; 17841281cf3SAxel Dörfler else { 1792ce9bab8SJohn Scipione if (fVertical) { 1802ce9bab8SJohn Scipione *height = iconBounds.Height() + kVPad * 4; 1812ce9bab8SJohn Scipione if (fDrawLabel && iconBounds.Width() > 32) 1822ce9bab8SJohn Scipione *height += fLabelAscent + fLabelDescent; 1832ce9bab8SJohn Scipione } else { 184c07e6ff2SJohn Scipione *height = iconBounds.Height() + kVPad * 4; 1852ce9bab8SJohn Scipione } 18641281cf3SAxel Dörfler } 18741281cf3SAxel Dörfler *height += 2; 18841281cf3SAxel Dörfler } 18941281cf3SAxel Dörfler 19041281cf3SAxel Dörfler 19141281cf3SAxel Dörfler void 19241281cf3SAxel Dörfler TTeamMenuItem::Draw() 19341281cf3SAxel Dörfler { 19441281cf3SAxel Dörfler BRect frame(Frame()); 19541281cf3SAxel Dörfler BMenu* menu = Menu(); 196fe624b39SJohn Scipione 19741281cf3SAxel Dörfler menu->PushState(); 1985b0fd10dSJohn Scipione 199cb6afcb1SStephan Aßmus rgb_color menuColor = menu->LowColor(); 2001dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 2011dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 202cb6afcb1SStephan Aßmus uint32 flags = 0; 203cb6afcb1SStephan Aßmus if (_IsSelected() && canHandle) 204cb6afcb1SStephan Aßmus flags |= BControlLook::B_ACTIVATED; 205cb6afcb1SStephan Aßmus 206cb6afcb1SStephan Aßmus uint32 borders = BControlLook::B_TOP_BORDER; 207cb6afcb1SStephan Aßmus if (fVertical) { 208cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_1_TINT)); 209cb6afcb1SStephan Aßmus borders |= BControlLook::B_LEFT_BORDER 210cb6afcb1SStephan Aßmus | BControlLook::B_RIGHT_BORDER; 211cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftBottom(), frame.RightBottom()); 212cb6afcb1SStephan Aßmus frame.bottom--; 213cb6afcb1SStephan Aßmus 214cb6afcb1SStephan Aßmus be_control_look->DrawMenuBarBackground(menu, frame, frame, 215cb6afcb1SStephan Aßmus menuColor, flags, borders); 216cb6afcb1SStephan Aßmus } else { 217cb6afcb1SStephan Aßmus if (flags & BControlLook::B_ACTIVATED) 218cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_3_TINT)); 219cb6afcb1SStephan Aßmus else 220cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, 1.22)); 221cb6afcb1SStephan Aßmus borders |= BControlLook::B_BOTTOM_BORDER; 222cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); 223cb6afcb1SStephan Aßmus frame.left++; 224cb6afcb1SStephan Aßmus 225cb6afcb1SStephan Aßmus be_control_look->DrawButtonBackground(menu, frame, frame, 226cb6afcb1SStephan Aßmus menuColor, flags, borders); 227cb6afcb1SStephan Aßmus } 228cb6afcb1SStephan Aßmus 229cb6afcb1SStephan Aßmus menu->MovePenTo(ContentLocation()); 230cb6afcb1SStephan Aßmus DrawContent(); 231fe624b39SJohn Scipione 232cb6afcb1SStephan Aßmus menu->PopState(); 23341281cf3SAxel Dörfler } 23441281cf3SAxel Dörfler 23541281cf3SAxel Dörfler 23641281cf3SAxel Dörfler void 23741281cf3SAxel Dörfler TTeamMenuItem::DrawContent() 23841281cf3SAxel Dörfler { 23941281cf3SAxel Dörfler BMenu* menu = Menu(); 2402ce9bab8SJohn Scipione if (fIcon != NULL) { 24159deaf10SStephan Aßmus if (fIcon->ColorSpace() == B_RGBA32) { 24259deaf10SStephan Aßmus menu->SetDrawingMode(B_OP_ALPHA); 24359deaf10SStephan Aßmus menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); 2441687edd0SFredrik Holmqvist } else 24541281cf3SAxel Dörfler menu->SetDrawingMode(B_OP_OVER); 24641281cf3SAxel Dörfler 2471687edd0SFredrik Holmqvist BRect frame(Frame()); 24841281cf3SAxel Dörfler BRect iconBounds(fIcon->Bounds()); 24941281cf3SAxel Dörfler BRect dstRect(iconBounds); 2502ce9bab8SJohn Scipione float extra = fVertical ? 0.0f : -1.0f; 25141281cf3SAxel Dörfler BPoint contLoc = ContentLocation(); 2522ce9bab8SJohn Scipione BPoint drawLoc = contLoc + BPoint(kHPad, kVPad); 2531687edd0SFredrik Holmqvist 2542ce9bab8SJohn Scipione if (!fDrawLabel || (fVertical && iconBounds.Width() > 32)) { 2552ce9bab8SJohn Scipione float offsetx = contLoc.x 2562ce9bab8SJohn Scipione + ((frame.Width() - iconBounds.Width()) / 2) + extra; 2572ce9bab8SJohn Scipione float offsety = contLoc.y + 3.0f + extra; 2582ce9bab8SJohn Scipione 2592ce9bab8SJohn Scipione dstRect.OffsetTo(BPoint(offsetx, offsety)); 2602ce9bab8SJohn Scipione menu->DrawBitmapAsync(fIcon, dstRect); 2612ce9bab8SJohn Scipione 2622ce9bab8SJohn Scipione drawLoc.x = ((frame.Width() - LabelWidth()) / 2); 2632ce9bab8SJohn Scipione drawLoc.y = frame.top + iconBounds.Height() + 4.0f; 2642ce9bab8SJohn Scipione } else { 2652ce9bab8SJohn Scipione float offsetx = contLoc.x + kHPad; 2662ce9bab8SJohn Scipione float offsety = contLoc.y + 2672ce9bab8SJohn Scipione ((frame.Height() - iconBounds.Height()) / 2) + extra; 2682ce9bab8SJohn Scipione 2692ce9bab8SJohn Scipione dstRect.OffsetTo(BPoint(offsetx, offsety)); 27041281cf3SAxel Dörfler menu->DrawBitmapAsync(fIcon, dstRect); 27141281cf3SAxel Dörfler 27241281cf3SAxel Dörfler float labelHeight = fLabelAscent + fLabelDescent; 27341281cf3SAxel Dörfler drawLoc.x += iconBounds.Width() + kLabelOffset; 2742ce9bab8SJohn Scipione drawLoc.y = frame.top + ((frame.Height() - labelHeight) / 2) + extra; 2752ce9bab8SJohn Scipione } 2762ce9bab8SJohn Scipione 27741281cf3SAxel Dörfler menu->MovePenTo(drawLoc); 27841281cf3SAxel Dörfler } 27941281cf3SAxel Dörfler 28041281cf3SAxel Dörfler if (fDrawLabel) { 281cb6afcb1SStephan Aßmus menu->SetDrawingMode(B_OP_OVER); 282e19488b2SRyan Leavengood menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 28341281cf3SAxel Dörfler 28441281cf3SAxel Dörfler // override the drawing of the content when the item is disabled 28541281cf3SAxel Dörfler // the wrong lowcolor is used when the item is disabled since the 28641281cf3SAxel Dörfler // text color does not change 28741281cf3SAxel Dörfler DrawContentLabel(); 28841281cf3SAxel Dörfler } 28941281cf3SAxel Dörfler 2901dccb7aaSJohn Scipione if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando 2911dccb7aaSJohn Scipione && fBarView->ExpandoState()) { 2921dccb7aaSJohn Scipione DrawExpanderArrow(); 2931dccb7aaSJohn Scipione } 294cb6afcb1SStephan Aßmus } 29541281cf3SAxel Dörfler 29641281cf3SAxel Dörfler 29741281cf3SAxel Dörfler void 29841281cf3SAxel Dörfler TTeamMenuItem::DrawContentLabel() 29941281cf3SAxel Dörfler { 30041281cf3SAxel Dörfler BMenu* menu = Menu(); 30141281cf3SAxel Dörfler menu->MovePenBy(0, fLabelAscent); 30241281cf3SAxel Dörfler 30341281cf3SAxel Dörfler float cachedWidth = menu->StringWidth(Label()); 30441281cf3SAxel Dörfler if (Submenu() && fVertical) 30541281cf3SAxel Dörfler cachedWidth += 18; 30641281cf3SAxel Dörfler 30741281cf3SAxel Dörfler const char* label = Label(); 30841281cf3SAxel Dörfler char* truncLabel = NULL; 30941281cf3SAxel Dörfler float max = 0; 3101687edd0SFredrik Holmqvist 3112ce9bab8SJohn Scipione if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando) 31241281cf3SAxel Dörfler max = menu->MaxContentWidth() - kSwitchWidth; 31341281cf3SAxel Dörfler else 3142ce9bab8SJohn Scipione max = menu->MaxContentWidth() - 4.0f; 31541281cf3SAxel Dörfler 31641281cf3SAxel Dörfler if (max > 0) { 31741281cf3SAxel Dörfler BPoint penloc = menu->PenLocation(); 31841281cf3SAxel Dörfler BRect frame = Frame(); 31941281cf3SAxel Dörfler float offset = penloc.x - frame.left; 32041281cf3SAxel Dörfler if (cachedWidth + offset > max) { 32141281cf3SAxel Dörfler truncLabel = (char*)malloc(strlen(label) + 4); 322*a7c02e02SJohn Scipione if (truncLabel == NULL) 32341281cf3SAxel Dörfler return; 32441281cf3SAxel Dörfler TruncateLabel(max-offset, truncLabel); 32541281cf3SAxel Dörfler label = truncLabel; 32641281cf3SAxel Dörfler } 32741281cf3SAxel Dörfler } 32841281cf3SAxel Dörfler 329*a7c02e02SJohn Scipione if (label == NULL) 33041281cf3SAxel Dörfler label = Label(); 33141281cf3SAxel Dörfler 3321dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 3331dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 334249a4a18SStephan Aßmus if (_IsSelected() && IsEnabled() && canHandle) 335ab4e79c3SRyan Leavengood menu->SetLowColor(tint_color(menu->LowColor(), 33641281cf3SAxel Dörfler B_HIGHLIGHT_BACKGROUND_TINT)); 33741281cf3SAxel Dörfler else 338ab4e79c3SRyan Leavengood menu->SetLowColor(menu->LowColor()); 33941281cf3SAxel Dörfler 340859c3781SJohn Scipione if (IsSelected()) 341859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR)); 342859c3781SJohn Scipione else 343859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 344859c3781SJohn Scipione 34541281cf3SAxel Dörfler menu->DrawString(label); 34641281cf3SAxel Dörfler 34741281cf3SAxel Dörfler free(truncLabel); 34841281cf3SAxel Dörfler } 34941281cf3SAxel Dörfler 35041281cf3SAxel Dörfler 3515b0fd10dSJohn Scipione void 3521dccb7aaSJohn Scipione TTeamMenuItem::DrawExpanderArrow() 3535b0fd10dSJohn Scipione { 3545b0fd10dSJohn Scipione BMenu* menu = Menu(); 3555b0fd10dSJohn Scipione BRect frame(Frame()); 3565b0fd10dSJohn Scipione BRect rect(0, 0, kSwitchWidth, 10); 3572b8d4131SJohn Scipione 3585b0fd10dSJohn Scipione rect.OffsetTo(BPoint(frame.right - rect.Width(), 3595b0fd10dSJohn Scipione ContentLocation().y + ((frame.Height() - rect.Height()) / 2))); 3605b0fd10dSJohn Scipione be_control_look->DrawArrowShape(menu, rect, rect, menu->LowColor(), 3611dccb7aaSJohn Scipione fArrowDirection, 0, B_DARKEN_3_TINT); 36241281cf3SAxel Dörfler } 36341281cf3SAxel Dörfler 36441281cf3SAxel Dörfler 36541281cf3SAxel Dörfler void 36641281cf3SAxel Dörfler TTeamMenuItem::ToggleExpandState(bool resizeWindow) 36741281cf3SAxel Dörfler { 36841281cf3SAxel Dörfler fExpanded = !fExpanded; 3691dccb7aaSJohn Scipione fArrowDirection = fExpanded ? BControlLook::B_DOWN_ARROW 3701dccb7aaSJohn Scipione : BControlLook::B_RIGHT_ARROW; 37141281cf3SAxel Dörfler 37241281cf3SAxel Dörfler if (fExpanded) { 37341281cf3SAxel Dörfler // Populate Menu() with the stuff from SubMenu(). 37441281cf3SAxel Dörfler TWindowMenu* sub = (static_cast<TWindowMenu*>(Submenu())); 3755b0fd10dSJohn Scipione if (sub != NULL) { 37641281cf3SAxel Dörfler // force the menu to update it's contents. 377bdfed6c0SAxel Dörfler bool locked = sub->LockLooper(); 378bdfed6c0SAxel Dörfler // if locking the looper failed, the menu is just not visible 379bdfed6c0SAxel Dörfler sub->AttachedToWindow(); 380bdfed6c0SAxel Dörfler if (locked) 381bdfed6c0SAxel Dörfler sub->UnlockLooper(); 382bdfed6c0SAxel Dörfler 38341281cf3SAxel Dörfler if (sub->CountItems() > 1) { 38441281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 38541281cf3SAxel Dörfler int myindex = parent->IndexOf(this) + 1; 38641281cf3SAxel Dörfler 38741281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 38841281cf3SAxel Dörfler int childIndex = 0; 38971bd3ba5SJonas Sundström int totalChildren = sub->CountItems() - 4; 39071bd3ba5SJonas Sundström // hide, show, close, separator. 39141281cf3SAxel Dörfler for (; childIndex < totalChildren; childIndex++) { 39271bd3ba5SJonas Sundström windowItem = static_cast<TWindowMenuItem*> 39371bd3ba5SJonas Sundström (sub->RemoveItem((int32)0)); 39441281cf3SAxel Dörfler parent->AddItem(windowItem, myindex + childIndex); 39541281cf3SAxel Dörfler windowItem->ExpandedItem(true); 39641281cf3SAxel Dörfler } 39741281cf3SAxel Dörfler sub->SetExpanded(true, myindex + childIndex); 39841281cf3SAxel Dörfler 39941281cf3SAxel Dörfler if (resizeWindow) 400afa1c291SJohn Scipione parent->SizeWindow(-1); 401c0107fb2SJonas Sundström } 40241281cf3SAxel Dörfler } 40341281cf3SAxel Dörfler } else { 40441281cf3SAxel Dörfler // Remove the goodies from the Menu() that should be in the SubMenu(); 40541281cf3SAxel Dörfler TWindowMenu* sub = static_cast<TWindowMenu*>(Submenu()); 4065b0fd10dSJohn Scipione if (sub != NULL) { 40741281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 40841281cf3SAxel Dörfler 40941281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 41041281cf3SAxel Dörfler int childIndex = parent->IndexOf(this) + 1; 41171bd3ba5SJonas Sundström while (!parent->SubmenuAt(childIndex) && childIndex 41271bd3ba5SJonas Sundström < parent->CountItems()) { 41371bd3ba5SJonas Sundström windowItem = static_cast<TWindowMenuItem*> 41471bd3ba5SJonas Sundström (parent->RemoveItem(childIndex)); 41541281cf3SAxel Dörfler sub->AddItem(windowItem, 0); 41641281cf3SAxel Dörfler windowItem->ExpandedItem(false); 41741281cf3SAxel Dörfler } 41841281cf3SAxel Dörfler sub->SetExpanded(false, 0); 41941281cf3SAxel Dörfler 42041281cf3SAxel Dörfler if (resizeWindow) 42149ff476dSJohn Scipione parent->SizeWindow(1); 422c0107fb2SJonas Sundström } 42341281cf3SAxel Dörfler } 42441281cf3SAxel Dörfler } 42541281cf3SAxel Dörfler 42641281cf3SAxel Dörfler 42741281cf3SAxel Dörfler TWindowMenuItem* 42841281cf3SAxel Dörfler TTeamMenuItem::ExpandedWindowItem(int32 id) 42941281cf3SAxel Dörfler { 4301687edd0SFredrik Holmqvist if (!fExpanded) { 4311687edd0SFredrik Holmqvist // Paranoia 43241281cf3SAxel Dörfler return NULL; 4331687edd0SFredrik Holmqvist } 43441281cf3SAxel Dörfler 43541281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 43641281cf3SAxel Dörfler int childIndex = parent->IndexOf(this) + 1; 43741281cf3SAxel Dörfler 43871bd3ba5SJonas Sundström while (!parent->SubmenuAt(childIndex) 43971bd3ba5SJonas Sundström && childIndex < parent->CountItems()) { 44071bd3ba5SJonas Sundström TWindowMenuItem* item 44171bd3ba5SJonas Sundström = static_cast<TWindowMenuItem*>(parent->ItemAt(childIndex)); 44241281cf3SAxel Dörfler if (item->ID() == id) 44341281cf3SAxel Dörfler return item; 44441281cf3SAxel Dörfler 44541281cf3SAxel Dörfler childIndex++; 44641281cf3SAxel Dörfler } 44741281cf3SAxel Dörfler return NULL; 44841281cf3SAxel Dörfler } 44941281cf3SAxel Dörfler 45041281cf3SAxel Dörfler 45141281cf3SAxel Dörfler BRect 45241281cf3SAxel Dörfler TTeamMenuItem::ExpanderBounds() const 45341281cf3SAxel Dörfler { 45441281cf3SAxel Dörfler BRect bounds(Frame()); 45541281cf3SAxel Dörfler bounds.left = bounds.right - kSwitchWidth; 45641281cf3SAxel Dörfler return bounds; 45741281cf3SAxel Dörfler } 45841281cf3SAxel Dörfler 459249a4a18SStephan Aßmus 4605b0fd10dSJohn Scipione // #pragma mark - Private methods 4615b0fd10dSJohn Scipione 4625b0fd10dSJohn Scipione 4635b0fd10dSJohn Scipione void 4645b0fd10dSJohn Scipione TTeamMenuItem::_InitData(BList* team, BBitmap* icon, char* name, char* sig, 4655b0fd10dSJohn Scipione float width, float height, bool drawLabel, bool vertical) 4665b0fd10dSJohn Scipione { 4675b0fd10dSJohn Scipione fTeam = team; 4685b0fd10dSJohn Scipione fIcon = icon; 4695b0fd10dSJohn Scipione fName = name; 4705b0fd10dSJohn Scipione fSig = sig; 4715b0fd10dSJohn Scipione if (fName == NULL) { 4725b0fd10dSJohn Scipione char temp[32]; 4735b0fd10dSJohn Scipione snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0)); 4745b0fd10dSJohn Scipione fName = strdup(temp); 4755b0fd10dSJohn Scipione } 4765b0fd10dSJohn Scipione SetLabel(fName); 4771dccb7aaSJohn Scipione fOverrideWidth = width; 4781dccb7aaSJohn Scipione fOverrideHeight = height; 4791dccb7aaSJohn Scipione fDrawLabel = drawLabel; 4801dccb7aaSJohn Scipione fVertical = vertical; 4815b0fd10dSJohn Scipione 4821dccb7aaSJohn Scipione fBarView = static_cast<TBarApp*>(be_app)->BarView(); 4835b0fd10dSJohn Scipione BFont font(be_plain_font); 4845b0fd10dSJohn Scipione fLabelWidth = ceilf(font.StringWidth(fName)); 4855b0fd10dSJohn Scipione font_height fontHeight; 4865b0fd10dSJohn Scipione font.GetHeight(&fontHeight); 4875b0fd10dSJohn Scipione fLabelAscent = ceilf(fontHeight.ascent); 4885b0fd10dSJohn Scipione fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading); 4895b0fd10dSJohn Scipione 4905b0fd10dSJohn Scipione fOverriddenSelected = false; 4915b0fd10dSJohn Scipione 4925b0fd10dSJohn Scipione fExpanded = false; 4931dccb7aaSJohn Scipione fArrowDirection = BControlLook::B_RIGHT_ARROW; 4945b0fd10dSJohn Scipione } 4955b0fd10dSJohn Scipione 4965b0fd10dSJohn Scipione 497249a4a18SStephan Aßmus bool 498249a4a18SStephan Aßmus TTeamMenuItem::_IsSelected() const 499249a4a18SStephan Aßmus { 500249a4a18SStephan Aßmus return IsSelected() || fOverriddenSelected; 501249a4a18SStephan Aßmus } 502