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; 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 int32 CountBitmaps() const; 82 ServerBitmap* FindBitmap(int32 token) const; 83 84 int32 CountPictures() const; 85 ServerPicture* CreatePicture( 86 const ServerPicture* original = NULL); 87 ServerPicture* FindPicture(int32 token) const; 88 bool DeletePicture(int32 token); 89 90 Desktop* GetDesktop() const { return fDesktop; } 91 92 const ServerFont& PlainFont() const { return fPlainFont; } 93 94 BPrivate::BTokenSpace& ViewTokens() { return fViewTokens; } 95 96 private: 97 virtual void _DispatchMessage(int32 code, 98 BPrivate::LinkReceiver& link); 99 virtual void _MessageLooper(); 100 virtual void _GetLooperName(char* name, size_t size); 101 status_t _CreateWindow(int32 code, 102 BPrivate::LinkReceiver& link, 103 port_id& clientReplyPort); 104 105 bool _HasWindowUnderMouse(); 106 107 private: 108 port_id fMessagePort; 109 port_id fClientReplyPort; 110 // our BApplication's event port 111 112 BMessenger fHandlerMessenger; 113 port_id fClientLooperPort; 114 int32 fClientToken; 115 // To send a BMessage to the client 116 // (port + token) 117 118 Desktop* fDesktop; 119 BString fSignature; 120 team_id fClientTeam; 121 122 ServerFont fPlainFont; 123 ServerFont fBoldFont; 124 ServerFont fFixedFont; 125 126 mutable BLocker fWindowListLock; 127 BObjectList<ServerWindow> fWindowList; 128 BPrivate::BTokenSpace fViewTokens; 129 130 int32 fInitialWorkspace; 131 uint32 fTemporaryDisplayModeChange; 132 133 // NOTE: Bitmaps and Pictures are stored globally, but ServerApps 134 // remember which ones they own so that they can destroy them when 135 // they quit. 136 BList fBitmapList; 137 BList fPictureList; 138 139 ServerCursor* fAppCursor; 140 ServerCursor* fViewCursor; 141 int32 fCursorHideLevel; 142 // 0 = cursor visible 143 144 bool fIsActive; 145 146 ClientMemoryAllocator fMemoryAllocator; 147 }; 148 149 #endif // SERVER_APP_H 150