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