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" 5341281cf3SAxel Dörfler #include "ExpandoMenuBar.h" 5441281cf3SAxel Dörfler #include "ResourceSet.h" 5541281cf3SAxel Dörfler #include "ShowHideMenuItem.h" 5641281cf3SAxel Dörfler #include "TeamMenu.h" 5741281cf3SAxel Dörfler #include "WindowMenu.h" 5841281cf3SAxel Dörfler #include "WindowMenuItem.h" 5941281cf3SAxel Dörfler 6041281cf3SAxel Dörfler 6141281cf3SAxel Dörfler const float kHPad = 8.0f; 6241281cf3SAxel Dörfler const float kVPad = 1.0f; 6341281cf3SAxel Dörfler const float kLabelOffset = 8.0f; 6441281cf3SAxel Dörfler const float kSwitchWidth = 12; 6541281cf3SAxel Dörfler 6641281cf3SAxel Dörfler 6741281cf3SAxel Dörfler TTeamMenuItem::TTeamMenuItem(BList* team, BBitmap* icon, char* name, char* sig, 6841281cf3SAxel Dörfler float width, float height, bool drawLabel, bool vertical) 6941281cf3SAxel Dörfler : BMenuItem(new TWindowMenu(team, sig)) 7041281cf3SAxel Dörfler { 715b0fd10dSJohn Scipione _InitData(team, icon, name, sig, width, height, drawLabel, vertical); 7241281cf3SAxel Dörfler } 7341281cf3SAxel Dörfler 7441281cf3SAxel Dörfler 7541281cf3SAxel Dörfler TTeamMenuItem::TTeamMenuItem(float width, float height, bool vertical) 7641281cf3SAxel Dörfler : BMenuItem("", NULL) 7741281cf3SAxel Dörfler { 785b0fd10dSJohn Scipione _InitData(NULL, NULL, strdup(""), strdup(""), width, height, false, 791687edd0SFredrik Holmqvist vertical); 8041281cf3SAxel Dörfler } 8141281cf3SAxel Dörfler 8241281cf3SAxel Dörfler 8341281cf3SAxel Dörfler TTeamMenuItem::~TTeamMenuItem() 8441281cf3SAxel Dörfler { 8541281cf3SAxel Dörfler delete fTeam; 8641281cf3SAxel Dörfler delete fIcon; 8741281cf3SAxel Dörfler free(fName); 8841281cf3SAxel Dörfler free(fSig); 8941281cf3SAxel Dörfler } 9041281cf3SAxel Dörfler 9141281cf3SAxel Dörfler 9241281cf3SAxel Dörfler status_t 9341281cf3SAxel Dörfler TTeamMenuItem::Invoke(BMessage* message) 9441281cf3SAxel Dörfler { 951dccb7aaSJohn Scipione if (fBarView->InvokeItem(Signature())) { 9641281cf3SAxel Dörfler // handles drop on application 9741281cf3SAxel Dörfler return B_OK; 981dccb7aaSJohn Scipione } 9941281cf3SAxel Dörfler 10041281cf3SAxel Dörfler // if the app could not handle the drag message 10141281cf3SAxel Dörfler // and we were dragging, then kill the drag 10241281cf3SAxel Dörfler // should never get here, disabled item will not invoke 1031dccb7aaSJohn Scipione if (fBarView != NULL && fBarView->Dragging()) 1041dccb7aaSJohn Scipione fBarView->DragStop(); 10541281cf3SAxel Dörfler 10641281cf3SAxel Dörfler // bring to front or minimize shortcuts 10741281cf3SAxel Dörfler uint32 mods = modifiers(); 1081687edd0SFredrik Holmqvist if (mods & B_CONTROL_KEY) { 10941281cf3SAxel Dörfler TShowHideMenuItem::TeamShowHideCommon((mods & B_SHIFT_KEY) 11041281cf3SAxel Dörfler ? B_MINIMIZE_WINDOW : B_BRING_TO_FRONT, Teams()); 1111687edd0SFredrik Holmqvist } 11241281cf3SAxel Dörfler 11341281cf3SAxel Dörfler return BMenuItem::Invoke(message); 11441281cf3SAxel Dörfler } 11541281cf3SAxel Dörfler 11641281cf3SAxel Dörfler 11741281cf3SAxel Dörfler void 11841281cf3SAxel Dörfler TTeamMenuItem::SetOverrideWidth(float width) 11941281cf3SAxel Dörfler { 12041281cf3SAxel Dörfler fOverrideWidth = width; 12141281cf3SAxel Dörfler } 12241281cf3SAxel Dörfler 12341281cf3SAxel Dörfler 12441281cf3SAxel Dörfler void 12541281cf3SAxel Dörfler TTeamMenuItem::SetOverrideHeight(float height) 12641281cf3SAxel Dörfler { 12741281cf3SAxel Dörfler fOverrideHeight = height; 12841281cf3SAxel Dörfler } 12941281cf3SAxel Dörfler 13041281cf3SAxel Dörfler 131249a4a18SStephan Aßmus void 132249a4a18SStephan Aßmus TTeamMenuItem::SetOverrideSelected(bool selected) 133249a4a18SStephan Aßmus { 134249a4a18SStephan Aßmus fOverriddenSelected = selected; 135249a4a18SStephan Aßmus Highlight(selected); 136249a4a18SStephan Aßmus } 137249a4a18SStephan Aßmus 138249a4a18SStephan Aßmus 1391dccb7aaSJohn Scipione void 1401dccb7aaSJohn Scipione TTeamMenuItem::SetArrowDirection(int32 direction) 1411f0c9f18SJohn Scipione { 1421dccb7aaSJohn Scipione fArrowDirection = direction; 1431f0c9f18SJohn Scipione } 1441f0c9f18SJohn Scipione 1451f0c9f18SJohn Scipione 1462ce9bab8SJohn Scipione void 147dc05c262SJohn Scipione TTeamMenuItem::SetHasLabel(bool drawLabel) 1482ce9bab8SJohn Scipione { 1492ce9bab8SJohn Scipione fDrawLabel = drawLabel; 1502ce9bab8SJohn Scipione } 1512ce9bab8SJohn Scipione 1522ce9bab8SJohn Scipione 15341281cf3SAxel Dörfler void 15441281cf3SAxel Dörfler TTeamMenuItem::GetContentSize(float* width, float* height) 15541281cf3SAxel Dörfler { 15641281cf3SAxel Dörfler BRect iconBounds; 15741281cf3SAxel Dörfler 15841281cf3SAxel Dörfler if (fIcon) 15941281cf3SAxel Dörfler iconBounds = fIcon->Bounds(); 16041281cf3SAxel Dörfler else 1612ce9bab8SJohn Scipione iconBounds = BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1); 16241281cf3SAxel Dörfler 16341281cf3SAxel Dörfler BMenuItem::GetContentSize(width, height); 16441281cf3SAxel Dörfler 16541281cf3SAxel Dörfler if (fOverrideWidth != -1.0f) 16641281cf3SAxel Dörfler *width = fOverrideWidth; 1672ce9bab8SJohn Scipione else { 1682ce9bab8SJohn Scipione *width = kHPad + iconBounds.Width() + kHPad; 1692ce9bab8SJohn Scipione if (iconBounds.Width() <= 32 && fDrawLabel) 1702ce9bab8SJohn Scipione *width += LabelWidth() + kHPad; 1712ce9bab8SJohn Scipione } 17241281cf3SAxel Dörfler 17341281cf3SAxel Dörfler if (fOverrideHeight != -1.0f) 17441281cf3SAxel Dörfler *height = fOverrideHeight; 17541281cf3SAxel Dörfler else { 1762ce9bab8SJohn Scipione if (fVertical) { 1772ce9bab8SJohn Scipione *height = iconBounds.Height() + kVPad * 4; 1782ce9bab8SJohn Scipione if (fDrawLabel && iconBounds.Width() > 32) 1792ce9bab8SJohn Scipione *height += fLabelAscent + fLabelDescent; 1802ce9bab8SJohn Scipione } else { 181c07e6ff2SJohn Scipione *height = iconBounds.Height() + kVPad * 4; 1822ce9bab8SJohn Scipione } 18341281cf3SAxel Dörfler } 18441281cf3SAxel Dörfler *height += 2; 18541281cf3SAxel Dörfler } 18641281cf3SAxel Dörfler 18741281cf3SAxel Dörfler 18841281cf3SAxel Dörfler void 18941281cf3SAxel Dörfler TTeamMenuItem::Draw() 19041281cf3SAxel Dörfler { 19141281cf3SAxel Dörfler BRect frame(Frame()); 19241281cf3SAxel Dörfler BMenu* menu = Menu(); 19341281cf3SAxel Dörfler menu->PushState(); 1945b0fd10dSJohn Scipione 195cb6afcb1SStephan Aßmus rgb_color menuColor = menu->LowColor(); 1961dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 1971dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 198cb6afcb1SStephan Aßmus uint32 flags = 0; 199cb6afcb1SStephan Aßmus if (_IsSelected() && canHandle) 200cb6afcb1SStephan Aßmus flags |= BControlLook::B_ACTIVATED; 201cb6afcb1SStephan Aßmus 202cb6afcb1SStephan Aßmus uint32 borders = BControlLook::B_TOP_BORDER; 203cb6afcb1SStephan Aßmus if (fVertical) { 204cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_1_TINT)); 205cb6afcb1SStephan Aßmus borders |= BControlLook::B_LEFT_BORDER 206cb6afcb1SStephan Aßmus | BControlLook::B_RIGHT_BORDER; 207cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftBottom(), frame.RightBottom()); 208cb6afcb1SStephan Aßmus frame.bottom--; 209cb6afcb1SStephan Aßmus 210cb6afcb1SStephan Aßmus be_control_look->DrawMenuBarBackground(menu, frame, frame, 211cb6afcb1SStephan Aßmus menuColor, flags, borders); 212cb6afcb1SStephan Aßmus } else { 213cb6afcb1SStephan Aßmus if (flags & BControlLook::B_ACTIVATED) 214cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, B_DARKEN_3_TINT)); 215cb6afcb1SStephan Aßmus else 216cb6afcb1SStephan Aßmus menu->SetHighColor(tint_color(menuColor, 1.22)); 217cb6afcb1SStephan Aßmus borders |= BControlLook::B_BOTTOM_BORDER; 218cb6afcb1SStephan Aßmus menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); 219cb6afcb1SStephan Aßmus frame.left++; 220cb6afcb1SStephan Aßmus 221cb6afcb1SStephan Aßmus be_control_look->DrawButtonBackground(menu, frame, frame, 222cb6afcb1SStephan Aßmus menuColor, flags, borders); 223cb6afcb1SStephan Aßmus } 224cb6afcb1SStephan Aßmus 225cb6afcb1SStephan Aßmus menu->MovePenTo(ContentLocation()); 226cb6afcb1SStephan Aßmus DrawContent(); 227cb6afcb1SStephan Aßmus menu->PopState(); 22841281cf3SAxel Dörfler } 22941281cf3SAxel Dörfler 23041281cf3SAxel Dörfler 23141281cf3SAxel Dörfler void 23241281cf3SAxel Dörfler TTeamMenuItem::DrawContent() 23341281cf3SAxel Dörfler { 23441281cf3SAxel Dörfler BMenu* menu = Menu(); 2352ce9bab8SJohn Scipione if (fIcon != NULL) { 23659deaf10SStephan Aßmus if (fIcon->ColorSpace() == B_RGBA32) { 23759deaf10SStephan Aßmus menu->SetDrawingMode(B_OP_ALPHA); 23859deaf10SStephan Aßmus menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); 2391687edd0SFredrik Holmqvist } else 24041281cf3SAxel Dörfler menu->SetDrawingMode(B_OP_OVER); 24141281cf3SAxel Dörfler 2421687edd0SFredrik Holmqvist BRect frame(Frame()); 24341281cf3SAxel Dörfler BRect iconBounds(fIcon->Bounds()); 24441281cf3SAxel Dörfler BRect dstRect(iconBounds); 2452ce9bab8SJohn Scipione float extra = fVertical ? 0.0f : -1.0f; 24641281cf3SAxel Dörfler BPoint contLoc = ContentLocation(); 2472ce9bab8SJohn Scipione BPoint drawLoc = contLoc + BPoint(kHPad, kVPad); 2481687edd0SFredrik Holmqvist 2492ce9bab8SJohn Scipione if (!fDrawLabel || (fVertical && iconBounds.Width() > 32)) { 2502ce9bab8SJohn Scipione float offsetx = contLoc.x 2512ce9bab8SJohn Scipione + ((frame.Width() - iconBounds.Width()) / 2) + extra; 2522ce9bab8SJohn Scipione float offsety = contLoc.y + 3.0f + extra; 2532ce9bab8SJohn Scipione 2542ce9bab8SJohn Scipione dstRect.OffsetTo(BPoint(offsetx, offsety)); 2552ce9bab8SJohn Scipione menu->DrawBitmapAsync(fIcon, dstRect); 2562ce9bab8SJohn Scipione 2572ce9bab8SJohn Scipione drawLoc.x = ((frame.Width() - LabelWidth()) / 2); 2582ce9bab8SJohn Scipione drawLoc.y = frame.top + iconBounds.Height() + 4.0f; 2592ce9bab8SJohn Scipione } else { 2602ce9bab8SJohn Scipione float offsetx = contLoc.x + kHPad; 2612ce9bab8SJohn Scipione float offsety = contLoc.y + 2622ce9bab8SJohn Scipione ((frame.Height() - iconBounds.Height()) / 2) + extra; 2632ce9bab8SJohn Scipione 2642ce9bab8SJohn Scipione dstRect.OffsetTo(BPoint(offsetx, offsety)); 26541281cf3SAxel Dörfler menu->DrawBitmapAsync(fIcon, dstRect); 26641281cf3SAxel Dörfler 26741281cf3SAxel Dörfler float labelHeight = fLabelAscent + fLabelDescent; 26841281cf3SAxel Dörfler drawLoc.x += iconBounds.Width() + kLabelOffset; 2692ce9bab8SJohn Scipione drawLoc.y = frame.top + ((frame.Height() - labelHeight) / 2) + extra; 2702ce9bab8SJohn Scipione } 2712ce9bab8SJohn Scipione 27241281cf3SAxel Dörfler menu->MovePenTo(drawLoc); 27341281cf3SAxel Dörfler } 27441281cf3SAxel Dörfler 27541281cf3SAxel Dörfler if (fDrawLabel) { 276cb6afcb1SStephan Aßmus menu->SetDrawingMode(B_OP_OVER); 277e19488b2SRyan Leavengood menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 27841281cf3SAxel Dörfler 27941281cf3SAxel Dörfler // override the drawing of the content when the item is disabled 28041281cf3SAxel Dörfler // the wrong lowcolor is used when the item is disabled since the 28141281cf3SAxel Dörfler // text color does not change 28241281cf3SAxel Dörfler DrawContentLabel(); 28341281cf3SAxel Dörfler } 28441281cf3SAxel Dörfler 2851dccb7aaSJohn Scipione if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando 2861dccb7aaSJohn Scipione && fBarView->ExpandoState()) { 2871dccb7aaSJohn Scipione DrawExpanderArrow(); 2881dccb7aaSJohn Scipione } 289cb6afcb1SStephan Aßmus } 29041281cf3SAxel Dörfler 29141281cf3SAxel Dörfler 29241281cf3SAxel Dörfler void 29341281cf3SAxel Dörfler TTeamMenuItem::DrawContentLabel() 29441281cf3SAxel Dörfler { 29541281cf3SAxel Dörfler BMenu* menu = Menu(); 29641281cf3SAxel Dörfler menu->MovePenBy(0, fLabelAscent); 29741281cf3SAxel Dörfler 29841281cf3SAxel Dörfler float cachedWidth = menu->StringWidth(Label()); 29941281cf3SAxel Dörfler if (Submenu() && fVertical) 30041281cf3SAxel Dörfler cachedWidth += 18; 30141281cf3SAxel Dörfler 30241281cf3SAxel Dörfler const char* label = Label(); 30341281cf3SAxel Dörfler char* truncLabel = NULL; 30441281cf3SAxel Dörfler float max = 0; 3051687edd0SFredrik Holmqvist 3062ce9bab8SJohn Scipione if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando) 30741281cf3SAxel Dörfler max = menu->MaxContentWidth() - kSwitchWidth; 30841281cf3SAxel Dörfler else 3092ce9bab8SJohn Scipione max = menu->MaxContentWidth() - 4.0f; 31041281cf3SAxel Dörfler 31141281cf3SAxel Dörfler if (max > 0) { 31241281cf3SAxel Dörfler BPoint penloc = menu->PenLocation(); 31341281cf3SAxel Dörfler BRect frame = Frame(); 31441281cf3SAxel Dörfler float offset = penloc.x - frame.left; 31541281cf3SAxel Dörfler if (cachedWidth + offset > max) { 31641281cf3SAxel Dörfler truncLabel = (char*)malloc(strlen(label) + 4); 31741281cf3SAxel Dörfler if (!truncLabel) 31841281cf3SAxel Dörfler return; 31941281cf3SAxel Dörfler TruncateLabel(max-offset, truncLabel); 32041281cf3SAxel Dörfler label = truncLabel; 32141281cf3SAxel Dörfler } 32241281cf3SAxel Dörfler } 32341281cf3SAxel Dörfler 32441281cf3SAxel Dörfler if (!label) 32541281cf3SAxel Dörfler label = Label(); 32641281cf3SAxel Dörfler 3271dccb7aaSJohn Scipione bool canHandle = !fBarView->Dragging() 3281dccb7aaSJohn Scipione || fBarView->AppCanHandleTypes(Signature()); 329249a4a18SStephan Aßmus if (_IsSelected() && IsEnabled() && canHandle) 330ab4e79c3SRyan Leavengood menu->SetLowColor(tint_color(menu->LowColor(), 33141281cf3SAxel Dörfler B_HIGHLIGHT_BACKGROUND_TINT)); 33241281cf3SAxel Dörfler else 333ab4e79c3SRyan Leavengood menu->SetLowColor(menu->LowColor()); 33441281cf3SAxel Dörfler 335859c3781SJohn Scipione if (IsSelected()) 336859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR)); 337859c3781SJohn Scipione else 338859c3781SJohn Scipione menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 339859c3781SJohn Scipione 34041281cf3SAxel Dörfler menu->DrawString(label); 34141281cf3SAxel Dörfler 34241281cf3SAxel Dörfler free(truncLabel); 34341281cf3SAxel Dörfler } 34441281cf3SAxel Dörfler 34541281cf3SAxel Dörfler 3465b0fd10dSJohn Scipione void 3471dccb7aaSJohn Scipione TTeamMenuItem::DrawExpanderArrow() 3485b0fd10dSJohn Scipione { 3495b0fd10dSJohn Scipione BMenu* menu = Menu(); 3505b0fd10dSJohn Scipione BRect frame(Frame()); 3515b0fd10dSJohn Scipione BRect rect(0, 0, kSwitchWidth, 10); 352*2b8d4131SJohn Scipione 3535b0fd10dSJohn Scipione rect.OffsetTo(BPoint(frame.right - rect.Width(), 3545b0fd10dSJohn Scipione ContentLocation().y + ((frame.Height() - rect.Height()) / 2))); 3555b0fd10dSJohn Scipione be_control_look->DrawArrowShape(menu, rect, rect, menu->LowColor(), 3561dccb7aaSJohn Scipione fArrowDirection, 0, B_DARKEN_3_TINT); 35741281cf3SAxel Dörfler } 35841281cf3SAxel Dörfler 35941281cf3SAxel Dörfler 36041281cf3SAxel Dörfler void 36141281cf3SAxel Dörfler TTeamMenuItem::ToggleExpandState(bool resizeWindow) 36241281cf3SAxel Dörfler { 36341281cf3SAxel Dörfler fExpanded = !fExpanded; 3641dccb7aaSJohn Scipione fArrowDirection = fExpanded ? BControlLook::B_DOWN_ARROW 3651dccb7aaSJohn Scipione : BControlLook::B_RIGHT_ARROW; 36641281cf3SAxel Dörfler 36741281cf3SAxel Dörfler if (fExpanded) { 36841281cf3SAxel Dörfler // Populate Menu() with the stuff from SubMenu(). 36941281cf3SAxel Dörfler TWindowMenu* sub = (static_cast<TWindowMenu*>(Submenu())); 3705b0fd10dSJohn Scipione if (sub != NULL) { 37141281cf3SAxel Dörfler // force the menu to update it's contents. 372bdfed6c0SAxel Dörfler bool locked = sub->LockLooper(); 373bdfed6c0SAxel Dörfler // if locking the looper failed, the menu is just not visible 374bdfed6c0SAxel Dörfler sub->AttachedToWindow(); 375bdfed6c0SAxel Dörfler if (locked) 376bdfed6c0SAxel Dörfler sub->UnlockLooper(); 377bdfed6c0SAxel Dörfler 37841281cf3SAxel Dörfler if (sub->CountItems() > 1) { 37941281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 38041281cf3SAxel Dörfler int myindex = parent->IndexOf(this) + 1; 38141281cf3SAxel Dörfler 38241281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 38341281cf3SAxel Dörfler int childIndex = 0; 38471bd3ba5SJonas Sundström int totalChildren = sub->CountItems() - 4; 38571bd3ba5SJonas Sundström // hide, show, close, separator. 38641281cf3SAxel Dörfler for (; childIndex < totalChildren; childIndex++) { 38771bd3ba5SJonas Sundström windowItem = static_cast<TWindowMenuItem*> 38871bd3ba5SJonas Sundström (sub->RemoveItem((int32)0)); 38941281cf3SAxel Dörfler parent->AddItem(windowItem, myindex + childIndex); 39041281cf3SAxel Dörfler windowItem->ExpandedItem(true); 39141281cf3SAxel Dörfler } 39241281cf3SAxel Dörfler sub->SetExpanded(true, myindex + childIndex); 39341281cf3SAxel Dörfler 39441281cf3SAxel Dörfler if (resizeWindow) 395afa1c291SJohn Scipione parent->SizeWindow(-1); 396c0107fb2SJonas Sundström } 39741281cf3SAxel Dörfler } 39841281cf3SAxel Dörfler } else { 39941281cf3SAxel Dörfler // Remove the goodies from the Menu() that should be in the SubMenu(); 40041281cf3SAxel Dörfler TWindowMenu* sub = static_cast<TWindowMenu*>(Submenu()); 4015b0fd10dSJohn Scipione if (sub != NULL) { 40241281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 40341281cf3SAxel Dörfler 40441281cf3SAxel Dörfler TWindowMenuItem* windowItem = NULL; 40541281cf3SAxel Dörfler int childIndex = parent->IndexOf(this) + 1; 40671bd3ba5SJonas Sundström while (!parent->SubmenuAt(childIndex) && childIndex 40771bd3ba5SJonas Sundström < parent->CountItems()) { 40871bd3ba5SJonas Sundström windowItem = static_cast<TWindowMenuItem*> 40971bd3ba5SJonas Sundström (parent->RemoveItem(childIndex)); 41041281cf3SAxel Dörfler sub->AddItem(windowItem, 0); 41141281cf3SAxel Dörfler windowItem->ExpandedItem(false); 41241281cf3SAxel Dörfler } 41341281cf3SAxel Dörfler sub->SetExpanded(false, 0); 41441281cf3SAxel Dörfler 41541281cf3SAxel Dörfler if (resizeWindow) 41649ff476dSJohn Scipione parent->SizeWindow(1); 417c0107fb2SJonas Sundström } 41841281cf3SAxel Dörfler } 41941281cf3SAxel Dörfler } 42041281cf3SAxel Dörfler 42141281cf3SAxel Dörfler 42241281cf3SAxel Dörfler TWindowMenuItem* 42341281cf3SAxel Dörfler TTeamMenuItem::ExpandedWindowItem(int32 id) 42441281cf3SAxel Dörfler { 4251687edd0SFredrik Holmqvist if (!fExpanded) { 4261687edd0SFredrik Holmqvist // Paranoia 42741281cf3SAxel Dörfler return NULL; 4281687edd0SFredrik Holmqvist } 42941281cf3SAxel Dörfler 43041281cf3SAxel Dörfler TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu()); 43141281cf3SAxel Dörfler int childIndex = parent->IndexOf(this) + 1; 43241281cf3SAxel Dörfler 43371bd3ba5SJonas Sundström while (!parent->SubmenuAt(childIndex) 43471bd3ba5SJonas Sundström && childIndex < parent->CountItems()) { 43571bd3ba5SJonas Sundström TWindowMenuItem* item 43671bd3ba5SJonas Sundström = static_cast<TWindowMenuItem*>(parent->ItemAt(childIndex)); 43741281cf3SAxel Dörfler if (item->ID() == id) 43841281cf3SAxel Dörfler return item; 43941281cf3SAxel Dörfler 44041281cf3SAxel Dörfler childIndex++; 44141281cf3SAxel Dörfler } 44241281cf3SAxel Dörfler return NULL; 44341281cf3SAxel Dörfler } 44441281cf3SAxel Dörfler 44541281cf3SAxel Dörfler 44641281cf3SAxel Dörfler BRect 44741281cf3SAxel Dörfler TTeamMenuItem::ExpanderBounds() const 44841281cf3SAxel Dörfler { 44941281cf3SAxel Dörfler BRect bounds(Frame()); 45041281cf3SAxel Dörfler bounds.left = bounds.right - kSwitchWidth; 45141281cf3SAxel Dörfler return bounds; 45241281cf3SAxel Dörfler } 45341281cf3SAxel Dörfler 454249a4a18SStephan Aßmus 4555b0fd10dSJohn Scipione // #pragma mark - Private methods 4565b0fd10dSJohn Scipione 4575b0fd10dSJohn Scipione 4585b0fd10dSJohn Scipione void 4595b0fd10dSJohn Scipione TTeamMenuItem::_InitData(BList* team, BBitmap* icon, char* name, char* sig, 4605b0fd10dSJohn Scipione float width, float height, bool drawLabel, bool vertical) 4615b0fd10dSJohn Scipione { 4625b0fd10dSJohn Scipione fTeam = team; 4635b0fd10dSJohn Scipione fIcon = icon; 4645b0fd10dSJohn Scipione fName = name; 4655b0fd10dSJohn Scipione fSig = sig; 4665b0fd10dSJohn Scipione if (fName == NULL) { 4675b0fd10dSJohn Scipione char temp[32]; 4685b0fd10dSJohn Scipione snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0)); 4695b0fd10dSJohn Scipione fName = strdup(temp); 4705b0fd10dSJohn Scipione } 4715b0fd10dSJohn Scipione SetLabel(fName); 4721dccb7aaSJohn Scipione fOverrideWidth = width; 4731dccb7aaSJohn Scipione fOverrideHeight = height; 4741dccb7aaSJohn Scipione fDrawLabel = drawLabel; 4751dccb7aaSJohn Scipione fVertical = vertical; 4765b0fd10dSJohn Scipione 4771dccb7aaSJohn Scipione fBarView = static_cast<TBarApp*>(be_app)->BarView(); 4785b0fd10dSJohn Scipione BFont font(be_plain_font); 4795b0fd10dSJohn Scipione fLabelWidth = ceilf(font.StringWidth(fName)); 4805b0fd10dSJohn Scipione font_height fontHeight; 4815b0fd10dSJohn Scipione font.GetHeight(&fontHeight); 4825b0fd10dSJohn Scipione fLabelAscent = ceilf(fontHeight.ascent); 4835b0fd10dSJohn Scipione fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading); 4845b0fd10dSJohn Scipione 4855b0fd10dSJohn Scipione fOverriddenSelected = false; 4865b0fd10dSJohn Scipione 4875b0fd10dSJohn Scipione fExpanded = false; 4881dccb7aaSJohn Scipione fArrowDirection = BControlLook::B_RIGHT_ARROW; 4895b0fd10dSJohn Scipione } 4905b0fd10dSJohn Scipione 4915b0fd10dSJohn Scipione 492249a4a18SStephan Aßmus bool 493249a4a18SStephan Aßmus TTeamMenuItem::_IsSelected() const 494249a4a18SStephan Aßmus { 495249a4a18SStephan Aßmus return IsSelected() || fOverriddenSelected; 496249a4a18SStephan Aßmus } 497