1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
//
// "$Id: fl_cursor.cxx 8055 2010-12-18 22:31:01Z manolo $"
//
// Mouse cursor support for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
// Change the current cursor.
// Under X the cursor is attached to the X window. I tried to hide
// this and pretend that changing the cursor is a drawing function.
// This avoids a field in the Fl_Window, and I suspect is more
// portable to other systems.
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Pixmap.H>
#include <FL/Fl_RGB_Image.H>
#include <FL/x.H>
#include <FL/fl_draw.H>
#include "fl_cursor_wait.xpm"
#include "fl_cursor_help.xpm"
#include "fl_cursor_nwse.xpm"
#include "fl_cursor_nesw.xpm"
#include "fl_cursor_none.xpm"
/**
Sets the cursor for the current window to the specified shape and colors.
The cursors are defined in the <FL/Enumerations.H> header file.
*/
void fl_cursor(Fl_Cursor c) {
if (Fl::first_window()) Fl::first_window()->cursor(c);
}
/* For back compatibility only. */
void fl_cursor(Fl_Cursor c, Fl_Color fg, Fl_Color bg) {
fl_cursor(c);
}
/**
Sets the default window cursor. This is the cursor that will be used
after the mouse pointer leaves a widget with a custom cursor set.
\see cursor(const Fl_RGB_Image*, int, int), default_cursor()
*/
void Fl_Window::default_cursor(Fl_Cursor c) {
cursor_default = c;
cursor(c);
}
void fallback_cursor(Fl_Window *w, Fl_Cursor c) {
const char **xpm;
int hotx, hoty;
// The standard arrow is our final fallback, so something is broken
// if we get called back here with that as an argument.
if (c == FL_CURSOR_ARROW)
return;
switch (c) {
case FL_CURSOR_WAIT:
xpm = (const char**)fl_cursor_wait_xpm;
hotx = 8;
hoty = 15;
break;
case FL_CURSOR_HELP:
xpm = (const char**)fl_cursor_help_xpm;
hotx = 1;
hoty = 3;
break;
case FL_CURSOR_NWSE:
xpm = (const char**)fl_cursor_nwse_xpm;
hotx = 7;
hoty = 7;
break;
case FL_CURSOR_NESW:
xpm = (const char**)fl_cursor_nesw_xpm;
hotx = 7;
hoty = 7;
break;
case FL_CURSOR_NONE:
xpm = (const char**)fl_cursor_none_xpm;
hotx = 0;
hoty = 0;
break;
default:
w->cursor(FL_CURSOR_ARROW);
return;
}
Fl_Pixmap pxm(xpm);
Fl_RGB_Image image(&pxm);
w->cursor(&image, hotx, hoty);
}
void Fl_Window::cursor(Fl_Cursor c) {
int ret;
// the cursor must be set for the top level window, not for subwindows
Fl_Window *w = window(), *toplevel = this;
while (w) {
toplevel = w;
w = w->window();
}
if (toplevel != this) {
toplevel->cursor(c);
return;
}
if (c == FL_CURSOR_DEFAULT)
c = cursor_default;
if (!i)
return;
ret = i->set_cursor(c);
if (ret)
return;
fallback_cursor(this, c);
}
/**
Changes the cursor for this window. This always calls the system, if
you are changing the cursor a lot you may want to keep track of how
you set it in a static variable and call this only if the new cursor
is different.
The default cursor will be used if the provided image cannot be used
as a cursor.
\see cursor(Fl_Cursor), default_cursor()
*/
void Fl_Window::cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
int ret;
// the cursor must be set for the top level window, not for subwindows
Fl_Window *w = window(), *toplevel = this;
while (w) {
toplevel = w;
w = w->window();
}
if (toplevel != this) {
toplevel->cursor(image, hotx, hoty);
return;
}
if (!i)
return;
ret = i->set_cursor(image, hotx, hoty);
if (ret)
return;
cursor(FL_CURSOR_DEFAULT);
}
//
// End of "$Id: fl_cursor.cxx 8055 2010-12-18 22:31:01Z manolo $".
//
|