xref: /haiku/headers/os/interface/Window.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
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 			bool				RemoveChild(BView* child);
107 			int32				CountChildren() const;
108 			BView*				ChildAt(int32 index) const;
109 
110 	virtual	void				DispatchMessage(BMessage* message,
111 									BHandler* handler);
112 	virtual	void				MessageReceived(BMessage* message);
113 	virtual	void				FrameMoved(BPoint newPosition);
114 	virtual void				WorkspacesChanged(uint32 oldWorkspaces,
115 									uint32 newWorkspaces);
116 	virtual void				WorkspaceActivated(int32 workspace,
117 									bool state);
118 	virtual	void				FrameResized(float newWidth, float newHeight);
119 	virtual void				Minimize(bool minimize);
120 	virtual	void				Zoom(BPoint origin, float width, float height);
121 			void				Zoom();
122 			void				SetZoomLimits(float maxWidth, float maxHeight);
123 	virtual void				ScreenChanged(BRect screenSize,
124 									color_space format);
125 
126 			void				SetPulseRate(bigtime_t rate);
127 			bigtime_t			PulseRate() const;
128 
129 			void				AddShortcut(uint32 key, uint32 modifiers,
130 									BMessage* message);
131 			void				AddShortcut(uint32 key, uint32 modifiers,
132 									BMessage* message, BHandler* target);
133 			void				RemoveShortcut(uint32 key, uint32 modifiers);
134 
135 			void				SetDefaultButton(BButton* button);
136 			BButton*			DefaultButton() const;
137 
138 	virtual	void				MenusBeginning();
139 	virtual	void				MenusEnded();
140 
141 			bool				NeedsUpdate() const;
142 			void				UpdateIfNeeded();
143 
144 			BView*				FindView(const char* viewName) const;
145 			BView*				FindView(BPoint) const;
146 			BView*				CurrentFocus() const;
147 
148 			void				Activate(bool = true);
149 	virtual	void				WindowActivated(bool state);
150 
151 			void				ConvertToScreen(BPoint* point) const;
152 			BPoint				ConvertToScreen(BPoint point) const;
153 			void				ConvertFromScreen(BPoint* point) const;
154 			BPoint				ConvertFromScreen(BPoint point) const;
155 			void				ConvertToScreen(BRect* rect) const;
156 			BRect				ConvertToScreen(BRect rect) const;
157 			void				ConvertFromScreen(BRect* rect) const;
158 			BRect				ConvertFromScreen(BRect rect) const;
159 
160 			void				MoveBy(float dx, float dy);
161 			void				MoveTo(BPoint);
162 			void				MoveTo(float x, float y);
163 			void				ResizeBy(float dx, float dy);
164 			void				ResizeTo(float width, float height);
165 
166 			void 				CenterIn(const BRect& rect);
167 			void 				CenterOnScreen();
168 
169 	virtual	void				Show();
170 	virtual	void				Hide();
171 			bool				IsHidden() const;
172 			bool				IsMinimized() const;
173 
174 			void				Flush() const;
175 			void				Sync() const;
176 
177 			status_t			SendBehind(const BWindow* window);
178 
179 			void				DisableUpdates();
180 			void				EnableUpdates();
181 
182 			void				BeginViewTransaction();
183 									// referred as OpenViewTransaction()
184 									// in BeBook
185 			void				EndViewTransaction();
186 									// referred as CommitViewTransaction()
187 									// in BeBook
188 
189 			BRect				Bounds() const;
190 			BRect				Frame() const;
191 			BRect				DecoratorFrame() const;
192 			BSize				Size() const;
193 			const char*			Title() const;
194 			void				SetTitle(const char* title);
195 			bool				IsFront() const;
196 			bool				IsActive() const;
197 
198 			void				SetKeyMenuBar(BMenuBar* bar);
199 			BMenuBar*			KeyMenuBar() const;
200 
201 			void				SetSizeLimits(float minWidth, float maxWidth,
202 									float minHeight, float maxHeight);
203 			void				GetSizeLimits(float* minWidth, float* maxWidth,
204 									float* minHeight, float* maxHeight);
205 
206 			status_t			SetDecoratorSettings(const BMessage& settings);
207 			status_t			GetDecoratorSettings(BMessage* settings) const;
208 
209 			uint32				Workspaces() const;
210 			void				SetWorkspaces(uint32);
211 
212 			BView*				LastMouseMovedView() const;
213 
214 	virtual BHandler*			ResolveSpecifier(BMessage* message,
215 									int32 index, BMessage* specifier,
216 									int32 form, const char* property);
217 	virtual status_t			GetSupportedSuites(BMessage* data);
218 
219 			status_t			AddToSubset(BWindow* window);
220 			status_t			RemoveFromSubset(BWindow* window);
221 
222 	virtual status_t			Perform(perform_code code, void* data);
223 
224 			status_t			SetType(window_type type);
225 			window_type			Type() const;
226 
227 			status_t			SetLook(window_look look);
228 			window_look			Look() const;
229 
230 			status_t			SetFeel(window_feel feel);
231 			window_feel			Feel() const;
232 
233 			status_t			SetFlags(uint32);
234 			uint32				Flags() const;
235 
236 			bool				IsModal() const;
237 			bool				IsFloating() const;
238 
239 			status_t			SetWindowAlignment(window_alignment mode,
240 									int32 h, int32 hOffset = 0,
241 									int32 width = 0, int32 widthOffset = 0,
242 									int32 v = 0, int32 vOffset = 0,
243 									int32 height = 0, int32 heightOffset = 0);
244 			status_t			GetWindowAlignment(
245 									window_alignment* mode = NULL,
246 									int32* h = NULL, int32* hOffset = NULL,
247 									int32* width = NULL,
248 									int32* widthOffset = NULL,
249 									int32* v = NULL, int32* vOffset = NULL,
250 									int32* height = NULL,
251 									int32* heightOffset = NULL) const;
252 
253 	virtual	bool				QuitRequested();
254 	virtual thread_id			Run();
255 
256 	virtual	void				SetLayout(BLayout* layout);
257 			BLayout*			GetLayout() const;
258 
259 			void				InvalidateLayout(bool descendants = false);
260 
261 private:
262 	// FBC padding and forbidden methods
263 	virtual	void				_ReservedWindow2();
264 	virtual	void				_ReservedWindow3();
265 	virtual	void				_ReservedWindow4();
266 	virtual	void				_ReservedWindow5();
267 	virtual	void				_ReservedWindow6();
268 	virtual	void				_ReservedWindow7();
269 	virtual	void				_ReservedWindow8();
270 
271 								BWindow();
272 								BWindow(BWindow&);
273 			BWindow&			operator=(BWindow&);
274 
275 private:
276 	typedef BLooper inherited;
277 	struct unpack_cookie;
278 	class Shortcut;
279 
280 	friend class BApplication;
281 	friend class BBitmap;
282 	friend class BView;
283 	friend class BMenuItem;
284 	friend class BWindowScreen;
285 	friend class BDirectWindow;
286 	friend class BFilePanel;
287 
288 	friend void _set_menu_sem_(BWindow* w, sem_id sem);
289 	friend status_t _safe_get_server_token_(const BLooper*, int32*);
290 
291 								BWindow(BRect frame, int32 bitmapToken);
292 			void				_InitData(BRect frame, const char* title,
293 									window_look look, window_feel feel,
294 									uint32 flags, uint32 workspace,
295 									int32 bitmapToken = -1);
296 
297 	virtual	void				task_looper();
298 
299 	virtual BMessage*			ConvertToMessage(void* raw, int32 code);
300 
301 			void				AddShortcut(uint32 key, uint32 modifiers,
302 									BMenuItem* item);
303 			BHandler*			_DetermineTarget(BMessage* message,
304 									BHandler* target);
305 			bool				_IsFocusMessage(BMessage* message);
306 			bool				_UnpackMessage(unpack_cookie& state,
307 									BMessage** _message, BHandler** _target,
308 									bool* _usePreferred);
309 			void				_SanitizeMessage(BMessage* message,
310 									BHandler* target, bool usePreferred);
311 			bool				_StealMouseMessage(BMessage* message,
312 									bool& deleteMessage);
313 			uint32				_TransitForMouseMoved(BView* view,
314 									BView* viewUnderMouse) const;
315 
316 			bool				InUpdate();
317 			void				_DequeueAll();
318 			window_type			_ComposeType(window_look look,
319 									window_feel feel) const;
320 			void				_DecomposeType(window_type type,
321 									window_look* look,
322 									window_feel* feel) const;
323 
324 			void				SetIsFilePanel(bool yes);
325 			bool				IsFilePanel() const;
326 
327 			void				_CreateTopView();
328 			void				_AdoptResize();
329 			void				_SetFocus(BView* focusView,
330 									bool notifyIputServer = false);
331 			void				_SetName(const char* title);
332 
333 			Shortcut*			_FindShortcut(uint32 key, uint32 modifiers);
334 			BView*				_FindView(BView* view, BPoint point) const;
335 			BView*				_FindView(int32 token);
336 			BView*				_LastViewChild(BView* parent);
337 
338 			BView*				_FindNextNavigable(BView* focus, uint32 flags);
339 			BView*				_FindPreviousNavigable(BView* focus,
340 									uint32 flags);
341 			void				_Switcher(int32 rawKey, uint32 modifiers,
342 									bool repeat);
343 			bool				_HandleKeyDown(BMessage* event);
344 			bool				_HandleUnmappedKeyDown(BMessage* event);
345 			void				_KeyboardNavigation();
346 
347 			void				_GetDecoratorSize(float* _borderWidth,
348 									float* _tabHeight) const;
349 
350 			void				_CheckSizeLimits();
351 
352 private:
353 			char*				fTitle;
354 			int32				_unused0;
355 			bool				fInTransaction;
356 			bool				fActive;
357 			short				fShowLevel;
358 			uint32				fFlags;
359 
360 			BView*				fTopView;
361 			BView*				fFocus;
362 			BView*				fLastMouseMovedView;
363 			BMessageRunner*		fIdleMouseRunner;
364 			BMenuBar*			fKeyMenuBar;
365 			BButton*			fDefaultButton;
366 			BList				fShortcuts;
367 			int32				fTopViewToken;
368 			bool				fUpdateRequested;
369 			bool				fOffscreen;
370 			bool				fIsFilePanel;
371 			bool				_unused4;
372 			bigtime_t			fPulseRate;
373 			bool				_unused5;
374 			bool				fMinimized;
375 			bool				fNoQuitShortcut;
376 			bool				_unused6;
377 			sem_id				fMenuSem;
378 			float				fMaxZoomHeight;
379 			float				fMaxZoomWidth;
380 			float				fMinHeight;
381 			float				fMinWidth;
382 			float				fMaxHeight;
383 			float				fMaxWidth;
384 			BRect				fFrame;
385 			window_look			fLook;
386 			window_feel			fFeel;
387 			int32				fLastViewToken;
388 			BPrivate::PortLink*	fLink;
389 			BMessageRunner*		fPulseRunner;
390 			BRect				fPreviousFrame;
391 
392 			uint32				_reserved[9];
393 };
394 
395 #endif // _WINDOW_H
396