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