xref: /haiku/headers/os/interface/MenuField.h (revision bddcee2a27042b4d8d6b0142b466f30abc886648)
1 /*
2  * Copyright 2006-2016 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _MENU_FIELD_H
6 #define _MENU_FIELD_H
7 
8 
9 #include <Menu.h>
10 
11 
12 class BMenuBar;
13 class BMessageFilter;
14 
15 
16 class BMenuField : public BView {
17 public:
18 								BMenuField(BRect frame, const char* name,
19 									const char* label, BMenu* menu,
20 									uint32 resizingMode = B_FOLLOW_LEFT_TOP,
21 									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
22 								BMenuField(BRect frame, const char* name,
23 									const char* label, BMenu* menu,
24 									bool fixed_size,
25 									uint32 resizingMode = B_FOLLOW_LEFT_TOP,
26 									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
27 								BMenuField(const char* name,
28 									const char* label, BMenu* menu,
29 									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
30 								BMenuField(const char* label, BMenu* menu,
31 									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
32 								BMenuField(BMessage* data);
33 	virtual						~BMenuField();
34 
35 	static	BArchivable*		Instantiate(BMessage* archive);
36 	virtual	status_t			Archive(BMessage* archive,
37 									bool deep = true) const;
38 
39 	virtual	void				Draw(BRect updateRect);
40 	virtual	void				AttachedToWindow();
41 	virtual	void				AllAttached();
42 	virtual	void				MouseDown(BPoint where);
43 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
44 	virtual	void				MakeFocus(bool focused);
45 	virtual	void				MessageReceived(BMessage* message);
46 	virtual	void				WindowActivated(bool active);
47 	virtual	void				MouseUp(BPoint where);
48 	virtual	void				MouseMoved(BPoint where, uint32 transit,
49 									const BMessage* dragMessage);
50 	virtual	void				DetachedFromWindow();
51 	virtual	void				AllDetached();
52 	virtual	void				FrameMoved(BPoint where);
53 	virtual	void				FrameResized(float width, float height);
54 
55 			BMenu*				Menu() const;
56 			BMenuBar*			MenuBar() const;
57 			BMenuItem*			MenuItem() const;
58 
59 	virtual	void				SetLabel(const char* label);
60 			const char*			Label() const;
61 
62 	virtual	void				SetEnabled(bool on);
63 			bool				IsEnabled() const;
64 
65 	virtual	void				SetAlignment(alignment label);
66 			alignment			Alignment() const;
67 	virtual	void				SetDivider(float position);
68 			float				Divider() const;
69 
70 			void				ShowPopUpMarker();
71 			void				HidePopUpMarker();
72 
73 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
74 									int32 index, BMessage* specifier,
75 									int32 form, const char* property);
76 	virtual	status_t			GetSupportedSuites(BMessage* data);
77 
78 	virtual	void				ResizeToPreferred();
79 	virtual	void				GetPreferredSize(float* width, float* height);
80 
81 	virtual	BSize				MinSize();
82 	virtual	BSize				MaxSize();
83 	virtual	BSize				PreferredSize();
84 
85 			BLayoutItem*		CreateLabelLayoutItem();
86 			BLayoutItem*		CreateMenuBarLayoutItem();
87 
88 	virtual status_t			Perform(perform_code d, void* arg);
89 
90 protected:
91 	virtual	status_t			AllArchived(BMessage* into) const;
92 	virtual	status_t			AllUnarchived(const BMessage* from);
93 
94 	virtual	void				LayoutInvalidated(bool descendants);
95 	virtual	void				DoLayout();
96 
97 private:
98 	// FBC padding
99 	virtual	void				_ReservedMenuField1();
100 	virtual	void				_ReservedMenuField2();
101 	virtual	void				_ReservedMenuField3();
102 
103 	// Forbidden
104 			BMenuField&			operator=(const BMenuField& other);
105 
106 private:
107 	class LabelLayoutItem;
108 	class MenuBarLayoutItem;
109 	struct LayoutData;
110 
111 	friend class _BMCMenuBar_;
112 	friend class LabelLayoutItem;
113 	friend class MenuBarLayoutItem;
114 	friend struct LayoutData;
115 
116 								BMenuField(const char* name,
117 									const char* label, BMenu* menu,
118 									BMessage* message,
119 									uint32 flags);
120 								BMenuField(const char* label,
121 									BMenu* menu, BMessage* message);
122 
123 			void				_DrawLabel(BRect updateRect);
124 			void				_DrawMenuBar(BRect updateRect);
125 
126 			void				InitObject(const char* label);
127 			void				InitObject2();
128 
129 	static	void				InitMenu(BMenu* menu);
130 
131 			int32				_MenuTask();
132 	static	int32				_thread_entry(void *arg);
133 
134 			void				_UpdateFrame();
135 			void				_InitMenuBar(BMenu* menu,
136 									BRect frame, bool fixedSize);
137 			void				_InitMenuBar(const BMessage* archive);
138 			void				_AddMenu(BMenu* menu);
139 
140 			void				_ValidateLayoutData();
141 			float				_MenuBarOffset() const;
142 			float				_MenuBarWidth() const;
143 
144 			void				_DoneTracking(BPoint point);
145 			void				_Track(BPoint point, uint32);
146 
147 private:
148 			char*				fLabel;
149 			BMenu*				fMenu;
150 			BMenuBar*			fMenuBar;
151 			alignment			fAlign;
152 			float				fDivider;
153 			bool				fEnabled;
154 			bool				fFixedSizeMB;
155 			thread_id			fMenuTaskID;
156 
157 			LayoutData*			fLayoutData;
158 			BMessageFilter*		fMouseDownFilter;
159 
160 			uint32				_reserved[2];
161 };
162 
163 
164 #endif // _MENU_FIELD_H
165