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