xref: /haiku/src/servers/app/ServerWindow.h (revision f23596149e0d173463f70629581aa10cc305d32e)
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 private:
105 			ViewLayer*			_CreateLayerTree(BPrivate::LinkReceiver &link,
106 									ViewLayer **_parent);
107 
108 			void				_Show();
109 			void				_Hide();
110 
111 			// message handling methods.
112 			void				_DispatchMessage(int32 code, BPrivate::LinkReceiver &link);
113 			void				_DispatchViewMessage(int32 code,
114 									BPrivate::LinkReceiver &link);
115 			void				_DispatchViewDrawingMessage(int32 code,
116 									BPrivate::LinkReceiver &link);
117 			bool				_DispatchPictureMessage(int32 code,
118 									BPrivate::LinkReceiver &link);
119 			void				_MessageLooper();
120 	virtual void				_PrepareQuit();
121 	virtual void				_GetLooperName(char* name, size_t size);
122 
123 			status_t			_EnableDirectWindowMode();
124 
125 			void				_SetCurrentLayer(ViewLayer* view);
126 
127 			// TODO: Move me elsewhere
128 			status_t			PictureToRegion(ServerPicture *picture,
129 												BRegion &,
130 												bool inverse,
131 												BPoint where);
132 
133 private:
134 			char*				fTitle;
135 
136 			::Desktop*			fDesktop;
137 			ServerApp*			fServerApp;
138 			WindowLayer*		fWindowLayer;
139 			bool				fWindowAddedToDesktop;
140 
141 			team_id				fClientTeam;
142 
143 			port_id				fMessagePort;
144 			port_id				fClientReplyPort;
145 			port_id				fClientLooperPort;
146 			BMessenger			fFocusMessenger;
147 			BMessenger			fHandlerMessenger;
148 			::EventTarget		fEventTarget;
149 
150 			int32				fRedrawRequested;
151 
152 			int32				fServerToken;
153 			int32				fClientToken;
154 
155 			ViewLayer*			fCurrentLayer;
156 			BRegion				fCurrentDrawingRegion;
157 			bool				fCurrentDrawingRegionValid;
158 
159 			direct_window_data*	fDirectWindowData;
160 };
161 
162 #endif	// SERVER_WINDOW_H
163