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