xref: /haiku/headers/os/interface/MenuBar.h (revision 97dfeb96704e5dbc5bec32ad7b21379d0125e031)
1 /*
2  * Copyright 2003-2015, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _MENU_BAR_H
6 #define _MENU_BAR_H
7 
8 
9 #include <InterfaceDefs.h>
10 #include <Menu.h>
11 #include <OS.h>
12 
13 
14 enum menu_bar_border {
15 	B_BORDER_FRAME,
16 	B_BORDER_CONTENTS,
17 	B_BORDER_EACH_ITEM
18 };
19 
20 class BMenu;
21 class BWindow;
22 class BMenuItem;
23 class BMenuField;
24 
25 
26 class BMenuBar : public BMenu {
27 public:
28 								BMenuBar(BRect frame, const char* name,
29 									uint32 resizingMode = B_FOLLOW_LEFT_RIGHT
30 										| B_FOLLOW_TOP,
31 									menu_layout layout = B_ITEMS_IN_ROW,
32 									bool resizeToFit = true);
33 								BMenuBar(const char* name,
34 									menu_layout layout = B_ITEMS_IN_ROW,
35 									uint32 flags = B_WILL_DRAW
36 										| B_FRAME_EVENTS);
37 								BMenuBar(BMessage* archive);
38 	virtual						~BMenuBar();
39 
40 	static	BArchivable*		Instantiate(BMessage* archive);
41 	virtual	status_t			Archive(BMessage* archive,
42 									bool deep = true) const;
43 
44 	virtual	void				AttachedToWindow();
45 	virtual	void				DetachedFromWindow();
46 	virtual void				AllAttached();
47 	virtual void				AllDetached();
48 
49 	virtual	void				WindowActivated(bool state);
50 	virtual void				MakeFocus(bool state = true);
51 
52 	virtual void				ResizeToPreferred();
53 	virtual void				GetPreferredSize(float* _width,
54 									float* _height);
55 	virtual	BSize				MinSize();
56 	virtual	BSize				MaxSize();
57 	virtual	BSize				PreferredSize();
58 	virtual	void				FrameMoved(BPoint newPosition);
59 	virtual	void				FrameResized(float newWidth, float newHeight);
60 
61 	virtual	void				Show();
62 	virtual	void				Hide();
63 
64 	virtual	void				Draw(BRect updateRect);
65 
66 	virtual	void				MessageReceived(BMessage *message);
67 	virtual	void				MouseDown(BPoint where);
68 	virtual	void				MouseUp(BPoint where);
69 
70 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
71 									int32 index, BMessage* specifier,
72 									int32 form, const char* property);
73 	virtual status_t			GetSupportedSuites(BMessage* data);
74 
75 	virtual	void				SetBorder(menu_bar_border border);
76 			menu_bar_border		Border() const;
77 			void				SetBorders(uint32 borders);
78 			uint32				Borders() const;
79 
80 	virtual status_t			Perform(perform_code code, void* data);
81 
82 private:
83 	friend class BWindow;
84 	friend class BMenuField;
85 	friend class BMenu;
86 
87 	virtual	void				_ReservedMenuBar1();
88 	virtual	void				_ReservedMenuBar2();
89 	virtual	void				_ReservedMenuBar3();
90 	virtual	void				_ReservedMenuBar4();
91 
92 			BMenuBar			&operator=(const BMenuBar &);
93 
94 	// TODO: Tracker uses this function so we can't change
95 	// its signature without breaking it
96 			void				StartMenuBar(int32 menuIndex,
97 									bool sticky = true, bool showMenu = false,
98 									BRect* special_rect = NULL);
99 
100 	static	int32				_TrackTask(void *arg);
101 			BMenuItem*			_Track(int32 *action, int32 startIndex = -1,
102 									bool showMenu = false);
103 			void				_StealFocus();
104 			void				_RestoreFocus();
105 			void				_InitData(menu_layout layout);
106 
107 			menu_bar_border		fBorder;
108 			thread_id			fTrackingPID;
109 			int32				fPrevFocusToken;
110 			sem_id				fMenuSem;
111 			BRect*				fLastBounds;
112 			uint32				fBorders;
113 			uint32				_reserved[1];
114 
115 			bool				fTracking;
116 };
117 
118 
119 #endif /* _MENU_BAR_H */
120