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()
70 if ( m_hCursor
&& m_destroyCursor
)
71 ::DestroyCursor((HCURSOR
)m_hCursor
);
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
82 wxCursor::wxCursor(const char WXUNUSED(bits
)[],
85 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
),
86 const char WXUNUSED(maskBits
)[])
90 wxCursor::wxCursor(const wxString
& cursor_file
,
92 int hotSpotX
, int hotSpotY
)
94 wxCursorRefData
*refData
= new wxCursorRefData
;
97 refData
->m_destroyCursor
= FALSE
;
99 if (flags
== wxBITMAP_TYPE_CUR_RESOURCE
)
102 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, 0);
104 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), cursor_file
);
107 else if (flags
== wxBITMAP_TYPE_CUR
)
110 refData
->m_hCursor
= (WXHCURSOR
) LoadImage(wxGetInstance(), cursor_file
, IMAGE_CURSOR
, 0, 0, LR_LOADFROMFILE
);
112 #if wxUSE_RESOURCE_LOADING_IN_MSW
113 refData
->m_hCursor
= (WXHCURSOR
) ReadCursorFile(WXSTRINGCAST cursor_file
, wxGetInstance(), &refData
->m_width
, &refData
->m_height
);
114 refData
->m_destroyCursor
= TRUE
;
118 else if (flags
== wxBITMAP_TYPE_ICO
)
120 #if wxUSE_RESOURCE_LOADING_IN_MSW
121 refData
->m_hCursor
= (WXHCURSOR
) IconToCursor(WXSTRINGCAST cursor_file
, wxGetInstance(), hotSpotX
, hotSpotY
, &refData
->m_width
, &refData
->m_height
);
122 refData
->m_destroyCursor
= TRUE
;
125 else if (flags
== wxBITMAP_TYPE_BMP
)
127 #if wxUSE_RESOURCE_LOADING_IN_MSW
129 HPALETTE hPalette
= 0;
130 bool success
= wxReadDIB(WXSTRINGCAST cursor_file
, &hBitmap
, &hPalette
) != 0;
134 DeleteObject(hPalette
);
138 refData
->m_hCursor
= (WXHCURSOR
) MakeCursorFromBitmap(wxGetInstance(), hBitmap
, &pnt
);
139 refData
->m_destroyCursor
= TRUE
;
140 DeleteObject(hBitmap
);
144 #if WXWIN_COMPATIBILITY_2
146 #endif // WXWIN_COMPATIBILITY_2
149 // Cursors by stock number
150 wxCursor::wxCursor(int cursor_type
)
152 wxCursorRefData
*refData
= new wxCursorRefData
;
158 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_WAIT
);
161 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_IBEAM
);
164 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_CROSS
);
166 case wxCURSOR_SIZENWSE
:
167 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENWSE
);
169 case wxCURSOR_SIZENESW
:
170 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENESW
);
172 case wxCURSOR_SIZEWE
:
173 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZEWE
);
175 case wxCURSOR_SIZENS
:
176 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_SIZENS
);
180 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
185 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
188 case wxCURSOR_BULLSEYE
:
190 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
193 case wxCURSOR_PENCIL
:
195 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
198 case wxCURSOR_MAGNIFIER
:
200 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
203 case wxCURSOR_NO_ENTRY
:
205 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
208 case wxCURSOR_LEFT_BUTTON
:
210 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
213 case wxCURSOR_RIGHT_BUTTON
:
215 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
218 case wxCURSOR_MIDDLE_BUTTON
:
220 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
223 case wxCURSOR_SIZING
:
225 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
230 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
233 case wxCURSOR_SPRAYCAN
:
235 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
238 case wxCURSOR_PAINT_BRUSH
:
240 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
243 case wxCURSOR_POINT_LEFT
:
245 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
248 case wxCURSOR_POINT_RIGHT
:
250 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
253 case wxCURSOR_QUESTION_ARROW
:
255 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
260 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
265 refData
->m_hCursor
= (WXHCURSOR
) LoadCursor((HINSTANCE
) NULL
, IDC_ARROW
);
270 wxCursor::~wxCursor()
274 // ----------------------------------------------------------------------------
275 // Global cursor setting
276 // ----------------------------------------------------------------------------
278 void wxSetCursor(const wxCursor
& cursor
)
280 extern wxCursor
*g_globalCursor
;
282 if ( cursor
.Ok() && cursor
.GetHCURSOR() )
284 ::SetCursor((HCURSOR
) cursor
.GetHCURSOR());
286 if ( g_globalCursor
)
287 (*g_globalCursor
) = cursor
;