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