1 /* 2 * Copyright 2001-2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Stephan Aßmus <superstippi@gmx.de> 8 * Axel Dörfler, axeld@pinc-software.de 9 */ 10 #ifndef SERVER_CURSOR_H 11 #define SERVER_CURSOR_H 12 13 14 #include "ServerBitmap.h" 15 16 #include <Point.h> 17 #include <String.h> 18 19 class ServerApp; 20 class CursorManager; 21 22 23 class ServerCursor : public ServerBitmap { 24 public: 25 ServerCursor(BRect r, color_space space, 26 int32 flags, BPoint hotspot, 27 int32 bytesperrow = -1, 28 screen_id screen = B_MAIN_SCREEN_ID); 29 ServerCursor(const uint8* cursorDataFromR5); 30 ServerCursor(const uint8* alreadyPaddedData, 31 uint32 width, uint32 height, 32 color_space format); 33 ServerCursor(const ServerCursor* cursor); 34 35 virtual ~ServerCursor(); 36 37 //! Returns the cursor's hot spot 38 void SetHotSpot(BPoint pt); 39 BPoint GetHotSpot() const 40 { return fHotSpot; } 41 42 void SetOwningTeam(team_id tid) 43 { fOwningTeam = tid; } 44 team_id OwningTeam() const 45 { return fOwningTeam; } 46 47 int32 Token() const 48 { return fToken; } 49 50 void Acquire() 51 { atomic_add(&fReferenceCount, 1); } 52 bool Release(); 53 int32 ReferenceCount() { return fReferenceCount; } 54 55 void SetPendingViewCursor(bool pending); 56 57 void AttachedToManager(CursorManager* manager); 58 59 const uint8* CursorData() const 60 { return fCursorData; } 61 62 private: 63 friend class CursorManager; 64 65 BPoint fHotSpot; 66 team_id fOwningTeam; 67 vint32 fReferenceCount; 68 uint8* fCursorData; 69 CursorManager* fManager; 70 vint32 fPendingViewCursor; 71 }; 72 73 74 class ServerCursorReference { 75 public: 76 ServerCursorReference() 77 : fCursor(NULL) 78 { 79 } 80 ServerCursorReference(ServerCursor* cursor) 81 : fCursor(cursor) 82 { 83 if (fCursor) 84 fCursor->Acquire(); 85 } 86 ServerCursorReference(const ServerCursorReference& other) 87 : fCursor(other.fCursor) 88 { 89 if (fCursor) 90 fCursor->Acquire(); 91 } 92 virtual ~ServerCursorReference() 93 { 94 if (fCursor) 95 fCursor->Release(); 96 } 97 98 ServerCursorReference& operator=(const ServerCursorReference& other) 99 { 100 SetCursor(other.fCursor); 101 return *this; 102 } 103 104 void SetCursor(ServerCursor* cursor) 105 { 106 if (fCursor == cursor) 107 return; 108 if (cursor) 109 cursor->Acquire(); 110 ServerCursor* oldCursor = fCursor; 111 fCursor = cursor; 112 if (oldCursor) 113 oldCursor->Release(); 114 } 115 ServerCursor* Cursor() const 116 { 117 return fCursor; 118 } 119 private: 120 ServerCursor* fCursor; 121 }; 122 123 124 #endif // SERVER_CURSOR_H 125