xref: /haiku/src/servers/app/ServerWindow.h (revision acc71e7c7c666824557eacb3bd42a9aa802c1196)
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 "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 Window;
40 class Workspace;
41 class View;
42 class ServerPicture;
43 class DirectWindowData;
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 port_id				MessagePort() const { return fMessagePort; }
61 
62 			::EventTarget&		EventTarget() { return fEventTarget; }
63 
64 			// methods for sending various messages to client.
65 			void				NotifyQuitRequested();
66 			void				NotifyMinimize(bool minimize);
67 			void				NotifyZoom();
68 
69 			// util methods.
70 			const BMessenger&	FocusMessenger() const
71 									{ return fFocusMessenger; }
72 			const BMessenger&	HandlerMessenger() const
73 									{ return fHandlerMessenger; }
74 
75 			void			ScreenChanged(const BMessage *screenChangedMessage);
76 			status_t			SendMessageToClient(const BMessage* msg,
77 									int32 target = B_NULL_TOKEN) const;
78 
79 	virtual	::Window*			MakeWindow(BRect frame, const char* name,
80 									window_look look, window_feel feel,
81 									uint32 flags, 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 			::Window*			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,
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 						// TODO: Change this
107 	inline	void				UpdateCurrentDrawingRegion()
108 									{ _UpdateCurrentDrawingRegion(); };
109 
110 private:
111 			View*				_CreateView(BPrivate::LinkReceiver &link,
112 									View **_parent);
113 
114 			void				_Show();
115 			void				_Hide();
116 
117 			// message handling methods.
118 			void				_DispatchMessage(int32 code,
119 									BPrivate::LinkReceiver &link);
120 			void				_DispatchViewMessage(int32 code,
121 									BPrivate::LinkReceiver &link);
122 			void				_DispatchViewDrawingMessage(int32 code,
123 									BPrivate::LinkReceiver &link);
124 			bool				_DispatchPictureMessage(int32 code,
125 									BPrivate::LinkReceiver &link);
126 			void				_MessageLooper();
127 	virtual void				_PrepareQuit();
128 	virtual void				_GetLooperName(char* name, size_t size);
129 
130 			status_t			_EnableDirectWindowMode();
131 
132 			void				_SetCurrentView(View* view);
133 			void				_UpdateDrawState(View* view);
134 			void				_UpdateCurrentDrawingRegion();
135 
136 			bool				_MessageNeedsAllWindowsLocked(
137 									uint32 code) const;
138 
139 			void				_DirectWindowSetFullScreen(bool set);
140 
141 			// TODO: Move me elsewhere
142 			status_t			PictureToRegion(ServerPicture *picture,
143 									BRegion& region, bool inverse,
144 									BPoint where);
145 
146 private:
147 			char*				fTitle;
148 
149 			::Desktop*			fDesktop;
150 			ServerApp*			fServerApp;
151 			::Window*			fWindow;
152 			bool				fWindowAddedToDesktop;
153 
154 			team_id				fClientTeam;
155 
156 			port_id				fMessagePort;
157 			port_id				fClientReplyPort;
158 			port_id				fClientLooperPort;
159 			BMessenger			fFocusMessenger;
160 			BMessenger			fHandlerMessenger;
161 			::EventTarget		fEventTarget;
162 
163 			int32				fRedrawRequested;
164 
165 			int32				fServerToken;
166 			int32				fClientToken;
167 
168 			View*				fCurrentView;
169 			BRegion				fCurrentDrawingRegion;
170 			bool				fCurrentDrawingRegionValid;
171 
172 			DirectWindowData*	fDirectWindowData;
173 			window_feel			fDirectWindowFeel;
174 };
175 
176 #endif	// SERVER_WINDOW_H
177