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