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