1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 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: 14 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. 17 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. 24 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. 28 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. 34 */ 35 36 #include <Debug.h> 37 38 #include "BarMenuBar.h" 39 40 #include <string.h> 41 42 #include <Bitmap.h> 43 #include <NodeInfo.h> 44 45 #include "icons.h" 46 #include "icons_logo.h" 47 #include "BarWindow.h" 48 #include "DeskbarMenu.h" 49 #include "DeskbarUtils.h" 50 #include "ResourceSet.h" 51 #include "TeamMenu.h" 52 53 54 TBarMenuBar::TBarMenuBar(TBarView* bar, BRect frame, const char* name) 55 : BMenuBar(frame, name, B_FOLLOW_NONE, B_ITEMS_IN_ROW, false), 56 fBarView(bar), 57 fAppListMenuItem(NULL) 58 { 59 SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f); 60 61 TDeskbarMenu* beMenu = new TDeskbarMenu(bar); 62 TBarWindow::SetDeskbarMenu(beMenu); 63 64 fDeskbarMenuItem = new TBarMenuTitle(frame.Width(), frame.Height(), 65 AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_LeafLogoBitmap), beMenu); 66 AddItem(fDeskbarMenuItem); 67 } 68 69 70 TBarMenuBar::~TBarMenuBar() 71 { 72 } 73 74 75 void 76 TBarMenuBar::SmartResize(float width, float height) 77 { 78 if (width == -1.0f && height == -1.0f) { 79 BRect frame = Frame(); 80 width = frame.Width(); 81 height = frame.Height(); 82 } else 83 ResizeTo(width, height); 84 85 width -= 1; 86 87 int32 count = CountItems(); 88 if (fDeskbarMenuItem) 89 fDeskbarMenuItem->SetWidthHeight(width / count, height); 90 if (fAppListMenuItem) 91 fAppListMenuItem->SetWidthHeight(width / count, height); 92 93 InvalidateLayout(); 94 } 95 96 97 void 98 TBarMenuBar::AddTeamMenu() 99 { 100 if (CountItems() > 1) 101 return; 102 103 BRect frame(Frame()); 104 delete fAppListMenuItem; 105 106 fAppListMenuItem = new TBarMenuTitle(0.0f, 0.0f, 107 AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_TeamIcon), new TTeamMenu()); 108 AddItem(fAppListMenuItem); 109 SmartResize(frame.Width() - 1.0f, frame.Height()); 110 } 111 112 113 void 114 TBarMenuBar::RemoveTeamMenu() 115 { 116 if (CountItems() < 2) 117 return; 118 119 if (fAppListMenuItem) { 120 RemoveItem((BMenuItem*)fAppListMenuItem); 121 delete fAppListMenuItem; 122 fAppListMenuItem = NULL; 123 } 124 125 BRect frame = Frame(); 126 SmartResize(frame.Width(), frame.Height()); 127 } 128 129 130 void 131 TBarMenuBar::Draw(BRect rect) 132 { 133 // want to skip the fancy BMenuBar drawing code. 134 BMenu::Draw(rect); 135 } 136 137 138 void 139 TBarMenuBar::DrawBackground(BRect rect) 140 { 141 BMenu::DrawBackground(rect); 142 } 143 144 145 void 146 TBarMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message) 147 { 148 // the following code parallels that in ExpandoMenuBar for DnD tracking 149 150 if (!message) { 151 // force a cleanup 152 fBarView->DragStop(true); 153 BMenuBar::MouseMoved(where, code, message); 154 return; 155 } 156 157 switch (code) { 158 case B_ENTERED_VIEW: 159 { 160 BPoint loc; 161 uint32 buttons; 162 GetMouse(&loc, &buttons); 163 // attempt to start DnD tracking 164 if (message && buttons != 0) { 165 fBarView->CacheDragData(const_cast<BMessage*>(message)); 166 MouseDown(loc); 167 } 168 break; 169 } 170 } 171 BMenuBar::MouseMoved(where, code, message); 172 } 173 174 175 static void 176 init_tracking_hook(BMenuItem* item, bool (*hookFunction)(BMenu*, void*), 177 void* state) 178 { 179 if (!item) 180 return; 181 182 BMenu* windowMenu = item->Submenu(); 183 if (windowMenu) { 184 // have a menu, set the tracking hook 185 windowMenu->SetTrackingHook(hookFunction, state); 186 } 187 } 188 189 190 void 191 TBarMenuBar::InitTrackingHook(bool (*hookFunction)(BMenu*, void*), 192 void* state, bool both) 193 { 194 BPoint loc; 195 uint32 buttons; 196 GetMouse(&loc, &buttons); 197 // set the hook functions for the two menus 198 // will always have the deskbar menu 199 // may have the app menu as well (mini mode) 200 if (fDeskbarMenuItem->Frame().Contains(loc) || both) 201 init_tracking_hook(fDeskbarMenuItem, hookFunction, state); 202 203 if (fAppListMenuItem && (fAppListMenuItem->Frame().Contains(loc) || both)) 204 init_tracking_hook(fAppListMenuItem, hookFunction, state); 205 } 206 207