Window.h revision 99b4affa
1/*
2 * Copyright 2001-2011, 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
87class BWindow : public BLooper {
88public:
89								BWindow(BRect frame, const char* title,
90									window_type type, uint32 flags,
91									uint32 workspace = B_CURRENT_WORKSPACE);
92								BWindow(BRect frame, const char* title,
93									window_look look, window_feel feel,
94									uint32 flags, uint32 workspace
95										= B_CURRENT_WORKSPACE);
96	virtual						~BWindow();
97
98								BWindow(BMessage* archive);
99	static	BArchivable*		Instantiate(BMessage* archive);
100	virtual	status_t			Archive(BMessage* archive,
101									bool deep = true) const;
102
103	virtual	void				Quit();
104			void				Close() { Quit(); }
105
106			void				AddChild(BView* child, BView* before = NULL);
107			void				AddChild(BLayoutItem* child);
108			bool				RemoveChild(BView* child);
109			int32				CountChildren() const;
110			BView*				ChildAt(int32 index) const;
111
112	virtual	void				DispatchMessage(BMessage* message,
113									BHandler* handler);
114	virtual	void				MessageReceived(BMessage* message);
115	virtual	void				FrameMoved(BPoint newPosition);
116	virtual void				WorkspacesChanged(uint32 oldWorkspaces,
117									uint32 newWorkspaces);
118	virtual void				WorkspaceActivated(int32 workspace,
119									bool state);
120	virtual	void				FrameResized(float newWidth, float newHeight);
121	virtual void				Minimize(bool minimize);
122	virtual	void				Zoom(BPoint origin, float width, float height);
123			void				Zoom();
124			void				SetZoomLimits(float maxWidth, float maxHeight);
125	virtual void				ScreenChanged(BRect screenSize,
126									color_space depth);
127
128			void				SetPulseRate(bigtime_t rate);
129			bigtime_t			PulseRate() const;
130
131			void				AddShortcut(uint32 key, uint32 modifiers,
132									BMessage* message);
133			void				AddShortcut(uint32 key, uint32 modifiers,
134									BMessage* message, BHandler* target);
135			bool				HasShortcut(uint32 key, uint32 modifiers);
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 focus);
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			void				ResizeToPreferred();
169
170			void				CenterIn(const BRect& rect);
171			void				CenterOnScreen();
172			void				CenterOnScreen(screen_id id);
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()
189									// in BeBook
190			void				EndViewTransaction();
191									// referred as CommitViewTransaction()
192									// in BeBook
193			bool				InViewTransaction() const;
194
195			BRect				Bounds() const;
196			BRect				Frame() const;
197			BRect				DecoratorFrame() const;
198			BSize				Size() const;
199			const char*			Title() const;
200			void				SetTitle(const char* title);
201			bool				IsFront() const;
202			bool				IsActive() const;
203
204			void				SetKeyMenuBar(BMenuBar* bar);
205			BMenuBar*			KeyMenuBar() const;
206
207			void				SetSizeLimits(float minWidth, float maxWidth,
208									float minHeight, float maxHeight);
209			void				GetSizeLimits(float* minWidth, float* maxWidth,
210									float* minHeight, float* maxHeight);
211			void				UpdateSizeLimits();
212
213			status_t			SetDecoratorSettings(const BMessage& settings);
214			status_t			GetDecoratorSettings(BMessage* settings) const;
215
216			uint32				Workspaces() const;
217			void				SetWorkspaces(uint32);
218
219			BView*				LastMouseMovedView() const;
220
221	virtual BHandler*			ResolveSpecifier(BMessage* message,
222									int32 index, BMessage* specifier,
223									int32 what, const char* property);
224	virtual status_t			GetSupportedSuites(BMessage* data);
225
226			status_t			AddToSubset(BWindow* window);
227			status_t			RemoveFromSubset(BWindow* window);
228
229	virtual status_t			Perform(perform_code code, void* data);
230
231			status_t			SetType(window_type type);
232			window_type			Type() const;
233
234			status_t			SetLook(window_look look);
235			window_look			Look() const;
236
237			status_t			SetFeel(window_feel feel);
238			window_feel			Feel() const;
239
240			status_t			SetFlags(uint32);
241			uint32				Flags() const;
242
243			bool				IsModal() const;
244			bool				IsFloating() const;
245
246			status_t			SetWindowAlignment(window_alignment mode,
247									int32 h, int32 hOffset = 0,
248									int32 width = 0, int32 widthOffset = 0,
249									int32 v = 0, int32 vOffset = 0,
250									int32 height = 0, int32 heightOffset = 0);
251			status_t			GetWindowAlignment(
252									window_alignment* mode = NULL,
253									int32* h = NULL, int32* hOffset = NULL,
254									int32* width = NULL,
255									int32* widthOffset = NULL,
256									int32* v = NULL, int32* vOffset = NULL,
257									int32* height = NULL,
258									int32* heightOffset = NULL) const;
259
260	virtual	bool				QuitRequested();
261	virtual thread_id			Run();
262
263	virtual	void				SetLayout(BLayout* layout);
264			BLayout*			GetLayout() const;
265
266			void				InvalidateLayout(bool descendants = false);
267			void				Layout(bool force);
268
269private:
270	// FBC padding and forbidden methods
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
283private:
284	typedef BLooper inherited;
285	struct unpack_cookie;
286	class Shortcut;
287
288	friend class BAlert;
289	friend class BApplication;
290	friend class BBitmap;
291	friend class BView;
292	friend class BMenuItem;
293	friend class BWindowScreen;
294	friend class BDirectWindow;
295	friend class BFilePanel;
296	friend class BWindowStack;
297
298	friend void _set_menu_sem_(BWindow* w, sem_id sem);
299	friend status_t _safe_get_server_token_(const BLooper*, int32*);
300
301								BWindow(BRect frame, int32 bitmapToken);
302			void				_InitData(BRect frame, const char* title,
303									window_look look, window_feel feel,
304									uint32 flags, uint32 workspace,
305									int32 bitmapToken = -1);
306
307	virtual	void				task_looper();
308
309			BPoint				AlertPosition(const BRect& frame);
310	virtual BMessage*			ConvertToMessage(void* raw, int32 code);
311
312			void				AddShortcut(uint32 key, uint32 modifiers,
313									BMenuItem* item);
314			BHandler*			_DetermineTarget(BMessage* message,
315									BHandler* target);
316			bool				_IsFocusMessage(BMessage* message);
317			bool				_UnpackMessage(unpack_cookie& state,
318									BMessage** _message, BHandler** _target,
319									bool* _usePreferred);
320			void				_SanitizeMessage(BMessage* message,
321									BHandler* target, bool usePreferred);
322			bool				_StealMouseMessage(BMessage* message,
323									bool& deleteMessage);
324			uint32				_TransitForMouseMoved(BView* view,
325									BView* viewUnderMouse) const;
326
327			bool				InUpdate();
328			void				_DequeueAll();
329			window_type			_ComposeType(window_look look,
330									window_feel feel) const;
331			void				_DecomposeType(window_type type,
332									window_look* look,
333									window_feel* feel) const;
334
335			void				SetIsFilePanel(bool yes);
336			bool				IsFilePanel() const;
337
338			void				_CreateTopView();
339			void				_AdoptResize();
340			void				_SetFocus(BView* focusView,
341									bool notifyIputServer = false);
342			void				_SetName(const char* title);
343
344			Shortcut*			_FindShortcut(uint32 key, uint32 modifiers);
345			BView*				_FindView(BView* view, BPoint point) const;
346			BView*				_FindView(int32 token);
347			BView*				_LastViewChild(BView* parent);
348
349			BView*				_FindNextNavigable(BView* focus, uint32 flags);
350			BView*				_FindPreviousNavigable(BView* focus,
351									uint32 flags);
352			void				_Switcher(int32 rawKey, uint32 modifiers,
353									bool repeat);
354			bool				_HandleKeyDown(BMessage* event);
355			bool				_HandleUnmappedKeyDown(BMessage* event);
356			void				_KeyboardNavigation();
357
358			void				_GetDecoratorSize(float* _borderWidth,
359									float* _tabHeight) const;
360			void				_SendShowOrHideMessage();
361
362private:
363			char*				fTitle;
364			int32				_unused0;
365			bool				fInTransaction;
366			bool				fActive;
367			short				fShowLevel;
368			uint32				fFlags;
369
370			BView*				fTopView;
371			BView*				fFocus;
372			BView*				fLastMouseMovedView;
373			uint32				_unused1;
374			BMenuBar*			fKeyMenuBar;
375			BButton*			fDefaultButton;
376			BList				fShortcuts;
377			int32				fTopViewToken;
378			bool				fUpdateRequested;
379			bool				fOffscreen;
380			bool				fIsFilePanel;
381			bool				_unused4;
382			bigtime_t			fPulseRate;
383			bool				_unused5;
384			bool				fMinimized;
385			bool				fNoQuitShortcut;
386			bool				_unused6;
387			sem_id				fMenuSem;
388			float				fMaxZoomHeight;
389			float				fMaxZoomWidth;
390			float				fMinHeight;
391			float				fMinWidth;
392			float				fMaxHeight;
393			float				fMaxWidth;
394			BRect				fFrame;
395			window_look			fLook;
396			window_feel			fFeel;
397			int32				fLastViewToken;
398			::BPrivate::PortLink* fLink;
399			BMessageRunner*		fPulseRunner;
400			BRect				fPreviousFrame;
401
402			uint32				_reserved[9];
403};
404
405
406#endif // _WINDOW_H
407