btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / interface / MenuPrivate.cpp
blob4339654f77cd6b9c83372e5252e975afbe97e451
1 /*
2 * Copyright 2001-2009, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stefano Ceccherini (stefano.ceccherini@gmail.com)
7 */
9 #include <MenuPrivate.h>
11 #include <Bitmap.h>
12 #include <Menu.h>
15 const unsigned char kShiftBits[] = {
16 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x14,
17 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
18 0x1d,0x1a,0x1a,0x17,0x04,0x04,0x17,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
19 0x1d,0x1a,0x1a,0x04,0x17,0x17,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x04,0x04,0x1a,0x04,0x04,0x04,0x1a,0x17,0x14,
20 0x1d,0x1a,0x1a,0x17,0x04,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
21 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x04,0x1a,0x04,0x1a,0x04,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
22 0x1d,0x1a,0x1a,0x04,0x17,0x17,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
23 0x1d,0x1a,0x1a,0x17,0x04,0x04,0x17,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
24 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
25 0x1d,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14,
26 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14
30 const unsigned char kCtrlBits[] = {
31 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x14,
32 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
33 0x1d,0x1a,0x1a,0x13,0x04,0x04,0x13,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
34 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x04,0x1a,0x04,0x04,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x17,0x14,
35 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x17,0x14,
36 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x04,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x17,0x14,
37 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x1a,0x17,0x14,
38 0x1d,0x1a,0x1a,0x13,0x04,0x04,0x13,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x13,0x04,0x1a,0x04,0x04,0x04,0x1a,0x17,0x14,
39 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
40 0x1d,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14,
41 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14
45 const unsigned char kOptBits[] = {
46 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x14,
47 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
48 0x1d,0x1a,0x1a,0x13,0x04,0x04,0x13,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
49 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x1a,0x04,0x04,0x04,0x1a,0x17,0x14,
50 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x17,0x14,
51 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
52 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
53 0x1d,0x1a,0x1a,0x13,0x04,0x04,0x13,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
54 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
55 0x1d,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14,
56 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14
60 const unsigned char kAltBits[] = {
61 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x14,
62 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
63 0x1d,0x1a,0x1a,0x13,0x04,0x04,0x13,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
64 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x04,0x04,0x04,0x1a,0x17,0x14,
65 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
66 0x1d,0x1a,0x1a,0x04,0x04,0x04,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
67 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14,
68 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x04,0x1a,0x04,0x1a,0x1a,0x17,0x14,
69 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
70 0x1d,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14,
71 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14
75 const unsigned char kMenuBits[] = {
76 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x14,
77 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
78 0x1d,0x1a,0x1a,0x04,0x04,0x1a,0x04,0x04,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
79 0x1d,0x1a,0x1a,0x04,0x04,0x04,0x04,0x04,0x1a,0x04,0x04,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x17,0x14,
80 0x1d,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x04,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x17,0x14,
81 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x1a,0x04,0x04,0x04,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x17,0x14,
82 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x17,0x14,
83 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x04,0x1a,0x17,0x14,
84 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14,
85 0x1d,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14,
86 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14
90 namespace BPrivate {
93 BBitmap* MenuPrivate::sMenuItemShift;
94 BBitmap* MenuPrivate::sMenuItemControl;
95 BBitmap* MenuPrivate::sMenuItemOption;
96 BBitmap* MenuPrivate::sMenuItemAlt;
97 BBitmap* MenuPrivate::sMenuItemMenu;
100 MenuPrivate::MenuPrivate(BMenu* menu)
102 fMenu(menu)
107 menu_layout
108 MenuPrivate::Layout() const
110 return fMenu->Layout();
114 void
115 MenuPrivate::SetLayout(menu_layout layout)
117 fMenu->fLayout = layout;
121 void
122 MenuPrivate::ItemMarked(BMenuItem* item)
124 fMenu->_ItemMarked(item);
128 void
129 MenuPrivate::CacheFontInfo()
131 fMenu->_CacheFontInfo();
135 float
136 MenuPrivate::FontHeight() const
138 return fMenu->fFontHeight;
142 float
143 MenuPrivate::Ascent() const
145 return fMenu->fAscent;
149 BRect
150 MenuPrivate::Padding() const
152 return fMenu->fPad;
156 void
157 MenuPrivate::GetItemMargins(float* left, float* top, float* right,
158 float* bottom) const
160 fMenu->GetItemMargins(left, top, right, bottom);
164 void
165 MenuPrivate::SetItemMargins(float left, float top, float right, float bottom)
167 fMenu->SetItemMargins(left, top, right, bottom);
172 MenuPrivate::State(BMenuItem** item) const
174 return fMenu->_State(item);
178 void
179 MenuPrivate::Install(BWindow* window)
181 fMenu->_Install(window);
185 void
186 MenuPrivate::Uninstall()
188 fMenu->_Uninstall();
192 void
193 MenuPrivate::SetSuper(BMenu* menu)
195 fMenu->fSuper = menu;
199 void
200 MenuPrivate::SetSuperItem(BMenuItem* item)
202 fMenu->fSuperitem = item;
206 void
207 MenuPrivate::InvokeItem(BMenuItem* item, bool now)
209 fMenu->_InvokeItem(item, now);
213 void
214 MenuPrivate::QuitTracking(bool thisMenuOnly)
216 fMenu->_QuitTracking(thisMenuOnly);
220 /* static */
221 status_t
222 MenuPrivate::CreateBitmaps()
224 BRect smallRect(0.0f, 0.0f, 16.0f, 10.0f);
226 try {
227 sMenuItemShift = new BBitmap(BRect(0.0f, 0.0f, 23.0f, 10.0f), B_CMAP8);
228 sMenuItemControl = new BBitmap(BRect(0.0f, 0.0f, 21.0f, 10.0f),
229 B_CMAP8);
230 sMenuItemOption = new BBitmap(smallRect, B_CMAP8);
231 sMenuItemAlt = new BBitmap(smallRect, B_CMAP8);
232 sMenuItemMenu = new BBitmap(BRect(0.0f, 0.0f, 22.0f, 10.0f), B_CMAP8);
233 } catch (...) {
234 return B_NO_MEMORY;
237 sMenuItemShift->ImportBits(kShiftBits, sizeof(kShiftBits),
238 24, 0, B_CMAP8);
239 sMenuItemControl->ImportBits(kCtrlBits, sizeof(kCtrlBits),
240 22, 0, B_CMAP8);
241 sMenuItemOption->ImportBits(kOptBits, sizeof(kOptBits),
242 17, 0, B_CMAP8);
243 sMenuItemAlt->ImportBits(kAltBits, sizeof(kAltBits),
244 17, 0, B_CMAP8);
245 sMenuItemMenu->ImportBits(kMenuBits, sizeof(kMenuBits),
246 23, 0, B_CMAP8);
248 return B_OK;
252 /* static */
253 void
254 MenuPrivate::DeleteBitmaps()
256 delete sMenuItemShift;
257 delete sMenuItemControl;
258 delete sMenuItemOption;
259 delete sMenuItemAlt;
260 delete sMenuItemMenu;
264 /* static */
265 const BBitmap*
266 MenuPrivate::MenuItemShift()
268 return sMenuItemShift;
272 /* static */
273 const BBitmap*
274 MenuPrivate::MenuItemControl()
276 switch (BMenu::sControlKey) {
277 case 0x5d:
278 case 0x5f:
279 return sMenuItemAlt;
281 case 0x66:
282 case 0x67:
283 return sMenuItemOption;
286 return sMenuItemControl;
290 /* static */
291 const BBitmap*
292 MenuPrivate::MenuItemOption()
294 switch (BMenu::sOptionKey) {
295 case 0x5c:
296 case 0x60:
297 return sMenuItemControl;
299 case 0x66:
300 case 0x67:
301 return sMenuItemOption;
304 return sMenuItemAlt;
308 /* static */
309 const BBitmap*
310 MenuPrivate::MenuItemCommand()
312 switch (BMenu::sCommandKey) {
313 case 0x5c:
314 case 0x60:
315 return sMenuItemControl;
317 case 0x66:
318 case 0x67:
319 return sMenuItemOption;
322 return sMenuItemAlt;
326 /* static */
327 const BBitmap*
328 MenuPrivate::MenuItemMenu()
330 return sMenuItemMenu;
334 } // namespace BPrivate