xref: /haiku/src/servers/app/ServerWindow.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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@gmail.com>
8  *		Stephan Aßmus <superstippi@gmx.de>
9  *		Stefano Ceccherini (burton666@libero.it)
10  *		Axel Dörfler, axeld@pinc-software.de
11  */
12 #ifndef SERVER_WINDOW_H
13 #define SERVER_WINDOW_H
14 
15 
16 #include "EventDispatcher.h"
17 #include "MessageLooper.h"
18 
19 #include <PortLink.h>
20 #include <TokenSpace.h>
21 
22 #include <GraphicsDefs.h>
23 #include <Locker.h>
24 #include <Message.h>
25 #include <Messenger.h>
26 #include <Rect.h>
27 #include <String.h>
28 #include <Window.h>
29 
30 class BString;
31 class BMessenger;
32 class BPoint;
33 class BMessage;
34 
35 class Desktop;
36 class ServerApp;
37 class Decorator;
38 class WindowLayer;
39 class Workspace;
40 class ViewLayer;
41 class ServerPicture;
42 struct direct_window_data;
43 struct window_info;
44 
45 #define AS_UPDATE_DECORATOR 'asud'
46 #define AS_UPDATE_COLORS 'asuc'
47 #define AS_UPDATE_FONTS 'asuf'
48 
49 class ServerWindow : public MessageLooper {
50 public:
51 								ServerWindow(const char *title, ServerApp *app,
52 									port_id clientPort, port_id looperPort,
53 									int32 clientToken);
54 	virtual						~ServerWindow();
55 
56 			status_t			Init(BRect frame, window_look look,
57 									window_feel feel, uint32 flags,
58 									uint32 workspace);
59 	virtual bool				Run();
60 	virtual port_id				MessagePort() const { return fMessagePort; }
61 
62 			::EventTarget&		EventTarget() { return fEventTarget; }
63 
64 			void				ReplaceDecorator();
65 			void				Show();
66 			void				Hide();
67 
68 			// methods for sending various messages to client.
69 			void				NotifyQuitRequested();
70 			void				NotifyMinimize(bool minimize);
71 			void				NotifyZoom();
72 
73 			// util methods.
74 			const BMessenger&	FocusMessenger() const { return fFocusMessenger; }
75 			const BMessenger&	HandlerMessenger() const { return fHandlerMessenger; }
76 
77 			status_t			SendMessageToClient(const BMessage* msg,
78 									int32 target = B_NULL_TOKEN) const;
79 
80 	virtual	WindowLayer*		MakeWindowLayer(BRect frame, const char* name,
81 									window_look look, window_feel feel, uint32 flags,
82 									uint32 workspace);
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 			::Desktop*			Desktop() const { return fDesktop; }
91 	inline	const WindowLayer*	GetWindowLayer() const { return fWindowLayer; }
92 
93 			void				SetTitle(const char* newTitle);
94 	inline	const char*			Title() const { return fTitle; }
95 
96 			// related thread/team_id(s).
97 	inline	team_id				ClientTeam() const { return fClientTeam; }
98 
99 			void				HandleDirectConnection(int32 bufferState = -1,
100 									int32 driverState = -1);
101 
102 	inline	int32				ClientToken() const { return fClientToken; }
103 	inline	int32				ServerToken() const { return fServerToken; }
104 
105 			void				RequestRedraw();
106 
107 			void				GetInfo(window_info& info);
108 
109 private:
110 			// methods for retrieving and creating a tree strcture of Layers.
111 			ViewLayer*			CreateLayerTree(BPrivate::LinkReceiver &link,
112 									ViewLayer **_parent);
113 			void				SetLayerState(ViewLayer *layer,
114 									BPrivate::LinkReceiver &link);
115 			void				SetLayerFontState(ViewLayer *layer,
116 									BPrivate::LinkReceiver &link);
117 
118 			// message handling methods.
119 			void				_DispatchMessage(int32 code, BPrivate::LinkReceiver &link);
120 			void				_DispatchViewMessage(int32 code,
121 									BPrivate::LinkReceiver &link);
122 			void				_DispatchViewDrawingMessage(int32 code,
123 									BPrivate::LinkReceiver &link);
124 			void				_MessageLooper();
125 	virtual void				_PrepareQuit();
126 	virtual void				_GetLooperName(char* name, size_t size);
127 
128 			status_t			_EnableDirectWindowMode();
129 
130 			void				_SetCurrentLayer(ViewLayer* view);
131 
132 			// TODO: Move me elsewhere
133 			status_t			PictureToRegion(ServerPicture *picture,
134 												BRegion &,
135 												bool inverse,
136 												BPoint where);
137 
138 private:
139 			char*				fTitle;
140 
141 			::Desktop*			fDesktop;
142 			ServerApp*			fServerApp;
143 			WindowLayer*		fWindowLayer;
144 
145 			team_id				fClientTeam;
146 
147 			port_id				fMessagePort;
148 			port_id				fClientReplyPort;
149 			port_id				fClientLooperPort;
150 			BMessenger			fFocusMessenger;
151 			BMessenger			fHandlerMessenger;
152 			::EventTarget		fEventTarget;
153 
154 			BMessage			fClientViewsWithInvalidCoords;
155 			int32				fRedrawRequested;
156 
157 			int32				fServerToken;
158 			int32				fClientToken;
159 
160 			ViewLayer*			fCurrentLayer;
161 			BRegion				fCurrentDrawingRegion;
162 			bool				fCurrentDrawingRegionValid;
163 
164 			direct_window_data*	fDirectWindowData;
165 };
166 
167 #endif	// SERVER_WINDOW_H
168