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 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 private: 98 virtual void _GetLooperName(char* name, size_t size); 99 virtual void _DispatchMessage(int32 code, 100 BPrivate::LinkReceiver& link); 101 virtual void _MessageLooper(); 102 status_t _CreateWindow(int32 code, 103 BPrivate::LinkReceiver& link, 104 port_id& clientReplyPort); 105 106 bool _HasWindowUnderMouse(); 107 108 bool _AddBitmap(ServerBitmap* bitmap); 109 void _DeleteBitmap(ServerBitmap* bitmap); 110 ServerBitmap* _FindBitmap(int32 token) const; 111 112 ServerPicture* _FindPicture(int32 token) const; 113 114 private: 115 typedef std::map<int32, ServerBitmap*> BitmapMap; 116 typedef std::map<int32, ServerPicture*> PictureMap; 117 118 port_id fMessagePort; 119 port_id fClientReplyPort; 120 // our BApplication's event port 121 122 BMessenger fHandlerMessenger; 123 port_id fClientLooperPort; 124 int32 fClientToken; 125 // To send a BMessage to the client 126 // (port + token) 127 128 Desktop* fDesktop; 129 BString fSignature; 130 team_id fClientTeam; 131 132 ServerFont fPlainFont; 133 ServerFont fBoldFont; 134 ServerFont fFixedFont; 135 136 mutable BLocker fWindowListLock; 137 BObjectList<ServerWindow> fWindowList; 138 BPrivate::BTokenSpace fViewTokens; 139 140 int32 fInitialWorkspace; 141 uint32 fTemporaryDisplayModeChange; 142 143 // NOTE: Bitmaps and Pictures are stored globally, but ServerApps 144 // remember which ones they own so that they can destroy them when 145 // they quit. 146 mutable BLocker fMapLocker; 147 BitmapMap fBitmapMap; 148 PictureMap fPictureMap; 149 150 ServerCursor* fAppCursor; 151 ServerCursor* fViewCursor; 152 int32 fCursorHideLevel; 153 // 0 = cursor visible 154 155 bool fIsActive; 156 157 ClientMemoryAllocator fMemoryAllocator; 158 }; 159 160 #endif // SERVER_APP_H 161