xref: /haiku/src/servers/app/ServerWindow.h (revision 079c69cbfd7cd3c97baae91332251c8388a8bb02)
1 /*
2  * Copyright 2001-2006, 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 <Region.h>
28 #include <String.h>
29 #include <Window.h>
30 
31 class BString;
32 class BMessenger;
33 class BPoint;
34 class BMessage;
35 
36 class Desktop;
37 class ServerApp;
38 class Decorator;
39 class WindowLayer;
40 class Workspace;
41 class ViewLayer;
42 class ServerPicture;
43 struct direct_window_data;
44 struct window_info;
45 
46 #define AS_UPDATE_DECORATOR 'asud'
47 #define AS_UPDATE_COLORS 'asuc'
48 #define AS_UPDATE_FONTS 'asuf'
49 
50 class ServerWindow : public MessageLooper {
51 public:
52 								ServerWindow(const char *title, ServerApp *app,
53 									port_id clientPort, port_id looperPort,
54 									int32 clientToken);
55 	virtual						~ServerWindow();
56 
57 			status_t			Init(BRect frame, window_look look,
58 									window_feel feel, uint32 flags,
59 									uint32 workspace);
60 	virtual bool				Run();
61 	virtual port_id				MessagePort() const { return fMessagePort; }
62 
63 			::EventTarget&		EventTarget() { return fEventTarget; }
64 
65 			void				ReplaceDecorator();
66 
67 			// methods for sending various messages to client.
68 			void				NotifyQuitRequested();
69 			void				NotifyMinimize(bool minimize);
70 			void				NotifyZoom();
71 
72 			// util methods.
73 			const BMessenger&	FocusMessenger() const { return fFocusMessenger; }
74 			const BMessenger&	HandlerMessenger() const { return fHandlerMessenger; }
75 
76 			status_t			SendMessageToClient(const BMessage* msg,
77 									int32 target = B_NULL_TOKEN) const;
78 
79 	virtual	WindowLayer*		MakeWindowLayer(BRect frame, const char* name,
80 									window_look look, window_feel feel, uint32 flags,
81 									uint32 workspace);
82 
83 			// to who we belong. who do we own. our title.
84 	inline	ServerApp*			App() const { return fServerApp; }
85 			::Desktop*			Desktop() const { return fDesktop; }
86 			::WindowLayer*		Window() const;
87 
88 			void				SetTitle(const char* newTitle);
89 	inline	const char*			Title() const { return fTitle; }
90 
91 			// related thread/team_id(s).
92 	inline	team_id				ClientTeam() const { return fClientTeam; }
93 
94 			void				HandleDirectConnection(int32 bufferState = -1,
95 									int32 driverState = -1);
96 
97 	inline	int32				ClientToken() const { return fClientToken; }
98 	inline	int32				ServerToken() const { return fServerToken; }
99 
100 			void				RequestRedraw();
101 
102 			void				GetInfo(window_info& info);
103 
104 			void				ResyncDrawState();
105 
106 private:
107 			ViewLayer*			_CreateLayerTree(BPrivate::LinkReceiver &link,
108 									ViewLayer **_parent);
109 
110 			void				_Show();
111 			void				_Hide();
112 
113 			// message handling methods.
114 			void				_DispatchMessage(int32 code, BPrivate::LinkReceiver &link);
115 			void				_DispatchViewMessage(int32 code,
116 									BPrivate::LinkReceiver &link);
117 			void				_DispatchViewDrawingMessage(int32 code,
118 									BPrivate::LinkReceiver &link);
119 			bool				_DispatchPictureMessage(int32 code,
120 									BPrivate::LinkReceiver &link);
121 			void				_MessageLooper();
122 	virtual void				_PrepareQuit();
123 	virtual void				_GetLooperName(char* name, size_t size);
124 
125 			status_t			_EnableDirectWindowMode();
126 
127 			void				_SetCurrentLayer(ViewLayer* view);
128 			void				_UpdateDrawState(ViewLayer* view);
129 
130 			// TODO: Move me elsewhere
131 			status_t			PictureToRegion(ServerPicture *picture,
132 												BRegion &,
133 												bool inverse,
134 												BPoint where);
135 
136 private:
137 			char*				fTitle;
138 
139 			::Desktop*			fDesktop;
140 			ServerApp*			fServerApp;
141 			WindowLayer*		fWindowLayer;
142 			bool				fWindowAddedToDesktop;
143 
144 			team_id				fClientTeam;
145 
146 			port_id				fMessagePort;
147 			port_id				fClientReplyPort;
148 			port_id				fClientLooperPort;
149 			BMessenger			fFocusMessenger;
150 			BMessenger			fHandlerMessenger;
151 			::EventTarget		fEventTarget;
152 
153 			int32				fRedrawRequested;
154 
155 			int32				fServerToken;
156 			int32				fClientToken;
157 
158 			ViewLayer*			fCurrentLayer;
159 			BRegion				fCurrentDrawingRegion;
160 			bool				fCurrentDrawingRegionValid;
161 
162 			direct_window_data*	fDirectWindowData;
163 };
164 
165 #endif	// SERVER_WINDOW_H
166