Removed redundant cursor files
[wxWidgets.git] / src / os2 / cursor.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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/setup.h"
18 #include "wx/list.h"
19 #include "wx/utils.h"
20 #include "wx/app.h"
21 #include "wx/cursor.h"
22 #include "wx/icon.h"
23 #endif
24
25 #include "wx/os2/private.h"
26 #include "wx/os2/wxrsc.h"
27 #include "wx/image.h"
28
29 #include "assert.h"
30
31 IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
32
33 wxCursorRefData::wxCursorRefData(void)
34 {
35 m_nWidth = 32;
36 m_nHeight = 32;
37 m_hCursor = 0 ;
38 m_bDestroyCursor = FALSE;
39 }
40
41 void wxCursorRefData::Free()
42 {
43 if (m_hCursor)
44 {
45 if (m_bDestroyCursor)
46 ::WinDestroyPointer((HPOINTER)m_hCursor);
47 m_hCursor = 0;
48 }
49 } // end of wxCursorRefData::Free
50
51 // Cursors
52 wxCursor::wxCursor(void)
53 {
54 }
55
56 wxCursor::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 )
64 {
65 }
66
67 wxCursor::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
100 wxCursor::wxCursor(
101 const wxString& rsCursorFile
102 , long lFlags
103 , int nHotSpotX
104 , int nHotSpotY
105 )
106 {
107 wxCursorRefData* pRefData = new wxCursorRefData;
108
109 pRefData = new wxCursorRefData;
110 m_refData = pRefData;
111 pRefData->m_bDestroyCursor = FALSE;
112 if (lFlags == wxBITMAP_TYPE_CUR_RESOURCE)
113 {
114 pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP
115 ,0
116 ,(ULONG)lFlags // if OS/2 this should be the resource Id
117 );
118 }
119 } // end of wxCursor::wxCursor
120
121 // Cursors by stock number
122 wxCursor::wxCursor(
123 int nCursorType
124 )
125 {
126 wxCursorRefData* pRefData = new wxCursorRefData;
127
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;
137
138 case wxCURSOR_WATCH:
139 case wxCURSOR_WAIT:
140 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
141 ,(ULONG)SPTR_WAIT
142 ,FALSE
143 );
144 break;
145
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:
224 pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP
225 ,(ULONG)SPTR_ILLEGAL
226 ,FALSE
227 );
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
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 }
308 //
309 // No need to destroy the stock cursors
310 //
311 ((wxCursorRefData *)m_refData)->m_bDestroyCursor = FALSE;
312 } // end of wxCursor::wxCursor
313
314 // Global cursor setting
315 void wxSetCursor(const wxCursor& cursor)
316 {
317 extern wxCursor *g_globalCursor;
318
319 if ( cursor.Ok() && cursor.GetHCURSOR() )
320 {
321 // ::SetCursor((HCURSOR) cursor.GetHCURSOR());
322
323 if ( g_globalCursor )
324 (*g_globalCursor) = cursor;
325 }
326 }
327