xref: /haiku/headers/os/interface/Window.h (revision b9a5b9a6ee494261f2882bfc0ee9fde92282bef6)
1 /*
2  * Copyright 2001-2007, 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 	B_AUTO_UPDATE_SIZE_LIMITS	= 0x00400000,
85 	B_CLOSE_ON_ESCAPE			= 0x00800000
86 };
87 
88 #define B_CURRENT_WORKSPACE	0
89 #define B_ALL_WORKSPACES	0xffffffff
90 
91 //----------------------------------------------------------------
92 
93 class BWindow : public BLooper {
94 public:
95 								BWindow(BRect frame, const char* title,
96 										window_type type, uint32 flags,
97 										uint32 workspace = B_CURRENT_WORKSPACE);
98 								BWindow(BRect frame, const char* title,
99 										window_look look, window_feel feel,
100 										uint32 flags,
101 										uint32 workspace = B_CURRENT_WORKSPACE);
102 	virtual						~BWindow();
103 
104 								BWindow(BMessage* data);
105 
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 new_position);
121 	virtual void				WorkspacesChanged(uint32 oldWorkspaces,
122 												  uint32 newWorkspaces);
123 	virtual void				WorkspaceActivated(int32 workspace,
124 												   bool state);
125 	virtual	void				FrameResized(float newWidth, float newHeight);
126 	virtual void				Minimize(bool minimize);
127 	virtual	void				Zoom(BPoint origin, float width, float height);
128 			void				Zoom();
129 			void				SetZoomLimits(float maxWidth, float maxHeight);
130 	virtual void				ScreenChanged(BRect screenSize,
131 											  color_space format);
132 
133 			void				SetPulseRate(bigtime_t rate);
134 			bigtime_t			PulseRate() const;
135 
136 			void				AddShortcut(uint32 key, uint32 modifiers,
137 											BMessage *message);
138 			void				AddShortcut(uint32 key, uint32 modifiers,
139 											BMessage *message,
140 											BHandler *target);
141 			void				RemoveShortcut(uint32 key, uint32 modifiers);
142 
143 			void				SetDefaultButton(BButton* button);
144 			BButton*			DefaultButton() const;
145 
146 	virtual	void				MenusBeginning();
147 	virtual	void				MenusEnded();
148 
149 			bool				NeedsUpdate() const;
150 			void				UpdateIfNeeded();
151 
152 			BView*				FindView(const char* viewName) const;
153 			BView*				FindView(BPoint) const;
154 			BView*				CurrentFocus() const;
155 
156 			void				Activate(bool = true);
157 	virtual	void				WindowActivated(bool state);
158 
159 			void				ConvertToScreen(BPoint* point) const;
160 			BPoint				ConvertToScreen(BPoint point) const;
161 			void				ConvertFromScreen(BPoint* point) const;
162 			BPoint				ConvertFromScreen(BPoint point) const;
163 			void				ConvertToScreen(BRect* rect) const;
164 			BRect				ConvertToScreen(BRect rect) const;
165 			void				ConvertFromScreen(BRect* rect) const;
166 			BRect				ConvertFromScreen(BRect rect) const;
167 
168 			void				MoveBy(float dx, float dy);
169 			void				MoveTo(BPoint);
170 			void				MoveTo(float x, float y);
171 			void				ResizeBy(float dx, float dy);
172 			void				ResizeTo(float width, float height);
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 			const char*			Title() const;
195 			void				SetTitle(const char* title);
196 			bool				IsFront() const;
197 			bool				IsActive() const;
198 
199 			void				SetKeyMenuBar(BMenuBar* bar);
200 			BMenuBar*			KeyMenuBar() const;
201 
202 			void				SetSizeLimits(float minWidth, float maxWidth,
203 											  float minHeight, float maxHeight);
204 			void				GetSizeLimits(float* minWidth, float* maxWidth,
205 											  float* minHeight, float* maxHeight);
206 
207 			status_t			SetDecoratorSettings(const BMessage& settings);
208 			status_t			GetDecoratorSettings(BMessage* settings) const;
209 
210 			uint32				Workspaces() const;
211 			void				SetWorkspaces(uint32);
212 
213 			BView*				LastMouseMovedView() const;
214 
215 	virtual BHandler*			ResolveSpecifier(BMessage* message, int32 index,
216 												 BMessage* specifier, int32 form,
217 												 const char* property);
218 	virtual status_t			GetSupportedSuites(BMessage* data);
219 
220 			status_t			AddToSubset(BWindow* window);
221 			status_t			RemoveFromSubset(BWindow* window);
222 
223 	virtual status_t			Perform(perform_code d, void* arg);
224 
225 			status_t			SetType(window_type type);
226 			window_type			Type() const;
227 
228 			status_t			SetLook(window_look look);
229 			window_look			Look() const;
230 
231 			status_t			SetFeel(window_feel feel);
232 			window_feel			Feel() const;
233 
234 			status_t			SetFlags(uint32);
235 			uint32				Flags() const;
236 
237 			bool				IsModal() const;
238 			bool				IsFloating() const;
239 
240 			status_t			SetWindowAlignment(window_alignment mode,
241 												   int32 h,
242 												   int32 hOffset = 0,
243 												   int32 width = 0,
244 												   int32 widthOffset = 0,
245 												   int32 v = 0,
246 												   int32 vOffset = 0,
247 												   int32 height = 0,
248 												   int32 heightOffset = 0);
249 			status_t			GetWindowAlignment(window_alignment* mode = NULL,
250 												   int32* h = NULL,
251 												   int32* hOffset = NULL,
252 												   int32* width = NULL,
253 												   int32* widthOffset = NULL,
254 												   int32* v = NULL,
255 												   int32* vOffset = NULL,
256 												   int32* height = NULL,
257 												   int32* heightOffset = NULL) const;
258 
259 	virtual	bool				QuitRequested();
260 	virtual thread_id			Run();
261 
262 	virtual	void				SetLayout(BLayout* layout);
263 			BLayout*			GetLayout() const;
264 
265 			void				InvalidateLayout(bool descendants = false);
266 
267 private:
268 	typedef BLooper inherited;
269 	struct unpack_cookie;
270 	class Shortcut;
271 
272 	friend class BApplication;
273 	friend class BBitmap;
274 	friend class BScrollBar;
275 	friend class BView;
276 	friend class BMenuItem;
277 	friend class BWindowScreen;
278 	friend class BDirectWindow;
279 	friend class BFilePanel;
280 	friend class BHandler;
281 	friend class _BEventMask;
282 	friend void _set_menu_sem_(BWindow* w, sem_id sem);
283 	friend status_t _safe_get_server_token_(const BLooper*, int32*);
284 
285 	virtual	void				_ReservedWindow1();
286 	virtual	void				_ReservedWindow2();
287 	virtual	void				_ReservedWindow3();
288 	virtual	void				_ReservedWindow4();
289 	virtual	void				_ReservedWindow5();
290 	virtual	void				_ReservedWindow6();
291 	virtual	void				_ReservedWindow7();
292 	virtual	void				_ReservedWindow8();
293 
294 								BWindow();
295 								BWindow(BWindow&);
296 			BWindow&			operator=(BWindow&);
297 
298 								BWindow(BRect frame, int32 bitmapToken);
299 			void				_InitData(BRect frame, const char* title,
300 										  window_look look, window_feel feel,
301 										  uint32 flags, uint32 workspace,
302 										  int32 bitmapToken = -1);
303 
304 			void				BitmapClose(); // to be implemented
305 	virtual	void				task_looper();
306 
307 	virtual BMessage*			ConvertToMessage(void* raw, int32 code);
308 
309 			void				AddShortcut(uint32 key, uint32 modifiers,
310 											BMenuItem* item);
311 			BHandler*			_DetermineTarget(BMessage* message,
312 												 BHandler* target);
313 			bool				_UnpackMessage(unpack_cookie& state,
314 											   BMessage** _message,
315 											   BHandler** _target,
316 											   bool* _usePreferred);
317 			void				_SanitizeMessage(BMessage* message,
318 												 BHandler* target,
319 												 bool usePreferred);
320 			bool				_StealMouseMessage(BMessage* message,
321 									bool& deleteMessage);
322 
323 			bool				InUpdate();
324 			void				_DequeueAll();
325 			window_type			_ComposeType(window_look look,
326 											 window_feel feel) const;
327 			void				_DecomposeType(window_type type,
328 											   window_look* look,
329 											   window_feel* feel) const;
330 
331 			void				SetIsFilePanel(bool yes);
332 			bool				IsFilePanel() const;
333 
334 			void				_CreateTopView();
335 			void				_AdoptResize();
336 			void				_SetFocus(BView* focusView,
337 										  bool notifyIputServer = false);
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 			bool				_HandleKeyDown(BMessage* event);
348 			void				_KeyboardNavigation();
349 
350 			// Debug (TODO: to be removed)
351 			void				PrintToStream() const;
352 
353 private:
354 			char*				fTitle;
355 			int32				server_token;				// not yet used
356 			bool				fInTransaction;
357 			bool				fActive;
358 			short				fShowLevel;
359 			uint32				fFlags;
360 
361 			BView*				fTopView;
362 			BView*				fFocus;
363 			BView*				fLastMouseMovedView;
364 			uint32				_unused1;
365 			BMenuBar*			fKeyMenuBar;
366 			BButton*			fDefaultButton;
367 			BList				fShortcuts;
368 			int32				fTopViewToken;
369 			bool				_unused2;					// was fPulseEnabled
370 			bool				fViewsNeedPulse;			// not yet used
371 			bool				fIsFilePanel;
372 			bool				fMaskActivated;
373 			bigtime_t			fPulseRate;
374 			bool				fWaitingForMenu;
375 			bool				fMinimized;
376 			bool				fNoQuitShortcut;
377 			bool				_unused3;
378 			sem_id				fMenuSem;
379 			float				fMaxZoomHeight;
380 			float				fMaxZoomWidth;
381 			float				fMinHeight;
382 			float				fMinWidth;
383 			float				fMaxHeight;
384 			float				fMaxWidth;
385 			BRect				fFrame;
386 			window_look			fLook;
387 			window_feel			fFeel;
388 			int32				fLastViewToken;
389 			BPrivate::PortLink*	fLink;
390 			BMessageRunner*		fPulseRunner;
391 			BRect				fPreviousFrame;
392 
393 			uint32				_reserved[9];
394 };
395 
396 #endif	// _WINDOW_H
397