1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/cursor.cpp
3 // Purpose: wxCursor class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/cursor.h"
26 #include "wx/os2/private.h"
27 #include "wx/os2/wxrsc.h"
31 IMPLEMENT_DYNAMIC_CLASS(wxCursor
, wxBitmap
)
33 wxCursorRefData::wxCursorRefData(void)
38 m_bDestroyCursor
= false;
41 void wxCursorRefData::Free()
46 ::WinDestroyPointer((HPOINTER
)m_hCursor
);
49 } // end of wxCursorRefData::Free
52 wxCursor::wxCursor(void)
56 wxCursor::wxCursor(const wxImage
& rImage
)
58 wxImage vImage32
= rImage
.Scale(32,32);
59 int nWidth
= vImage32
.GetWidth();
60 int nHeight
= vImage32
.GetHeight();
63 // Need a bitmap handle somehow
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
);
69 if (nHotSpotX
< 0 || nHotSpotX
>= nWidth
)
71 if (nHotSpotY
< 0 || nHotSpotY
>= nHeight
)
75 wxCursorRefData
* pRefData
= new wxCursorRefData
;
78 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinCreatePointer( HWND_DESKTOP
85 } // end of wxCursor::wxCursor
87 wxCursor::wxCursor( const wxString
& WXUNUSED(rsCursorFile
),
89 int WXUNUSED(nHotSpotX
),
90 int WXUNUSED(nHotSpotY
) )
92 wxCursorRefData
* pRefData
= new wxCursorRefData
;
94 pRefData
= new wxCursorRefData
;
96 pRefData
->m_bDestroyCursor
= false;
97 if (type
== wxBITMAP_TYPE_CUR_RESOURCE
)
99 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
101 ,(ULONG
)type
// if OS/2 this should be the resource Id
105 wxLogError("Invalid cursor bitmap type '%d'", type
);
106 } // end of wxCursor::wxCursor
108 // Cursors by stock number
109 void wxCursor::InitFromStock(wxStockCursor nCursorType
)
111 wxCursorRefData
* pRefData
= new wxCursorRefData
;
113 m_refData
= pRefData
;
116 case wxCURSOR_ARROWWAIT
:
117 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
125 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
132 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
139 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
145 case wxCURSOR_SIZENWSE
:
146 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
147 ,(ULONG
)SPTR_SIZENWSE
152 case wxCURSOR_SIZENESW
:
153 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
154 ,(ULONG
)SPTR_SIZENESW
159 case wxCURSOR_SIZEWE
:
160 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
166 case wxCURSOR_SIZENS
:
167 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
174 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
181 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
183 ,(ULONG
)wxCURSOR_HAND
187 case wxCURSOR_BULLSEYE
:
188 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
190 ,(ULONG
)wxCURSOR_BULLSEYE
194 case wxCURSOR_PENCIL
:
195 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
197 ,(ULONG
)wxCURSOR_PENCIL
201 case wxCURSOR_MAGNIFIER
:
202 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
204 ,(ULONG
)wxCURSOR_MAGNIFIER
208 case wxCURSOR_NO_ENTRY
:
209 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
215 case wxCURSOR_LEFT_BUTTON
:
216 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
222 case wxCURSOR_RIGHT_BUTTON
:
223 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
229 case wxCURSOR_MIDDLE_BUTTON
:
230 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
236 case wxCURSOR_SIZING
:
237 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
243 case wxCURSOR_SPRAYCAN
:
244 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
246 ,(ULONG
)WXCURSOR_ROLLER
250 case wxCURSOR_PAINT_BRUSH
:
251 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
253 ,(ULONG
)WXCURSOR_PBRUSH
257 case wxCURSOR_POINT_LEFT
:
258 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
260 ,(ULONG
)WXCURSOR_PLEFT
264 case wxCURSOR_POINT_RIGHT
:
265 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
267 ,(ULONG
)WXCURSOR_PRIGHT
271 case wxCURSOR_QUESTION_ARROW
:
272 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
274 ,(ULONG
)WXCURSOR_QARROW
279 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
281 ,(ULONG
)WXCURSOR_BLANK
287 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
294 // No need to destroy the stock cursors
296 ((wxCursorRefData
*)m_refData
)->m_bDestroyCursor
= false;
297 } // end of wxCursor::wxCursor
299 // Global cursor setting
300 void wxSetCursor(const wxCursor
& cursor
)
302 extern wxCursor
*g_globalCursor
;
304 if ( cursor
.Ok() && cursor
.GetHCURSOR() )
306 // ::SetCursor((HCURSOR) cursor.GetHCURSOR());
308 if ( g_globalCursor
)
309 (*g_globalCursor
) = cursor
;