xref: /haiku/headers/os/interface/Window.h (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
1 /*
2  * Copyright 2001-2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Adrian Oanca <adioanca@cotty.iren.ro>
7  */
8 #ifndef	_WINDOW_H
9 #define	_WINDOW_H
10 
11 
12 #include <BeBuild.h>
13 #include <InterfaceDefs.h>
14 #include <List.h>
15 #include <Looper.h>
16 #include <Rect.h>
17 #include <StorageDefs.h>
18 #include <View.h>
19 
20 class BButton;
21 class BMenuBar;
22 class BMenuItem;
23 class BMessage;
24 class BMessageRunner;
25 class BMessenger;
26 class BView;
27 
28 namespace BPrivate {
29 	class PortLink;
30 };
31 
32 
33 enum window_type {
34 	B_UNTYPED_WINDOW	= 0,
35 	B_TITLED_WINDOW 	= 1,
36 	B_MODAL_WINDOW 		= 3,
37 	B_DOCUMENT_WINDOW	= 11,
38 	B_BORDERED_WINDOW	= 20,
39 	B_FLOATING_WINDOW	= 21
40 };
41 
42 enum window_look {
43 	B_BORDERED_WINDOW_LOOK	= 20,
44 	B_NO_BORDER_WINDOW_LOOK	= 19,
45 	B_TITLED_WINDOW_LOOK	= 1,
46 	B_DOCUMENT_WINDOW_LOOK	= 11,
47 	B_MODAL_WINDOW_LOOK		= 3,
48 	B_FLOATING_WINDOW_LOOK	= 7
49 };
50 
51 enum window_feel {
52 	B_NORMAL_WINDOW_FEEL			= 0,
53 	B_MODAL_SUBSET_WINDOW_FEEL		= 2,
54 	B_MODAL_APP_WINDOW_FEEL			= 1,
55 	B_MODAL_ALL_WINDOW_FEEL			= 3,
56 	B_FLOATING_SUBSET_WINDOW_FEEL	= 5,
57 	B_FLOATING_APP_WINDOW_FEEL		= 4,
58 	B_FLOATING_ALL_WINDOW_FEEL		= 6
59 };
60 
61 enum window_alignment {
62 	B_BYTE_ALIGNMENT	= 0,
63 	B_PIXEL_ALIGNMENT	= 1
64 };
65 
66 // window flags
67 enum {
68 	B_NOT_MOVABLE				= 0x00000001,
69 	B_NOT_CLOSABLE				= 0x00000020,
70 	B_NOT_ZOOMABLE				= 0x00000040,
71 	B_NOT_MINIMIZABLE			= 0x00004000,
72 	B_NOT_RESIZABLE				= 0x00000002,
73 	B_NOT_H_RESIZABLE			= 0x00000004,
74 	B_NOT_V_RESIZABLE			= 0x00000008,
75 	B_AVOID_FRONT				= 0x00000080,
76 	B_AVOID_FOCUS				= 0x00002000,
77 	B_WILL_ACCEPT_FIRST_CLICK	= 0x00000010,
78 	B_OUTLINE_RESIZE			= 0x00001000,
79 	B_NO_WORKSPACE_ACTIVATION	= 0x00000100,
80 	B_NOT_ANCHORED_ON_ACTIVATE	= 0x00020000,
81 	B_ASYNCHRONOUS_CONTROLS		= 0x00080000,
82 	B_QUIT_ON_WINDOW_CLOSE		= 0x00100000,
83 	B_SAME_POSITION_IN_ALL_WORKSPACES = 0x00200000,
84 };
85 
86 #define B_CURRENT_WORKSPACE	0
87 #define B_ALL_WORKSPACES	0xffffffff
88 
89 //----------------------------------------------------------------
90 
91 class BWindow : public BLooper {
92 public:
93 						BWindow(BRect frame, const char* title,
94 							window_type type, uint32 flags,
95 							uint32 workspace = B_CURRENT_WORKSPACE);
96 						BWindow(BRect frame, const char* title,
97 							window_look look, window_feel feel,
98 							uint32 flags,
99 							uint32 workspace = B_CURRENT_WORKSPACE);
100 	virtual				~BWindow();
101 
102 						BWindow(BMessage* data);
103 	static	BArchivable	*Instantiate(BMessage* data);
104 	virtual	status_t	Archive(BMessage* data, bool deep = true) const;
105 
106 	virtual	void		Quit();
107 			void		Close() { Quit(); }
108 
109 			void		AddChild(BView* child, BView* before = NULL);
110 			bool		RemoveChild(BView* child);
111 			int32		CountChildren() const;
112 			BView		*ChildAt(int32 index) const;
113 
114 	virtual	void		DispatchMessage(BMessage* message, BHandler* handler);
115 	virtual	void		MessageReceived(BMessage* message);
116 	virtual	void		FrameMoved(BPoint new_position);
117 	virtual void		WorkspacesChanged(uint32 old_ws, uint32 new_ws);
118 	virtual void		WorkspaceActivated(int32 ws, bool state);
119 	virtual	void		FrameResized(float new_width, float new_height);
120 	virtual void		Minimize(bool minimize);
121 	virtual void		Zoom(BPoint origin, float width, float height);
122 			void		Zoom();
123 			void		SetZoomLimits(float maxWidth, float maxHeight);
124 	virtual void		ScreenChanged(BRect screen_size, color_space depth);
125 			void		SetPulseRate(bigtime_t rate);
126 			bigtime_t	PulseRate() const;
127 			void		AddShortcut(uint32 key, uint32 modifiers,
128 							BMessage *msg);
129 			void		AddShortcut(uint32 key, uint32 modifiers,
130 							BMessage *msg, BHandler *target);
131 			void		RemoveShortcut(uint32 key, uint32 modifiers);
132 			void		SetDefaultButton(BButton* button);
133 			BButton		*DefaultButton() const;
134 	virtual	void		MenusBeginning();
135 	virtual	void		MenusEnded();
136 			bool		NeedsUpdate() const;
137 			void		UpdateIfNeeded();
138 			BView		*FindView(const char *viewName) const;
139 			BView		*FindView(BPoint) const;
140 			BView		*CurrentFocus() const;
141 			void		Activate(bool = true);
142 	virtual	void		WindowActivated(bool state);
143 
144 			void		ConvertToScreen(BPoint* pt) const;
145 			BPoint		ConvertToScreen(BPoint pt) const;
146 			void		ConvertFromScreen(BPoint* pt) const;
147 			BPoint		ConvertFromScreen(BPoint pt) const;
148 			void		ConvertToScreen(BRect* rect) const;
149 			BRect		ConvertToScreen(BRect rect) const;
150 			void		ConvertFromScreen(BRect* rect) const;
151 			BRect		ConvertFromScreen(BRect rect) const;
152 
153 			void		MoveBy(float dx, float dy);
154 			void		MoveTo(BPoint);
155 			void		MoveTo(float x, float y);
156 			void		ResizeBy(float dx, float dy);
157 			void		ResizeTo(float width, float height);
158 
159 	virtual	void		Show();
160 	virtual	void		Hide();
161 			bool		IsHidden() const;
162 			bool		IsMinimized() const;
163 
164 			void		Flush() const;
165 			void		Sync() const;
166 
167 			status_t	SendBehind(const BWindow* window);
168 
169 			void		DisableUpdates();
170 			void		EnableUpdates();
171 
172 			void		BeginViewTransaction();	// referred as OpenViewTransaction() in BeBook
173 			void		EndViewTransaction();	// referred as CommitViewTransaction() in BeBook
174 
175 			BRect		Bounds() const;
176 			BRect		Frame() const;
177 			const char	*Title() const;
178 			void		SetTitle(const char* title);
179 			bool		IsFront() const;
180 			bool		IsActive() const;
181 			void		SetKeyMenuBar(BMenuBar* bar);
182 			BMenuBar	*KeyMenuBar() const;
183 			void		SetSizeLimits(float minWidth, float maxWidth,
184 							float minHeight, float maxHeight);
185 			void		GetSizeLimits(float *minWidth, float *maxWidth,
186 							float *minHeight, float *maxHeight);
187 			uint32		Workspaces() const;
188 			void		SetWorkspaces(uint32);
189 			BView		*LastMouseMovedView() const;
190 
191 	virtual BHandler	*ResolveSpecifier(BMessage* msg, int32 index,
192 							BMessage* specifier, int32 form, const char* property);
193 	virtual status_t	GetSupportedSuites(BMessage* data);
194 
195 			status_t	AddToSubset(BWindow* window);
196 			status_t	RemoveFromSubset(BWindow* window);
197 
198 	virtual status_t	Perform(perform_code d, void* arg);
199 
200 			status_t	SetType(window_type type);
201 			window_type	Type() const;
202 
203 			status_t	SetLook(window_look look);
204 			window_look	Look() const;
205 
206 			status_t	SetFeel(window_feel feel);
207 			window_feel	Feel() const;
208 
209 			status_t	SetFlags(uint32);
210 			uint32		Flags() const;
211 
212 			bool		IsModal() const;
213 			bool		IsFloating() const;
214 
215 			status_t	SetWindowAlignment(window_alignment mode, int32 h,
216 							int32 hOffset = 0, int32 width = 0, int32 widthOffset = 0,
217 							int32 v = 0, int32 vOffset = 0, int32 height = 0,
218 							int32 heightOffset = 0);
219 			status_t	GetWindowAlignment(window_alignment* mode = NULL,
220 							int32* h = NULL, int32* hOffset = NULL,
221 							int32* width = NULL, int32* widthOffset = NULL,
222 							int32* v = NULL, int32* vOffset = NULL,
223 							int32* height = NULL, int32* heightOffset = NULL) const;
224 
225 	virtual	bool		QuitRequested();
226 	virtual thread_id	Run();
227 
228 private:
229 	typedef BLooper inherited;
230 	struct unpack_cookie;
231 	class Shortcut;
232 
233 	friend class BApplication;
234 	friend class BBitmap;
235 	friend class BScrollBar;
236 	friend class BView;
237 	friend class BMenuItem;
238 	friend class BWindowScreen;
239 	friend class BDirectWindow;
240 	friend class BFilePanel;
241 	friend class BHandler;
242 	friend class _BEventMask;
243 	friend void _set_menu_sem_(BWindow* w, sem_id sem);
244 	friend status_t _safe_get_server_token_(const BLooper* , int32* );
245 
246 	virtual	void		_ReservedWindow1();
247 	virtual	void		_ReservedWindow2();
248 	virtual	void		_ReservedWindow3();
249 	virtual	void		_ReservedWindow4();
250 	virtual	void		_ReservedWindow5();
251 	virtual	void		_ReservedWindow6();
252 	virtual	void		_ReservedWindow7();
253 	virtual	void		_ReservedWindow8();
254 
255 						BWindow();
256 						BWindow(BWindow&);
257 			BWindow		&operator=(BWindow&);
258 
259 						BWindow(BRect frame, int32 bitmapToken);
260 			void		_InitData(BRect frame, const char* title,
261 								window_look look, window_feel feel,
262 								uint32 flags, uint32 workspace,
263 								int32 bitmapToken = -1);
264 			void		BitmapClose();						// to be implemented
265 	virtual	void		task_looper();
266 
267 	virtual BMessage	*ConvertToMessage(void* raw, int32 code);
268 
269 			void		AddShortcut(uint32 key, uint32 modifiers,
270 							BMenuItem* item);
271 			BHandler*	_DetermineTarget(BMessage* message, BHandler* target);
272 			bool		_UnpackMessage(unpack_cookie& state, BMessage** _message,
273 							BHandler** _target, bool* _usePreferred);
274 			void		_SanitizeMessage(BMessage* message, BHandler* target,
275 							bool usePreferred);
276 
277 			bool		InUpdate();
278 			void		_DequeueAll();
279 			window_type	_ComposeType(window_look look,
280 									 window_feel feel) const;
281 			void		_DecomposeType(window_type type,
282 									   window_look* look,
283 									   window_feel* feel) const;
284 
285 			void		SetIsFilePanel(bool yes);
286 			bool		IsFilePanel() const;
287 
288 			void		_CreateTopView();
289 			void		_AdoptResize();
290 			void		_SetFocus(BView *focusView, bool notifyIputServer = false);
291 
292 			Shortcut*	_FindShortcut(uint32 key, uint32 modifiers);
293 			BView*		_FindView(BView* view, BPoint point) const;
294 			BView*		_FindView(int32 token);
295 			BView*		_LastViewChild(BView *parent);
296 
297 			BView*		_FindNextNavigable(BView *focus, uint32 flags);
298 			BView*		_FindPreviousNavigable(BView *focus, uint32 flags);
299 			bool		_HandleKeyDown(char key, uint32 modifiers);
300 			void		_KeyboardNavigation();
301 
302 			// Debug (TODO: to be removed)
303 			void		PrintToStream() const;
304 
305 private:
306 	char			*fTitle;
307 	int32			server_token;				// not yet used
308 	bool			fInTransaction;
309 	bool			fActive;
310 	short			fShowLevel;
311 	uint32			fFlags;
312 
313 	BView			*fTopView;
314 	BView			*fFocus;
315 	BView			*fLastMouseMovedView;
316 	uint32			_unused1;
317 	BMenuBar		*fKeyMenuBar;
318 	BButton			*fDefaultButton;
319 	BList			fShortcuts;
320 	int32			fTopViewToken;
321 	bool			_unused2;					// was fPulseEnabled
322 	bool			fViewsNeedPulse;			// not yet used
323 	bool			fIsFilePanel;
324 	bool			fMaskActivated;
325 	bigtime_t		fPulseRate;
326 	bool			fWaitingForMenu;
327 	bool			fMinimized;
328 	bool			fNoQuitShortcut;
329 	bool			_unused3;
330 	sem_id			fMenuSem;
331 	float			fMaxZoomHeight;
332 	float			fMaxZoomWidth;
333 	float			fMinHeight;
334 	float			fMinWidth;
335 	float			fMaxHeight;
336 	float			fMaxWidth;
337 	BRect			fFrame;
338 	window_look		fLook;
339 	window_feel		fFeel;
340 	int32			fLastViewToken;
341 	BPrivate::PortLink	*fLink;
342 	BMessageRunner	*fPulseRunner;
343 	BRect			fPreviousFrame;
344 
345 	uint32			_reserved[9];
346 };
347 
348 #endif	// _WINDOW_H
349