BPicture: Fix archive constructor.
[haiku.git] / src / kits / app / Cursor.cpp
blob0623d0a50db3f5dea9b28c2a105f2e1bbdaa8790
1 /*
2 * Copyright 2001-2006, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Frans van Nispen (xlr8@tref.nl)
7 * Gabe Yoder (gyoder@stny.rr.com)
8 * Axel Dörfler, axeld@pinc-software.de
9 */
11 /** BCursor describes a view-wide or application-wide cursor. */
13 /**
14 @note: As BeOS only supports 16x16 monochrome cursors, and I would like
15 to see a nice shadowes one, we will need to extend this one.
18 #include <AppDefs.h>
19 #include <Cursor.h>
21 #include <AppServerLink.h>
22 #include <ServerProtocol.h>
25 const BCursor *B_CURSOR_SYSTEM_DEFAULT;
26 const BCursor *B_CURSOR_I_BEAM;
27 // these are initialized in BApplication::InitData()
29 BCursor::BCursor(const void *cursorData)
31 fServerToken(-1),
32 fNeedToFree(false)
34 const uint8 *data = (const uint8 *)cursorData;
36 if (data == B_HAND_CURSOR || data == B_I_BEAM_CURSOR) {
37 // just use the default cursors from the app_server
38 fServerToken = data == B_HAND_CURSOR ?
39 B_CURSOR_ID_SYSTEM_DEFAULT : B_CURSOR_ID_I_BEAM;
40 return;
43 // Create a new cursor in the app_server
45 if (data == NULL
46 || data[0] != 16 // size
47 || data[1] != 1 // depth
48 || data[2] >= 16 || data[3] >= 16) // hot-spot
49 return;
51 // Send data directly to server
52 BPrivate::AppServerLink link;
53 link.StartMessage(AS_CREATE_CURSOR);
54 link.Attach(cursorData, 68);
56 status_t status;
57 if (link.FlushWithReply(status) == B_OK && status == B_OK) {
58 link.Read<int32>(&fServerToken);
59 fNeedToFree = true;
64 BCursor::BCursor(BCursorID id)
66 fServerToken(id),
67 fNeedToFree(false)
72 BCursor::BCursor(const BCursor& other)
74 fServerToken(-1),
75 fNeedToFree(false)
77 *this = other;
81 BCursor::BCursor(BMessage *data)
83 // undefined on BeOS
84 fServerToken = -1;
85 fNeedToFree = false;
89 BCursor::~BCursor()
91 _FreeCursorData();
95 status_t
96 BCursor::Archive(BMessage *into, bool deep) const
98 // not implemented on BeOS
99 return B_OK;
103 BArchivable *
104 BCursor::Instantiate(BMessage *data)
106 // not implemented on BeOS
107 return NULL;
111 BCursor&
112 BCursor::operator=(const BCursor& other)
114 if (&other != this && other != *this) {
115 _FreeCursorData();
117 fServerToken = other.fServerToken;
118 fNeedToFree = other.fNeedToFree;
120 if (fNeedToFree) {
121 // Tell app_server that there is another reference for this
122 // cursor data!
123 BPrivate::AppServerLink link;
124 link.StartMessage(AS_REFERENCE_CURSOR);
125 link.Attach<int32>(fServerToken);
128 return *this;
132 bool
133 BCursor::operator==(const BCursor& other) const
135 return fServerToken == other.fServerToken;
139 bool
140 BCursor::operator!=(const BCursor& other) const
142 return fServerToken != other.fServerToken;
146 status_t
147 BCursor::Perform(perform_code d, void *arg)
149 return B_OK;
153 void BCursor::_ReservedCursor1() {}
154 void BCursor::_ReservedCursor2() {}
155 void BCursor::_ReservedCursor3() {}
156 void BCursor::_ReservedCursor4() {}
159 void
160 BCursor::_FreeCursorData()
162 // Notify server to deallocate server-side objects for this cursor
163 if (fNeedToFree) {
164 BPrivate::AppServerLink link;
165 link.StartMessage(AS_DELETE_CURSOR);
166 link.Attach<int32>(fServerToken);
167 link.Flush();