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 2941281cf3SAxel Dörfler Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 3041281cf3SAxel Dörfler of Be Incorporated in the United States and other countries. Other brand product 3141281cf3SAxel Dörfler names are registered trademarks or trademarks of their respective holders. 3241281cf3SAxel Dörfler All rights reserved. 3341281cf3SAxel Dörfler */ 3441281cf3SAxel Dörfler 3541281cf3SAxel Dörfler #include <Debug.h> 36*1cf94bf9SStephan Aßmus 37*1cf94bf9SStephan Aßmus #include "BarMenuBar.h" 38*1cf94bf9SStephan Aßmus 39*1cf94bf9SStephan Aßmus #include <string.h> 40*1cf94bf9SStephan Aßmus 4141281cf3SAxel Dörfler #include <Bitmap.h> 4241281cf3SAxel Dörfler #include <NodeInfo.h> 4341281cf3SAxel Dörfler 4441281cf3SAxel Dörfler #include "icons.h" 4541281cf3SAxel Dörfler #include "icons_logo.h" 4641281cf3SAxel Dörfler #include "BarWindow.h" 4741281cf3SAxel Dörfler #include "BeMenu.h" 4841281cf3SAxel Dörfler #include "DeskBarUtils.h" 4941281cf3SAxel Dörfler #include "ResourceSet.h" 5041281cf3SAxel Dörfler #include "TeamMenu.h" 5141281cf3SAxel Dörfler 5241281cf3SAxel Dörfler 5341281cf3SAxel Dörfler TBarMenuBar::TBarMenuBar(TBarView *bar, BRect frame, const char *name) 5441281cf3SAxel Dörfler : BMenuBar(frame, name, B_FOLLOW_NONE, B_ITEMS_IN_ROW, false), 5541281cf3SAxel Dörfler fBarView(bar), 5641281cf3SAxel Dörfler fAppListMenuItem(NULL) 5741281cf3SAxel Dörfler { 5841281cf3SAxel Dörfler SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f); 5941281cf3SAxel Dörfler 6041281cf3SAxel Dörfler TBeMenu *beMenu = new TBeMenu(bar); 6141281cf3SAxel Dörfler TBarWindow::SetBeMenu(beMenu); 6241281cf3SAxel Dörfler 6341281cf3SAxel Dörfler fBeMenuItem = new TBarMenuTitle(frame.Width(), frame.Height(), 6441281cf3SAxel Dörfler AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_BeLogoIcon), beMenu); 6541281cf3SAxel Dörfler AddItem(fBeMenuItem); 6641281cf3SAxel Dörfler } 6741281cf3SAxel Dörfler 6841281cf3SAxel Dörfler 6941281cf3SAxel Dörfler TBarMenuBar::~TBarMenuBar() 7041281cf3SAxel Dörfler { 7141281cf3SAxel Dörfler } 7241281cf3SAxel Dörfler 7341281cf3SAxel Dörfler 7441281cf3SAxel Dörfler void 7541281cf3SAxel Dörfler TBarMenuBar::SmartResize(float width, float height) 7641281cf3SAxel Dörfler { 777da06231SAxel Dörfler if (width == -1.0f && height == -1.0f) { 7841281cf3SAxel Dörfler BRect frame = Frame(); 7941281cf3SAxel Dörfler width = frame.Width(); 8041281cf3SAxel Dörfler height = frame.Height(); 8141281cf3SAxel Dörfler } else 8241281cf3SAxel Dörfler ResizeTo(width, height); 8341281cf3SAxel Dörfler 8441281cf3SAxel Dörfler width -= 1; 8541281cf3SAxel Dörfler 8641281cf3SAxel Dörfler int32 count = CountItems(); 8741281cf3SAxel Dörfler if (fBeMenuItem) 8841281cf3SAxel Dörfler fBeMenuItem->SetWidthHeight(width / count, height); 8941281cf3SAxel Dörfler if (fAppListMenuItem) 9041281cf3SAxel Dörfler fAppListMenuItem->SetWidthHeight(width / count, height); 9141281cf3SAxel Dörfler 9241281cf3SAxel Dörfler InvalidateLayout(); 9341281cf3SAxel Dörfler } 9441281cf3SAxel Dörfler 9541281cf3SAxel Dörfler 9641281cf3SAxel Dörfler void 9741281cf3SAxel Dörfler TBarMenuBar::AddTeamMenu() 9841281cf3SAxel Dörfler { 9941281cf3SAxel Dörfler if (CountItems() > 1) 10041281cf3SAxel Dörfler return; 10141281cf3SAxel Dörfler 10241281cf3SAxel Dörfler BRect frame(Frame()); 10341281cf3SAxel Dörfler delete fAppListMenuItem; 10441281cf3SAxel Dörfler 10541281cf3SAxel Dörfler fAppListMenuItem = new TBarMenuTitle(0.0f, 0.0f, 10641281cf3SAxel Dörfler AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_TeamIcon), new TTeamMenu()); 10741281cf3SAxel Dörfler AddItem(fAppListMenuItem); 10841281cf3SAxel Dörfler SmartResize(frame.Width() - 1.0f, frame.Height()); 10941281cf3SAxel Dörfler } 11041281cf3SAxel Dörfler 11141281cf3SAxel Dörfler 11241281cf3SAxel Dörfler void 11341281cf3SAxel Dörfler TBarMenuBar::RemoveTeamMenu() 11441281cf3SAxel Dörfler { 11541281cf3SAxel Dörfler if (CountItems() < 2) 11641281cf3SAxel Dörfler return; 11741281cf3SAxel Dörfler 11841281cf3SAxel Dörfler if (fAppListMenuItem) { 11941281cf3SAxel Dörfler RemoveItem((BMenuItem *)fAppListMenuItem); 12041281cf3SAxel Dörfler delete fAppListMenuItem; 12141281cf3SAxel Dörfler fAppListMenuItem = NULL; 12241281cf3SAxel Dörfler } 12341281cf3SAxel Dörfler 12441281cf3SAxel Dörfler BRect frame = Frame(); 12541281cf3SAxel Dörfler SmartResize(frame.Width(), frame.Height()); 12641281cf3SAxel Dörfler } 12741281cf3SAxel Dörfler 12841281cf3SAxel Dörfler 12941281cf3SAxel Dörfler void 13041281cf3SAxel Dörfler TBarMenuBar::Draw(BRect rect) 13141281cf3SAxel Dörfler { 13241281cf3SAxel Dörfler // want to skip the fancy BMenuBar drawing code. 13341281cf3SAxel Dörfler BMenu::Draw(rect); 13441281cf3SAxel Dörfler } 13541281cf3SAxel Dörfler 13641281cf3SAxel Dörfler 13741281cf3SAxel Dörfler void 13841281cf3SAxel Dörfler TBarMenuBar::DrawBackground(BRect rect) 13941281cf3SAxel Dörfler { 14041281cf3SAxel Dörfler BMenu::DrawBackground(rect); 14141281cf3SAxel Dörfler } 14241281cf3SAxel Dörfler 14341281cf3SAxel Dörfler 14441281cf3SAxel Dörfler void 14541281cf3SAxel Dörfler TBarMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage *message) 14641281cf3SAxel Dörfler { 1477da06231SAxel Dörfler // the following code parallels that in ExpandoMenuBar for DnD tracking 1487da06231SAxel Dörfler 14941281cf3SAxel Dörfler if (!message) { 15041281cf3SAxel Dörfler // force a cleanup 15141281cf3SAxel Dörfler fBarView->DragStop(true); 15241281cf3SAxel Dörfler BMenuBar::MouseMoved(where, code, message); 15341281cf3SAxel Dörfler return; 15441281cf3SAxel Dörfler } 15541281cf3SAxel Dörfler 15641281cf3SAxel Dörfler switch (code) { 15741281cf3SAxel Dörfler case B_ENTERED_VIEW: 15841281cf3SAxel Dörfler { 15941281cf3SAxel Dörfler BPoint loc; 16041281cf3SAxel Dörfler uint32 buttons; 16141281cf3SAxel Dörfler GetMouse(&loc, &buttons); 1627da06231SAxel Dörfler // attempt to start DnD tracking 16341281cf3SAxel Dörfler if (message && buttons != 0) { 16441281cf3SAxel Dörfler fBarView->CacheDragData(const_cast<BMessage *>(message)); 16541281cf3SAxel Dörfler MouseDown(loc); 16641281cf3SAxel Dörfler } 16741281cf3SAxel Dörfler break; 16841281cf3SAxel Dörfler } 1697da06231SAxel Dörfler } 17041281cf3SAxel Dörfler BMenuBar::MouseMoved(where, code, message); 17141281cf3SAxel Dörfler } 17241281cf3SAxel Dörfler 17341281cf3SAxel Dörfler 17441281cf3SAxel Dörfler static void 1757da06231SAxel Dörfler init_tracking_hook(BMenuItem *item, bool (*hookFunction)(BMenu *, void *), 1767da06231SAxel Dörfler void *state) 17741281cf3SAxel Dörfler { 17841281cf3SAxel Dörfler if (!item) 17941281cf3SAxel Dörfler return; 18041281cf3SAxel Dörfler 1817da06231SAxel Dörfler BMenu *windowMenu = item->Submenu(); 1827da06231SAxel Dörfler if (windowMenu) 18341281cf3SAxel Dörfler // have a menu, set the tracking hook 1847da06231SAxel Dörfler windowMenu->SetTrackingHook(hookFunction, state); 18541281cf3SAxel Dörfler } 18641281cf3SAxel Dörfler 18741281cf3SAxel Dörfler 18841281cf3SAxel Dörfler void 1897da06231SAxel Dörfler TBarMenuBar::InitTrackingHook(bool (*hookFunction)(BMenu *, void *), 1907da06231SAxel Dörfler void *state, bool both) 19141281cf3SAxel Dörfler { 19241281cf3SAxel Dörfler BPoint loc; 19341281cf3SAxel Dörfler uint32 buttons; 19441281cf3SAxel Dörfler GetMouse(&loc, &buttons); 19541281cf3SAxel Dörfler // set the hook functions for the two menus 19641281cf3SAxel Dörfler // will always have the be menu 19741281cf3SAxel Dörfler // may have the app menu as well (mini mode) 19841281cf3SAxel Dörfler if (fBeMenuItem->Frame().Contains(loc) || both) 1997da06231SAxel Dörfler init_tracking_hook(fBeMenuItem, hookFunction, state); 20041281cf3SAxel Dörfler 20141281cf3SAxel Dörfler if (fAppListMenuItem && (fAppListMenuItem->Frame().Contains(loc) || both)) 2027da06231SAxel Dörfler init_tracking_hook(fAppListMenuItem, hookFunction, state); 20341281cf3SAxel Dörfler } 204