]> git.saurik.com Git - wxWidgets.git/blame - src/os2/cursor.cpp
[wxGTK] Remove wxTLW::RequestUserAttention related backwards compatibility hacks
[wxWidgets.git] / src / os2 / cursor.cpp
CommitLineData
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 8// Copyright: (c) David Webster
65571936 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"
28410cdc 26#include "wx/os2/wxrsc.h"
b9b1d6c8 27#include "wx/image.h"
37f214d5
DW
28
29#include "assert.h"
0e320a79 30
0e320a79 31IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
0e320a79 32
37f214d5 33wxCursorRefData::wxCursorRefData(void)
0e320a79 34{
43543d98
DW
35 m_nWidth = 32;
36 m_nHeight = 32;
37f214d5 37 m_hCursor = 0 ;
b389a12d 38 m_bDestroyCursor = FALSE;
0e320a79
DW
39}
40
b389a12d 41void wxCursorRefData::Free()
0e320a79 42{
b389a12d
DW
43 if (m_hCursor)
44 {
45 if (m_bDestroyCursor)
46 ::WinDestroyPointer((HPOINTER)m_hCursor);
47 m_hCursor = 0;
48 }
49} // end of wxCursorRefData::Free
0e320a79
DW
50
51// Cursors
37f214d5 52wxCursor::wxCursor(void)
0e320a79
DW
53{
54}
55
b389a12d
DW
56wxCursor::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)
0e320a79
DW
64{
65}
66
b9b1d6c8
DW
67wxCursor::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
6670f564
WS
100wxCursor::wxCursor( const wxString& WXUNUSED(rsCursorFile),
101 long lFlags,
102 int WXUNUSED(nHotSpotX),
103 int WXUNUSED(nHotSpotY) )
0e320a79 104{
6670f564 105 wxCursorRefData* pRefData = new wxCursorRefData;
0e320a79 106
b389a12d
DW
107 pRefData = new wxCursorRefData;
108 m_refData = pRefData;
109 pRefData->m_bDestroyCursor = FALSE;
110 if (lFlags == wxBITMAP_TYPE_CUR_RESOURCE)
0e320a79 111 {
b389a12d
DW
112 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
113 ,0
114 ,(ULONG)lFlags // if OS/2 this should be the resource Id
115 );
0e320a79 116 }
b389a12d 117} // end of wxCursor::wxCursor
0e320a79 118
b389a12d
DW
119// Cursors by stock number
120wxCursor::wxCursor(
121 int nCursorType
122)
37f214d5 123{
b389a12d 124 wxCursorRefData* pRefData = new wxCursorRefData;
0e320a79 125
b389a12d
DW
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;
37f214d5 135
3c203a18 136 case wxCURSOR_WATCH:
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:
3c203a18
JS
222 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
223 ,(ULONG)SPTR_ILLEGAL
224 ,FALSE
225 );
b389a12d
DW
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
b389a12d
DW
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 }
6e348b12
DW
306 //
307 // No need to destroy the stock cursors
308 //
309 ((wxCursorRefData *)m_refData)->m_bDestroyCursor = FALSE;
b389a12d 310} // end of wxCursor::wxCursor
0e320a79
DW
311
312// Global cursor setting
313void wxSetCursor(const wxCursor& cursor)
314{
37f214d5 315 extern wxCursor *g_globalCursor;
0e320a79 316
37f214d5
DW
317 if ( cursor.Ok() && cursor.GetHCURSOR() )
318 {
319// ::SetCursor((HCURSOR) cursor.GetHCURSOR());
320
321 if ( g_globalCursor )
322 (*g_globalCursor) = cursor;
323 }
324}