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/module.h"
41 #include "wx/msw/private.h"
42 #ifndef __WXMICROWIN__
43 #include "wx/msw/dib.h"
46 #if wxUSE_RESOURCE_LOADING_IN_MSW
47 #include "wx/msw/curico.h"
48 #include "wx/msw/curicop.h"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 IMPLEMENT_DYNAMIC_CLASS(wxCursor
, wxCursorBase
)
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // Current cursor, in order to hang on to cursor handle when setting the cursor
63 static wxCursor
*gs_globalCursor
= NULL
;
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 class wxCursorModule
: public wxModule
74 gs_globalCursor
= new wxCursor
;
81 delete gs_globalCursor
;
82 gs_globalCursor
= (wxCursor
*)NULL
;
86 // ============================================================================
88 // ============================================================================
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 wxCursorRefData::wxCursorRefData()
99 m_destroyCursor
= FALSE
;
102 void wxCursorRefData::Free()
106 #ifndef __WXMICROWIN__
107 if ( m_destroyCursor
)
108 ::DestroyCursor((HCURSOR
)m_hCursor
);
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
123 wxCursor::wxCursor(const char WXUNUSED(bits
)[],
125 int WXUNUSED(height
),
126 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
),
127 const char WXUNUSED(maskBits
)[])
131 wxCursor::wxCursor(const wxString
& cursor_file
,
133 int hotSpotX
, int hotSpotY
)
135 #ifdef __WXMICROWIN__
138 wxCursorRefData
*refData
= new wxCursorRefData
;
141 refData
->m_destroyCursor
= FALSE
;
143 if (flags
== wxBITMAP_TYPE_CUR_RESOURCE
)
146 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, 0);
148 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), cursor_file
);
151 else if (flags
== wxBITMAP_TYPE_CUR
)
154 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, LR_LOADFROMFILE
);
156 #if wxUSE_RESOURCE_LOADING_IN_MSW
157 refData
->m_hCursor
= (WXHCURSOR
) ReadCursorFile(WXSTRINGCAST cursor_file
, wxGetInstance(), &refData
->m_width
, &refData
->m_height
);
158 refData
->m_destroyCursor
= TRUE
;
162 else if (flags
== wxBITMAP_TYPE_ICO
)
164 #if wxUSE_RESOURCE_LOADING_IN_MSW
165 refData
->m_hCursor
= (WXHCURSOR
) IconToCursor(WXSTRINGCAST cursor_file
, wxGetInstance(), hotSpotX
, hotSpotY
, &refData
->m_width
, &refData
->m_height
);
166 refData
->m_destroyCursor
= TRUE
;
169 else if (flags
== wxBITMAP_TYPE_BMP
)
171 #if wxUSE_RESOURCE_LOADING_IN_MSW
173 HPALETTE hPalette
= 0;
174 bool success
= wxReadDIB(WXSTRINGCAST cursor_file
, &hBitmap
, &hPalette
) != 0;
178 DeleteObject(hPalette
);
182 refData
->m_hCursor
= (WXHCURSOR
) MakeCursorFromBitmap(wxGetInstance(), hBitmap
, &pnt
);
183 refData
->m_destroyCursor
= TRUE
;
184 DeleteObject(hBitmap
);
188 #if WXWIN_COMPATIBILITY_2
190 #endif // WXWIN_COMPATIBILITY_2
195 // Cursors by stock number
196 wxCursor::wxCursor(int cursor_type
)
198 #ifdef __WXMICROWIN__
201 wxCursorRefData
*refData
= new wxCursorRefData
;
206 case wxCURSOR_ARROWWAIT
:
208 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_APPSTARTING
);
212 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_WAIT
);
215 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_IBEAM
);
218 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_CROSS
);
220 case wxCURSOR_SIZENWSE
:
221 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENWSE
);
223 case wxCURSOR_SIZENESW
:
224 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENESW
);
226 case wxCURSOR_SIZEWE
:
227 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZEWE
);
229 case wxCURSOR_SIZENS
:
230 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENS
);
234 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
239 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
242 case wxCURSOR_BULLSEYE
:
244 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
247 case wxCURSOR_PENCIL
:
249 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
252 case wxCURSOR_MAGNIFIER
:
254 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
257 case wxCURSOR_NO_ENTRY
:
259 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
262 case wxCURSOR_LEFT_BUTTON
:
264 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
267 case wxCURSOR_RIGHT_BUTTON
:
269 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
272 case wxCURSOR_MIDDLE_BUTTON
:
274 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
277 case wxCURSOR_SIZING
:
279 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
284 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
287 case wxCURSOR_SPRAYCAN
:
289 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
292 case wxCURSOR_PAINT_BRUSH
:
294 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
297 case wxCURSOR_POINT_LEFT
:
299 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
302 case wxCURSOR_POINT_RIGHT
:
304 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
307 case wxCURSOR_QUESTION_ARROW
:
309 // refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), wxT("wxCURSOR_QARROW"), IMAGE_CURSOR, 16, 16, LR_MONOCHROME);
310 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
315 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
320 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
326 wxCursor::~wxCursor()
330 // ----------------------------------------------------------------------------
331 // Global cursor setting
332 // ----------------------------------------------------------------------------
334 const wxCursor
*wxGetGlobalCursor()
336 return gs_globalCursor
;
339 void wxSetCursor(const wxCursor
& cursor
)
343 #ifndef __WXMICROWIN__
344 ::SetCursor(GetHcursorOf(cursor
));
347 if ( gs_globalCursor
)
348 *gs_globalCursor
= cursor
;