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 "BarMenuBar.h"
40 #include <ControlLook.h>
46 #include "BarMenuTitle.h"
48 #include "BarWindow.h"
49 #include "DeskbarMenu.h"
50 #include "DeskbarUtils.h"
51 #include "ResourceSet.h"
55 const float kSepItemWidth
= 5.0f
;
58 // #pragma mark - TSeparatorItem
61 TSeparatorItem::TSeparatorItem()
69 TSeparatorItem::Draw()
76 frame
.right
= frame
.left
+ kSepItemWidth
;
77 rgb_color base
= ui_color(B_MENU_BACKGROUND_COLOR
);
81 menu
->SetHighColor(tint_color(base
, 1.22));
83 // need to expand the frame for some reason
85 // stroke a darker line on the left edge
86 menu
->StrokeLine(frame
.LeftTop(), frame
.LeftBottom());
90 be_control_look
->DrawButtonBackground(menu
, frame
, frame
, base
);
96 // #pragma mark - TBarMenuBar
99 TBarMenuBar::TBarMenuBar(BRect frame
, const char* name
, TBarView
* barView
)
101 BMenuBar(frame
, name
, B_FOLLOW_NONE
, B_ITEMS_IN_ROW
, false),
103 fAppListMenuItem(NULL
),
106 SetItemMargins(0.0f
, 0.0f
, 0.0f
, 0.0f
);
108 TDeskbarMenu
* beMenu
= new TDeskbarMenu(barView
);
109 TBarWindow::SetDeskbarMenu(beMenu
);
111 fDeskbarMenuItem
= new TBarMenuTitle(0.0f
, 0.0f
,
112 AppResSet()->FindBitmap(B_MESSAGE_TYPE
, R_LeafLogoBitmap
), beMenu
);
113 AddItem(fDeskbarMenuItem
);
117 TBarMenuBar::~TBarMenuBar()
123 TBarMenuBar::SmartResize(float width
, float height
)
125 if (width
== -1.0f
&& height
== -1.0f
) {
126 BRect frame
= Frame();
127 width
= frame
.Width();
128 height
= frame
.Height();
130 ResizeTo(width
, height
);
134 if (fSeparatorItem
!= NULL
)
135 fDeskbarMenuItem
->SetContentSize(width
- kSepItemWidth
, height
);
137 int32 count
= CountItems();
138 if (fDeskbarMenuItem
)
139 fDeskbarMenuItem
->SetContentSize(width
/ count
, height
);
140 if (fAppListMenuItem
)
141 fAppListMenuItem
->SetContentSize(width
/ count
, height
);
149 TBarMenuBar::AddTeamMenu()
151 if (CountItems() > 1)
154 BRect
frame(Frame());
156 delete fAppListMenuItem
;
157 fAppListMenuItem
= new TBarMenuTitle(0.0f
, 0.0f
,
158 AppResSet()->FindBitmap(B_MESSAGE_TYPE
, R_TeamIcon
), new TTeamMenu());
160 bool added
= AddItem(fAppListMenuItem
);
163 SmartResize(frame
.Width() - 1.0f
, frame
.Height());
165 SmartResize(frame
.Width(), frame
.Height());
172 TBarMenuBar::RemoveTeamMenu()
174 if (CountItems() < 2)
177 bool removed
= false;
179 if (fAppListMenuItem
!= NULL
&& RemoveItem(fAppListMenuItem
)) {
180 delete fAppListMenuItem
;
181 fAppListMenuItem
= NULL
;
191 TBarMenuBar::AddSeparatorItem()
193 if (CountItems() > 1)
196 BRect
frame(Frame());
198 delete fSeparatorItem
;
199 fSeparatorItem
= new TSeparatorItem();
201 bool added
= AddItem(fSeparatorItem
);
204 SmartResize(frame
.Width() - 1.0f
, frame
.Height());
206 SmartResize(frame
.Width(), frame
.Height());
213 TBarMenuBar::RemoveSeperatorItem()
215 if (CountItems() < 2)
218 bool removed
= false;
220 if (fSeparatorItem
!= NULL
&& RemoveItem(fSeparatorItem
)) {
221 delete fSeparatorItem
;
222 fSeparatorItem
= NULL
;
232 TBarMenuBar::Draw(BRect updateRect
)
234 // skip the fancy BMenuBar drawing code
235 BMenu::Draw(updateRect
);
240 TBarMenuBar::DrawBackground(BRect updateRect
)
242 BMenu::DrawBackground(updateRect
);
247 TBarMenuBar::MouseMoved(BPoint where
, uint32 code
, const BMessage
* message
)
249 // the following code parallels that in ExpandoMenuBar for DnD tracking
253 fBarView
->DragStop(true);
254 BMenuBar::MouseMoved(where
, code
, message
);
263 GetMouse(&loc
, &buttons
);
264 if (message
!= NULL
&& buttons
!= 0) {
265 // attempt to start DnD tracking
266 fBarView
->CacheDragData(const_cast<BMessage
*>(message
));
273 BMenuBar::MouseMoved(where
, code
, message
);
278 init_tracking_hook(BMenuItem
* item
, bool (*hookFunction
)(BMenu
*, void*),
284 BMenu
* windowMenu
= item
->Submenu();
286 // have a menu, set the tracking hook
287 windowMenu
->SetTrackingHook(hookFunction
, state
);
293 TBarMenuBar::InitTrackingHook(bool (*hookFunction
)(BMenu
*, void*),
294 void* state
, bool both
)
298 GetMouse(&loc
, &buttons
);
299 // set the hook functions for the two menus
300 // will always have the deskbar menu
301 // may have the app menu as well (mini mode)
302 if (fDeskbarMenuItem
->Frame().Contains(loc
) || both
)
303 init_tracking_hook(fDeskbarMenuItem
, hookFunction
, state
);
305 if (fAppListMenuItem
&& (fAppListMenuItem
->Frame().Contains(loc
) || both
))
306 init_tracking_hook(fAppListMenuItem
, hookFunction
, state
);