Window.h revision 8e96ec34
1/*
2 * Copyright 2001-2015, 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
14class BButton;
15class BMenuBar;
16class BMenuItem;
17class BMessage;
18class BMessageRunner;
19class BMessenger;
20class BView;
21
22namespace BPrivate {
23	class PortLink;
24};
25
26
27enum window_type {
28	B_UNTYPED_WINDOW					= 0,
29	B_TITLED_WINDOW						= 1,
30	B_MODAL_WINDOW						= 3,
31	B_DOCUMENT_WINDOW					= 11,
32	B_BORDERED_WINDOW					= 20,
33	B_FLOATING_WINDOW					= 21
34};
35
36enum window_look {
37	B_BORDERED_WINDOW_LOOK				= 20,
38	B_NO_BORDER_WINDOW_LOOK				= 19,
39	B_TITLED_WINDOW_LOOK				= 1,
40	B_DOCUMENT_WINDOW_LOOK				= 11,
41	B_MODAL_WINDOW_LOOK					= 3,
42	B_FLOATING_WINDOW_LOOK				= 7
43};
44
45enum window_feel {
46	B_NORMAL_WINDOW_FEEL				= 0,
47	B_MODAL_SUBSET_WINDOW_FEEL			= 2,
48	B_MODAL_APP_WINDOW_FEEL				= 1,
49	B_MODAL_ALL_WINDOW_FEEL				= 3,
50	B_FLOATING_SUBSET_WINDOW_FEEL		= 5,
51	B_FLOATING_APP_WINDOW_FEEL			= 4,
52	B_FLOATING_ALL_WINDOW_FEEL			= 6
53};
54
55enum window_alignment {
56	B_BYTE_ALIGNMENT	= 0,
57	B_PIXEL_ALIGNMENT	= 1
58};
59
60// window flags
61enum {
62	B_NOT_MOVABLE						= 0x00000001,
63	B_NOT_CLOSABLE						= 0x00000020,
64	B_NOT_ZOOMABLE						= 0x00000040,
65	B_NOT_MINIMIZABLE					= 0x00004000,
66	B_NOT_RESIZABLE						= 0x00000002,
67	B_NOT_H_RESIZABLE					= 0x00000004,
68	B_NOT_V_RESIZABLE					= 0x00000008,
69	B_AVOID_FRONT						= 0x00000080,
70	B_AVOID_FOCUS						= 0x00002000,
71	B_WILL_ACCEPT_FIRST_CLICK			= 0x00000010,
72	B_OUTLINE_RESIZE					= 0x00001000,
73	B_NO_WORKSPACE_ACTIVATION			= 0x00000100,
74	B_NOT_ANCHORED_ON_ACTIVATE			= 0x00020000,
75	B_ASYNCHRONOUS_CONTROLS				= 0x00080000,
76	B_QUIT_ON_WINDOW_CLOSE				= 0x00100000,
77	B_SAME_POSITION_IN_ALL_WORKSPACES	= 0x00200000,
78	B_AUTO_UPDATE_SIZE_LIMITS			= 0x00400000,
79	B_CLOSE_ON_ESCAPE					= 0x00800000,
80	B_NO_SERVER_SIDE_WINDOW_MODIFIERS	= 0x00000200
81};
82
83#define B_CURRENT_WORKSPACE				0
84#define B_ALL_WORKSPACES				0xffffffff
85
86// MoveOnScreen() flags
87enum {
88	B_DO_NOT_RESIZE_TO_FIT				= 0x0001,
89	B_MOVE_IF_PARTIALLY_OFFSCREEN		= 0x0002
90};
91
92
93class BWindow : public BLooper {
94public:
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, uint32 workspace
101										= B_CURRENT_WORKSPACE);
102	virtual						~BWindow();
103
104								BWindow(BMessage* archive);
105	static	BArchivable*		Instantiate(BMessage* archive);
106	virtual	status_t			Archive(BMessage* archive,
107									bool deep = true) const;
108
109	virtual	void				Quit();
110			void				Close() { Quit(); }
111
112			void				AddChild(BView* child, BView* before = NULL);
113			void				AddChild(BLayoutItem* child);
114			bool				RemoveChild(BView* child);
115			int32				CountChildren() const;
116			BView*				ChildAt(int32 index) const;
117
118	virtual	void				DispatchMessage(BMessage* message,
119									BHandler* handler);
120	virtual	void				MessageReceived(BMessage* message);
121	virtual	void				FrameMoved(BPoint newPosition);
122	virtual void				WorkspacesChanged(uint32 oldWorkspaces,
123									uint32 newWorkspaces);
124	virtual void				WorkspaceActivated(int32 workspace,
125									bool state);
126	virtual	void				FrameResized(float newWidth, float newHeight);
127	virtual void				Minimize(bool minimize);
128	virtual	void				Zoom(BPoint origin, float width, float height);
129			void				Zoom();
130			void				SetZoomLimits(float maxWidth, float maxHeight);
131	virtual void				ScreenChanged(BRect screenSize,
132									color_space depth);
133
134			void				SetPulseRate(bigtime_t rate);
135			bigtime_t			PulseRate() const;
136
137			void				AddShortcut(uint32 key, uint32 modifiers,
138									BMessage* message);
139			void				AddShortcut(uint32 key, uint32 modifiers,
140									BMessage* message, BHandler* target);
141			bool				HasShortcut(uint32 key, uint32 modifiers);
142			void				RemoveShortcut(uint32 key, uint32 modifiers);
143
144			void				SetDefaultButton(BButton* button);
145			BButton*			DefaultButton() const;
146
147	virtual	void				MenusBeginning();
148	virtual	void				MenusEnded();
149
150			bool				NeedsUpdate() const;
151			void				UpdateIfNeeded();
152
153			BView*				FindView(const char* viewName) const;
154			BView*				FindView(BPoint) const;
155			BView*				CurrentFocus() const;
156
157			void				Activate(bool = true);
158	virtual	void				WindowActivated(bool focus);
159
160			void				ConvertToScreen(BPoint* point) const;
161			BPoint				ConvertToScreen(BPoint point) const;
162			void				ConvertFromScreen(BPoint* point) const;
163			BPoint				ConvertFromScreen(BPoint point) const;
164			void				ConvertToScreen(BRect* rect) const;
165			BRect				ConvertToScreen(BRect rect) const;
166			void				ConvertFromScreen(BRect* rect) const;
167			BRect				ConvertFromScreen(BRect rect) const;
168
169			void				MoveBy(float dx, float dy);
170			void				MoveTo(BPoint);
171			void				MoveTo(float x, float y);
172			void				ResizeBy(float dx, float dy);
173			void				ResizeTo(float width, float height);
174			void				ResizeToPreferred();
175
176			void				CenterIn(const BRect& rect);
177			void				CenterOnScreen();
178			void				CenterOnScreen(screen_id id);
179			void				MoveOnScreen(uint32 flags = 0);
180
181	virtual	void				Show();
182	virtual	void				Hide();
183			bool				IsHidden() const;
184			bool				IsMinimized() const;
185
186			void				Flush() const;
187			void				Sync() const;
188
189			status_t			SendBehind(const BWindow* window);
190
191			void				DisableUpdates();
192			void				EnableUpdates();
193
194			void				BeginViewTransaction();
195									// referred as OpenViewTransaction()
196									// in BeBook
197			void				EndViewTransaction();
198									// referred as CommitViewTransaction()
199									// in BeBook
200			bool				InViewTransaction() const;
201
202			BRect				Bounds() const;
203			BRect				Frame() const;
204			BRect				DecoratorFrame() const;
205			BSize				Size() const;
206			const char*			Title() const;
207			void				SetTitle(const char* title);
208			bool				IsFront() const;
209			bool				IsActive() const;
210
211			void				SetKeyMenuBar(BMenuBar* bar);
212			BMenuBar*			KeyMenuBar() const;
213
214			void				SetSizeLimits(float minWidth, float maxWidth,
215									float minHeight, float maxHeight);
216			void				GetSizeLimits(float* minWidth, float* maxWidth,
217									float* minHeight, float* maxHeight);
218			void				UpdateSizeLimits();
219
220			status_t			SetDecoratorSettings(const BMessage& settings);
221			status_t			GetDecoratorSettings(BMessage* settings) const;
222
223			uint32				Workspaces() const;
224			void				SetWorkspaces(uint32);
225
226			BView*				LastMouseMovedView() const;
227
228	virtual BHandler*			ResolveSpecifier(BMessage* message,
229									int32 index, BMessage* specifier,
230									int32 what, const char* property);
231	virtual status_t			GetSupportedSuites(BMessage* data);
232
233			status_t			AddToSubset(BWindow* window);
234			status_t			RemoveFromSubset(BWindow* window);
235
236	virtual status_t			Perform(perform_code code, void* data);
237
238			status_t			SetType(window_type type);
239			window_type			Type() const;
240
241			status_t			SetLook(window_look look);
242			window_look			Look() const;
243
244			status_t			SetFeel(window_feel feel);
245			window_feel			Feel() const;
246
247			status_t			SetFlags(uint32);
248			uint32				Flags() const;
249
250			bool				IsModal() const;
251			bool				IsFloating() const;
252
253			status_t			SetWindowAlignment(window_alignment mode,
254									int32 h, int32 hOffset = 0,
255									int32 width = 0, int32 widthOffset = 0,
256									int32 v = 0, int32 vOffset = 0,
257									int32 height = 0, int32 heightOffset = 0);
258			status_t			GetWindowAlignment(
259									window_alignment* mode = NULL,
260									int32* h = NULL, int32* hOffset = NULL,
261									int32* width = NULL,
262									int32* widthOffset = NULL,
263									int32* v = NULL, int32* vOffset = NULL,
264									int32* height = NULL,
265									int32* heightOffset = NULL) const;
266
267	virtual	bool				QuitRequested();
268	virtual thread_id			Run();
269
270	virtual	void				SetLayout(BLayout* layout);
271			BLayout*			GetLayout() const;
272
273			void				InvalidateLayout(bool descendants = false);
274			void				Layout(bool force);
275
276private:
277	// FBC padding and forbidden methods
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
290private:
291	typedef BLooper inherited;
292	struct unpack_cookie;
293	class Shortcut;
294
295	friend class BAlert;
296	friend class BApplication;
297	friend class BBitmap;
298	friend class BView;
299	friend class BMenuItem;
300	friend class BWindowScreen;
301	friend class BDirectWindow;
302	friend class BFilePanel;
303	friend class BWindowStack;
304
305	friend void _set_menu_sem_(BWindow* w, sem_id sem);
306	friend status_t _safe_get_server_token_(const BLooper*, int32*);
307
308								BWindow(BRect frame, int32 bitmapToken);
309			void				_InitData(BRect frame, const char* title,
310									window_look look, window_feel feel,
311									uint32 flags, uint32 workspace,
312									int32 bitmapToken = -1);
313
314	virtual	void				task_looper();
315
316			BPoint				AlertPosition(const BRect& frame);
317	virtual BMessage*			ConvertToMessage(void* raw, int32 code);
318
319			void				AddShortcut(uint32 key, uint32 modifiers,
320									BMenuItem* item);
321			BHandler*			_DetermineTarget(BMessage* message,
322									BHandler* target);
323			bool				_IsFocusMessage(BMessage* message);
324			bool				_UnpackMessage(unpack_cookie& state,
325									BMessage** _message, BHandler** _target,
326									bool* _usePreferred);
327			void				_SanitizeMessage(BMessage* message,
328									BHandler* target, bool usePreferred);
329			bool				_StealMouseMessage(BMessage* message,
330									bool& deleteMessage);
331			uint32				_TransitForMouseMoved(BView* view,
332									BView* viewUnderMouse) const;
333
334			bool				InUpdate();
335			void				_DequeueAll();
336			window_type			_ComposeType(window_look look,
337									window_feel feel) const;
338			void				_DecomposeType(window_type type,
339									window_look* look,
340									window_feel* feel) const;
341
342			void				SetIsFilePanel(bool yes);
343			bool				IsFilePanel() const;
344
345			void				_CreateTopView();
346			void				_AdoptResize();
347			void				_SetFocus(BView* focusView,
348									bool notifyIputServer = false);
349			void				_SetName(const char* title);
350
351			Shortcut*			_FindShortcut(uint32 key, uint32 modifiers);
352			BView*				_FindView(BView* view, BPoint point) const;
353			BView*				_FindView(int32 token);
354			BView*				_LastViewChild(BView* parent);
355
356			BView*				_FindNextNavigable(BView* focus, uint32 flags);
357			BView*				_FindPreviousNavigable(BView* focus,
358									uint32 flags);
359			void				_Switcher(int32 rawKey, uint32 modifiers,
360									bool repeat);
361			bool				_HandleKeyDown(BMessage* event);
362			bool				_HandleUnmappedKeyDown(BMessage* event);
363			void				_KeyboardNavigation();
364
365			void				_GetDecoratorSize(float* _borderWidth,
366									float* _tabHeight) const;
367			void				_SendShowOrHideMessage();
368
369private:
370			char*				fTitle;
371			int32				_unused0;
372			bool				fInTransaction;
373			bool				fActive;
374			short				fShowLevel;
375			uint32				fFlags;
376
377			BView*				fTopView;
378			BView*				fFocus;
379			BView*				fLastMouseMovedView;
380			uint32				_unused1;
381			BMenuBar*			fKeyMenuBar;
382			BButton*			fDefaultButton;
383			BList				fShortcuts;
384			int32				fTopViewToken;
385			bool				fUpdateRequested;
386			bool				fOffscreen;
387			bool				fIsFilePanel;
388			bool				_unused4;
389			bigtime_t			fPulseRate;
390			bool				_unused5;
391			bool				fMinimized;
392			bool				fNoQuitShortcut;
393			bool				_unused6;
394			sem_id				fMenuSem;
395			float				fMaxZoomHeight;
396			float				fMaxZoomWidth;
397			float				fMinHeight;
398			float				fMinWidth;
399			float				fMaxHeight;
400			float				fMaxWidth;
401			BRect				fFrame;
402			window_look			fLook;
403			window_feel			fFeel;
404			int32				fLastViewToken;
405			::BPrivate::PortLink* fLink;
406			BMessageRunner*		fPulseRunner;
407			BRect				fPreviousFrame;
408
409			uint32				_reserved[9];
410};
411
412
413#endif // _WINDOW_H
414