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" 53*4ae3e542SJohn 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; 6541281cf3SAxel Dörfler const float kSwitchWidth = 12; 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) 7041281cf3SAxel Dörfler : BMenuItem(new TWindowMenu(team, sig)) 7141281cf3SAxel Dörfler { 725b0fd10dSJohn Scipione _InitData(team, icon, name, sig, width, height, drawLabel, vertical); 7341281cf3SAxel Dörfler } 7441281cf3SAxel Dörfler 7541281cf3SAxel Dörfler 7641281cf3SAxel Dörfler TTeamMenuItem::TTeamMenuItem(float width, float height, bool vertical) 7741281cf3SAxel Dörfler : BMenuItem("", NULL) 7841281cf3SAxel Dörfler { 795b0fd10dSJohn Scipione _InitData(NULL, NULL, strdup(""), strdup(""), width, height, false, 801687edd0SFredrik Holmqvist vertical); 8141281cf3SAxel Dörfler } 8241281cf3SAxel Dörfler 8341281cf3SAxel Dörfler 8441281cf3SAxel Dörfler TTeamMenuItem::~TTeamMenuItem() 8541281cf3SAxel Dörfler { 8641281cf3SAxel Dörfler delete fTeam; 8741281cf3SAxel Dörfler delete fIcon; 8841281cf3SAxel Dörfler free(fName); 8941281cf3SAxel Dörfler free(fSig); 9041281cf3SAxel Dörfler } 9141281cf3SAxel Dörfler 9241281cf3SAxel Dörfler 9341281cf3SAxel Dörfler status_t 9441281cf3SAxel Dörfler TTeamMenuItem::Invoke(BMessage* message) 9541281cf3SAxel Dörfler { 961dccb7aaSJohn Scipione if (fBarView->InvokeItem(Signature())) { 9741281cf3SAxel Dörfler // handles drop on application 9841281cf3SAxel Dörfler return B_OK; 991dccb7aaSJohn Scipione } 10041281cf3SAxel Dörfler 10141281cf3SAxel Dörfler // if the app could not handle the drag message 10241281cf3SAxel Dörfler // and we were dragging, then kill the drag 10341281cf3SAxel Dörfler // should never get here, disabled item will not invoke 1041dccb7aaSJohn Scipione if (fBarView != NULL && fBarView->Dragging()) 1051dccb7aaSJohn Scipione fBarView->DragStop(); 10641281cf3SAxel Dörfler 10741281cf3SAxel Dörfler // bring to front or minimize shortcuts 10841281cf3SAxel Dörfler uint32 mods = modifiers(); 1091687edd0SFredrik Holmqvist if (mods & B_CONTROL_KEY) { 11041281cf3SAxel Dörfler TShowHideMenuItem::TeamShowHideCommon((mods & B_SHIFT_KEY) 11141281cf3SAxel Dörfler ? B_MINIMIZE_WINDOW : B_BRING_TO_FRONT, Teams()); 1121687edd0SFredrik Holmqvist } 11341281cf3SAxel Dörfler 11441281cf3SAxel Dörfler return BMenuItem::Invoke(message); 11541281cf3SAxel Dörfler } 11641281cf3SAxel Dörfler 11741281cf3SAxel Dörfler 11841281cf3SAxel Dörfler void 11941281cf3SAxel Dörfler TTeamMenuItem::SetOverrideWidth(float width) 12041281cf3SAxel Dörfler { 12141281cf3SAxel Dörfler fOverrideWidth = width; 12241281cf3SAxel Dörfler } 12341281cf3SAxel Dörfler 12441281cf3SAxel Dörfler 12541281cf3SAxel Dörfler void 12641281cf3SAxel Dörfler TTeamMenuItem::SetOverrideHeight(float height) 12741281cf3SAxel Dörfler { 12841281cf3SAxel Dörfler fOverrideHeight = height; 12941281cf3SAxel Dörfler } 13041281cf3SAxel Dörfler 13141281cf3SAxel Dörfler 132249a4a18SStephan Aßmus void 133249a4a18SStephan Aßmus TTeamMenuItem::SetOverrideSelected(bool selected) 134249a4a18SStephan Aßmus { 135249a4a18SStephan Aßmus fOverriddenSelected = selected; 136249a4a18SStephan Aßmus Highlight(selected); 137249a4a18SStephan Aßmus } 138249a4a18SStephan Aßmus 139249a4a18SStephan Aßmus 1401dccb7aaSJohn Scipione void 1411dccb7aaSJohn Scipione TTeamMenuItem::SetArrowDirection(int32 direction) 1421f0c9f18SJohn Scipione { 1431dccb7aaSJohn Scipione fArrowDirection = direction; 1441f0c9f18SJohn Scipione } 1451f0c9f18SJohn Scipione 1461f0c9f18SJohn Scipione 1472ce9bab8SJohn Scipione void 148dc05c262SJohn Scipione TTeamMenuItem::SetHasLabel(bool drawLabel) 1492ce9bab8SJohn Scipione { 1502ce9bab8SJohn Scipione fDrawLabel = drawLabel; 1512ce9bab8SJohn Scipione } 1522ce9bab8SJohn Scipione 1532ce9bab8SJohn Scipione 15441281cf3SAxel Dörfler void 15541281cf3SAxel Dörfler TTeamMenuItem::GetContentSize(float* width, float* height) 15641281cf3SAxel Dörfler { 15741281cf3SAxel Dörfler BRect iconBounds; 15841281cf3SAxel Dörfler 15941281cf3SAxel Dörfler if (fIcon) 16041281cf3SAxel Dörfler iconBounds = fIcon->Bounds(); 16141281cf3SAxel Dörfler else 1622ce9bab8SJohn Scipione iconBounds = BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1); 16341281cf3SAxel Dörfler 16441281cf3SAxel Dörfler BMenuItem::GetContentSize(width, height); 16541281cf3SAxel Dörfler 16641281cf3SAxel Dörfler if (fOverrideWidth != -1.0f) 16741281cf3SAxel Dörfler *width = fOverrideWidth; 1682ce9bab8SJohn Scipione else { 1692ce9bab8SJohn Scipione *width = kHPad + iconBounds.Width() + kHPad; 1702ce9bab8SJohn Scipione if (iconBounds.Width() <= 32 && fDrawLabel) 1712ce9bab8SJohn Scipione *width += LabelWidth() + kHPad; 1722ce9bab8SJohn Scipione } 17341281cf3SAxel Dörfler 17441281cf3SAxel Dörfler if (fOverrideHeight != -1.0f) 17541281cf3SAxel Dörfler *height = fOverrideHeight; 17641281cf3SAxel Dörfler else { 1772ce9bab8SJohn Scipione if (fVertical) { 1782ce9bab8SJohn Scipione *height = iconBounds.Height() + kVPad * 4; 1792ce9bab8SJohn Scipione if (fDrawLabel && iconBounds.Width() > 32) 1802ce9bab8SJohn Scipione *height += fLabelAscent + fLabelDescent; 1812ce9bab8SJohn Scipione } else { 182c07e6ff2SJohn Scipione *height = iconBounds.Height() + kVPad * 4; 1832ce9bab8SJohn Scipione } 18441281cf3SAxel Dörfler } 18541281cf3SAxel Dörfler *height += 2; 18641281cf3SAxel Dörfler } 18741281cf3SAxel Dörfler 18841281cf3SAxel Dörfler 18941281cf3SAxel Dörfler void 19041281cf3SAxel Dörfler TTeamMenuItem::Draw() 19141281cf3SAxel Dörfler { 19241281cf3SAxel Dörfler BRect frame(Frame()); 19341281cf3SAxel Dörfler BMenu* menu = Menu(); 194fe624b39SJohn Scipione 19541281cf3SAxel Dörfler menu->PushState(); 1965b0fd10dSJohn Scipione 197cb6afcb1SStephan Aßmus rgb_color menuColor = menu->LowColor(); 1981dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 1991dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 200cb6afcb1SStephan Aßmus uint32 flags = 0; 201cb6afcb1SStephan Aßmus if (_IsSelected() && canHandle) 202cb6afcb1SStephan Aßmus flags |= BControlLook::B_ACTIVATED; 203cb6afcb1SStephan Aßmus 204cb6afcb1SStephan Aßmus uint32 borders = BControlLook::B_TOP_BORDER; 205cb6afcb1SStephan Aßmus if (fVertical) { 206cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_1_TINT)); 207cb6afcb1SStephan Aßmus borders |= BControlLook::B_LEFT_BORDER 208cb6afcb1SStephan Aßmus | BControlLook::B_RIGHT_BORDER; 209cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftBottom(), frame.RightBottom()); 210cb6afcb1SStephan Aßmus frame.bottom--; 211cb6afcb1SStephan Aßmus 212cb6afcb1SStephan Aßmus be_control_look->DrawMenuBarBackground(menu, frame, frame, 213cb6afcb1SStephan Aßmus menuColor, flags, borders); 214cb6afcb1SStephan Aßmus } else { 215cb6afcb1SStephan Aßmus if (flags & BControlLook::B_ACTIVATED) 216cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_3_TINT)); 217cb6afcb1SStephan Aßmus else 218cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, 1.22)); 219cb6afcb1SStephan Aßmus borders |= BControlLook::B_BOTTOM_BORDER; 220cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); 221cb6afcb1SStephan Aßmus frame.left++; 222cb6afcb1SStephan Aßmus 223cb6afcb1SStephan Aßmus be_control_look->DrawButtonBackground(menu, frame, frame, 224cb6afcb1SStephan Aßmus menuColor, flags, borders); 225cb6afcb1SStephan Aßmus } 226cb6afcb1SStephan Aßmus 227cb6afcb1SStephan Aßmus menu->MovePenTo(ContentLocation()); 228cb6afcb1SStephan Aßmus DrawContent(); 229fe624b39SJohn Scipione 230cb6afcb1SStephan Aßmus menu->PopState(); 23141281cf3SAxel Dörfler } 23241281cf3SAxel Dörfler 23341281cf3SAxel Dörfler 23441281cf3SAxel Dörfler void 23541281cf3SAxel Dörfler TTeamMenuItem::DrawContent() 23641281cf3SAxel Dörfler { 23741281cf3SAxel Dörfler BMenu* menu = Menu(); 2382ce9bab8SJohn Scipione if (fIcon != NULL) { 23959deaf10SStephan Aßmus if (fIcon->ColorSpace() == B_RGBA32) { 24059deaf10SStephan Aßmus menu->SetDrawingMode(B_OP_ALPHA); 24159deaf10SStephan Aßmus menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); 2421687edd0SFredrik Holmqvist } else 24341281cf3SAxel Dörfler menu->SetDrawingMode(B_OP_OVER); 24441281cf3SAxel Dörfler 2451687edd0SFredrik Holmqvist BRect frame(Frame()); 24641281cf3SAxel Dörfler BRect iconBounds(fIcon->Bounds()); 24741281cf3SAxel Dörfler BRect dstRect(iconBounds); 2482ce9bab8SJohn Scipione float extra = fVertical ? 0.0f : -1.0f; 24941281cf3SAxel Dörfler BPoint contLoc = ContentLocation(); 2502ce9bab8SJohn Scipione BPoint drawLoc = contLoc + BPoint(kHPad, kVPad); 2511687edd0SFredrik Holmqvist 2522ce9bab8SJohn Scipione if (!fDrawLabel || (fVertical && iconBounds.Width() > 32)) { 2532ce9bab8SJohn Scipione float offsetx = contLoc.x 2542ce9bab8SJohn Scipione + ((frame.Width() - iconBounds.Width()) / 2) + extra; 2552ce9bab8SJohn Scipione float offsety = contLoc.y + 3.0f + extra; 2562ce9bab8SJohn Scipione 2572ce9bab8SJohn Scipione dstRect.OffsetTo(BPoint(offsetx, offsety)); 2582ce9bab8SJohn Scipione menu->DrawBitmapAsync(fIcon, dstRect); 2592ce9bab8SJohn Scipione 2602ce9bab8SJohn Scipione drawLoc.x = ((frame.Width() - LabelWidth()) / 2); 2612ce9bab8SJohn Scipione drawLoc.y = frame.top + iconBounds.Height() + 4.0f; 2622ce9bab8SJohn Scipione } else { 2632ce9bab8SJohn Scipione float offsetx = contLoc.x + kHPad; 2642ce9bab8SJohn Scipione float offsety = contLoc.y + 2652ce9bab8SJohn Scipione ((frame.Height() - iconBounds.Height()) / 2) + extra; 2662ce9bab8SJohn Scipione 2672ce9bab8SJohn Scipione dstRect.OffsetTo(BPoint(offsetx, offsety)); 26841281cf3SAxel Dörfler menu->DrawBitmapAsync(fIcon, dstRect); 26941281cf3SAxel Dörfler 27041281cf3SAxel Dörfler float labelHeight = fLabelAscent + fLabelDescent; 27141281cf3SAxel Dörfler drawLoc.x += iconBounds.Width() + kLabelOffset; 2722ce9bab8SJohn Scipione drawLoc.y = frame.top + ((frame.Height() - labelHeight) / 2) + extra; 2732ce9bab8SJohn Scipione } 2742ce9bab8SJohn Scipione 27541281cf3SAxel Dörfler menu->MovePenTo(drawLoc); 27641281cf3SAxel Dörfler } 27741281cf3SAxel Dörfler 27841281cf3SAxel Dörfler if (fDrawLabel) { 279cb6afcb1SStephan Aßmus menu->SetDrawingMode(B_OP_OVER); 280e19488b2SRyan Leavengood menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 28141281cf3SAxel Dörfler 28241281cf3SAxel Dörfler // override the drawing of the content when the item is disabled 28341281cf3SAxel Dörfler // the wrong lowcolor is used when the item is disabled since the 28441281cf3SAxel Dörfler // text color does not change 28541281cf3SAxel Dörfler DrawContentLabel(); 28641281cf3SAxel Dörfler } 28741281cf3SAxel Dörfler 2881dccb7aaSJohn Scipione if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando 2891dccb7aaSJohn Scipione && fBarView->ExpandoState()) { 2901dccb7aaSJohn Scipione DrawExpanderArrow(); 2911dccb7aaSJohn Scipione } 292cb6afcb1SStephan Aßmus } 29341281cf3SAxel Dörfler 29441281cf3SAxel Dörfler 29541281cf3SAxel Dörfler void 29641281cf3SAxel Dörfler TTeamMenuItem::DrawContentLabel() 29741281cf3SAxel Dörfler { 29841281cf3SAxel Dörfler BMenu* menu = Menu(); 29941281cf3SAxel Dörfler menu->MovePenBy(0, fLabelAscent); 30041281cf3SAxel Dörfler 30141281cf3SAxel Dörfler float cachedWidth = menu->StringWidth(Label()); 30241281cf3SAxel Dörfler if (Submenu() && fVertical) 30341281cf3SAxel Dörfler cachedWidth += 18; 30441281cf3SAxel Dörfler 30541281cf3SAxel Dörfler const char* label = Label(); 30641281cf3SAxel Dörfler char* truncLabel = NULL; 30741281cf3SAxel Dörfler float max = 0; 3081687edd0SFredrik Holmqvist 3092ce9bab8SJohn Scipione if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando) 31041281cf3SAxel Dörfler max = menu->MaxContentWidth() - kSwitchWidth; 31141281cf3SAxel Dörfler else 3122ce9bab8SJohn Scipione max = menu->MaxContentWidth() - 4.0f; 31341281cf3SAxel Dörfler 31441281cf3SAxel Dörfler if (max > 0) { 31541281cf3SAxel Dörfler BPoint penloc = menu->PenLocation(); 31641281cf3SAxel Dörfler BRect frame = Frame(); 31741281cf3SAxel Dörfler float offset = penloc.x - frame.left; 31841281cf3SAxel Dörfler if (cachedWidth + offset > max) { 31941281cf3SAxel Dörfler truncLabel = (char*)malloc(strlen(label) + 4); 32041281cf3SAxel Dörfler if (!truncLabel) 32141281cf3SAxel Dörfler return; 32241281cf3SAxel Dörfler TruncateLabel(max-offset, truncLabel); 32341281cf3SAxel Dörfler label = truncLabel; 32441281cf3SAxel Dörfler } 32541281cf3SAxel Dörfler } 32641281cf3SAxel Dörfler 32741281cf3SAxel Dörfler if (!label) 32841281cf3SAxel Dörfler label = Label(); 32941281cf3SAxel Dörfler 3301dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 3311dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 332249a4a18SStephan Aßmus if (_IsSelected() && IsEnabled() && canHandle) 333ab4e79c3SRyan Leavengood menu->SetLowColor(tint_color(menu->LowColor(), 33441281cf3SAxel Dörfler B_HIGHLIGHT_BACKGROUND_TINT)); 33541281cf3SAxel Dörfler else 336ab4e79c3SRyan Leavengood menu->SetLowColor(menu->LowColor()); 33741281cf3SAxel Dörfler 338859c3781SJohn Scipione if (IsSelected()) 339859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR)); 340859c3781SJohn Scipione else 341859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 342859c3781SJohn Scipione 34341281cf3SAxel Dörfler menu->DrawString(label); 34441281cf3SAxel Dörfler 34541281cf3SAxel Dörfler free(truncLabel); 34641281cf3SAxel Dörfler } 34741281cf3SAxel Dörfler 34841281cf3SAxel Dörfler 3495b0fd10dSJohn Scipione void 3501dccb7aaSJohn Scipione TTeamMenuItem::DrawExpanderArrow() 3515b0fd10dSJohn Scipione { 3525b0fd10dSJohn Scipione BMenu* menu = Menu(); 3535b0fd10dSJohn Scipione BRect frame(Frame()); 3545b0fd10dSJohn Scipione BRect rect(0, 0, kSwitchWidth, 10); 3552b8d4131SJohn Scipione 3565b0fd10dSJohn Scipione rect.OffsetTo(BPoint(frame.right - rect.Width(), 3575b0fd10dSJohn Scipione ContentLocation().y + ((frame.Height() - rect.Height()) / 2))); 3585b0fd10dSJohn Scipione be_control_look->DrawArrowShape(menu, rect, rect, menu->LowColor(), 3591dccb7aaSJohn Scipione fArrowDirection, 0, B_DARKEN_3_TINT); 36041281cf3SAxel Dörfler } 36141281cf3SAxel Dörfler 36241281cf3SAxel Dörfler 36341281cf3SAxel Dörfler void 36441281cf3SAxel Dörfler TTeamMenuItem::ToggleExpandState(bool resizeWindow) 36541281cf3SAxel Dörfler { 36641281cf3SAxel Dörfler fExpanded = !fExpanded; 3671dccb7aaSJohn Scipione fArrowDirection = fExpanded ? BControlLook::B_DOWN_ARROW 3681dccb7aaSJohn Scipione : BControlLook::B_RIGHT_ARROW; 36941281cf3SAxel Dörfler 37041281cf3SAxel Dörfler if (fExpanded) { 37141281cf3SAxel Dörfler // Populate Menu() with the stuff from SubMenu(). 37241281cf3SAxel Dörfler TWindowMenu* sub = (static_cast<TWindowMenu*>(Submenu())); 3735b0fd10dSJohn Scipione if (sub != NULL) { 37441281cf3SAxel Dörfler // force the menu to update it's contents. 375bdfed6c0SAxel Dörfler bool locked = sub->LockLooper(); 376bdfed6c0SAxel Dörfler // if locking the looper failed, the menu is just not visible 377bdfed6c0SAxel Dörfler sub->AttachedToWindow(); 378bdfed6c0SAxel Dörfler if (locked) 379bdfed6c0SAxel Dörfler sub->UnlockLooper(); 380bdfed6c0SAxel Dörfler 38141281cf3SAxel Dörfler if (sub->CountItems() > 1) { 38241281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 38341281cf3SAxel Dörfler int myindex = parent->IndexOf(this) + 1; 38441281cf3SAxel Dörfler 38541281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 38641281cf3SAxel Dörfler int childIndex = 0; 38771bd3ba5SJonas Sundström int totalChildren = sub->CountItems() - 4; 38871bd3ba5SJonas Sundström // hide, show, close, separator. 38941281cf3SAxel Dörfler for (; childIndex < totalChildren; childIndex++) { 39071bd3ba5SJonas Sundström windowItem = static_cast<TWindowMenuItem*> 39171bd3ba5SJonas Sundström (sub->RemoveItem((int32)0)); 39241281cf3SAxel Dörfler parent->AddItem(windowItem, myindex + childIndex); 39341281cf3SAxel Dörfler windowItem->ExpandedItem(true); 39441281cf3SAxel Dörfler } 39541281cf3SAxel Dörfler sub->SetExpanded(true, myindex + childIndex); 39641281cf3SAxel Dörfler 39741281cf3SAxel Dörfler if (resizeWindow) 398afa1c291SJohn Scipione parent->SizeWindow(-1); 399c0107fb2SJonas Sundström } 40041281cf3SAxel Dörfler } 40141281cf3SAxel Dörfler } else { 40241281cf3SAxel Dörfler // Remove the goodies from the Menu() that should be in the SubMenu(); 40341281cf3SAxel Dörfler TWindowMenu* sub = static_cast<TWindowMenu*>(Submenu()); 4045b0fd10dSJohn Scipione if (sub != NULL) { 40541281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 40641281cf3SAxel Dörfler 40741281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 40841281cf3SAxel Dörfler int childIndex = parent->IndexOf(this) + 1; 40971bd3ba5SJonas Sundström while (!parent->SubmenuAt(childIndex) && childIndex 41071bd3ba5SJonas Sundström < parent->CountItems()) { 41171bd3ba5SJonas Sundström windowItem = static_cast<TWindowMenuItem*> 41271bd3ba5SJonas Sundström (parent->RemoveItem(childIndex)); 41341281cf3SAxel Dörfler sub->AddItem(windowItem, 0); 41441281cf3SAxel Dörfler windowItem->ExpandedItem(false); 41541281cf3SAxel Dörfler } 41641281cf3SAxel Dörfler sub->SetExpanded(false, 0); 41741281cf3SAxel Dörfler 41841281cf3SAxel Dörfler if (resizeWindow) 41949ff476dSJohn Scipione parent->SizeWindow(1); 420c0107fb2SJonas Sundström } 42141281cf3SAxel Dörfler } 42241281cf3SAxel Dörfler } 42341281cf3SAxel Dörfler 42441281cf3SAxel Dörfler 42541281cf3SAxel Dörfler TWindowMenuItem* 42641281cf3SAxel Dörfler TTeamMenuItem::ExpandedWindowItem(int32 id) 42741281cf3SAxel Dörfler { 4281687edd0SFredrik Holmqvist if (!fExpanded) { 4291687edd0SFredrik Holmqvist // Paranoia 43041281cf3SAxel Dörfler return NULL; 4311687edd0SFredrik Holmqvist } 43241281cf3SAxel Dörfler 43341281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 43441281cf3SAxel Dörfler int childIndex = parent->IndexOf(this) + 1; 43541281cf3SAxel Dörfler 43671bd3ba5SJonas Sundström while (!parent->SubmenuAt(childIndex) 43771bd3ba5SJonas Sundström && childIndex < parent->CountItems()) { 43871bd3ba5SJonas Sundström TWindowMenuItem* item 43971bd3ba5SJonas Sundström = static_cast<TWindowMenuItem*>(parent->ItemAt(childIndex)); 44041281cf3SAxel Dörfler if (item->ID() == id) 44141281cf3SAxel Dörfler return item; 44241281cf3SAxel Dörfler 44341281cf3SAxel Dörfler childIndex++; 44441281cf3SAxel Dörfler } 44541281cf3SAxel Dörfler return NULL; 44641281cf3SAxel Dörfler } 44741281cf3SAxel Dörfler 44841281cf3SAxel Dörfler 44941281cf3SAxel Dörfler BRect 45041281cf3SAxel Dörfler TTeamMenuItem::ExpanderBounds() const 45141281cf3SAxel Dörfler { 45241281cf3SAxel Dörfler BRect bounds(Frame()); 45341281cf3SAxel Dörfler bounds.left = bounds.right - kSwitchWidth; 45441281cf3SAxel Dörfler return bounds; 45541281cf3SAxel Dörfler } 45641281cf3SAxel Dörfler 457249a4a18SStephan Aßmus 4585b0fd10dSJohn Scipione // #pragma mark - Private methods 4595b0fd10dSJohn Scipione 4605b0fd10dSJohn Scipione 4615b0fd10dSJohn Scipione void 4625b0fd10dSJohn Scipione TTeamMenuItem::_InitData(BList* team, BBitmap* icon, char* name, char* sig, 4635b0fd10dSJohn Scipione float width, float height, bool drawLabel, bool vertical) 4645b0fd10dSJohn Scipione { 4655b0fd10dSJohn Scipione fTeam = team; 4665b0fd10dSJohn Scipione fIcon = icon; 4675b0fd10dSJohn Scipione fName = name; 4685b0fd10dSJohn Scipione fSig = sig; 4695b0fd10dSJohn Scipione if (fName == NULL) { 4705b0fd10dSJohn Scipione char temp[32]; 4715b0fd10dSJohn Scipione snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0)); 4725b0fd10dSJohn Scipione fName = strdup(temp); 4735b0fd10dSJohn Scipione } 4745b0fd10dSJohn Scipione SetLabel(fName); 4751dccb7aaSJohn Scipione fOverrideWidth = width; 4761dccb7aaSJohn Scipione fOverrideHeight = height; 4771dccb7aaSJohn Scipione fDrawLabel = drawLabel; 4781dccb7aaSJohn Scipione fVertical = vertical; 4795b0fd10dSJohn Scipione 4801dccb7aaSJohn Scipione fBarView = static_cast<TBarApp*>(be_app)->BarView(); 4815b0fd10dSJohn Scipione BFont font(be_plain_font); 4825b0fd10dSJohn Scipione fLabelWidth = ceilf(font.StringWidth(fName)); 4835b0fd10dSJohn Scipione font_height fontHeight; 4845b0fd10dSJohn Scipione font.GetHeight(&fontHeight); 4855b0fd10dSJohn Scipione fLabelAscent = ceilf(fontHeight.ascent); 4865b0fd10dSJohn Scipione fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading); 4875b0fd10dSJohn Scipione 4885b0fd10dSJohn Scipione fOverriddenSelected = false; 4895b0fd10dSJohn Scipione 4905b0fd10dSJohn Scipione fExpanded = false; 4911dccb7aaSJohn Scipione fArrowDirection = BControlLook::B_RIGHT_ARROW; 4925b0fd10dSJohn Scipione } 4935b0fd10dSJohn Scipione 4945b0fd10dSJohn Scipione 495249a4a18SStephan Aßmus bool 496249a4a18SStephan Aßmus TTeamMenuItem::_IsSelected() const 497249a4a18SStephan Aßmus { 498249a4a18SStephan Aßmus return IsSelected() || fOverriddenSelected; 499249a4a18SStephan Aßmus } 500