xref: /haiku/headers/os/interface/Window.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		Window.h
23 //	Author:			Adrian Oanca (e2joseph@hotpop.com)
24 //	Description:	BWindow is the base class for all windows (graphic areas
25 //					displayed on-screen).
26 //
27 //
28 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29 //	NOTE(!!!)		All private non virtual functions are to be renamed following
30 //					this scheme: word_another_third <-> wordAnotherThird
31 //	OBOS Team:	If you use one of BWindow's private functions, please addapt to this code
32 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
33 //------------------------------------------------------------------------------
34 
35 #ifndef	_WINDOW_H
36 #define	_WINDOW_H
37 
38 // Standard Includes -----------------------------------------------------------
39 
40 // System Includes -------------------------------------------------------------
41 #include <BeBuild.h>
42 #include <InterfaceDefs.h>
43 #include <List.h>
44 #include <Looper.h>
45 #include <Rect.h>
46 #include <StorageDefs.h>
47 
48 // Project Includes ------------------------------------------------------------
49 
50 // Local Includes --------------------------------------------------------------
51 
52 // Local Defines ---------------------------------------------------------------
53 
54 // Globals ---------------------------------------------------------------------
55 
56 
57 // window definitions ----------------------------------------------------------
58 
59 enum window_type {
60 	B_UNTYPED_WINDOW	= 0,
61 	B_TITLED_WINDOW 	= 1,
62 	B_MODAL_WINDOW 		= 3,
63 	B_DOCUMENT_WINDOW	= 11,
64 	B_BORDERED_WINDOW	= 20,
65 	B_FLOATING_WINDOW	= 21
66 };
67 
68 //----------------------------------------------------------------
69 
70 enum window_look {
71 	B_BORDERED_WINDOW_LOOK	= 20,
72 	B_NO_BORDER_WINDOW_LOOK	= 19,
73 	B_TITLED_WINDOW_LOOK	= 1,
74 	B_DOCUMENT_WINDOW_LOOK	= 11,
75 	B_MODAL_WINDOW_LOOK		= 3,
76 	B_FLOATING_WINDOW_LOOK	= 7
77 };
78 
79 //----------------------------------------------------------------
80 
81 enum window_feel {
82 	B_NORMAL_WINDOW_FEEL			= 0,
83 	B_MODAL_SUBSET_WINDOW_FEEL		= 2,
84 	B_MODAL_APP_WINDOW_FEEL			= 1,
85 	B_MODAL_ALL_WINDOW_FEEL			= 3,
86 	B_FLOATING_SUBSET_WINDOW_FEEL	= 5,
87 	B_FLOATING_APP_WINDOW_FEEL		= 4,
88 	B_FLOATING_ALL_WINDOW_FEEL		= 6
89 };
90 
91 //----------------------------------------------------------------
92 
93 enum window_alignment {
94 	B_BYTE_ALIGNMENT	= 0,
95 	B_PIXEL_ALIGNMENT	= 1
96 };
97 
98 //----------------------------------------------------------------
99 
100 enum {
101 	B_NOT_MOVABLE				= 0x00000001,
102 	B_NOT_CLOSABLE				= 0x00000020,
103 	B_NOT_ZOOMABLE				= 0x00000040,
104 	B_NOT_MINIMIZABLE			= 0x00004000,
105 	B_NOT_RESIZABLE				= 0x00000002,
106 	B_NOT_H_RESIZABLE			= 0x00000004,
107 	B_NOT_V_RESIZABLE			= 0x00000008,
108 	B_AVOID_FRONT				= 0x00000080,
109 	B_AVOID_FOCUS				= 0x00002000,
110 	B_WILL_ACCEPT_FIRST_CLICK	= 0x00000010,
111 	B_OUTLINE_RESIZE			= 0x00001000,
112 	B_NO_WORKSPACE_ACTIVATION	= 0x00000100,
113 	B_NOT_ANCHORED_ON_ACTIVATE	= 0x00020000,
114 	B_ASYNCHRONOUS_CONTROLS		= 0x00080000,
115 	B_QUIT_ON_WINDOW_CLOSE		= 0x00100000
116 };
117 
118 #define B_CURRENT_WORKSPACE	0
119 #define B_ALL_WORKSPACES	0xffffffff
120 
121 //----------------------------------------------------------------
122 
123 class BSession;
124 class BButton;
125 class BMenuBar;
126 class BMenuItem;
127 class BMessage;
128 class BMessageRunner;
129 class BMessenger;
130 class BView;
131 
132 struct message;
133 struct _cmd_key_;
134 struct _view_attr_;
135 
136 // BWindow class ---------------------------------------------------------------
137 class BWindow : public BLooper {
138 
139 public:
140 						BWindow(BRect frame,
141 								const char* title,
142 								window_type type,
143 								uint32 flags,
144 								uint32 workspace = B_CURRENT_WORKSPACE);
145 						BWindow(BRect frame,
146 								const char* title,
147 								window_look look,
148 								window_feel feel,
149 								uint32 flags,
150 								uint32 workspace = B_CURRENT_WORKSPACE);
151 virtual					~BWindow();
152 
153 						BWindow(BMessage* data);
154 static	BArchivable		*Instantiate(BMessage* data);
155 virtual	status_t		Archive(BMessage* data, bool deep = true) const;
156 
157 virtual	void			Quit();
158 		void			Close(); // Synonym of Quit()
159 
160 		void			AddChild(BView* child, BView* before = NULL);
161 		bool			RemoveChild(BView* child);
162 		int32			CountChildren() const;
163 		BView			*ChildAt(int32 index) const;
164 
165 virtual	void			DispatchMessage(BMessage* message, BHandler* handler);
166 virtual	void			MessageReceived(BMessage* message);
167 virtual	void			FrameMoved(BPoint new_position);
168 virtual void			WorkspacesChanged(uint32 old_ws, uint32 new_ws);
169 virtual void			WorkspaceActivated(int32 ws, bool state);
170 virtual	void			FrameResized(float new_width, float new_height);
171 virtual void			Minimize(bool minimize);
172 virtual void			Zoom(	BPoint rec_position,
173 								float rec_width,
174 								float rec_height);
175 		void			Zoom();
176 		void			SetZoomLimits(float maxWidth, float maxHeight);				// changed from: SetZoomLimits(float max_h, float max_v);
177 virtual void			ScreenChanged(BRect screen_size, color_space depth);
178 		void			SetPulseRate(bigtime_t rate);
179 		bigtime_t		PulseRate() const;
180 		void			AddShortcut(	uint32 key,
181 										uint32 modifiers,
182 										BMessage* msg);
183 		void			AddShortcut(	uint32 key,
184 										uint32 modifiers,
185 										BMessage* msg,
186 										BHandler* target);
187 		void			RemoveShortcut(uint32 key, uint32 modifiers);
188 		void			SetDefaultButton(BButton* button);
189 		BButton			*DefaultButton() const;
190 virtual	void			MenusBeginning();
191 virtual	void			MenusEnded();
192 		bool			NeedsUpdate() const;
193 		void			UpdateIfNeeded();
194 		BView			*FindView(const char* viewName) const;						// changed from: FindView( const char* view_name );
195 		BView			*FindView(BPoint) const;
196 		BView			*CurrentFocus() const;
197 		void			Activate(bool = true);
198 virtual	void			WindowActivated(bool state);
199 		void			ConvertToScreen(BPoint* pt) const;
200 		BPoint			ConvertToScreen(BPoint pt) const;
201 		void			ConvertFromScreen(BPoint* pt) const;
202 		BPoint			ConvertFromScreen(BPoint pt) const;
203 		void			ConvertToScreen(BRect* rect) const;
204 		BRect			ConvertToScreen(BRect rect) const;
205 		void			ConvertFromScreen(BRect* rect) const;
206 		BRect			ConvertFromScreen(BRect rect) const;
207 		void			MoveBy(float dx, float dy);
208 		void			MoveTo(BPoint);
209 		void			MoveTo(float x, float y);
210 		void			ResizeBy(float dx, float dy);
211 		void			ResizeTo(float width, float height);
212 virtual	void			Show();
213 virtual	void			Hide();
214 		bool			IsHidden() const;
215 		bool			IsMinimized() const;
216 
217 		void			Flush() const;
218 		void			Sync() const;
219 
220 		status_t		SendBehind(const BWindow* window);
221 
222 		void			DisableUpdates();
223 		void			EnableUpdates();
224 
225 		void			BeginViewTransaction();										// referred as OpenViewTransaction() in BeBook
226 		void			EndViewTransaction();										// referred as CommitViewTransaction() in BeBook
227 
228 		BRect			Bounds() const;
229 		BRect			Frame() const;
230 		const char		*Title() const;
231 		void			SetTitle(const char* title);
232 		bool			IsFront() const;
233 		bool			IsActive() const;
234 		void			SetKeyMenuBar(BMenuBar* bar);
235 		BMenuBar		*KeyMenuBar() const;
236 		void			SetSizeLimits(	float minWidth,								// changed from: SetSizeLimits(float min_h, float max_h, float min_v, float max_v);
237 										float maxWidth,
238 										float minHeight,
239 										float maxHeight);
240 		void			GetSizeLimits(	float *minWidth,							// changed from: SetSizeLimits(float* min_h, float* max_h, float* min_v, float* max_v);
241 										float *maxWidth,
242 										float *minHeight,
243 										float *maxHeight);
244 		uint32			Workspaces() const;
245 		void			SetWorkspaces(uint32);
246 		BView			*LastMouseMovedView() const;
247 
248 virtual BHandler		*ResolveSpecifier(BMessage* msg,
249 										int32 index,
250 										BMessage* specifier,
251 										int32 form,
252 										const char* property);
253 virtual status_t		GetSupportedSuites(BMessage* data);
254 
255 		status_t		AddToSubset(BWindow* window);
256 		status_t		RemoveFromSubset(BWindow* window);
257 
258 virtual status_t		Perform(perform_code d, void* arg);
259 
260 		status_t		SetType(window_type type);
261 		window_type		Type() const;
262 
263 		status_t		SetLook(window_look look);
264 		window_look		Look() const;
265 
266 		status_t		SetFeel(window_feel feel);
267 		window_feel		Feel() const;
268 
269 		status_t		SetFlags(uint32);
270 		uint32			Flags() const;
271 
272 		bool			IsModal() const;
273 		bool			IsFloating() const;
274 
275 		status_t		SetWindowAlignment(window_alignment mode,
276 											int32 h,
277 											int32 hOffset = 0,
278 											int32 width = 0,
279 											int32 widthOffset = 0,
280 											int32 v = 0,
281 											int32 vOffset = 0,
282 											int32 height = 0,
283 											int32 heightOffset = 0);
284 		status_t		GetWindowAlignment(window_alignment* mode = NULL,
285 											int32* h = NULL,
286 											int32* hOffset = NULL,
287 											int32* width = NULL,
288 											int32* widthOffset = NULL,
289 											int32* v = NULL,
290 											int32* vOffset = NULL,
291 											int32* height = NULL,
292 											int32* heightOffset = NULL) const;
293 
294 virtual	bool			QuitRequested();
295 virtual thread_id		Run();
296 
297 // Private or reserved ---------------------------------------------------------
298 private:
299 
300 typedef BLooper inherited;
301 
302 friend class BApplication;
303 friend class BBitmap;
304 friend class BScrollBar;
305 friend class BView;
306 friend class BMenuItem;
307 friend class BWindowScreen;
308 friend class BDirectWindow;
309 friend class BFilePanel;
310 friend class BHandler;
311 friend class _BEventMask;
312 friend void _set_menu_sem_(BWindow* w, sem_id sem);
313 friend status_t _safe_get_server_token_(const BLooper* , int32* );
314 
315 virtual	void			_ReservedWindow1();
316 virtual	void			_ReservedWindow2();
317 virtual	void			_ReservedWindow3();
318 virtual	void			_ReservedWindow4();
319 virtual	void			_ReservedWindow5();
320 virtual	void			_ReservedWindow6();
321 virtual	void			_ReservedWindow7();
322 virtual	void			_ReservedWindow8();
323 
324 					BWindow();
325 					BWindow(BWindow&);
326 		BWindow		&operator=(BWindow&);
327 
328 					BWindow(BRect frame, color_space depth,			// to be implemented
329 							uint32 bitmapFlags, int32 rowBytes);
330 		void		InitData(BRect frame,
331 							const char* title,
332 							window_look look,
333 							window_feel feel,
334 							uint32 flags,
335 							uint32 workspace);
336 		status_t	ArchiveChildren(BMessage* data, bool deep) const;	// call made from within Archive
337 		status_t	UnarchiveChildren(BMessage* data);		// Instantiate(BMessage* data)->BWindow(BMessage)->UnarchiveChildren(BMessage* data)
338 		void		BitmapClose();							// to be implemented
339 virtual	void		task_looper();							// thread function - it's here where app_server messages are received
340 /*		void		start_drag(	BMessage* msg,
341 								int32 token,
342 								BPoint offset,
343 								BRect track_rect,
344 								BHandler* reply_to);
345 		void		start_drag(	BMessage* msg,
346 								int32 token,
347 								BPoint offset,
348 								int32 bitmap_token,
349 								drawing_mode dragMode,
350 								BHandler* reply_to);
351 */
352 		void		prepareView(BView* aView);						// changed from view_builder(BView* a_view);
353 		void		attachView(BView* aView);						// changed from attach_builder(BView* a_view);
354 		void		detachView(BView* aView);						// changed from detach_builder(BView* a_view);
355 		//int32		get_server_token() const;
356 		BMessage	*extract_drop(BMessage* an_event, BHandler* *target);
357 		//void		movesize(uint32 opcode, float h, float v);
358 
359 		BMessage* 	ReadMessageFromPort(bigtime_t tout = B_INFINITE_TIMEOUT);
360 		//int32		MessagesWaiting();
361 
362 		void		handle_activate(BMessage* an_event);
363 		//void		do_view_frame(BMessage* an_event);
364 		//void		do_value_change(BMessage* an_event, BHandler* handler);
365 		//void		do_mouse_down(BMessage* an_event, BView* target);
366 		//void		do_mouse_moved(BMessage* an_event, BView* target);
367 		//void		do_key_down(BMessage* an_event, BHandler* handler);
368 		//void		do_key_up(BMessage* an_event, BHandler* handler);
369 		void		do_menu_event(BMessage* an_event);
370 		//void		do_draw_views();
371 virtual BMessage	*ConvertToMessage(void* raw, int32 code);					// HUGE function - it converts PortLink messages into BMessages
372 		//_cmd_key_	*allocShortcut(uint32 key, uint32 modifiers);
373 		//_cmd_key_	*FindShortcut(uint32 key, uint32 modifiers);
374 		void		AddShortcut(uint32 key,										// !!! - and menu shortcuts to list when a menu is added
375 								uint32 modifiers,
376 								BMenuItem* item);
377 		//void		post_message(BMessage* message);
378 		//void		SetLocalTitle(const char* new_title);
379 		//void		enable_pulsing(bool enable);
380 		BHandler	*determine_target(BMessage* msg, BHandler* target, bool pref);
381 		//void		kb_navigate();
382 		//void		navigate_to_next(int32 direction, bool group = false);
383 		//void		set_focus(BView* focus, bool notify_input_server);		// what does notify_input_server mean??? why???
384 		bool		InUpdate();
385 		void		DequeueAll();
386 		//bool		find_token_and_handler(BMessage* msg, int32* token,	BHandler* *handler);
387 		window_type	composeType(window_look look,						// changed from: compose_type(...)
388 								 window_feel feel) const;
389 		void		decomposeType(window_type type,						// changed from: decompose_type(...)
390 								   window_look* look,
391 								   window_feel* feel) const;
392 
393 		void		SetIsFilePanel(bool yes);
394 		bool		IsFilePanel() const;
395 // OBOS BWindow's addon functions
396 		uint32		WindowLookToInteger(window_look wl);
397 		uint32		WindowFeelToInteger(window_feel wf);
398 		void		BuildTopView();
399 		void		stopConnection();
400 		void		setFocus(BView *focusView, bool notifyIputServer=false);
401 
402 		bool		handleKeyDown( uint32 key, uint32 modifiers);
403 
404 						// message: B_MOUSE_UP, B_MOUSE_DOWN, B_MOUSE_MOVED
405 		void		sendMessageUsingEventMask( int32 message, BPoint where );
406 		BView*		sendMessageUsingEventMask2( BView* aView, int32 message, BPoint where );
407 		void		sendPulse( BView* );
408 		int32		findShortcut(uint32 key, uint32 modifiers);
409 		bool		findHandler( BView* start, BHandler* handler );
410 		BView*		findView(BView* aView, const char* viewName) const;
411 		BView*		findView(BView* aView, BPoint point) const;
412 		BView*		findView(BView* aView, int32 token);
413 
414 		BView*		findNextView( BView *focus, uint32 flags);
415 		BView*		findPrevView( BView *focus, uint32 flags);
416 		BView*		findLastChild(BView *parent);
417 		bool		handleKeyDown( int32 raw_char, uint32 modifiers);
418 		void		handleActivation( bool active );
419 		void		activateView( BView *aView, bool active );
420 
421 		void		drawAllViews(BView* aView);
422 		void		drawView(BView* aView, BRect area);
423 
424 		// Debug
425 		void		PrintToStream() const;
426 // END: OBOS addon functions
427 
428 		// 3 deprecated calls
429 		//void			AddFloater(BWindow* a_floating_window);
430 		//void			RemoveFloater(BWindow* a_floating_window);
431 		//window_type		WindowType() const;
432 
433 		char			*fTitle;					// used
434 		int32			server_token;
435 		bool			fInTransaction;				// used		// changed from: char			fInUpdate;
436 		bool			fActive;					// used		// changed from: char			f_active;
437 		short			fShowLevel;					// used
438 		uint32			fFlags;						// used
439 
440 		port_id			send_port;					// used
441 		port_id			receive_port;				// used
442 
443 		BView			*top_view;					// used
444 		BView			*fFocus;					// used
445 		BView			*fLastMouseMovedView;		// used
446 		BSession		*session;				// used
447 		BMenuBar		*fKeyMenuBar;				// used
448 		BButton			*fDefaultButton;			// used
449 		BList			accelList;					// used
450 		int32			fTopViewToken;				//			// changed from: int32			top_view_token;
451 		bool			fPulseEnabled;				// used		// changed from: bool			pulse_enabled;
452 		bool			fViewsNeedPulse;
453 		bool			fIsFilePanel;				// used
454 		bool			fMaskActivated;
455 		bigtime_t		fPulseRate;					// used		// changed from: bigtime_t		pulse_rate;
456 		bool			fWaitingForMenu;
457 		bool			fMinimized;					// used		// changed from: bool			fOffscreen;
458 		sem_id			fMenuSem;
459 		float			fMaxZoomHeight;				// used		// changed from: float			fMaxZoomH;
460 		float			fMaxZoomWidth;				// used		// changed from: float			fMaxZoomV;
461 		float			fMinWindHeight;				// used		// changed from: float			fMinWindH;
462 		float			fMinWindWidth;				// used		// changed from: float			fMinWindV;
463 		float			fMaxWindHeight;				// used		// changed from: float			fMaxWindH;
464 		float			fMaxWindWidth;				// used		// changed from: float			fMaxWindV;
465 		BRect			fFrame;						// used
466 		window_look		fLook;						// used
467 		_view_attr_		*fCurDrawViewState;
468 		window_feel		fFeel;						// used
469 		int32			fLastViewToken;
470 		uint32			fUnused1;					// changed from: _CEventPort_* 	fEventPort;
471 		BMessageRunner	*fPulseRunner;				// used
472 		BRect			fCurrentFrame;
473 
474 		uint32			_reserved[2];	// was 8
475 #if !_PR3_COMPATIBLE_
476 		uint32			_more_reserved[4];
477 #endif
478 };
479 
480 // inline definitions ----------------------------------------------------------
481 inline void  BWindow::Close()
482 {
483 	Quit();
484 }
485 //------------------------------------------------------------------------------
486 
487 #endif	// _WINDOW_H
488 
489 /*
490  * $Log $
491  *
492  * $Id  $
493  *
494  */
495 
496