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