]> git.saurik.com Git - wxWidgets.git/blame - src/os2/cursor.cpp
Clipboard usage fixes inspired by Tinderbox logs.
[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
b389a12d
DW
100wxCursor::wxCursor(
101 const wxString& rsCursorFile
102, long lFlags
103, int nHotSpotX
104, int nHotSpotY
105)
0e320a79 106{
b389a12d 107 wxCursorRefData* pRefData = new wxCursorRefData;
0e320a79 108
b389a12d
DW
109 pRefData = new wxCursorRefData;
110 m_refData = pRefData;
111 pRefData->m_bDestroyCursor = FALSE;
112 if (lFlags == wxBITMAP_TYPE_CUR_RESOURCE)
0e320a79 113 {
b389a12d
DW
114 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
115 ,0
116 ,(ULONG)lFlags // if OS/2 this should be the resource Id
117 );
0e320a79 118 }
b389a12d 119} // end of wxCursor::wxCursor
0e320a79 120
b389a12d
DW
121// Cursors by stock number
122wxCursor::wxCursor(
123 int nCursorType
124)
37f214d5 125{
b389a12d 126 wxCursorRefData* pRefData = new wxCursorRefData;
0e320a79 127
b389a12d
DW
128 m_refData = pRefData;
129 switch (nCursorType)
130 {
131 case wxCURSOR_ARROWWAIT:
132 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
133 ,(ULONG)SPTR_WAIT
134 ,FALSE
135 );
136 break;
37f214d5 137
3c203a18 138 case wxCURSOR_WATCH:
b389a12d
DW
139 case wxCURSOR_WAIT:
140 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
141 ,(ULONG)SPTR_WAIT
142 ,FALSE
143 );
144 break;
37f214d5 145
b389a12d
DW
146 case wxCURSOR_IBEAM:
147 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
148 ,(ULONG)SPTR_TEXT
149 ,FALSE
150 );
151 break;
152
153 case wxCURSOR_CROSS:
154 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
155 ,(ULONG)SPTR_MOVE
156 ,FALSE
157 );
158 break;
159
160 case wxCURSOR_SIZENWSE:
161 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
162 ,(ULONG)SPTR_SIZENWSE
163 ,FALSE
164 );
165 break;
166
167 case wxCURSOR_SIZENESW:
168 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
169 ,(ULONG)SPTR_SIZENESW
170 ,FALSE
171 );
172 break;
173
174 case wxCURSOR_SIZEWE:
175 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
176 ,(ULONG)SPTR_SIZEWE
177 ,FALSE
178 );
179 break;
180
181 case wxCURSOR_SIZENS:
182 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
183 ,(ULONG)SPTR_SIZENS
184 ,FALSE
185 );
186 break;
187
188 case wxCURSOR_CHAR:
189 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
190 ,(ULONG)SPTR_ARROW
191 ,FALSE
192 );
193 break;
194
195 case wxCURSOR_HAND:
196 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
197 ,0
198 ,(ULONG)wxCURSOR_HAND
199 );
200 break;
201
202 case wxCURSOR_BULLSEYE:
203 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
204 ,0
205 ,(ULONG)wxCURSOR_BULLSEYE
206 );
207 break;
208
209 case wxCURSOR_PENCIL:
210 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
211 ,0
212 ,(ULONG)wxCURSOR_PENCIL
213 );
214 break;
215
216 case wxCURSOR_MAGNIFIER:
217 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
218 ,0
219 ,(ULONG)wxCURSOR_MAGNIFIER
220 );
221 break;
222
223 case wxCURSOR_NO_ENTRY:
3c203a18
JS
224 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
225 ,(ULONG)SPTR_ILLEGAL
226 ,FALSE
227 );
b389a12d
DW
228 break;
229
230 case wxCURSOR_LEFT_BUTTON:
231 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
232 ,(ULONG)SPTR_ARROW
233 ,FALSE
234 );
235 break;
236
237 case wxCURSOR_RIGHT_BUTTON:
238 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
239 ,(ULONG)SPTR_ARROW
240 ,FALSE
241 );
242 break;
243
244 case wxCURSOR_MIDDLE_BUTTON:
245 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
246 ,(ULONG)SPTR_ARROW
247 ,FALSE
248 );
249 break;
250
251 case wxCURSOR_SIZING:
252 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
253 ,(ULONG)SPTR_SIZE
254 ,FALSE
255 );
256 break;
257
b389a12d
DW
258 case wxCURSOR_SPRAYCAN:
259 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
260 ,0
261 ,(ULONG)WXCURSOR_ROLLER
262 );
263 break;
264
265 case wxCURSOR_PAINT_BRUSH:
266 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
267 ,0
268 ,(ULONG)WXCURSOR_PBRUSH
269 );
270 break;
271
272 case wxCURSOR_POINT_LEFT:
273 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
274 ,0
275 ,(ULONG)WXCURSOR_PLEFT
276 );
277 break;
278
279 case wxCURSOR_POINT_RIGHT:
280 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
281 ,0
282 ,(ULONG)WXCURSOR_PRIGHT
283 );
284 break;
285
286 case wxCURSOR_QUESTION_ARROW:
287 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
288 ,0
289 ,(ULONG)WXCURSOR_QARROW
290 );
291 break;
292
293 case wxCURSOR_BLANK:
294 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
295 ,0
296 ,(ULONG)WXCURSOR_BLANK
297 );
298 break;
299
300 default:
301 case wxCURSOR_ARROW:
302 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
303 ,(ULONG)SPTR_ARROW
304 ,FALSE
305 );
306 break;
307 }
6e348b12
DW
308 //
309 // No need to destroy the stock cursors
310 //
311 ((wxCursorRefData *)m_refData)->m_bDestroyCursor = FALSE;
b389a12d 312} // end of wxCursor::wxCursor
0e320a79
DW
313
314// Global cursor setting
315void wxSetCursor(const wxCursor& cursor)
316{
37f214d5 317 extern wxCursor *g_globalCursor;
0e320a79 318
37f214d5
DW
319 if ( cursor.Ok() && cursor.GetHCURSOR() )
320 {
321// ::SetCursor((HCURSOR) cursor.GetHCURSOR());
322
323 if ( g_globalCursor )
324 (*g_globalCursor) = cursor;
325 }
326}
0e320a79 327