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