]>
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 | #endif | |
24 | ||
25 | #include "wx/os2/private.h" | |
26 | #include "wx/os2/wxrsc.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(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 | { | |
63 | } | |
64 | ||
65 | wxCursor::wxCursor(const wxImage& rImage) | |
66 | { | |
67 | wxImage vImage32 = rImage.Scale(32,32); | |
68 | int nWidth = vImage32.GetWidth(); | |
69 | int nHeight = vImage32.GetHeight(); | |
70 | ||
71 | // | |
72 | // Need a bitmap handle somehow | |
73 | // | |
74 | HBITMAP hBitmap = wxBitmap(vImage32).GetHBITMAP(); | |
75 | int nHotSpotX = vImage32.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X); | |
76 | int nHotSpotY = vImage32.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y); | |
77 | ||
78 | if (nHotSpotX < 0 || nHotSpotX >= nWidth) | |
79 | nHotSpotX = 0; | |
80 | if (nHotSpotY < 0 || nHotSpotY >= nHeight) | |
81 | nHotSpotY = 0; | |
82 | ||
83 | ||
84 | wxCursorRefData* pRefData = new wxCursorRefData; | |
85 | ||
86 | m_refData = pRefData; | |
87 | pRefData->m_hCursor = (WXHCURSOR) ::WinCreatePointer( HWND_DESKTOP | |
88 | ,hBitmap | |
89 | ,TRUE | |
90 | ,nHotSpotY | |
91 | ,nHotSpotX | |
92 | ); | |
93 | ||
94 | } // end of wxCursor::wxCursor | |
95 | ||
96 | wxCursor::wxCursor( const wxString& WXUNUSED(rsCursorFile), | |
97 | long lFlags, | |
98 | int WXUNUSED(nHotSpotX), | |
99 | int WXUNUSED(nHotSpotY) ) | |
100 | { | |
101 | wxCursorRefData* pRefData = new wxCursorRefData; | |
102 | ||
103 | pRefData = new wxCursorRefData; | |
104 | m_refData = pRefData; | |
105 | pRefData->m_bDestroyCursor = false; | |
106 | if (lFlags == wxBITMAP_TYPE_CUR_RESOURCE) | |
107 | { | |
108 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
109 | ,0 | |
110 | ,(ULONG)lFlags // if OS/2 this should be the resource Id | |
111 | ); | |
112 | } | |
113 | } // end of wxCursor::wxCursor | |
114 | ||
115 | // Cursors by stock number | |
116 | wxCursor::wxCursor(int nCursorType) | |
117 | { | |
118 | wxCursorRefData* pRefData = new wxCursorRefData; | |
119 | ||
120 | m_refData = pRefData; | |
121 | switch (nCursorType) | |
122 | { | |
123 | case wxCURSOR_ARROWWAIT: | |
124 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
125 | ,(ULONG)SPTR_WAIT | |
126 | ,FALSE | |
127 | ); | |
128 | break; | |
129 | ||
130 | case wxCURSOR_WATCH: | |
131 | case wxCURSOR_WAIT: | |
132 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
133 | ,(ULONG)SPTR_WAIT | |
134 | ,FALSE | |
135 | ); | |
136 | break; | |
137 | ||
138 | case wxCURSOR_IBEAM: | |
139 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
140 | ,(ULONG)SPTR_TEXT | |
141 | ,FALSE | |
142 | ); | |
143 | break; | |
144 | ||
145 | case wxCURSOR_CROSS: | |
146 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
147 | ,(ULONG)SPTR_MOVE | |
148 | ,FALSE | |
149 | ); | |
150 | break; | |
151 | ||
152 | case wxCURSOR_SIZENWSE: | |
153 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
154 | ,(ULONG)SPTR_SIZENWSE | |
155 | ,FALSE | |
156 | ); | |
157 | break; | |
158 | ||
159 | case wxCURSOR_SIZENESW: | |
160 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
161 | ,(ULONG)SPTR_SIZENESW | |
162 | ,FALSE | |
163 | ); | |
164 | break; | |
165 | ||
166 | case wxCURSOR_SIZEWE: | |
167 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
168 | ,(ULONG)SPTR_SIZEWE | |
169 | ,FALSE | |
170 | ); | |
171 | break; | |
172 | ||
173 | case wxCURSOR_SIZENS: | |
174 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
175 | ,(ULONG)SPTR_SIZENS | |
176 | ,FALSE | |
177 | ); | |
178 | break; | |
179 | ||
180 | case wxCURSOR_CHAR: | |
181 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
182 | ,(ULONG)SPTR_ARROW | |
183 | ,FALSE | |
184 | ); | |
185 | break; | |
186 | ||
187 | case wxCURSOR_HAND: | |
188 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
189 | ,0 | |
190 | ,(ULONG)wxCURSOR_HAND | |
191 | ); | |
192 | break; | |
193 | ||
194 | case wxCURSOR_BULLSEYE: | |
195 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
196 | ,0 | |
197 | ,(ULONG)wxCURSOR_BULLSEYE | |
198 | ); | |
199 | break; | |
200 | ||
201 | case wxCURSOR_PENCIL: | |
202 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
203 | ,0 | |
204 | ,(ULONG)wxCURSOR_PENCIL | |
205 | ); | |
206 | break; | |
207 | ||
208 | case wxCURSOR_MAGNIFIER: | |
209 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
210 | ,0 | |
211 | ,(ULONG)wxCURSOR_MAGNIFIER | |
212 | ); | |
213 | break; | |
214 | ||
215 | case wxCURSOR_NO_ENTRY: | |
216 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
217 | ,(ULONG)SPTR_ILLEGAL | |
218 | ,FALSE | |
219 | ); | |
220 | break; | |
221 | ||
222 | case wxCURSOR_LEFT_BUTTON: | |
223 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
224 | ,(ULONG)SPTR_ARROW | |
225 | ,FALSE | |
226 | ); | |
227 | break; | |
228 | ||
229 | case wxCURSOR_RIGHT_BUTTON: | |
230 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
231 | ,(ULONG)SPTR_ARROW | |
232 | ,FALSE | |
233 | ); | |
234 | break; | |
235 | ||
236 | case wxCURSOR_MIDDLE_BUTTON: | |
237 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
238 | ,(ULONG)SPTR_ARROW | |
239 | ,FALSE | |
240 | ); | |
241 | break; | |
242 | ||
243 | case wxCURSOR_SIZING: | |
244 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
245 | ,(ULONG)SPTR_SIZE | |
246 | ,FALSE | |
247 | ); | |
248 | break; | |
249 | ||
250 | case wxCURSOR_SPRAYCAN: | |
251 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
252 | ,0 | |
253 | ,(ULONG)WXCURSOR_ROLLER | |
254 | ); | |
255 | break; | |
256 | ||
257 | case wxCURSOR_PAINT_BRUSH: | |
258 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
259 | ,0 | |
260 | ,(ULONG)WXCURSOR_PBRUSH | |
261 | ); | |
262 | break; | |
263 | ||
264 | case wxCURSOR_POINT_LEFT: | |
265 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
266 | ,0 | |
267 | ,(ULONG)WXCURSOR_PLEFT | |
268 | ); | |
269 | break; | |
270 | ||
271 | case wxCURSOR_POINT_RIGHT: | |
272 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
273 | ,0 | |
274 | ,(ULONG)WXCURSOR_PRIGHT | |
275 | ); | |
276 | break; | |
277 | ||
278 | case wxCURSOR_QUESTION_ARROW: | |
279 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
280 | ,0 | |
281 | ,(ULONG)WXCURSOR_QARROW | |
282 | ); | |
283 | break; | |
284 | ||
285 | case wxCURSOR_BLANK: | |
286 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP | |
287 | ,0 | |
288 | ,(ULONG)WXCURSOR_BLANK | |
289 | ); | |
290 | break; | |
291 | ||
292 | default: | |
293 | case wxCURSOR_ARROW: | |
294 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP | |
295 | ,(ULONG)SPTR_ARROW | |
296 | ,FALSE | |
297 | ); | |
298 | break; | |
299 | } | |
300 | // | |
301 | // No need to destroy the stock cursors | |
302 | // | |
303 | ((wxCursorRefData *)m_refData)->m_bDestroyCursor = false; | |
304 | } // end of wxCursor::wxCursor | |
305 | ||
306 | // Global cursor setting | |
307 | void wxSetCursor(const wxCursor& cursor) | |
308 | { | |
309 | extern wxCursor *g_globalCursor; | |
310 | ||
311 | if ( cursor.Ok() && cursor.GetHCURSOR() ) | |
312 | { | |
313 | // ::SetCursor((HCURSOR) cursor.GetHCURSOR()); | |
314 | ||
315 | if ( g_globalCursor ) | |
316 | (*g_globalCursor) = cursor; | |
317 | } | |
318 | } |