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