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/bitmap.h"
37 #include "wx/cursor.h"
40 #include "wx/msw/private.h"
41 #include "wx/msw/dib.h"
43 #if wxUSE_RESOURCE_LOADING_IN_MSW
44 #include "wx/msw/curico.h"
45 #include "wx/msw/curicop.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxCursor
, wxCursorBase
)
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 wxCursorRefData::wxCursorRefData()
63 m_destroyCursor
= FALSE
;
66 void wxCursorRefData::Free()
70 if ( m_destroyCursor
)
71 ::DestroyCursor((HCURSOR
)m_hCursor
);
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
85 wxCursor::wxCursor(const char WXUNUSED(bits
)[],
88 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
),
89 const char WXUNUSED(maskBits
)[])
93 wxCursor::wxCursor(const wxString
& cursor_file
,
95 int hotSpotX
, int hotSpotY
)
97 wxCursorRefData
*refData
= new wxCursorRefData
;
100 refData
->m_destroyCursor
= FALSE
;
102 if (flags
== wxBITMAP_TYPE_CUR_RESOURCE
)
105 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, 0);
107 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), cursor_file
);
110 else if (flags
== wxBITMAP_TYPE_CUR
)
113 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, LR_LOADFROMFILE
);
115 #if wxUSE_RESOURCE_LOADING_IN_MSW
116 refData
->m_hCursor
= (WXHCURSOR
) ReadCursorFile(WXSTRINGCAST cursor_file
, wxGetInstance(), &refData
->m_width
, &refData
->m_height
);
117 refData
->m_destroyCursor
= TRUE
;
121 else if (flags
== wxBITMAP_TYPE_ICO
)
123 #if wxUSE_RESOURCE_LOADING_IN_MSW
124 refData
->m_hCursor
= (WXHCURSOR
) IconToCursor(WXSTRINGCAST cursor_file
, wxGetInstance(), hotSpotX
, hotSpotY
, &refData
->m_width
, &refData
->m_height
);
125 refData
->m_destroyCursor
= TRUE
;
128 else if (flags
== wxBITMAP_TYPE_BMP
)
130 #if wxUSE_RESOURCE_LOADING_IN_MSW
132 HPALETTE hPalette
= 0;
133 bool success
= wxReadDIB(WXSTRINGCAST cursor_file
, &hBitmap
, &hPalette
) != 0;
137 DeleteObject(hPalette
);
141 refData
->m_hCursor
= (WXHCURSOR
) MakeCursorFromBitmap(wxGetInstance(), hBitmap
, &pnt
);
142 refData
->m_destroyCursor
= TRUE
;
143 DeleteObject(hBitmap
);
147 #if WXWIN_COMPATIBILITY_2
149 #endif // WXWIN_COMPATIBILITY_2
152 // Cursors by stock number
153 wxCursor::wxCursor(int cursor_type
)
155 wxCursorRefData
*refData
= new wxCursorRefData
;
161 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_WAIT
);
164 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_IBEAM
);
167 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_CROSS
);
169 case wxCURSOR_SIZENWSE
:
170 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENWSE
);
172 case wxCURSOR_SIZENESW
:
173 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENESW
);
175 case wxCURSOR_SIZEWE
:
176 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZEWE
);
178 case wxCURSOR_SIZENS
:
179 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENS
);
183 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
188 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
191 case wxCURSOR_BULLSEYE
:
193 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
196 case wxCURSOR_PENCIL
:
198 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
201 case wxCURSOR_MAGNIFIER
:
203 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
206 case wxCURSOR_NO_ENTRY
:
208 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
211 case wxCURSOR_LEFT_BUTTON
:
213 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
216 case wxCURSOR_RIGHT_BUTTON
:
218 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
221 case wxCURSOR_MIDDLE_BUTTON
:
223 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
226 case wxCURSOR_SIZING
:
228 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
233 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
236 case wxCURSOR_SPRAYCAN
:
238 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
241 case wxCURSOR_PAINT_BRUSH
:
243 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
246 case wxCURSOR_POINT_LEFT
:
248 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
251 case wxCURSOR_POINT_RIGHT
:
253 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
256 case wxCURSOR_QUESTION_ARROW
:
258 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
263 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
268 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
273 wxCursor::~wxCursor()
277 // ----------------------------------------------------------------------------
278 // Global cursor setting
279 // ----------------------------------------------------------------------------
281 void wxSetCursor(const wxCursor
& cursor
)
283 extern wxCursor
*g_globalCursor
;
285 if ( cursor
.Ok() && cursor
.GetHCURSOR() )
287 ::SetCursor((HCURSOR
) cursor
.GetHCURSOR());
289 if ( g_globalCursor
)
290 (*g_globalCursor
) = cursor
;