xref: /haiku/headers/private/interface/MenuPrivate.h (revision 99d027cd0238c1d86da86d7c3f4200509ccc61a6)
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 			int		State(BMenuItem **item = NULL) const;
46 
47 			void	Install(BWindow *window);
48 			void	Uninstall();
49 			void	SetSuper(BMenu *menu);
50 			void	SetSuperItem(BMenuItem *item);
51 			void	InvokeItem(BMenuItem *item, bool now = false);
52 			void	QuitTracking(bool thisMenuOnly = true);
53 
54 	static	status_t	CreateBitmaps();
55 	static	void		DeleteBitmaps();
56 
57 	static	const	BBitmap *MenuItemShift();
58 	static	const	BBitmap *MenuItemControl();
59 	static	const	BBitmap *MenuItemOption();
60 	static	const	BBitmap *MenuItemCommand();
61 	static	const	BBitmap *MenuItemMenu();
62 private:
63 	BMenu *fMenu;
64 
65 	static BBitmap *sMenuItemShift;
66 	static BBitmap *sMenuItemControl;
67 	static BBitmap *sMenuItemOption;
68 	static BBitmap *sMenuItemAlt;
69 	static BBitmap *sMenuItemMenu;
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