xref: /haiku/src/servers/app/ServerWindow.h (revision 0b2dbe7d46ee888392907c60131b7f7652314175)
1 /*
2  * Copyright 2001-2005, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Adrian Oanca <adioanca@cotty.iren.ro>
8  *		Stephan Aßmus <superstippi@gmx.de>
9  *		Stefano Ceccherini (burton666@libero.it)
10  *		Axel Dörfler, axeld@pinc-software.de
11  */
12 #ifndef _SERVERWIN_H_
13 #define _SERVERWIN_H_
14 
15 
16 #include <GraphicsDefs.h>
17 #include <PortLink.h>
18 #include <Locker.h>
19 #include <Message.h>
20 #include <OS.h>
21 #include <Rect.h>
22 #include <String.h>
23 #include <Window.h>
24 
25 #include "SubWindowList.h"
26 #include "TokenSpace.h"
27 
28 class BString;
29 class BMessenger;
30 class BPoint;
31 class BMessage;
32 
33 class ServerApp;
34 class Decorator;
35 class WinBorder;
36 class Workspace;
37 class RootLayer;
38 class Layer;
39 class ServerPicture;
40 
41 #define AS_UPDATE_DECORATOR 'asud'
42 #define AS_UPDATE_COLORS 'asuc'
43 #define AS_UPDATE_FONTS 'asuf'
44 
45 /*!
46 	\class ServerWindow ServerWindow.h
47 	\brief Shadow BWindow class
48 
49 	A ServerWindow handles all the intraserver tasks required of it by its BWindow. There are
50 	too many tasks to list as being done by them, but they include handling View transactions,
51 	coordinating and linking a window's WinBorder half with its messaging half, dispatching
52 	mouse and key events from the server to its window, and other such things.
53 */
54 class ServerWindow : public BLocker {
55 public:
56 								ServerWindow(const char *title, ServerApp *app,
57 									port_id clientPort, port_id looperPort,
58 									int32 handlerID, BRect frame, uint32 look,
59 									uint32 feel, uint32 flags, uint32 workspace);
60 	virtual						~ServerWindow();
61 
62 			status_t			InitCheck();
63 			bool				Run();
64 			void				Quit();
65 
66 			void				ReplaceDecorator();
67 			void				Show();
68 			void				Hide();
69 
70 			void				PostMessage(int32 code);
71 
72 			// methods for sending various messages to client.
73 			void				NotifyQuitRequested();
74 			void				NotifyMinimize(bool minimize);
75 			void				NotifyZoom();
76 			void				NotifyScreenModeChanged(const BRect frame,
77 									const color_space cspace);
78 
79 			// util methods.
80 			void				SendMessageToClient(const BMessage* msg,
81 													int32 target = B_NULL_TOKEN,
82 													bool usePreferred = false) const;
83 
84 			// TODO: Ouch, that's not exactly a nice name
85 			inline BMessage		&ClientViewsWithInvalidCoords()
86 									{ return fClientViewsWithInvalidCoords; };
87 
88 			// to who we belong. who do we own. our title.
89 	inline	ServerApp*			App() const { return fServerApp; }
90 	inline	const WinBorder*	GetWinBorder() const { return fWinBorder; }
91 	inline	const char*			Title() const { return fTitle; }
92 
93 			// related thread/team_id(s).
94 	inline	team_id				ClientTeam() const { return fClientTeam; }
95 	inline	thread_id			Thread() const { return fThread; }
96 
97 			// server "private" - try not to use.
98 	inline	int32				ClientToken() const { return fHandlerToken; }
99 
100 			// ToDo: public??
101 			SubWindowList	fSubWindowList;
102 
103 private:
104 			// methods for retrieving and creating a tree strcture of Layers.
105 			Layer*				CreateLayerTree(BPrivate::LinkReceiver &link, Layer **_parent);
106 			void				SetLayerState(Layer *layer, BPrivate::LinkReceiver &link);
107 			void				SetLayerFontState(Layer *layer, BPrivate::LinkReceiver &link);
108 
109 			// message handling methods.
110 			void				_DispatchMessage(int32 code, BPrivate::LinkReceiver &link);
111 			void				_DispatchGraphicsMessage(int32 code, BPrivate::LinkReceiver &link);
112 			void				_MessageLooper();
113 
114 	static	int32				_message_thread(void *_window);
115 
116 			// TODO: Move me elsewhere
117 			status_t			PictureToRegion(ServerPicture *picture,
118 												BRegion &,
119 												bool inverse,
120 												BPoint where);
121 
122 private:
123 			const char*			fTitle;
124 
125 			ServerApp*			fServerApp;
126 			WinBorder*			fWinBorder;
127 
128 			team_id				fClientTeam;
129 			thread_id			fThread;
130 
131 			port_id				fMessagePort;
132 			port_id				fClientReplyPort;
133 			port_id				fClientLooperPort;
134 
135 			BPrivate::PortLink	fLink;
136 			bool				fQuitting;
137 
138 			BMessage			fClientViewsWithInvalidCoords;
139 
140 			int32				fHandlerToken;
141 
142 			Layer*				fCurrentLayer;
143 };
144 
145 #endif	// _SERVERWIN_H_
146