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