1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCursor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "cursor.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/cursor.h"
32 #include "wx/msw/private.h"
33 #include "wx/msw/dib.h"
39 #include "..\..\contrib\wxxpm\libxpm.34b\lib\xpm34.h"
42 #if USE_RESOURCE_LOADING_IN_MSW
43 #include "wx/msw/curico.h"
44 #include "wx/msw/curicop.h"
47 #if !USE_SHARED_LIBRARIES
48 IMPLEMENT_DYNAMIC_CLASS(wxCursor
, wxBitmap
)
51 wxCursorRefData::wxCursorRefData(void)
53 m_width
= 32; m_height
= 32;
55 m_destroyCursor
= FALSE
;
58 wxCursorRefData::~wxCursorRefData(void)
60 if ( m_hCursor
&& m_destroyCursor
)
61 ::DestroyCursor((HICON
) m_hCursor
);
65 wxCursor::wxCursor(void)
69 wxCursor::wxCursor(const char WXUNUSED(bits
)[], const int WXUNUSED(width
), const int WXUNUSED(height
),
70 const int WXUNUSED(hotSpotX
), const int WXUNUSED(hotSpotY
), const char WXUNUSED(maskBits
)[])
74 wxCursor::wxCursor(const wxString
& cursor_file
, const long flags
, const int hotSpotX
, const int hotSpotY
)
76 m_refData
= new wxIconRefData
;
78 M_CURSORDATA
->m_destroyCursor
= FALSE
;
79 M_CURSORDATA
->m_hCursor
= 0;
80 M_CURSORDATA
->m_ok
= FALSE
;
81 if (flags
& wxBITMAP_TYPE_CUR_RESOURCE
)
83 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), cursor_file
);
84 if (M_CURSORDATA
->m_hCursor
)
85 M_CURSORDATA
->m_ok
= TRUE
;
87 M_CURSORDATA
->m_ok
= FALSE
;
89 else if (flags
& wxBITMAP_TYPE_CUR
)
91 #if USE_RESOURCE_LOADING_IN_MSW
92 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) ReadCursorFile((char *)(const char *)cursor_file
, wxGetInstance(), &M_CURSORDATA
->m_width
, &M_CURSORDATA
->m_height
);
93 M_CURSORDATA
->m_destroyCursor
= TRUE
;
96 else if (flags
& wxBITMAP_TYPE_ICO
)
98 #if USE_RESOURCE_LOADING_IN_MSW
99 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) IconToCursor((char *)(const char *)cursor_file
, wxGetInstance(), hotSpotX
, hotSpotY
, &M_CURSORDATA
->m_width
, &M_CURSORDATA
->m_height
);
100 M_CURSORDATA
->m_destroyCursor
= TRUE
;
103 else if (flags
& wxBITMAP_TYPE_BMP
)
105 #if USE_RESOURCE_LOADING_IN_MSW
107 HPALETTE hPalette
= 0;
108 bool success
= ReadDIB((char *)(const char *)cursor_file
, &hBitmap
, &hPalette
);
112 DeleteObject(hPalette
);
116 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) MakeCursorFromBitmap(wxGetInstance(), hBitmap
, &pnt
);
117 M_CURSORDATA
->m_destroyCursor
= TRUE
;
118 DeleteObject(hBitmap
);
119 if (M_CURSORDATA
->m_hCursor
)
120 M_CURSORDATA
->m_ok
= TRUE
;
125 // Cursors by stock number
126 wxCursor::wxCursor(const int cursor_type
)
128 m_refData
= new wxIconRefData
;
133 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_WAIT
);
136 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_IBEAM
);
139 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_CROSS
);
141 case wxCURSOR_SIZENWSE
:
142 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_SIZENWSE
);
144 case wxCURSOR_SIZENESW
:
145 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_SIZENESW
);
147 case wxCURSOR_SIZEWE
:
148 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_SIZEWE
);
150 case wxCURSOR_SIZENS
:
151 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_SIZENS
);
155 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_ARROW
);
160 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_HAND");
163 case wxCURSOR_BULLSEYE
:
165 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_BULLSEYE");
168 case wxCURSOR_PENCIL
:
170 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_PENCIL");
173 case wxCURSOR_MAGNIFIER
:
175 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_MAGNIFIER");
178 case wxCURSOR_NO_ENTRY
:
180 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_NO_ENTRY");
183 case wxCURSOR_LEFT_BUTTON
:
185 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_ARROW
);
188 case wxCURSOR_RIGHT_BUTTON
:
190 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_ARROW
);
193 case wxCURSOR_MIDDLE_BUTTON
:
195 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_ARROW
);
198 case wxCURSOR_SIZING
:
200 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_SIZING");
205 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_WATCH");
208 case wxCURSOR_SPRAYCAN
:
210 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_ROLLER");
213 case wxCURSOR_PAINT_BRUSH
:
215 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_PBRUSH");
218 case wxCURSOR_POINT_LEFT
:
220 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_PLEFT");
223 case wxCURSOR_POINT_RIGHT
:
225 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_PRIGHT");
228 case wxCURSOR_QUESTION_ARROW
:
230 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_QARROW");
235 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(wxGetInstance(), "wxCURSOR_BLANK");
240 M_CURSORDATA
->m_hCursor
= (WXHCURSOR
) LoadCursor(NULL
, IDC_ARROW
);
245 wxCursor::~wxCursor(void)
247 // FreeResource(TRUE);
250 bool wxCursor::FreeResource(bool force
)
252 if (M_CURSORDATA
&& M_CURSORDATA
->m_hCursor
&& M_CURSORDATA
->m_destroyCursor
)
254 DestroyCursor((HCURSOR
) M_CURSORDATA
->m_hCursor
);
255 M_CURSORDATA
->m_hCursor
= 0;
260 void wxCursor::SetHCURSOR(WXHCURSOR cursor
)
263 m_refData
= new wxCursorRefData
;
265 M_CURSORDATA
->m_hCursor
= cursor
;
268 // Global cursor setting
269 void wxSetCursor(const wxCursor
& cursor
)
271 extern wxCursor
*g_globalCursor
;
272 if ( g_globalCursor
)
273 (*g_globalCursor
) = cursor
;
275 if (cursor
.Ok() && cursor
.GetHCURSOR())
276 ::SetCursor((HCURSOR
) cursor
.GetHCURSOR());