1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCursor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "cursor.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/cursor.h"
39 #include "wx/msw/private.h"
40 #include "wx/msw/dib.h"
42 #if wxUSE_RESOURCE_LOADING_IN_MSW
43 #include "wx/msw/curico.h"
44 #include "wx/msw/curicop.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 #if !USE_SHARED_LIBRARIES
52 IMPLEMENT_DYNAMIC_CLASS(wxCursor
, wxCursorBase
)
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 wxCursorRefData::wxCursorRefData()
64 m_destroyCursor
= FALSE
;
67 void wxCursorRefData::Free()
69 if ( m_hCursor
&& m_destroyCursor
)
70 ::DestroyCursor((HCURSOR
)m_hCursor
);
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
81 wxCursor::wxCursor(const char WXUNUSED(bits
)[],
84 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
),
85 const char WXUNUSED(maskBits
)[])
89 wxCursor::wxCursor(const wxString
& cursor_file
,
91 int hotSpotX
, int hotSpotY
)
93 wxCursorRefData
*refData
= new wxCursorRefData
;
96 refData
->m_destroyCursor
= FALSE
;
98 if (flags
== wxBITMAP_TYPE_CUR_RESOURCE
)
101 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, 0);
103 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), cursor_file
);
106 else if (flags
== wxBITMAP_TYPE_CUR
)
109 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, LR_LOADFROMFILE
);
111 #if wxUSE_RESOURCE_LOADING_IN_MSW
112 refData
->m_hCursor
= (WXHCURSOR
) ReadCursorFile(WXSTRINGCAST cursor_file
, wxGetInstance(), &refData
->m_width
, &refData
->m_height
);
113 refData
->m_destroyCursor
= TRUE
;
117 else if (flags
== wxBITMAP_TYPE_ICO
)
119 #if wxUSE_RESOURCE_LOADING_IN_MSW
120 refData
->m_hCursor
= (WXHCURSOR
) IconToCursor(WXSTRINGCAST cursor_file
, wxGetInstance(), hotSpotX
, hotSpotY
, &refData
->m_width
, &refData
->m_height
);
121 refData
->m_destroyCursor
= TRUE
;
124 else if (flags
== wxBITMAP_TYPE_BMP
)
126 #if wxUSE_RESOURCE_LOADING_IN_MSW
128 HPALETTE hPalette
= 0;
129 bool success
= wxReadDIB(WXSTRINGCAST cursor_file
, &hBitmap
, &hPalette
) != 0;
133 DeleteObject(hPalette
);
137 refData
->m_hCursor
= (WXHCURSOR
) MakeCursorFromBitmap(wxGetInstance(), hBitmap
, &pnt
);
138 refData
->m_destroyCursor
= TRUE
;
139 DeleteObject(hBitmap
);
143 #if WXWIN_COMPATIBILITY_2
145 #endif // WXWIN_COMPATIBILITY_2
148 // Cursors by stock number
149 wxCursor::wxCursor(int cursor_type
)
151 wxCursorRefData
*refData
= new wxCursorRefData
;
157 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_WAIT
);
160 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_IBEAM
);
163 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_CROSS
);
165 case wxCURSOR_SIZENWSE
:
166 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENWSE
);
168 case wxCURSOR_SIZENESW
:
169 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENESW
);
171 case wxCURSOR_SIZEWE
:
172 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZEWE
);
174 case wxCURSOR_SIZENS
:
175 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENS
);
179 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
184 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
187 case wxCURSOR_BULLSEYE
:
189 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
192 case wxCURSOR_PENCIL
:
194 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
197 case wxCURSOR_MAGNIFIER
:
199 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
202 case wxCURSOR_NO_ENTRY
:
204 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
207 case wxCURSOR_LEFT_BUTTON
:
209 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
212 case wxCURSOR_RIGHT_BUTTON
:
214 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
217 case wxCURSOR_MIDDLE_BUTTON
:
219 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
222 case wxCURSOR_SIZING
:
224 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
229 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
232 case wxCURSOR_SPRAYCAN
:
234 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
237 case wxCURSOR_PAINT_BRUSH
:
239 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
242 case wxCURSOR_POINT_LEFT
:
244 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
247 case wxCURSOR_POINT_RIGHT
:
249 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
252 case wxCURSOR_QUESTION_ARROW
:
254 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
259 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
264 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
269 wxCursor::~wxCursor()
273 // ----------------------------------------------------------------------------
274 // Global cursor setting
275 // ----------------------------------------------------------------------------
277 void wxSetCursor(const wxCursor
& cursor
)
279 extern wxCursor
*g_globalCursor
;
281 if ( cursor
.Ok() && cursor
.GetHCURSOR() )
283 ::SetCursor((HCURSOR
) cursor
.GetHCURSOR());
285 if ( g_globalCursor
)
286 (*g_globalCursor
) = cursor
;