xref: /haiku/headers/private/interface/MenuPrivate.h (revision cda5b8808fd0262f0fac472f6cfa809f846a83cf)
1 /*
2  * Copyright 2006-2008, 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 
13 enum menu_states {
14 	MENU_STATE_TRACKING = 0,
15 	MENU_STATE_TRACKING_SUBMENU = 1,
16 	MENU_STATE_CLOSED = 5
17 };
18 
19 class BMenu;
20 class BWindow;
21 
22 namespace BPrivate {
23 
24 class MenuPrivate {
25 public:
26 	MenuPrivate(BMenu *menu);
27 
28 	menu_layout Layout() const;
29 
30 	void ItemMarked(BMenuItem *item);
31 	void CacheFontInfo();
32 
33 	float FontHeight() const;
34 	float Ascent() const;
35 	BRect Padding() const;
36 	void GetItemMargins(float *, float *, float *, float *) const;
37 
38 	bool IsAltCommandKey() const;
39 	int State(BMenuItem **item = NULL) const;
40 
41 	void Install(BWindow *window);
42 	void Uninstall();
43 	void SetSuper(BMenu *menu);
44 	void SetSuperItem(BMenuItem *item);
45 	void InvokeItem(BMenuItem *item, bool now = false);
46 	void QuitTracking(bool thisMenuOnly = true);
47 
48 private:
49 	BMenu *fMenu;
50 };
51 
52 };
53 
54 extern const char *kEmptyMenuLabel;
55 
56 
57 // Note: since sqrt is slow, we don't use it and return the square of the distance
58 #define square(x) ((x) * (x))
59 static inline float
60 point_distance(const BPoint &pointA, const BPoint &pointB)
61 {
62 	return square(pointA.x - pointB.x) + square(pointA.y - pointB.y);
63 }
64 
65 #undef square
66 
67 
68 #endif // __MENU_PRIVATE_H
69