]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: cursor.cpp | |
3 | // Purpose: wxCursor class | |
4 | // Author: David Webster | |
5 | // Modified by: | |
6 | // Created: 10/13/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) David Webster | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include <stdio.h> | |
17 | #include "wx/setup.h" | |
18 | #include "wx/list.h" | |
19 | #include "wx/utils.h" | |
20 | #include "wx/app.h" | |
21 | #include "wx/cursor.h" | |
22 | #include "wx/icon.h" | |
23 | #include "wx/resource.h" | |
24 | #endif | |
25 | ||
26 | #include "wx/os2/private.h" | |
27 | #include "wx/image.h" | |
28 | ||
29 | #include "assert.h" | |
30 | ||
31 | IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) | |
32 | ||
33 | wxCursorRefData::wxCursorRefData(void) | |
34 | { | |
35 | m_nWidth = 32; | |
36 | m_nHeight = 32; | |
37 | m_hCursor = 0 ; | |
38 | m_bDestroyCursor = FALSE; | |
39 | } | |
40 | ||
41 | void wxCursorRefData::Free() | |
42 | { | |
43 | if (m_hCursor) | |
44 | { | |
45 | if (m_bDestroyCursor) | |
46 | ::WinDestroyPointer((HPOINTER)m_hCursor); | |
47 | m_hCursor = 0; | |
48 | } | |
49 | } // end of wxCursorRefData::Free | |
50 | ||
51 | // Cursors | |
52 | wxCursor::wxCursor(void) | |
53 | { | |
54 | } | |
55 | ||
56 | wxCursor::wxCursor( | |
57 | const char WXUNUSED(bits)[] | |
58 | , int WXUNUSED(width) | |
59 | , int WXUNUSED(height) | |
60 | , int WXUNUSED(hotSpotX) | |
61 | , int WXUNUSED(hotSpotY) | |
62 | , const char WXUNUSED(maskBits)[] | |
63 | ) | |
64 | { | |
65 | } | |
66 | ||
67 | wxCursor::wxCursor( | |
68 | const wxImage& rImage | |
69 | ) | |
70 | { | |
71 | wxImage vImage32 = rImage.Scale(32,32); | |
72 | int nWidth = vImage32.GetWidth(); | |
73 | int nHeight = vImage32.GetHeight(); | |
74 | ||
75 | // | |
76 | // Need a bitmap handle somehow | |
77 | // | |
78 | HBITMAP hBitmap = wxBitmap(vImage32).GetHBITMAP(); | |
79 | int nHotSpotX = vImage32.GetOptionInt(wxCUR_HOTSPOT_X); | |
80 | int nHotSpotY = vImage32.GetOptionInt(wxCUR_HOTSPOT_Y); | |
81 | ||
82 | if (nHotSpotX < 0 || nHotSpotX >= nWidth) | |
83 | nHotSpotX = 0; | |
84 | if (nHotSpotY < 0 || nHotSpotY >= nHeight) | |
85 | nHotSpotY = 0; | |
86 | ||
87 | ||
88 | wxCursorRefData* pRefData = new wxCursorRefData; | |
89 | ||
90 | m_refData = pRefData; | |
91 | pRefData->m_hCursor = (WXHCURSOR) ::WinCreatePointer( HWND_DESKTOP | |
92 | ,hBitmap | |
93 | ,TRUE | |
94 | ,nHotSpotY | |
95 | ,nHotSpotX | |
96 | ); | |
97 | ||
98 | } // end of wxCursor::wxCursor | |
99 | ||
100 | wxCursor::wxCursor( | |
101 | const wxString& rsCursorFile | |
102 | , long lFlags | |
103 | , int nHotSpotX | |
104 | , int nHotSpotY | |
105 | ) | |
106 | { | |
107 | wxCursorRefData* pRefData = new wxCursorRefData; | |
108 | ||
109 | pRefData = new wxCursorRefData; | |
110 | m_refData = pRefData; | |
111 | pRefData->m_bDestroyCursor = FALSE; | |
112 | if (lFlags == wxBITMAP_TYPE_CUR_RESOURCE) | |
113 | { | |
114 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
115 | ,0 | |
116 | ,(ULONG)lFlags // if OS/2 this should be the resource Id | |
117 | ); | |
118 | } | |
119 | } // end of wxCursor::wxCursor | |
120 | ||
121 | // Cursors by stock number | |
122 | wxCursor::wxCursor( | |
123 | int nCursorType | |
124 | ) | |
125 | { | |
126 | wxCursorRefData* pRefData = new wxCursorRefData; | |
127 | ||
128 | m_refData = pRefData; | |
129 | switch (nCursorType) | |
130 | { | |
131 | case wxCURSOR_ARROWWAIT: | |
132 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
133 | ,(ULONG)SPTR_WAIT | |
134 | ,FALSE | |
135 | ); | |
136 | break; | |
137 | ||
138 | case wxCURSOR_WAIT: | |
139 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
140 | ,(ULONG)SPTR_WAIT | |
141 | ,FALSE | |
142 | ); | |
143 | break; | |
144 | ||
145 | case wxCURSOR_IBEAM: | |
146 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
147 | ,(ULONG)SPTR_TEXT | |
148 | ,FALSE | |
149 | ); | |
150 | break; | |
151 | ||
152 | case wxCURSOR_CROSS: | |
153 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
154 | ,(ULONG)SPTR_MOVE | |
155 | ,FALSE | |
156 | ); | |
157 | break; | |
158 | ||
159 | case wxCURSOR_SIZENWSE: | |
160 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
161 | ,(ULONG)SPTR_SIZENWSE | |
162 | ,FALSE | |
163 | ); | |
164 | break; | |
165 | ||
166 | case wxCURSOR_SIZENESW: | |
167 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
168 | ,(ULONG)SPTR_SIZENESW | |
169 | ,FALSE | |
170 | ); | |
171 | break; | |
172 | ||
173 | case wxCURSOR_SIZEWE: | |
174 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
175 | ,(ULONG)SPTR_SIZEWE | |
176 | ,FALSE | |
177 | ); | |
178 | break; | |
179 | ||
180 | case wxCURSOR_SIZENS: | |
181 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
182 | ,(ULONG)SPTR_SIZENS | |
183 | ,FALSE | |
184 | ); | |
185 | break; | |
186 | ||
187 | case wxCURSOR_CHAR: | |
188 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
189 | ,(ULONG)SPTR_ARROW | |
190 | ,FALSE | |
191 | ); | |
192 | break; | |
193 | ||
194 | case wxCURSOR_HAND: | |
195 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
196 | ,0 | |
197 | ,(ULONG)wxCURSOR_HAND | |
198 | ); | |
199 | break; | |
200 | ||
201 | case wxCURSOR_BULLSEYE: | |
202 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
203 | ,0 | |
204 | ,(ULONG)wxCURSOR_BULLSEYE | |
205 | ); | |
206 | break; | |
207 | ||
208 | case wxCURSOR_PENCIL: | |
209 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
210 | ,0 | |
211 | ,(ULONG)wxCURSOR_PENCIL | |
212 | ); | |
213 | break; | |
214 | ||
215 | case wxCURSOR_MAGNIFIER: | |
216 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
217 | ,0 | |
218 | ,(ULONG)wxCURSOR_MAGNIFIER | |
219 | ); | |
220 | break; | |
221 | ||
222 | case wxCURSOR_NO_ENTRY: | |
223 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
224 | ,0 | |
225 | ,(ULONG)wxCURSOR_NO_ENTRY | |
226 | ); | |
227 | break; | |
228 | ||
229 | case wxCURSOR_LEFT_BUTTON: | |
230 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
231 | ,(ULONG)SPTR_ARROW | |
232 | ,FALSE | |
233 | ); | |
234 | break; | |
235 | ||
236 | case wxCURSOR_RIGHT_BUTTON: | |
237 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
238 | ,(ULONG)SPTR_ARROW | |
239 | ,FALSE | |
240 | ); | |
241 | break; | |
242 | ||
243 | case wxCURSOR_MIDDLE_BUTTON: | |
244 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
245 | ,(ULONG)SPTR_ARROW | |
246 | ,FALSE | |
247 | ); | |
248 | break; | |
249 | ||
250 | case wxCURSOR_SIZING: | |
251 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
252 | ,(ULONG)SPTR_SIZE | |
253 | ,FALSE | |
254 | ); | |
255 | break; | |
256 | ||
257 | case wxCURSOR_WATCH: | |
258 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
259 | ,0 | |
260 | ,(ULONG)wxCURSOR_WATCH | |
261 | ); | |
262 | break; | |
263 | ||
264 | case wxCURSOR_SPRAYCAN: | |
265 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
266 | ,0 | |
267 | ,(ULONG)WXCURSOR_ROLLER | |
268 | ); | |
269 | break; | |
270 | ||
271 | case wxCURSOR_PAINT_BRUSH: | |
272 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
273 | ,0 | |
274 | ,(ULONG)WXCURSOR_PBRUSH | |
275 | ); | |
276 | break; | |
277 | ||
278 | case wxCURSOR_POINT_LEFT: | |
279 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
280 | ,0 | |
281 | ,(ULONG)WXCURSOR_PLEFT | |
282 | ); | |
283 | break; | |
284 | ||
285 | case wxCURSOR_POINT_RIGHT: | |
286 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
287 | ,0 | |
288 | ,(ULONG)WXCURSOR_PRIGHT | |
289 | ); | |
290 | break; | |
291 | ||
292 | case wxCURSOR_QUESTION_ARROW: | |
293 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
294 | ,0 | |
295 | ,(ULONG)WXCURSOR_QARROW | |
296 | ); | |
297 | break; | |
298 | ||
299 | case wxCURSOR_BLANK: | |
300 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
301 | ,0 | |
302 | ,(ULONG)WXCURSOR_BLANK | |
303 | ); | |
304 | break; | |
305 | ||
306 | default: | |
307 | case wxCURSOR_ARROW: | |
308 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
309 | ,(ULONG)SPTR_ARROW | |
310 | ,FALSE | |
311 | ); | |
312 | break; | |
313 | } | |
314 | } // end of wxCursor::wxCursor | |
315 | ||
316 | // Global cursor setting | |
317 | void wxSetCursor(const wxCursor& cursor) | |
318 | { | |
319 | extern wxCursor *g_globalCursor; | |
320 | ||
321 | if ( cursor.Ok() && cursor.GetHCURSOR() ) | |
322 | { | |
323 | // ::SetCursor((HCURSOR) cursor.GetHCURSOR()); | |
324 | ||
325 | if ( g_globalCursor ) | |
326 | (*g_globalCursor) = cursor; | |
327 | } | |
328 | } | |
329 |