xref: /haiku/headers/os/interface/Window.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
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 };
86 
87 #define B_CURRENT_WORKSPACE	0
88 #define B_ALL_WORKSPACES	0xffffffff
89 
90 //----------------------------------------------------------------
91 
92 class BWindow : public BLooper {
93 public:
94 								BWindow(BRect frame, const char* title,
95 										window_type type, uint32 flags,
96 										uint32 workspace = B_CURRENT_WORKSPACE);
97 								BWindow(BRect frame, const char* title,
98 										window_look look, window_feel feel,
99 										uint32 flags,
100 										uint32 workspace = B_CURRENT_WORKSPACE);
101 	virtual						~BWindow();
102 
103 								BWindow(BMessage* data);
104 
105 	static	BArchivable*		Instantiate(BMessage* data);
106 	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
107 
108 	virtual	void				Quit();
109 			void				Close() { Quit(); }
110 
111 			void				AddChild(BView* child, BView* before = NULL);
112 			bool				RemoveChild(BView* child);
113 			int32				CountChildren() const;
114 			BView*				ChildAt(int32 index) const;
115 
116 	virtual	void				DispatchMessage(BMessage* message,
117 												BHandler* handler);
118 	virtual	void				MessageReceived(BMessage* message);
119 	virtual	void				FrameMoved(BPoint new_position);
120 	virtual void				WorkspacesChanged(uint32 oldWorkspaces,
121 												  uint32 newWorkspaces);
122 	virtual void				WorkspaceActivated(int32 workspace,
123 												   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,
130 											  color_space format);
131 
132 			void				SetPulseRate(bigtime_t rate);
133 			bigtime_t			PulseRate() const;
134 
135 			void				AddShortcut(uint32 key, uint32 modifiers,
136 											BMessage *message);
137 			void				AddShortcut(uint32 key, uint32 modifiers,
138 											BMessage *message,
139 											BHandler *target);
140 			void				RemoveShortcut(uint32 key, uint32 modifiers);
141 
142 			void				SetDefaultButton(BButton* button);
143 			BButton*			DefaultButton() const;
144 
145 	virtual	void				MenusBeginning();
146 	virtual	void				MenusEnded();
147 
148 			bool				NeedsUpdate() const;
149 			void				UpdateIfNeeded();
150 
151 			BView*				FindView(const char* viewName) const;
152 			BView*				FindView(BPoint) const;
153 			BView*				CurrentFocus() const;
154 
155 			void				Activate(bool = true);
156 	virtual	void				WindowActivated(bool state);
157 
158 			void				ConvertToScreen(BPoint* point) const;
159 			BPoint				ConvertToScreen(BPoint point) const;
160 			void				ConvertFromScreen(BPoint* point) const;
161 			BPoint				ConvertFromScreen(BPoint point) const;
162 			void				ConvertToScreen(BRect* rect) const;
163 			BRect				ConvertToScreen(BRect rect) const;
164 			void				ConvertFromScreen(BRect* rect) const;
165 			BRect				ConvertFromScreen(BRect rect) const;
166 
167 			void				MoveBy(float dx, float dy);
168 			void				MoveTo(BPoint);
169 			void				MoveTo(float x, float y);
170 			void				ResizeBy(float dx, float dy);
171 			void				ResizeTo(float width, float height);
172 
173 	virtual	void				Show();
174 	virtual	void				Hide();
175 			bool				IsHidden() const;
176 			bool				IsMinimized() const;
177 
178 			void				Flush() const;
179 			void				Sync() const;
180 
181 			status_t			SendBehind(const BWindow* window);
182 
183 			void				DisableUpdates();
184 			void				EnableUpdates();
185 
186 			void				BeginViewTransaction();
187 								// referred as OpenViewTransaction() in BeBook
188 			void				EndViewTransaction();
189 								// referred as CommitViewTransaction() in BeBook
190 
191 			BRect				Bounds() const;
192 			BRect				Frame() 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, int32 index,
215 												 BMessage* specifier, int32 form,
216 												 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 d, void* arg);
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,
241 												   int32 hOffset = 0,
242 												   int32 width = 0,
243 												   int32 widthOffset = 0,
244 												   int32 v = 0,
245 												   int32 vOffset = 0,
246 												   int32 height = 0,
247 												   int32 heightOffset = 0);
248 			status_t			GetWindowAlignment(window_alignment* mode = NULL,
249 												   int32* h = NULL,
250 												   int32* hOffset = NULL,
251 												   int32* width = NULL,
252 												   int32* widthOffset = NULL,
253 												   int32* v = NULL,
254 												   int32* vOffset = NULL,
255 												   int32* height = NULL,
256 												   int32* heightOffset = NULL) const;
257 
258 	virtual	bool				QuitRequested();
259 	virtual thread_id			Run();
260 
261 	virtual	void			SetLayout(BLayout* layout);
262 			BLayout*		GetLayout() const;
263 
264 			void			InvalidateLayout(bool descendants = false);
265 
266 private:
267 	typedef BLooper inherited;
268 	struct unpack_cookie;
269 	class Shortcut;
270 
271 	friend class BApplication;
272 	friend class BBitmap;
273 	friend class BScrollBar;
274 	friend class BView;
275 	friend class BMenuItem;
276 	friend class BWindowScreen;
277 	friend class BDirectWindow;
278 	friend class BFilePanel;
279 	friend class BHandler;
280 	friend class _BEventMask;
281 	friend void _set_menu_sem_(BWindow* w, sem_id sem);
282 	friend status_t _safe_get_server_token_(const BLooper*, int32*);
283 
284 	virtual	void				_ReservedWindow1();
285 	virtual	void				_ReservedWindow2();
286 	virtual	void				_ReservedWindow3();
287 	virtual	void				_ReservedWindow4();
288 	virtual	void				_ReservedWindow5();
289 	virtual	void				_ReservedWindow6();
290 	virtual	void				_ReservedWindow7();
291 	virtual	void				_ReservedWindow8();
292 
293 								BWindow();
294 								BWindow(BWindow&);
295 			BWindow&			operator=(BWindow&);
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 			void				BitmapClose(); // to be implemented
304 	virtual	void				task_looper();
305 
306 	virtual BMessage*			ConvertToMessage(void* raw, int32 code);
307 
308 			void				AddShortcut(uint32 key, uint32 modifiers,
309 											BMenuItem* item);
310 			BHandler*			_DetermineTarget(BMessage* message,
311 												 BHandler* target);
312 			bool				_UnpackMessage(unpack_cookie& state,
313 											   BMessage** _message,
314 											   BHandler** _target,
315 											   bool* _usePreferred);
316 			void				_SanitizeMessage(BMessage* message,
317 												 BHandler* target,
318 												 bool usePreferred);
319 			bool				_StealMouseMessage(BMessage* message,
320 									bool& deleteMessage);
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 
338 			Shortcut*			_FindShortcut(uint32 key, uint32 modifiers);
339 			BView*				_FindView(BView* view, BPoint point) const;
340 			BView*				_FindView(int32 token);
341 			BView*				_LastViewChild(BView* parent);
342 
343 			BView*				_FindNextNavigable(BView *focus, uint32 flags);
344 			BView*				_FindPreviousNavigable(BView *focus,
345 													   uint32 flags);
346 			bool				_HandleKeyDown(BMessage* event);
347 			void				_KeyboardNavigation();
348 
349 			// Debug (TODO: to be removed)
350 			void				PrintToStream() const;
351 
352 private:
353 			char*				fTitle;
354 			int32				server_token;				// not yet used
355 			bool				fInTransaction;
356 			bool				fActive;
357 			short				fShowLevel;
358 			uint32				fFlags;
359 
360 			BView*				fTopView;
361 			BView*				fFocus;
362 			BView*				fLastMouseMovedView;
363 			uint32				_unused1;
364 			BMenuBar*			fKeyMenuBar;
365 			BButton*			fDefaultButton;
366 			BList				fShortcuts;
367 			int32				fTopViewToken;
368 			bool				_unused2;					// was fPulseEnabled
369 			bool				fViewsNeedPulse;			// not yet used
370 			bool				fIsFilePanel;
371 			bool				fMaskActivated;
372 			bigtime_t			fPulseRate;
373 			bool				fWaitingForMenu;
374 			bool				fMinimized;
375 			bool				fNoQuitShortcut;
376 			bool				_unused3;
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