xref: /haiku/src/servers/app/ServerWindow.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2  * Copyright 2001-2009, 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 <GraphicsDefs.h>
17 #include <Locker.h>
18 #include <Message.h>
19 #include <Messenger.h>
20 #include <Rect.h>
21 #include <Region.h>
22 #include <String.h>
23 #include <Window.h>
24 
25 #include <PortLink.h>
26 #include <TokenSpace.h>
27 
28 #include "EventDispatcher.h"
29 #include "MessageLooper.h"
30 
31 
32 class BString;
33 class BMessenger;
34 class BPoint;
35 class BMessage;
36 
37 class Desktop;
38 class ServerApp;
39 class Decorator;
40 class Window;
41 class Workspace;
42 class View;
43 class ServerPicture;
44 class DirectWindowInfo;
45 struct window_info;
46 
47 #define AS_UPDATE_DECORATOR 'asud'
48 #define AS_UPDATE_COLORS 'asuc'
49 #define AS_UPDATE_FONTS 'asuf'
50 
51 
52 class ServerWindow : public MessageLooper {
53 public:
54 								ServerWindow(const char *title, ServerApp *app,
55 									port_id clientPort, port_id looperPort,
56 									int32 clientToken);
57 	virtual						~ServerWindow();
58 
59 			status_t			Init(BRect frame, window_look look,
60 									window_feel feel, uint32 flags,
61 									uint32 workspace);
62 
63 	virtual port_id				MessagePort() const { return fMessagePort; }
64 
65 			::EventTarget&		EventTarget() { return fEventTarget; }
66 
67 	inline	ServerApp*			App() const { return fServerApp; }
68 			::Desktop*			Desktop() const { return fDesktop; }
69 			::Window*			Window() const;
70 
71 			// methods for sending various messages to client.
72 			void				NotifyQuitRequested();
73 			void				NotifyMinimize(bool minimize);
74 			void				NotifyZoom();
75 
76 			// util methods.
77 			const BMessenger&	FocusMessenger() const
78 									{ return fFocusMessenger; }
79 			const BMessenger&	HandlerMessenger() const
80 									{ return fHandlerMessenger; }
81 
82 			void				ScreenChanged(const BMessage* message);
83 			status_t			SendMessageToClient(const BMessage* message,
84 									int32 target = B_NULL_TOKEN) const;
85 
86 	virtual	::Window*			MakeWindow(BRect frame, const char* name,
87 									window_look look, window_feel feel,
88 									uint32 flags, uint32 workspace);
89 
90 			void				SetTitle(const char* newTitle);
91 	inline	const char*			Title() const { return fTitle; }
92 
93 			// related thread/team_id(s).
94 	inline	team_id				ClientTeam() const { return fClientTeam; }
95 
96 	inline	int32				ClientToken() const { return fClientToken; }
97 	inline	int32				ServerToken() const { return fServerToken; }
98 
99 			void				RequestRedraw();
100 
101 			void				GetInfo(window_info& info);
102 
103 			void				HandleDirectConnection(int32 bufferState,
104 									int32 driverState = 0);
105 			bool				HasDirectFrameBufferAccess() const
106 									{ return fDirectWindowInfo != NULL; }
107 			bool				IsDirectlyAccessing() const
108 									{ return fIsDirectlyAccessing; }
109 
110 			void				ResyncDrawState();
111 
112 						// TODO: Change this
113 	inline	void				UpdateCurrentDrawingRegion()
114 									{ _UpdateCurrentDrawingRegion(); };
115 
116 private:
117 			View*				_CreateView(BPrivate::LinkReceiver &link,
118 									View **_parent);
119 
120 			void				_Show();
121 			void				_Hide();
122 
123 			// message handling methods.
124 			void				_DispatchMessage(int32 code,
125 									BPrivate::LinkReceiver &link);
126 			void				_DispatchViewMessage(int32 code,
127 									BPrivate::LinkReceiver &link);
128 			void				_DispatchViewDrawingMessage(int32 code,
129 									BPrivate::LinkReceiver &link);
130 			bool				_DispatchPictureMessage(int32 code,
131 									BPrivate::LinkReceiver &link);
132 			void				_MessageLooper();
133 	virtual void				_PrepareQuit();
134 	virtual void				_GetLooperName(char* name, size_t size);
135 
136 			void				_ResizeToFullScreen();
137 			status_t			_EnableDirectWindowMode();
138 			void				_DirectWindowSetFullScreen(bool set);
139 
140 			void				_SetCurrentView(View* view);
141 			void				_UpdateDrawState(View* view);
142 			void				_UpdateCurrentDrawingRegion();
143 
144 			bool				_MessageNeedsAllWindowsLocked(
145 									uint32 code) const;
146 
147 			// TODO: Move me elsewhere
148 			status_t			PictureToRegion(ServerPicture *picture,
149 									BRegion& region, bool inverse,
150 									BPoint where);
151 
152 private:
153 			char*				fTitle;
154 
155 			::Desktop*			fDesktop;
156 			ServerApp*			fServerApp;
157 			::Window*			fWindow;
158 			bool				fWindowAddedToDesktop;
159 
160 			team_id				fClientTeam;
161 
162 			port_id				fMessagePort;
163 			port_id				fClientReplyPort;
164 			port_id				fClientLooperPort;
165 			BMessenger			fFocusMessenger;
166 			BMessenger			fHandlerMessenger;
167 			::EventTarget		fEventTarget;
168 
169 			int32				fRedrawRequested;
170 
171 			int32				fServerToken;
172 			int32				fClientToken;
173 
174 			View*				fCurrentView;
175 			BRegion				fCurrentDrawingRegion;
176 			bool				fCurrentDrawingRegionValid;
177 
178 			DirectWindowInfo*	fDirectWindowInfo;
179 			bool				fIsDirectlyAccessing;
180 };
181 
182 #endif	// SERVER_WINDOW_H
183