MenuPrivate.h revision e8d4db8e
1/*
2 * Copyright 2006-2015 Haiku, Inc. All rights reserved.
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#include <Menu.h>
14
15
16enum menu_states {
17	MENU_STATE_TRACKING = 0,
18	MENU_STATE_TRACKING_SUBMENU = 1,
19	MENU_STATE_KEY_TO_SUBMENU = 2,
20	MENU_STATE_KEY_LEAVE_SUBMENU = 3,
21	MENU_STATE_CLOSED = 5
22};
23
24
25class BBitmap;
26class BMenu;
27class BWindow;
28
29
30namespace BPrivate {
31
32extern const char* kEmptyMenuLabel;
33
34class MenuPrivate {
35public:
36								MenuPrivate(BMenu* menu);
37
38			menu_layout			Layout() const;
39			void				SetLayout(menu_layout layout);
40
41			void				ItemMarked(BMenuItem* item);
42			void				CacheFontInfo();
43
44			float				FontHeight() const;
45			float				Ascent() const;
46			BRect				Padding() const;
47			void				GetItemMargins(float*, float*, float*, float*)
48									const;
49			void				SetItemMargins(float, float, float, float);
50
51			int					State(BMenuItem** item = NULL) const;
52
53			void				Install(BWindow* window);
54			void				Uninstall();
55			void				SetSuper(BMenu* menu);
56			void				SetSuperItem(BMenuItem* item);
57			void				InvokeItem(BMenuItem* item, bool now = false);
58			void				QuitTracking(bool thisMenuOnly = true);
59
60	static	status_t			CreateBitmaps();
61	static	void				DeleteBitmaps();
62
63	static	const BBitmap*		MenuItemShift();
64	static	const BBitmap*		MenuItemControl();
65	static	const BBitmap*		MenuItemOption();
66	static	const BBitmap*		MenuItemCommand();
67	static	const BBitmap*		MenuItemMenu();
68
69private:
70			BMenu*				fMenu;
71
72	static	BBitmap*			sMenuItemShift;
73	static	BBitmap*			sMenuItemControl;
74	static	BBitmap*			sMenuItemOption;
75	static	BBitmap*			sMenuItemAlt;
76	static	BBitmap*			sMenuItemMenu;
77
78};
79
80};	// namespace BPrivate
81
82
83// Note: since sqrt is slow, we don't use it and return the square of the
84// distance
85#define square(x) ((x) * (x))
86static inline float
87point_distance(const BPoint &pointA, const BPoint &pointB)
88{
89	return square(pointA.x - pointB.x) + square(pointA.y - pointB.y);
90}
91#undef square
92
93
94#endif	// __MENU_PRIVATE_H
95