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