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