xref: /haiku/headers/os/interface/MenuField.h (revision 040a81419dda83d1014e9dc94936a4cb3f027303)
1 /*
2  * Copyright 2006-2011, 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 state);
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				InitObject(const char* label);
125 			void				InitObject2();
126 			void				DrawLabel(BRect updateRect);
127 	static	void				InitMenu(BMenu* menu);
128 
129 			int32				_MenuTask();
130 	static	int32				_thread_entry(void *arg);
131 
132 			void				_UpdateFrame();
133 			void				_InitMenuBar(BMenu* menu,
134 									BRect frame, bool fixedSize);
135 			void				_InitMenuBar(const BMessage* archive);
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				fSelected;
149 			bool				fTransition;
150 			bool				fFixedSizeMB;
151 			thread_id			fMenuTaskID;
152 
153 			LayoutData*			fLayoutData;
154 
155 			uint32				_reserved[3];
156 };
157 
158 #endif // _MENU_FIELD_H
159