]> git.saurik.com Git - wxWidgets.git/blob - src/os2/cursor.cpp
made SetFirstItem() work again (patch 1445170)
[wxWidgets.git] / src / os2 / cursor.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/cursor.cpp
3 // Purpose: wxCursor class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include <stdio.h>
17 #include "wx/list.h"
18 #include "wx/utils.h"
19 #include "wx/app.h"
20 #include "wx/cursor.h"
21 #include "wx/icon.h"
22 #endif
23
24 #include "wx/os2/private.h"
25 #include "wx/os2/wxrsc.h"
26 #include "wx/image.h"
27
28 #include "assert.h"
29
30 IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
31
32 wxCursorRefData::wxCursorRefData(void)
33 {
34 m_nWidth = 32;
35 m_nHeight = 32;
36 m_hCursor = 0 ;
37 m_bDestroyCursor = false;
38 }
39
40 void wxCursorRefData::Free()
41 {
42 if (m_hCursor)
43 {
44 if (m_bDestroyCursor)
45 ::WinDestroyPointer((HPOINTER)m_hCursor);
46 m_hCursor = 0;
47 }
48 } // end of wxCursorRefData::Free
49
50 // Cursors
51 wxCursor::wxCursor(void)
52 {
53 }
54
55 wxCursor::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)[])
61 {
62 }
63
64 wxCursor::wxCursor(const wxImage& rImage)
65 {
66 wxImage vImage32 = rImage.Scale(32,32);
67 int nWidth = vImage32.GetWidth();
68 int nHeight = vImage32.GetHeight();
69
70 //
71 // Need a bitmap handle somehow
72 //
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);
76
77 if (nHotSpotX < 0 || nHotSpotX >= nWidth)
78 nHotSpotX = 0;
79 if (nHotSpotY < 0 || nHotSpotY >= nHeight)
80 nHotSpotY = 0;
81
82
83 wxCursorRefData* pRefData = new wxCursorRefData;
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
95 wxCursor::wxCursor( const wxString& WXUNUSED(rsCursorFile),
96 long lFlags,
97 int WXUNUSED(nHotSpotX),
98 int WXUNUSED(nHotSpotY) )
99 {
100 wxCursorRefData* pRefData = new wxCursorRefData;
101
102 pRefData = new wxCursorRefData;
103 m_refData = pRefData;
104 pRefData->m_bDestroyCursor = false;
105 if (lFlags == wxBITMAP_TYPE_CUR_RESOURCE)
106 {
107 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
108 ,0
109 ,(ULONG)lFlags // if OS/2 this should be the resource Id
110 );
111 }
112 } // end of wxCursor::wxCursor
113
114 // Cursors by stock number
115 wxCursor::wxCursor(int nCursorType)
116 {
117 wxCursorRefData* pRefData = new wxCursorRefData;
118
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;
128
129 case wxCURSOR_WATCH:
130 case wxCURSOR_WAIT:
131 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
132 ,(ULONG)SPTR_WAIT
133 ,FALSE
134 );
135 break;
136
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:
215 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
216 ,(ULONG)SPTR_ILLEGAL
217 ,FALSE
218 );
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
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 }
299 //
300 // No need to destroy the stock cursors
301 //
302 ((wxCursorRefData *)m_refData)->m_bDestroyCursor = false;
303 } // end of wxCursor::wxCursor
304
305 // Global cursor setting
306 void wxSetCursor(const wxCursor& cursor)
307 {
308 extern wxCursor *g_globalCursor;
309
310 if ( cursor.Ok() && cursor.GetHCURSOR() )
311 {
312 // ::SetCursor((HCURSOR) cursor.GetHCURSOR());
313
314 if ( g_globalCursor )
315 (*g_globalCursor) = cursor;
316 }
317 }