xref: /haiku/headers/os/interface/MenuField.h (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 /*
2  * Copyright 2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef _MENU_FIELD_H
7 #define _MENU_FIELD_H
8 
9 #include <BeBuild.h>
10 #include <Menu.h>		/* For convenience */
11 #include <View.h>
12 
13 class BMenuBar;
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 								BMessage* message,
29 								uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
30 							BMenuField(const char* label,
31 								BMenu* menu, BMessage* message);
32 							BMenuField(BMessage* data);
33 	virtual					~BMenuField();
34 
35 	static	BArchivable*	Instantiate(BMessage* archive);
36 	virtual	status_t		Archive(BMessage* archive, 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 pt);
47 	virtual	void			MouseMoved(BPoint pt, uint32 code,
48 								const BMessage* dragMessage);
49 	virtual	void			DetachedFromWindow();
50 	virtual	void			AllDetached();
51 	virtual	void			FrameMoved(BPoint new_position);
52 	virtual	void			FrameResized(float new_width, float new_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 				BLayoutItem* CreateLabelLayoutItem();
81 				BLayoutItem* CreateMenuBarLayoutItem();
82 
83 
84 	/*----- Private or reserved -----------------------------------------*/
85 	virtual status_t		Perform(perform_code d, void* arg);
86 
87  private:
88 			class LabelLayoutItem;
89 			class MenuBarLayoutItem;
90 
91 			friend class _BMCMenuBar_;
92 			friend class LabelLayoutItem;
93 			friend class MenuBarLayoutItem;
94 
95 	virtual	void			_ReservedMenuField1();
96 	virtual	void			_ReservedMenuField2();
97 	virtual	void			_ReservedMenuField3();
98 
99 			BMenuField		&operator=(const BMenuField&);
100 
101 
102 			void			InitObject(const char* label);
103 			void			InitObject2();
104 			void			DrawLabel(BRect bounds, BRect update);
105 	static	void			InitMenu(BMenu* menu);
106 	static	long			MenuTask(void* arg);
107 			void			_UpdateFrame();
108 			void			_InitMenuBar(BMenu* menu,
109 								BRect frame, bool fixedSize);
110 
111 			char*			fLabel;
112 			BMenu*			fMenu;
113 			BMenuBar*		fMenuBar;
114 			alignment		fAlign;
115 			float			fDivider;
116 			float			fStringWidth;
117 			bool			fEnabled;
118 			bool			fSelected;
119 			bool			fTransition;
120 			bool			fFixedSizeMB;
121 			thread_id		fMenuTaskID;
122 
123 			BLayoutItem*	fLabelLayoutItem;
124 			BLayoutItem*	fMenuBarLayoutItem;
125 
126 			uint32			_reserved[1];
127 };
128 
129 #endif // _MENU_FIELD_H
130