xref: /haiku/src/servers/app/ServerWindow.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
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 <GraphicsDefs.h>
17 #include <PortLink.h>
18 #include <Locker.h>
19 #include <Message.h>
20 #include <OS.h>
21 #include <Rect.h>
22 #include <String.h>
23 #include <Window.h>
24 
25 #include "MessageLooper.h"
26 #include "SubWindowList.h"
27 #include "TokenSpace.h"
28 
29 class BString;
30 class BMessenger;
31 class BPoint;
32 class BMessage;
33 
34 class Desktop;
35 class ServerApp;
36 class Decorator;
37 class WinBorder;
38 class Workspace;
39 class RootLayer;
40 class Layer;
41 class ServerPicture;
42 struct dw_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, uint32 look,
57 									 uint32 feel, uint32 flags,
58 									 uint32 workspace);
59 	virtual bool				Run();
60 	virtual port_id				MessagePort() const { return fMessagePort; }
61 
62 			void				ReplaceDecorator();
63 			void				Show();
64 			void				Hide();
65 
66 			// methods for sending various messages to client.
67 			void				NotifyQuitRequested();
68 			void				NotifyMinimize(bool minimize);
69 			void				NotifyZoom();
70 			void				NotifyScreenModeChanged(const BRect frame,
71 									const color_space cspace);
72 
73 			// util methods.
74 			status_t			SendMessageToClient(const BMessage* msg,
75 													int32 target = B_NULL_TOKEN,
76 													bool usePreferred = false) const;
77 
78 	virtual	WinBorder*			MakeWinBorder(BRect frame,
79 											  const char* name,
80 											  uint32 look, uint32 feel,
81 											  uint32 flags, uint32 workspace);
82 
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 	inline	const WinBorder*	GetWinBorder() const { return fWinBorder; }
91 
92 			void				SetTitle(const char* newTitle);
93 	inline	const char*			Title() const { return fTitle; }
94 
95 			// related thread/team_id(s).
96 	inline	team_id				ClientTeam() const { return fClientTeam; }
97 
98 			void				HandleDirectConnection(int bufferState = -1, int driverState = -1);
99 
100 	inline	int32				ClientToken() const { return fClientToken; }
101 	inline	int32				ServerToken() const { return fServerToken; }
102 
103 			void				GetInfo(window_info& info);
104 
105 			// ToDo: public??
106 			SubWindowList	fSubWindowList;
107 
108 private:
109 			// methods for retrieving and creating a tree strcture of Layers.
110 			Layer*				CreateLayerTree(BPrivate::LinkReceiver &link, Layer **_parent);
111 			void				SetLayerState(Layer *layer, BPrivate::LinkReceiver &link);
112 			void				SetLayerFontState(Layer *layer, BPrivate::LinkReceiver &link);
113 
114 			// message handling methods.
115 			void				_DispatchMessage(int32 code, BPrivate::LinkReceiver &link);
116 			void				_DispatchGraphicsMessage(int32 code, BPrivate::LinkReceiver &link);
117 			void				_MessageLooper();
118 	virtual void				_PrepareQuit();
119 	virtual void				_GetLooperName(char* name, size_t size);
120 
121 			status_t			_EnableDirectWindowMode();
122 
123 			// TODO: Move me elsewhere
124 			status_t			PictureToRegion(ServerPicture *picture,
125 												BRegion &,
126 												bool inverse,
127 												BPoint where);
128 
129 private:
130 			char*				fTitle;
131 
132 			Desktop*			fDesktop;
133 			ServerApp*			fServerApp;
134 			WinBorder*			fWinBorder;
135 
136 			team_id				fClientTeam;
137 
138 			port_id				fMessagePort;
139 			port_id				fClientReplyPort;
140 			port_id				fClientLooperPort;
141 
142 			BMessage			fClientViewsWithInvalidCoords;
143 
144 			int32				fServerToken;
145 			int32				fClientToken;
146 
147 			Layer*				fCurrentLayer;
148 
149 			dw_data*			fDirectWindowData;
150 };
151 
152 #endif	// SERVER_WINDOW_H
153