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