xref: /haiku/src/kits/app/Cursor.cpp (revision 24159a0c7d6d6dcba9f2a0c1a7c08d2c8167f21b)
1 /*
2  * Copyright 2001-2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
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  */
10 
11 /**	BCursor describes a view-wide or application-wide cursor. */
12 
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.
16  */
17 
18 #include <AppDefs.h>
19 #include <Cursor.h>
20 
21 #include <CursorSet.h>
22 #include <AppServerLink.h>
23 #include <ServerProtocol.h>
24 
25 
26 const BCursor *B_CURSOR_SYSTEM_DEFAULT;
27 const BCursor *B_CURSOR_I_BEAM;
28 	// these are initialized in BApplication::InitData()
29 
30 
31 BCursor::BCursor(const void *cursorData)
32 	:
33 	fServerToken(-1),
34 	fNeedToFree(false),
35 	fPendingViewCursor(false)
36 {
37 	const uint8 *data = (const uint8 *)cursorData;
38 
39 	if (data == B_HAND_CURSOR || data == B_I_BEAM_CURSOR) {
40 		// just use the default cursors from the app_server
41 		fServerToken = data == B_HAND_CURSOR ?
42 			B_CURSOR_DEFAULT : B_CURSOR_TEXT;
43 		return;
44 	}
45 
46 	// Create a new cursor in the app_server
47 
48 	if (data == NULL
49 		|| data[0] != 16	// size
50 		|| data[1] != 1		// depth
51 		|| data[2] >= 16 || data[3] >= 16)	// hot-spot
52 		return;
53 
54 	// Send data directly to server
55 	BPrivate::AppServerLink link;
56 	link.StartMessage(AS_CREATE_CURSOR);
57 	link.Attach(cursorData, 68);
58 
59 	status_t status;
60 	if (link.FlushWithReply(status) == B_OK && status == B_OK) {
61 		link.Read<int32>(&fServerToken);
62 		fNeedToFree = true;
63 	}
64 }
65 
66 
67 BCursor::BCursor(BMessage *data)
68 {
69 	// undefined on BeOS
70 	fServerToken = -1;
71 	fNeedToFree = false;
72 	fPendingViewCursor = false;
73 }
74 
75 
76 BCursor::~BCursor()
77 {
78 	// Notify server to deallocate server-side objects for this cursor
79 	if (fNeedToFree) {
80 		BPrivate::AppServerLink link;
81 		link.StartMessage(AS_DELETE_CURSOR);
82 		link.Attach<int32>(fServerToken);
83 		link.Attach<bool>(fPendingViewCursor);
84 		link.Flush();
85 	}
86 }
87 
88 
89 status_t
90 BCursor::Archive(BMessage *into, bool deep) const
91 {
92 	// not implemented on BeOS
93 	return B_OK;
94 }
95 
96 
97 BArchivable	*
98 BCursor::Instantiate(BMessage *data)
99 {
100 	// not implemented on BeOS
101 	return NULL;
102 }
103 
104 
105 status_t
106 BCursor::Perform(perform_code d, void *arg)
107 {
108 	return B_OK;
109 }
110 
111 
112 void BCursor::_ReservedCursor1() {}
113 void BCursor::_ReservedCursor2() {}
114 void BCursor::_ReservedCursor3() {}
115 void BCursor::_ReservedCursor4() {}
116