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"
27 #include "wx/os2/private.h"
28 #include "wx/os2/wxrsc.h"
32 IMPLEMENT_DYNAMIC_CLASS(wxCursor
, wxBitmap
)
34 wxCursorRefData::wxCursorRefData(void)
39 m_bDestroyCursor
= false;
42 void wxCursorRefData::Free()
47 ::WinDestroyPointer((HPOINTER
)m_hCursor
);
50 } // end of wxCursorRefData::Free
53 wxCursor::wxCursor(void)
57 wxCursor::wxCursor(const wxImage
& rImage
)
59 wxImage vImage32
= rImage
.Scale(32,32);
60 int nWidth
= vImage32
.GetWidth();
61 int nHeight
= vImage32
.GetHeight();
64 // Need a bitmap handle somehow
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
);
70 if (nHotSpotX
< 0 || nHotSpotX
>= nWidth
)
72 if (nHotSpotY
< 0 || nHotSpotY
>= nHeight
)
76 wxCursorRefData
* pRefData
= new wxCursorRefData
;
79 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinCreatePointer( HWND_DESKTOP
86 } // end of wxCursor::wxCursor
88 wxCursor::wxCursor( const wxString
& WXUNUSED(rsCursorFile
),
90 int WXUNUSED(nHotSpotX
),
91 int WXUNUSED(nHotSpotY
) )
93 wxCursorRefData
* pRefData
= new wxCursorRefData
;
95 pRefData
= new wxCursorRefData
;
97 pRefData
->m_bDestroyCursor
= false;
98 if (type
== wxBITMAP_TYPE_CUR_RESOURCE
)
100 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
102 ,(ULONG
)type
// if OS/2 this should be the resource Id
106 wxLogError("Invalid cursor bitmap type '%d'", type
);
107 } // end of wxCursor::wxCursor
109 // Cursors by stock number
110 void wxCursor::InitFromStock(wxStockCursor nCursorType
)
112 wxCursorRefData
* pRefData
= new wxCursorRefData
;
114 m_refData
= pRefData
;
117 case wxCURSOR_ARROWWAIT
:
118 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
126 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
133 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
140 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
146 case wxCURSOR_SIZENWSE
:
147 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
148 ,(ULONG
)SPTR_SIZENWSE
153 case wxCURSOR_SIZENESW
:
154 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
155 ,(ULONG
)SPTR_SIZENESW
160 case wxCURSOR_SIZEWE
:
161 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
167 case wxCURSOR_SIZENS
:
168 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
175 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
182 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
184 ,(ULONG
)wxCURSOR_HAND
188 case wxCURSOR_BULLSEYE
:
189 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
191 ,(ULONG
)wxCURSOR_BULLSEYE
195 case wxCURSOR_PENCIL
:
196 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
198 ,(ULONG
)wxCURSOR_PENCIL
202 case wxCURSOR_MAGNIFIER
:
203 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
205 ,(ULONG
)wxCURSOR_MAGNIFIER
209 case wxCURSOR_NO_ENTRY
:
210 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
216 case wxCURSOR_LEFT_BUTTON
:
217 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
223 case wxCURSOR_RIGHT_BUTTON
:
224 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
230 case wxCURSOR_MIDDLE_BUTTON
:
231 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
237 case wxCURSOR_SIZING
:
238 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
244 case wxCURSOR_SPRAYCAN
:
245 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
247 ,(ULONG
)WXCURSOR_ROLLER
251 case wxCURSOR_PAINT_BRUSH
:
252 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
254 ,(ULONG
)WXCURSOR_PBRUSH
258 case wxCURSOR_POINT_LEFT
:
259 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
261 ,(ULONG
)WXCURSOR_PLEFT
265 case wxCURSOR_POINT_RIGHT
:
266 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
268 ,(ULONG
)WXCURSOR_PRIGHT
272 case wxCURSOR_QUESTION_ARROW
:
273 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
275 ,(ULONG
)WXCURSOR_QARROW
280 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinLoadPointer( HWND_DESKTOP
282 ,(ULONG
)WXCURSOR_BLANK
288 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinQuerySysPointer( HWND_DESKTOP
295 // No need to destroy the stock cursors
297 ((wxCursorRefData
*)m_refData
)->m_bDestroyCursor
= false;
298 } // end of wxCursor::wxCursor
300 // Global cursor setting
301 void wxSetCursor(const wxCursor
& cursor
)
303 extern wxCursor
*g_globalCursor
;
305 if ( cursor
.Ok() && cursor
.GetHCURSOR() )
307 // ::SetCursor((HCURSOR) cursor.GetHCURSOR());
309 if ( g_globalCursor
)
310 (*g_globalCursor
) = cursor
;