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 "WindowMenuItem.h"
41 #include <NaturalCompare.h>
44 #include "BarMenuBar.h"
46 #include "ExpandoMenuBar.h"
47 #include "ResourceSet.h"
49 #include "WindowMenu.h"
54 const float kHPad
= 10.0f
;
55 const float kVPad
= 2.0f
;
56 const float kLabelOffset
= 8.0f
;
58 const BRect
kIconRect(1.0f
, 1.0f
, 13.0f
, 14.0f
);
61 // #pragma mark - TWindowMenuItem
64 TWindowMenuItem::TWindowMenuItem(const char* name
, int32 id
, bool mini
,
65 bool currentWorkspace
, bool dragging
)
67 TTruncatableMenuItem(name
, NULL
),
70 fCurrentWorkSpace(currentWorkspace
),
73 fRequireUpdate(false),
81 TWindowMenuItem::GetContentSize(float* width
, float* height
)
85 *width
= kHPad
+ fLabelWidth
+ kHPad
;
87 *width
+= fBitmap
->Bounds().Width() + kLabelOffset
;
89 *width
= Frame().Width()/* - kHPad*/;
92 // Note: when the item is in "expanded mode", ie embedded into
93 // the Deskbar itself, then a truncated label is used in SetLabel()
94 // The code here is ignorant of this fact, but it doesn't seem to
98 *height
= (fID
>= 0) ? fBitmap
->Bounds().Height() : 0.0f
;
99 float labelHeight
= fLabelAscent
+ fLabelDescent
;
100 *height
= (labelHeight
> *height
) ? labelHeight
: *height
;
101 *height
+= kVPad
* 2;
107 TWindowMenuItem::Draw()
114 // TODO: Tint this smartly based on the low color, this does
116 rgb_color menuColor
= tint_color(ui_color(B_MENU_BACKGROUND_COLOR
), 1.07);
117 BRect
frame(Frame());
118 BMenu
* menu
= Menu();
122 // if not selected or being tracked on, fill with gray
123 TBarView
* barview
= (static_cast<TBarApp
*>(be_app
))->BarView();
124 if ((!IsSelected() && !menu
->IsRedrawAfterSticky())
125 || barview
->Dragging() || !IsEnabled()) {
127 rgb_color shadow
= tint_color(menuColor
, 1.09);
128 menu
->SetHighColor(shadow
);
129 frame
.right
= frame
.left
+ kHPad
/ 2;
130 menu
->FillRect(frame
);
132 menu
->SetHighColor(menuColor
);
133 frame
.left
= frame
.right
+ 1;
134 frame
.right
= Frame().right
;
135 menu
->FillRect(frame
);
138 if (IsEnabled() && IsSelected() && !menu
->IsRedrawAfterSticky()) {
140 rgb_color backColor
= tint_color(menuColor
,
141 B_HIGHLIGHT_BACKGROUND_TINT
);
142 menu
->SetLowColor(backColor
);
143 menu
->SetHighColor(backColor
);
144 menu
->FillRect(frame
);
146 menu
->SetLowColor(menuColor
);
147 menu
->SetHighColor(menuColor
);
157 TWindowMenuItem::DrawContent()
159 BMenu
* menu
= Menu();
160 BPoint contentLocation
= ContentLocation() + BPoint(kHPad
, kVPad
);
163 menu
->SetDrawingMode(B_OP_OVER
);
165 float width
= fBitmap
->Bounds().Width();
167 contentLocation
.x
-= 8;
169 menu
->MovePenTo(contentLocation
);
170 menu
->DrawBitmapAsync(fBitmap
);
173 contentLocation
.x
+= 8;
175 contentLocation
.x
+= kIconRect
.Width() + kLabelOffset
;
177 contentLocation
.y
+= fLabelAscent
;
179 menu
->SetDrawingMode(B_OP_COPY
);
180 menu
->MovePenTo(contentLocation
);
183 menu
->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR
));
185 menu
->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR
));
187 float labelWidth
= menu
->StringWidth(Label());
188 BPoint penLocation
= menu
->PenLocation();
189 float offset
= penLocation
.x
- Frame().left
;
191 menu
->DrawString(Label(labelWidth
+ offset
));
196 TWindowMenuItem::Invoke(BMessage
* /*message*/)
200 int32 action
= (modifiers() & B_CONTROL_KEY
) != 0
201 ? B_MINIMIZE_WINDOW
: B_BRING_TO_FRONT
;
204 BRect
zoomRect(0.0f
, 0.0f
, 0.0f
, 0.0f
);
207 item
= Menu()->Superitem();
211 if (item
->Menu()->Window() != NULL
) {
212 zoomRect
= item
->Menu()->ConvertToScreen(item
->Frame());
213 doZoom
= (fMini
&& action
== B_BRING_TO_FRONT
)
214 || (!fMini
&& action
== B_MINIMIZE_WINDOW
);
217 do_window_action(fID
, action
, zoomRect
, doZoom
);
225 TWindowMenuItem::SetTo(const char* name
, int32 id
, bool mini
,
226 bool currentWorkspace
, bool dragging
)
228 fModified
= fCurrentWorkSpace
!= currentWorkspace
|| fMini
!= mini
;
232 fCurrentWorkSpace
= currentWorkspace
;
233 fDragging
= dragging
;
234 fRequireUpdate
= false;
241 TWindowMenuItem::InsertIndexFor(BMenu
* menu
, int32 startIndex
,
242 TWindowMenuItem
* newItem
)
244 for (int32 index
= startIndex
;; index
++) {
245 TWindowMenuItem
* item
246 = dynamic_cast<TWindowMenuItem
*>(menu
->ItemAt(index
));
248 || NaturalCompare(item
->Label(), newItem
->Label()) > 0) {
255 // #pragma mark - private methods
259 TWindowMenuItem::_Init(const char* name
)
262 fBitmap
= fCurrentWorkSpace
263 ? AppResSet()->FindBitmap(B_MESSAGE_TYPE
, R_WindowHiddenIcon
)
264 : AppResSet()->FindBitmap(B_MESSAGE_TYPE
, R_WindowHiddenSwitchIcon
);
266 fBitmap
= fCurrentWorkSpace
267 ? AppResSet()->FindBitmap(B_MESSAGE_TYPE
, R_WindowShownIcon
)
268 : AppResSet()->FindBitmap(B_MESSAGE_TYPE
, R_WindowShownSwitchIcon
);
271 BFont
font(be_plain_font
);
272 fLabelWidth
= ceilf(font
.StringWidth(name
));
273 font_height fontHeight
;
274 font
.GetHeight(&fontHeight
);
275 fLabelAscent
= ceilf(fontHeight
.ascent
);
276 fLabelDescent
= ceilf(fontHeight
.descent
+ fontHeight
.leading
);