xref: /haiku/src/kits/interface/MenuPrivate.cpp (revision ca8ed5ea660fb6275799a3b7f138b201c41a667b)
1 /*
2  * Copyright 2001-2009, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stefano Ceccherini (stefano.ceccherini@gmail.com)
7  */
8 
9 #include <MenuPrivate.h>
10 
11 #include <Bitmap.h>
12 #include <Menu.h>
13 
14 
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
27 };
28 
29 
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
42 };
43 
44 
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
57 };
58 
59 
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
72 };
73 
74 
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
87 };
88 
89 
90 namespace BPrivate {
91 
92 
93 BBitmap* MenuPrivate::sMenuItemShift;
94 BBitmap* MenuPrivate::sMenuItemControl;
95 BBitmap* MenuPrivate::sMenuItemOption;
96 BBitmap* MenuPrivate::sMenuItemAlt;
97 BBitmap* MenuPrivate::sMenuItemMenu;
98 
99 
100 MenuPrivate::MenuPrivate(BMenu* menu)
101 	:
102 	fMenu(menu)
103 {
104 }
105 
106 
107 menu_layout
108 MenuPrivate::Layout() const
109 {
110 	return fMenu->Layout();
111 }
112 
113 
114 void
115 MenuPrivate::SetLayout(menu_layout layout)
116 {
117 	fMenu->fLayout = layout;
118 }
119 
120 
121 void
122 MenuPrivate::ItemMarked(BMenuItem *item)
123 {
124 	fMenu->_ItemMarked(item);
125 }
126 
127 
128 void
129 MenuPrivate::CacheFontInfo()
130 {
131 	fMenu->_CacheFontInfo();
132 }
133 
134 
135 float
136 MenuPrivate::FontHeight() const
137 {
138 	return fMenu->fFontHeight;
139 }
140 
141 
142 float
143 MenuPrivate::Ascent() const
144 {
145 	return fMenu->fAscent;
146 }
147 
148 
149 BRect
150 MenuPrivate::Padding() const
151 {
152 	return fMenu->fPad;
153 }
154 
155 
156 void
157 MenuPrivate::GetItemMargins(float* left, float* top, float* right,
158 	float* bottom) const
159 {
160 	fMenu->GetItemMargins(left, top, right, bottom);
161 }
162 
163 
164 int
165 MenuPrivate::State(BMenuItem** item) const
166 {
167 	return fMenu->_State(item);
168 }
169 
170 
171 void
172 MenuPrivate::Install(BWindow* window)
173 {
174 	fMenu->_Install(window);
175 }
176 
177 
178 void
179 MenuPrivate::Uninstall()
180 {
181 	fMenu->_Uninstall();
182 }
183 
184 
185 void
186 MenuPrivate::SetSuper(BMenu* menu)
187 {
188 	fMenu->fSuper = menu;
189 }
190 
191 
192 void
193 MenuPrivate::SetSuperItem(BMenuItem* item)
194 {
195 	fMenu->fSuperitem = item;
196 }
197 
198 
199 void
200 MenuPrivate::InvokeItem(BMenuItem* item, bool now)
201 {
202 	fMenu->_InvokeItem(item, now);
203 }
204 
205 
206 void
207 MenuPrivate::QuitTracking(bool thisMenuOnly)
208 {
209 	fMenu->_QuitTracking(thisMenuOnly);
210 }
211 
212 
213 /* static */
214 status_t
215 MenuPrivate::CreateBitmaps()
216 {
217 	BRect smallRect(0, 0, 16, 10);
218 
219 	try {
220 		sMenuItemShift = new BBitmap(BRect(0, 0, 23, 10), B_CMAP8);
221 		sMenuItemControl = new BBitmap(BRect(0, 0, 21, 10), B_CMAP8);
222 		sMenuItemOption = new BBitmap(smallRect, B_CMAP8);
223 		sMenuItemAlt = new BBitmap(smallRect, B_CMAP8);
224 		sMenuItemMenu = new BBitmap(BRect(0, 0, 22, 10), B_CMAP8);
225 	} catch (...) {
226 		return B_NO_MEMORY;
227 	}
228 
229 	sMenuItemShift->ImportBits(kShiftBits, sizeof(kShiftBits),
230 		24, 0, B_CMAP8);
231 	sMenuItemControl->ImportBits(kCtrlBits, sizeof(kCtrlBits),
232 		22, 0, B_CMAP8);
233 	sMenuItemOption->ImportBits(kOptBits, sizeof(kOptBits),
234 		17, 0, B_CMAP8);
235 	sMenuItemAlt->ImportBits(kAltBits, sizeof(kAltBits),
236 		17, 0, B_CMAP8);
237 	sMenuItemMenu->ImportBits(kMenuBits, sizeof(kMenuBits),
238 		23, 0, B_CMAP8);
239 
240 	return B_OK;
241 }
242 
243 
244 /* static */
245 void
246 MenuPrivate::DeleteBitmaps()
247 {
248 	delete sMenuItemShift;
249 	delete sMenuItemControl;
250 	delete sMenuItemOption;
251 	delete sMenuItemAlt;
252 	delete sMenuItemMenu;
253 }
254 
255 
256 /* static */
257 const BBitmap*
258 MenuPrivate::MenuItemShift()
259 {
260 	return sMenuItemShift;
261 }
262 
263 
264 /* static */
265 const BBitmap*
266 MenuPrivate::MenuItemControl()
267 {
268 	switch (BMenu::sControlKey) {
269 		case 0x5d:
270 		case 0x5f:
271 			return sMenuItemAlt;
272 		case 0x66:
273 		case 0x67:
274 			return sMenuItemOption;
275 	}
276 
277 	return sMenuItemControl;
278 }
279 
280 
281 /* static */
282 const BBitmap*
283 MenuPrivate::MenuItemOption()
284 {
285 	switch (BMenu::sOptionKey) {
286 		case 0x5c:
287 		case 0x60:
288 			return sMenuItemControl;
289 		case 0x66:
290 		case 0x67:
291 			return sMenuItemOption;
292 	}
293 
294 	return sMenuItemAlt;
295 }
296 
297 
298 /* static */
299 const BBitmap*
300 MenuPrivate::MenuItemCommand()
301 {
302 	switch (BMenu::sCommandKey) {
303 		case 0x5c:
304 		case 0x60:
305 			return sMenuItemControl;
306 		case 0x66:
307 		case 0x67:
308 			return sMenuItemOption;
309 	}
310 
311 	return sMenuItemAlt;
312 }
313 
314 
315 /* static */
316 const BBitmap*
317 MenuPrivate::MenuItemMenu()
318 {
319 	return sMenuItemMenu;
320 }
321 
322 
323 }	// namespace BPrivate
324