xref: /haiku/headers/private/interface/MenuPrivate.h (revision 7749d0bb0c358a3279b1b9cc76d8376e900130a5)
1 /*
2  * Copyright 2006-2011, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  * 		Stefano Ceccherini (stefano.ceccherini@gmail.com)
7  */
8 
9 #ifndef __MENU_PRIVATE_H
10 #define __MENU_PRIVATE_H
11 
12 #include <Menu.h>
13 
14 enum menu_states {
15 	MENU_STATE_TRACKING = 0,
16 	MENU_STATE_TRACKING_SUBMENU = 1,
17 	MENU_STATE_KEY_TO_SUBMENU = 2,
18 	MENU_STATE_KEY_LEAVE_SUBMENU = 3,
19 	MENU_STATE_CLOSED = 5
20 };
21 
22 
23 class BBitmap;
24 class BMenu;
25 class BWindow;
26 
27 namespace BPrivate {
28 
29 extern const char *kEmptyMenuLabel;
30 
31 class MenuPrivate {
32 public:
33 	MenuPrivate(BMenu *menu);
34 
35 	menu_layout Layout() const;
36 
37 	void ItemMarked(BMenuItem *item);
38 	void CacheFontInfo();
39 
40 	float FontHeight() const;
41 	float Ascent() const;
42 	BRect Padding() const;
43 	void GetItemMargins(float *, float *, float *, float *) const;
44 
45 	static bool IsAltCommandKey();
46 
47 	int State(BMenuItem **item = NULL) const;
48 
49 	void Install(BWindow *window);
50 	void Uninstall();
51 	void SetSuper(BMenu *menu);
52 	void SetSuperItem(BMenuItem *item);
53 	void InvokeItem(BMenuItem *item, bool now = false);
54 	void QuitTracking(bool thisMenuOnly = true);
55 
56 	static	status_t	CreateBitmaps();
57 	static	void		DeleteBitmaps();
58 
59 	static const BBitmap *MenuItemCommand();
60 	static const BBitmap *MenuItemControl();
61 	static const BBitmap *MenuItemOption();
62 	static const BBitmap *MenuItemShift();
63 private:
64 	BMenu *fMenu;
65 
66 	static BBitmap *sMenuItemAlt;
67 	static BBitmap *sMenuItemControl;
68 	static BBitmap *sMenuItemOption;
69 	static BBitmap *sMenuItemShift;
70 
71 };
72 
73 
74 };
75 
76 
77 // Note: since sqrt is slow, we don't use it and return the square of the distance
78 #define square(x) ((x) * (x))
79 static inline float
80 point_distance(const BPoint &pointA, const BPoint &pointB)
81 {
82 	return square(pointA.x - pointB.x) + square(pointA.y - pointB.y);
83 }
84 
85 #undef square
86 
87 
88 #endif // __MENU_PRIVATE_H
89