1 /* 2 * Copyright 2001-2009, 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 bool BitmapAdded(ServerBitmap* bitmap); 83 void BitmapRemoved(ServerBitmap* bitmap); 84 85 ServerPicture* CreatePicture( 86 const ServerPicture* original = NULL); 87 ServerPicture* GetPicture(int32 token) const; 88 bool PictureAdded(ServerPicture* picture); 89 void PictureRemoved(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 ServerBitmap* _FindBitmap(int32 token) const; 109 ServerPicture* _FindPicture(int32 token) const; 110 111 private: 112 typedef std::map<int32, ServerBitmap*> BitmapMap; 113 typedef std::map<int32, ServerPicture*> PictureMap; 114 115 port_id fMessagePort; 116 port_id fClientReplyPort; 117 // our BApplication's event port 118 119 BMessenger fHandlerMessenger; 120 port_id fClientLooperPort; 121 int32 fClientToken; 122 // To send a BMessage to the client 123 // (port + token) 124 125 Desktop* fDesktop; 126 BString fSignature; 127 team_id fClientTeam; 128 129 ServerFont fPlainFont; 130 ServerFont fBoldFont; 131 ServerFont fFixedFont; 132 133 mutable BLocker fWindowListLock; 134 BObjectList<ServerWindow> fWindowList; 135 BPrivate::BTokenSpace fViewTokens; 136 137 int32 fInitialWorkspace; 138 uint32 fTemporaryDisplayModeChange; 139 140 // NOTE: Bitmaps and Pictures are stored globally, but ServerApps 141 // remember which ones they own so that they can destroy them when 142 // they quit. 143 mutable BLocker fMapLocker; 144 BitmapMap fBitmapMap; 145 PictureMap fPictureMap; 146 147 ServerCursor* fAppCursor; 148 ServerCursor* fViewCursor; 149 int32 fCursorHideLevel; 150 // 0 = cursor visible 151 152 bool fIsActive; 153 154 ClientMemoryAllocator fMemoryAllocator; 155 }; 156 157 #endif // SERVER_APP_H 158