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