]> git.saurik.com Git - wxWidgets.git/blob - src/os2/cursor.cpp
fix showing keyboard cues under Win2k/XP
[wxWidgets.git] / src / os2 / cursor.cpp
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(
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( const wxString& WXUNUSED(rsCursorFile),
101 long lFlags,
102 int WXUNUSED(nHotSpotX),
103 int WXUNUSED(nHotSpotY) )
104 {
105 wxCursorRefData* pRefData = new wxCursorRefData;
106
107 pRefData = new wxCursorRefData;
108 m_refData = pRefData;
109 pRefData->m_bDestroyCursor = FALSE;
110 if (lFlags == wxBITMAP_TYPE_CUR_RESOURCE)
111 {
112 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
113 ,0
114 ,(ULONG)lFlags // if OS/2 this should be the resource Id
115 );
116 }
117 } // end of wxCursor::wxCursor
118
119 // Cursors by stock number
120 wxCursor::wxCursor(
121 int nCursorType
122 )
123 {
124 wxCursorRefData* pRefData = new wxCursorRefData;
125
126 m_refData = pRefData;
127 switch (nCursorType)
128 {
129 case wxCURSOR_ARROWWAIT:
130 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
131 ,(ULONG)SPTR_WAIT
132 ,FALSE
133 );
134 break;
135
136 case wxCURSOR_WATCH:
137 case wxCURSOR_WAIT:
138 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
139 ,(ULONG)SPTR_WAIT
140 ,FALSE
141 );
142 break;
143
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) ::WinQuerySysPointer( HWND_DESKTOP
223 ,(ULONG)SPTR_ILLEGAL
224 ,FALSE
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_SPRAYCAN:
257 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
258 ,0
259 ,(ULONG)WXCURSOR_ROLLER
260 );
261 break;
262
263 case wxCURSOR_PAINT_BRUSH:
264 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
265 ,0
266 ,(ULONG)WXCURSOR_PBRUSH
267 );
268 break;
269
270 case wxCURSOR_POINT_LEFT:
271 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
272 ,0
273 ,(ULONG)WXCURSOR_PLEFT
274 );
275 break;
276
277 case wxCURSOR_POINT_RIGHT:
278 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
279 ,0
280 ,(ULONG)WXCURSOR_PRIGHT
281 );
282 break;
283
284 case wxCURSOR_QUESTION_ARROW:
285 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
286 ,0
287 ,(ULONG)WXCURSOR_QARROW
288 );
289 break;
290
291 case wxCURSOR_BLANK:
292 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
293 ,0
294 ,(ULONG)WXCURSOR_BLANK
295 );
296 break;
297
298 default:
299 case wxCURSOR_ARROW:
300 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
301 ,(ULONG)SPTR_ARROW
302 ,FALSE
303 );
304 break;
305 }
306 //
307 // No need to destroy the stock cursors
308 //
309 ((wxCursorRefData *)m_refData)->m_bDestroyCursor = FALSE;
310 } // end of wxCursor::wxCursor
311
312 // Global cursor setting
313 void wxSetCursor(const wxCursor& cursor)
314 {
315 extern wxCursor *g_globalCursor;
316
317 if ( cursor.Ok() && cursor.GetHCURSOR() )
318 {
319 // ::SetCursor((HCURSOR) cursor.GetHCURSOR());
320
321 if ( g_globalCursor )
322 (*g_globalCursor) = cursor;
323 }
324 }