libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / deskbar / BarMenuBar.cpp
blob2189d127023d12f3c8e3608cdab657646262d518
1 /*
2 Open Tracker License
4 Terms and Conditions
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
32 holders.
33 All rights reserved.
37 #include "BarMenuBar.h"
39 #include <Bitmap.h>
40 #include <ControlLook.h>
41 #include <Debug.h>
42 #include <NodeInfo.h>
44 #include "icons.h"
46 #include "BarMenuTitle.h"
47 #include "BarView.h"
48 #include "BarWindow.h"
49 #include "DeskbarMenu.h"
50 #include "DeskbarUtils.h"
51 #include "ResourceSet.h"
52 #include "TeamMenu.h"
55 const float kSepItemWidth = 5.0f;
58 // #pragma mark - TSeparatorItem
61 TSeparatorItem::TSeparatorItem()
63 BSeparatorItem()
68 void
69 TSeparatorItem::Draw()
71 BMenu* menu = Menu();
72 if (menu == NULL)
73 return;
75 BRect frame(Frame());
76 frame.right = frame.left + kSepItemWidth;
77 rgb_color base = ui_color(B_MENU_BACKGROUND_COLOR);
79 menu->PushState();
81 menu->SetHighColor(tint_color(base, 1.22));
82 frame.top--;
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());
87 frame.left++;
89 // fill in background
90 be_control_look->DrawButtonBackground(menu, frame, frame, base);
92 menu->PopState();
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),
102 fBarView(barView),
103 fAppListMenuItem(NULL),
104 fSeparatorItem(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()
122 void
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();
129 } else
130 ResizeTo(width, height);
132 width -= 1;
134 if (fSeparatorItem != NULL)
135 fDeskbarMenuItem->SetContentSize(width - kSepItemWidth, height);
136 else {
137 int32 count = CountItems();
138 if (fDeskbarMenuItem)
139 fDeskbarMenuItem->SetContentSize(width / count, height);
140 if (fAppListMenuItem)
141 fAppListMenuItem->SetContentSize(width / count, height);
144 InvalidateLayout();
148 bool
149 TBarMenuBar::AddTeamMenu()
151 if (CountItems() > 1)
152 return false;
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);
162 if (added)
163 SmartResize(frame.Width() - 1.0f, frame.Height());
164 else
165 SmartResize(frame.Width(), frame.Height());
167 return added;
171 bool
172 TBarMenuBar::RemoveTeamMenu()
174 if (CountItems() < 2)
175 return false;
177 bool removed = false;
179 if (fAppListMenuItem != NULL && RemoveItem(fAppListMenuItem)) {
180 delete fAppListMenuItem;
181 fAppListMenuItem = NULL;
182 SmartResize(-1, -1);
183 removed = true;
186 return removed;
190 bool
191 TBarMenuBar::AddSeparatorItem()
193 if (CountItems() > 1)
194 return false;
196 BRect frame(Frame());
198 delete fSeparatorItem;
199 fSeparatorItem = new TSeparatorItem();
201 bool added = AddItem(fSeparatorItem);
203 if (added)
204 SmartResize(frame.Width() - 1.0f, frame.Height());
205 else
206 SmartResize(frame.Width(), frame.Height());
208 return added;
212 bool
213 TBarMenuBar::RemoveSeperatorItem()
215 if (CountItems() < 2)
216 return false;
218 bool removed = false;
220 if (fSeparatorItem != NULL && RemoveItem(fSeparatorItem)) {
221 delete fSeparatorItem;
222 fSeparatorItem = NULL;
223 SmartResize(-1, -1);
224 removed = true;
227 return removed;
231 void
232 TBarMenuBar::Draw(BRect updateRect)
234 // skip the fancy BMenuBar drawing code
235 BMenu::Draw(updateRect);
239 void
240 TBarMenuBar::DrawBackground(BRect updateRect)
242 BMenu::DrawBackground(updateRect);
246 void
247 TBarMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
249 // the following code parallels that in ExpandoMenuBar for DnD tracking
251 if (!message) {
252 // force a cleanup
253 fBarView->DragStop(true);
254 BMenuBar::MouseMoved(where, code, message);
255 return;
258 switch (code) {
259 case B_ENTERED_VIEW:
261 BPoint loc;
262 uint32 buttons;
263 GetMouse(&loc, &buttons);
264 if (message != NULL && buttons != 0) {
265 // attempt to start DnD tracking
266 fBarView->CacheDragData(const_cast<BMessage*>(message));
267 MouseDown(loc);
269 break;
273 BMenuBar::MouseMoved(where, code, message);
277 static void
278 init_tracking_hook(BMenuItem* item, bool (*hookFunction)(BMenu*, void*),
279 void* state)
281 if (!item)
282 return;
284 BMenu* windowMenu = item->Submenu();
285 if (windowMenu) {
286 // have a menu, set the tracking hook
287 windowMenu->SetTrackingHook(hookFunction, state);
292 void
293 TBarMenuBar::InitTrackingHook(bool (*hookFunction)(BMenu*, void*),
294 void* state, bool both)
296 BPoint loc;
297 uint32 buttons;
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);