xref: /haiku/src/servers/app/ServerApp.h (revision 385ee03ba83b7a40d315e17b03031b3ca37820c0)
1 /*
2  * Copyright 2001-2013, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Adrian Oanca <adioanca@cotty.iren.ro>
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_APP_H
13 #define SERVER_APP_H
14 
15 
16 #include "ClientMemoryAllocator.h"
17 #include "MessageLooper.h"
18 #include "ServerFont.h"
19 
20 #include <ObjectList.h>
21 #include <TokenSpace.h>
22 
23 #include <Messenger.h>
24 #include <String.h>
25 
26 
27 class AreaPool;
28 class BMessage;
29 class BList;
30 class Desktop;
31 class DrawingEngine;
32 class ServerPicture;
33 class ServerCursor;
34 class ServerBitmap;
35 class ServerWindow;
36 
37 namespace BPrivate {
38 	class PortLink;
39 };
40 
41 
42 class ServerApp : public MessageLooper {
43 public:
44 								ServerApp(Desktop* desktop,
45 									port_id clientAppPort,
46 									port_id clientLooperPort,
47 									team_id clientTeamID, int32 handlerID,
48 									const char* signature);
49 	virtual						~ServerApp();
50 
51 			status_t			InitCheck();
52 
53 	virtual	void				Quit();
54 			void				Quit(sem_id shutdownSemaphore);
55 
56 	virtual	port_id				MessagePort() const { return fMessagePort; }
57 
58 	/*!
59 		\brief Determines whether the application is the active one
60 		\return true if active, false if not.
61 	*/
62 			bool				IsActive() const { return fIsActive; }
63 			void				Activate(bool value);
64 
65 			void				SendMessageToClient(BMessage* message) const;
66 
67 			void				SetCurrentCursor(ServerCursor* cursor);
68 			ServerCursor*		CurrentCursor() const;
69 
70 			team_id				ClientTeam() const { return fClientTeam; }
71 
72 			const char*			Signature() const
73 									{ return fSignature.String(); }
74 			const char*			SignatureLeaf() const
75 									{ return fSignature.String() + 12; }
76 
77 			bool				AddWindow(ServerWindow* window);
78 			void				RemoveWindow(ServerWindow* window);
79 			bool				InWorkspace(int32 index) const;
80 			uint32				Workspaces() const;
81 			int32				InitialWorkspace() const
82 									{ return fInitialWorkspace; }
83 
84 			ServerBitmap*		GetBitmap(int32 token) const;
85 
86 			ServerPicture*		CreatePicture(
87 									const ServerPicture* original = NULL);
88 			ServerPicture*		GetPicture(int32 token) const;
89 			bool				AddPicture(ServerPicture* picture);
90 			void				RemovePicture(ServerPicture* picture);
91 
92 			Desktop*			GetDesktop() const { return fDesktop; }
93 
94 			const ServerFont&	PlainFont() const { return fPlainFont; }
95 
96 			BPrivate::BTokenSpace& ViewTokens() { return fViewTokens; }
97 
98 			void				NotifyDeleteClientArea(area_id serverArea);
99 
100 private:
101 	virtual	void				_GetLooperName(char* name, size_t size);
102 	virtual	void				_DispatchMessage(int32 code,
103 									BPrivate::LinkReceiver& link);
104 	virtual	void				_MessageLooper();
105 			status_t			_CreateWindow(int32 code,
106 									BPrivate::LinkReceiver& link,
107 									port_id& clientReplyPort);
108 
109 			bool				_HasWindowUnderMouse();
110 
111 			bool				_AddBitmap(ServerBitmap* bitmap);
112 			void				_DeleteBitmap(ServerBitmap* bitmap);
113 			ServerBitmap*		_FindBitmap(int32 token) const;
114 
115 			ServerPicture*		_FindPicture(int32 token) const;
116 
117 private:
118 	typedef std::map<int32, ServerBitmap*> BitmapMap;
119 	typedef std::map<int32, ServerPicture*> PictureMap;
120 
121 			port_id				fMessagePort;
122 			port_id				fClientReplyPort;
123 									// our BApplication's event port
124 
125 			BMessenger			fHandlerMessenger;
126 			port_id				fClientLooperPort;
127 			int32				fClientToken;
128 									// To send a BMessage to the client
129 									// (port + token)
130 
131 			Desktop*			fDesktop;
132 			BString				fSignature;
133 			team_id				fClientTeam;
134 
135 			ServerFont			fPlainFont;
136 			ServerFont			fBoldFont;
137 			ServerFont			fFixedFont;
138 
139 	mutable	BLocker				fWindowListLock;
140 			BObjectList<ServerWindow> fWindowList;
141 			BPrivate::BTokenSpace fViewTokens;
142 
143 			int32				fInitialWorkspace;
144 			uint32				fTemporaryDisplayModeChange;
145 
146 			// NOTE: Bitmaps and Pictures are stored globally, but ServerApps
147 			// remember which ones they own so that they can destroy them when
148 			// they quit.
149 	mutable	BLocker				fMapLocker;
150 			BitmapMap			fBitmapMap;
151 			PictureMap			fPictureMap;
152 
153 			ServerCursor*		fAppCursor;
154 			ServerCursor*		fViewCursor;
155 			int32				fCursorHideLevel;
156 									// 0 = cursor visible
157 
158 			bool				fIsActive;
159 
160 			ClientMemoryAllocator* fMemoryAllocator;
161 };
162 
163 
164 #endif	// SERVER_APP_H
165