6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
30 trademarks of Be Incorporated in the United States and other countries. Other
31 brand product names are registered trademarks or trademarks of their respective
37 #include "TeamMenuItem.h"
44 #include <ControlLook.h>
49 #include <Resources.h>
52 #include "BarMenuBar.h"
54 #include "ExpandoMenuBar.h"
55 #include "ResourceSet.h"
56 #include "ShowHideMenuItem.h"
58 #include "WindowMenu.h"
59 #include "WindowMenuItem.h"
62 const float kHPad
= 8.0f
;
63 const float kVPad
= 2.0f
;
64 const float kLabelOffset
= 8.0f
;
65 const float kSwitchWidth
= 12.0f
;
68 // #pragma mark - TTeamMenuItem
71 TTeamMenuItem::TTeamMenuItem(BList
* team
, BBitmap
* icon
, char* name
,
72 char* signature
, float width
, float height
)
74 TTruncatableMenuItem(new TWindowMenu(team
, signature
))
76 _Init(team
, icon
, name
, signature
, width
, height
);
80 TTeamMenuItem::TTeamMenuItem(float width
, float height
)
82 TTruncatableMenuItem("", NULL
)
84 _Init(NULL
, NULL
, strdup(""), strdup(""), width
, height
);
88 TTeamMenuItem::~TTeamMenuItem()
97 TTeamMenuItem::Invoke(BMessage
* message
)
99 if (fBarView
->InvokeItem(Signature())) {
100 // handles drop on application
104 // if the app could not handle the drag message
105 // and we were dragging, then kill the drag
106 // should never get here, disabled item will not invoke
107 if (fBarView
!= NULL
&& fBarView
->Dragging())
108 fBarView
->DragStop();
110 // bring to front or minimize shortcuts
111 uint32 mods
= modifiers();
112 if (mods
& B_CONTROL_KEY
) {
113 TShowHideMenuItem::TeamShowHideCommon((mods
& B_SHIFT_KEY
)
114 ? B_MINIMIZE_WINDOW
: B_BRING_TO_FRONT
, Teams());
117 return BMenuItem::Invoke(message
);
122 TTeamMenuItem::SetOverrideSelected(bool selected
)
124 fOverriddenSelected
= selected
;
130 TTeamMenuItem::SetIcon(BBitmap
* icon
) {
137 TTeamMenuItem::GetContentSize(float* width
, float* height
)
142 iconBounds
= fIcon
->Bounds();
144 iconBounds
= BRect(0, 0, kMinimumIconSize
- 1, kMinimumIconSize
- 1);
146 BMenuItem::GetContentSize(width
, height
);
148 if (fOverrideWidth
!= -1.0f
)
149 *width
= fOverrideWidth
;
151 *width
= kHPad
+ iconBounds
.Width() + kHPad
;
152 if (iconBounds
.Width() <= 32
153 && !static_cast<TBarApp
*>(be_app
)->Settings()->hideLabels
) {
154 *width
+= LabelWidth() + kHPad
;
158 if (fOverrideHeight
!= -1.0f
)
159 *height
= fOverrideHeight
;
161 if (fBarView
->Vertical()) {
162 *height
= iconBounds
.Height() + kVPad
* 2;
163 if (!static_cast<TBarApp
*>(be_app
)->Settings()->hideLabels
164 && iconBounds
.Width() > 32) {
165 *height
+= fLabelAscent
+ fLabelDescent
;
168 *height
= iconBounds
.Height() + kVPad
* 2;
176 TTeamMenuItem::Draw()
178 BRect frame
= Frame();
179 BMenu
* menu
= Menu();
183 rgb_color menuColor
= menu
->LowColor();
184 bool canHandle
= !fBarView
->Dragging()
185 || fBarView
->AppCanHandleTypes(Signature());
187 if (_IsSelected() && canHandle
)
188 flags
|= BControlLook::B_ACTIVATED
;
190 uint32 borders
= BControlLook::B_TOP_BORDER
;
191 if (fBarView
->Vertical()) {
192 menu
->SetHighColor(tint_color(menuColor
, B_DARKEN_1_TINT
));
193 borders
|= BControlLook::B_LEFT_BORDER
194 | BControlLook::B_RIGHT_BORDER
;
195 menu
->StrokeLine(frame
.LeftBottom(), frame
.RightBottom());
198 be_control_look
->DrawMenuBarBackground(menu
, frame
, frame
,
199 menuColor
, flags
, borders
);
201 if (flags
& BControlLook::B_ACTIVATED
)
202 menu
->SetHighColor(tint_color(menuColor
, B_DARKEN_3_TINT
));
204 menu
->SetHighColor(tint_color(menuColor
, 1.22));
205 borders
|= BControlLook::B_BOTTOM_BORDER
;
206 menu
->StrokeLine(frame
.LeftTop(), frame
.LeftBottom());
209 be_control_look
->DrawButtonBackground(menu
, frame
, frame
,
210 menuColor
, flags
, borders
);
213 menu
->MovePenTo(ContentLocation());
221 TTeamMenuItem::DrawContent()
223 BMenu
* menu
= Menu();
225 if (fIcon
->ColorSpace() == B_RGBA32
) {
226 menu
->SetDrawingMode(B_OP_ALPHA
);
227 menu
->SetBlendingMode(B_PIXEL_ALPHA
, B_ALPHA_OVERLAY
);
229 menu
->SetDrawingMode(B_OP_OVER
);
231 BRect frame
= Frame();
232 BRect iconBounds
= fIcon
->Bounds();
233 BRect updateRect
= iconBounds
;
234 float extra
= fBarView
->Vertical() ? 0.0f
: -1.0f
;
235 BPoint contentLocation
= ContentLocation();
236 BPoint drawLocation
= contentLocation
+ BPoint(kHPad
, kVPad
);
238 if (static_cast<TBarApp
*>(be_app
)->Settings()->hideLabels
239 || (fBarView
->Vertical() && iconBounds
.Width() > 32)) {
240 float offsetx
= contentLocation
.x
241 + ((frame
.Width() - iconBounds
.Width()) / 2) + extra
;
242 float offsety
= contentLocation
.y
+ 3.0f
+ extra
;
244 updateRect
.OffsetTo(BPoint(offsetx
, offsety
));
245 menu
->DrawBitmapAsync(fIcon
, updateRect
);
247 drawLocation
.x
= ((frame
.Width() - LabelWidth()) / 2);
248 drawLocation
.y
= frame
.top
+ iconBounds
.Height() + kVPad
* 2;
250 float offsetx
= contentLocation
.x
+ kHPad
;
251 float offsety
= contentLocation
.y
+
252 ((frame
.Height() - iconBounds
.Height()) / 2) + extra
;
254 updateRect
.OffsetTo(BPoint(offsetx
, offsety
));
255 menu
->DrawBitmapAsync(fIcon
, updateRect
);
257 float labelHeight
= fLabelAscent
+ fLabelDescent
;
258 drawLocation
.x
+= iconBounds
.Width() + kLabelOffset
;
259 drawLocation
.y
= frame
.top
+ ((frame
.Height() - labelHeight
) / 2)
263 menu
->MovePenTo(drawLocation
);
266 menu
->SetDrawingMode(B_OP_OVER
);
267 menu
->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR
));
269 // override the drawing of the content when the item is disabled
270 // the wrong lowcolor is used when the item is disabled since the
271 // text color does not change
272 menu
->MovePenBy(0, fLabelAscent
);
274 bool canHandle
= !fBarView
->Dragging()
275 || fBarView
->AppCanHandleTypes(Signature());
276 if (_IsSelected() && IsEnabled() && canHandle
)
277 menu
->SetLowColor(tint_color(menu
->LowColor(),
278 B_HIGHLIGHT_BACKGROUND_TINT
));
280 menu
->SetLowColor(menu
->LowColor());
283 menu
->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR
));
285 menu
->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR
));
287 if (!static_cast<TBarApp
*>(be_app
)->Settings()->hideLabels
) {
288 float labelWidth
= menu
->StringWidth(Label());
289 BPoint penLocation
= menu
->PenLocation();
290 float offset
= penLocation
.x
- Frame().left
;
291 menu
->DrawString(Label(labelWidth
+ offset
));
294 if (fBarView
->Vertical()
295 && static_cast<TBarApp
*>(be_app
)->Settings()->superExpando
296 && fBarView
->ExpandoState()) {
303 TTeamMenuItem::DrawExpanderArrow()
305 BMenu
* menu
= Menu();
306 BRect frame
= Frame();
307 BRect
rect(0.0f
, 0.0f
, kSwitchWidth
, kHPad
+ 2.0f
);
309 rect
.OffsetTo(BPoint(frame
.right
- rect
.Width(),
310 ContentLocation().y
+ ((frame
.Height() - rect
.Height()) / 2)));
311 be_control_look
->DrawArrowShape(menu
, rect
, rect
, menu
->LowColor(),
312 fArrowDirection
, 0, B_DARKEN_3_TINT
);
317 TTeamMenuItem::ToggleExpandState(bool resizeWindow
)
319 fExpanded
= !fExpanded
;
320 fArrowDirection
= fExpanded
? BControlLook::B_DOWN_ARROW
321 : BControlLook::B_RIGHT_ARROW
;
324 // Populate Menu() with the stuff from SubMenu().
325 TWindowMenu
* sub
= (static_cast<TWindowMenu
*>(Submenu()));
327 // force the menu to update it's contents.
328 bool locked
= sub
->LockLooper();
329 // if locking the looper failed, the menu is just not visible
330 sub
->AttachedToWindow();
334 if (sub
->CountItems() > 1) {
335 TExpandoMenuBar
* parent
= static_cast<TExpandoMenuBar
*>(Menu());
336 int myindex
= parent
->IndexOf(this) + 1;
338 TWindowMenuItem
* windowItem
= NULL
;
339 int32 childIndex
= 0;
340 int32 totalChildren
= sub
->CountItems() - 4;
341 // hide, show, close, separator.
342 for (; childIndex
< totalChildren
; childIndex
++) {
343 windowItem
= static_cast<TWindowMenuItem
*>
344 (sub
->RemoveItem((int32
)0));
345 parent
->AddItem(windowItem
, myindex
+ childIndex
);
346 windowItem
->SetExpanded(true);
348 sub
->SetExpanded(true, myindex
+ childIndex
);
351 parent
->SizeWindow(-1);
355 // Remove the goodies from the Menu() that should be in the SubMenu();
356 TWindowMenu
* sub
= static_cast<TWindowMenu
*>(Submenu());
358 TExpandoMenuBar
* parent
= static_cast<TExpandoMenuBar
*>(Menu());
360 TWindowMenuItem
* windowItem
= NULL
;
361 int32 childIndex
= parent
->IndexOf(this) + 1;
362 while (parent
->SubmenuAt(childIndex
) == NULL
363 && childIndex
< parent
->CountItems()) {
365 = static_cast<TWindowMenuItem
*>(parent
->RemoveItem(childIndex
));
366 sub
->AddItem(windowItem
, 0);
367 windowItem
->SetExpanded(false);
369 sub
->SetExpanded(false, 0);
372 parent
->SizeWindow(1);
379 TTeamMenuItem::ExpandedWindowItem(int32 id
)
386 TExpandoMenuBar
* parent
= static_cast<TExpandoMenuBar
*>(Menu());
387 int childIndex
= parent
->IndexOf(this) + 1;
389 while (!parent
->SubmenuAt(childIndex
)
390 && childIndex
< parent
->CountItems()) {
391 TWindowMenuItem
* item
392 = static_cast<TWindowMenuItem
*>(parent
->ItemAt(childIndex
));
393 if (item
->ID() == id
)
403 TTeamMenuItem::ExpanderBounds() const
405 BRect
bounds(Frame());
406 bounds
.left
= bounds
.right
- kSwitchWidth
;
411 // #pragma mark - Private methods
415 TTeamMenuItem::_Init(BList
* team
, BBitmap
* icon
, char* name
, char* signature
,
416 float width
, float height
)
420 fSignature
= signature
;
424 snprintf(temp
, sizeof(temp
), "team %ld", (addr_t
)team
->ItemAt(0));
430 fOverrideWidth
= width
;
431 fOverrideHeight
= height
;
433 fBarView
= static_cast<TBarApp
*>(be_app
)->BarView();
435 BFont
font(be_plain_font
);
436 fLabelWidth
= ceilf(font
.StringWidth(name
));
437 font_height fontHeight
;
438 font
.GetHeight(&fontHeight
);
439 fLabelAscent
= ceilf(fontHeight
.ascent
);
440 fLabelDescent
= ceilf(fontHeight
.descent
+ fontHeight
.leading
);
442 fOverriddenSelected
= false;
445 fArrowDirection
= BControlLook::B_RIGHT_ARROW
;
450 TTeamMenuItem::_IsSelected() const
452 return IsSelected() || fOverriddenSelected
;