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