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 format);
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 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			void 				CenterIn(const BRect& rect);
170			void 				CenterOnScreen();
171
172	virtual	void				Show();
173	virtual	void				Hide();
174			bool				IsHidden() const;
175			bool				IsMinimized() const;
176
177			void				Flush() const;
178			void				Sync() const;
179
180			status_t			SendBehind(const BWindow* window);
181
182			void				DisableUpdates();
183			void				EnableUpdates();
184
185			void				BeginViewTransaction();
186									// referred as OpenViewTransaction()
187									// in BeBook
188			void				EndViewTransaction();
189									// referred as CommitViewTransaction()
190									// in BeBook
191			bool				InViewTransaction() const;
192
193			BRect				Bounds() const;
194			BRect				Frame() const;
195			BRect				DecoratorFrame() const;
196			BSize				Size() const;
197			const char*			Title() const;
198			void				SetTitle(const char* title);
199			bool				IsFront() const;
200			bool				IsActive() const;
201
202			void				SetKeyMenuBar(BMenuBar* bar);
203			BMenuBar*			KeyMenuBar() const;
204
205			void				SetSizeLimits(float minWidth, float maxWidth,
206									float minHeight, float maxHeight);
207			void				GetSizeLimits(float* minWidth, float* maxWidth,
208									float* minHeight, float* maxHeight);
209			void				UpdateSizeLimits();
210
211			status_t			SetDecoratorSettings(const BMessage& settings);
212			status_t			GetDecoratorSettings(BMessage* settings) const;
213
214			uint32				Workspaces() const;
215			void				SetWorkspaces(uint32);
216
217			BView*				LastMouseMovedView() const;
218
219	virtual BHandler*			ResolveSpecifier(BMessage* message,
220									int32 index, BMessage* specifier,
221									int32 form, const char* property);
222	virtual status_t			GetSupportedSuites(BMessage* data);
223
224			status_t			AddToSubset(BWindow* window);
225			status_t			RemoveFromSubset(BWindow* window);
226
227	virtual status_t			Perform(perform_code code, void* data);
228
229			status_t			SetType(window_type type);
230			window_type			Type() const;
231
232			status_t			SetLook(window_look look);
233			window_look			Look() const;
234
235			status_t			SetFeel(window_feel feel);
236			window_feel			Feel() const;
237
238			status_t			SetFlags(uint32);
239			uint32				Flags() const;
240
241			bool				IsModal() const;
242			bool				IsFloating() const;
243
244			status_t			SetWindowAlignment(window_alignment mode,
245									int32 h, int32 hOffset = 0,
246									int32 width = 0, int32 widthOffset = 0,
247									int32 v = 0, int32 vOffset = 0,
248									int32 height = 0, int32 heightOffset = 0);
249			status_t			GetWindowAlignment(
250									window_alignment* mode = NULL,
251									int32* h = NULL, int32* hOffset = NULL,
252									int32* width = NULL,
253									int32* widthOffset = NULL,
254									int32* v = NULL, 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			void				Layout(bool force);
266
267private:
268	// FBC padding and forbidden methods
269	virtual	void				_ReservedWindow2();
270	virtual	void				_ReservedWindow3();
271	virtual	void				_ReservedWindow4();
272	virtual	void				_ReservedWindow5();
273	virtual	void				_ReservedWindow6();
274	virtual	void				_ReservedWindow7();
275	virtual	void				_ReservedWindow8();
276
277								BWindow();
278								BWindow(BWindow&);
279			BWindow&			operator=(BWindow&);
280
281private:
282	typedef BLooper inherited;
283	struct unpack_cookie;
284	class Shortcut;
285
286	friend class BApplication;
287	friend class BBitmap;
288	friend class BView;
289	friend class BMenuItem;
290	friend class BWindowScreen;
291	friend class BDirectWindow;
292	friend class BFilePanel;
293	friend class BWindowStack;
294
295	friend void _set_menu_sem_(BWindow* w, sem_id sem);
296	friend status_t _safe_get_server_token_(const BLooper*, int32*);
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	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				_IsFocusMessage(BMessage* message);
313			bool				_UnpackMessage(unpack_cookie& state,
314									BMessage** _message, BHandler** _target,
315									bool* _usePreferred);
316			void				_SanitizeMessage(BMessage* message,
317									BHandler* target, bool usePreferred);
318			bool				_StealMouseMessage(BMessage* message,
319									bool& deleteMessage);
320			uint32				_TransitForMouseMoved(BView* view,
321									BView* viewUnderMouse) const;
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			void				_SetName(const char* title);
339
340			Shortcut*			_FindShortcut(uint32 key, uint32 modifiers);
341			BView*				_FindView(BView* view, BPoint point) const;
342			BView*				_FindView(int32 token);
343			BView*				_LastViewChild(BView* parent);
344
345			BView*				_FindNextNavigable(BView* focus, uint32 flags);
346			BView*				_FindPreviousNavigable(BView* focus,
347									uint32 flags);
348			void				_Switcher(int32 rawKey, uint32 modifiers,
349									bool repeat);
350			bool				_HandleKeyDown(BMessage* event);
351			bool				_HandleUnmappedKeyDown(BMessage* event);
352			void				_KeyboardNavigation();
353
354			void				_GetDecoratorSize(float* _borderWidth,
355									float* _tabHeight) const;
356			void				_SendShowOrHideMessage();
357
358private:
359			char*				fTitle;
360			int32				_unused0;
361			bool				fInTransaction;
362			bool				fActive;
363			short				fShowLevel;
364			uint32				fFlags;
365
366			BView*				fTopView;
367			BView*				fFocus;
368			BView*				fLastMouseMovedView;
369			BMessageRunner*		fIdleMouseRunner;
370			BMenuBar*			fKeyMenuBar;
371			BButton*			fDefaultButton;
372			BList				fShortcuts;
373			int32				fTopViewToken;
374			bool				fUpdateRequested;
375			bool				fOffscreen;
376			bool				fIsFilePanel;
377			bool				_unused4;
378			bigtime_t			fPulseRate;
379			bool				_unused5;
380			bool				fMinimized;
381			bool				fNoQuitShortcut;
382			bool				_unused6;
383			sem_id				fMenuSem;
384			float				fMaxZoomHeight;
385			float				fMaxZoomWidth;
386			float				fMinHeight;
387			float				fMinWidth;
388			float				fMaxHeight;
389			float				fMaxWidth;
390			BRect				fFrame;
391			window_look			fLook;
392			window_feel			fFeel;
393			int32				fLastViewToken;
394			BPrivate::PortLink*	fLink;
395			BMessageRunner*		fPulseRunner;
396			BRect				fPreviousFrame;
397
398			uint32				_reserved[9];
399};
400
401
402#endif // _WINDOW_H
403