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 #if !USE_SHARED_LIBRARIES
53 IMPLEMENT_DYNAMIC_CLASS(wxCursor
, wxCursorBase
)
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 wxCursorRefData::wxCursorRefData()
65 m_destroyCursor
= FALSE
;
68 void wxCursorRefData::Free()
72 if ( m_destroyCursor
)
73 ::DestroyCursor((HCURSOR
)m_hCursor
);
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
87 wxCursor::wxCursor(const char WXUNUSED(bits
)[],
90 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
),
91 const char WXUNUSED(maskBits
)[])
95 wxCursor::wxCursor(const wxString
& cursor_file
,
97 int hotSpotX
, int hotSpotY
)
99 wxCursorRefData
*refData
= new wxCursorRefData
;
102 refData
->m_destroyCursor
= FALSE
;
104 if (flags
== wxBITMAP_TYPE_CUR_RESOURCE
)
107 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, 0);
109 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), cursor_file
);
112 else if (flags
== wxBITMAP_TYPE_CUR
)
115 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, LR_LOADFROMFILE
);
117 #if wxUSE_RESOURCE_LOADING_IN_MSW
118 refData
->m_hCursor
= (WXHCURSOR
) ReadCursorFile(WXSTRINGCAST cursor_file
, wxGetInstance(), &refData
->m_width
, &refData
->m_height
);
119 refData
->m_destroyCursor
= TRUE
;
123 else if (flags
== wxBITMAP_TYPE_ICO
)
125 #if wxUSE_RESOURCE_LOADING_IN_MSW
126 refData
->m_hCursor
= (WXHCURSOR
) IconToCursor(WXSTRINGCAST cursor_file
, wxGetInstance(), hotSpotX
, hotSpotY
, &refData
->m_width
, &refData
->m_height
);
127 refData
->m_destroyCursor
= TRUE
;
130 else if (flags
== wxBITMAP_TYPE_BMP
)
132 #if wxUSE_RESOURCE_LOADING_IN_MSW
134 HPALETTE hPalette
= 0;
135 bool success
= wxReadDIB(WXSTRINGCAST cursor_file
, &hBitmap
, &hPalette
) != 0;
139 DeleteObject(hPalette
);
143 refData
->m_hCursor
= (WXHCURSOR
) MakeCursorFromBitmap(wxGetInstance(), hBitmap
, &pnt
);
144 refData
->m_destroyCursor
= TRUE
;
145 DeleteObject(hBitmap
);
149 #if WXWIN_COMPATIBILITY_2
151 #endif // WXWIN_COMPATIBILITY_2
154 // Cursors by stock number
155 wxCursor::wxCursor(int cursor_type
)
157 wxCursorRefData
*refData
= new wxCursorRefData
;
163 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_WAIT
);
166 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_IBEAM
);
169 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_CROSS
);
171 case wxCURSOR_SIZENWSE
:
172 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENWSE
);
174 case wxCURSOR_SIZENESW
:
175 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENESW
);
177 case wxCURSOR_SIZEWE
:
178 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZEWE
);
180 case wxCURSOR_SIZENS
:
181 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENS
);
185 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
190 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
193 case wxCURSOR_BULLSEYE
:
195 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
198 case wxCURSOR_PENCIL
:
200 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
203 case wxCURSOR_MAGNIFIER
:
205 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
208 case wxCURSOR_NO_ENTRY
:
210 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
213 case wxCURSOR_LEFT_BUTTON
:
215 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
218 case wxCURSOR_RIGHT_BUTTON
:
220 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
223 case wxCURSOR_MIDDLE_BUTTON
:
225 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
228 case wxCURSOR_SIZING
:
230 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
235 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
238 case wxCURSOR_SPRAYCAN
:
240 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
243 case wxCURSOR_PAINT_BRUSH
:
245 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
248 case wxCURSOR_POINT_LEFT
:
250 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
253 case wxCURSOR_POINT_RIGHT
:
255 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
258 case wxCURSOR_QUESTION_ARROW
:
260 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
265 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
270 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
275 wxCursor::~wxCursor()
279 // ----------------------------------------------------------------------------
280 // Global cursor setting
281 // ----------------------------------------------------------------------------
283 void wxSetCursor(const wxCursor
& cursor
)
285 extern wxCursor
*g_globalCursor
;
287 if ( cursor
.Ok() && cursor
.GetHCURSOR() )
289 ::SetCursor((HCURSOR
) cursor
.GetHCURSOR());
291 if ( g_globalCursor
)
292 (*g_globalCursor
) = cursor
;