1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCursor class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/cursor.h"
25 #include "wx/os2/private.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxCursor
, wxBitmap
)
31 wxCursorRefData::wxCursorRefData(void)
36 m_destroyCursor
= FALSE
;
39 wxCursorRefData::~wxCursorRefData(void)
41 // if ( m_hCursor && m_destroyCursor)
42 // ::DestroyCursor((HICON) m_hCursor);
46 wxCursor::wxCursor(void)
50 wxCursor::wxCursor(const char WXUNUSED(bits
)[], int WXUNUSED(width
), int WXUNUSED(height
),
51 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
), const char WXUNUSED(maskBits
)[])
55 wxCursor::wxCursor(const wxString
& cursor_file
, long flags
, int hotSpotX
, int hotSpotY
)
57 m_refData
= new wxCursorRefData
;
59 M_CURSORDATA
->m_destroyCursor
= FALSE
;
60 M_CURSORDATA
->m_hCursor
= 0;
63 M_CURSORDATA->m_bOK = FALSE;
64 if (flags & wxBITMAP_TYPE_CUR_RESOURCE)
66 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, 0);
67 if (M_CURSORDATA->m_hCursor)
68 M_CURSORDATA->m_ok = TRUE;
70 M_CURSORDATA->m_ok = FALSE;
72 else if (flags & wxBITMAP_TYPE_CUR)
74 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
76 else if (flags & wxBITMAP_TYPE_ICO)
79 else if (flags & wxBITMAP_TYPE_BMP)
85 // Cursors by stock number
86 wxCursor::wxCursor(int cursor_type
)
88 m_refData
= new wxCursorRefData
;
94 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT);
97 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM);
100 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS);
102 case wxCURSOR_SIZENWSE:
103 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE);
105 case wxCURSOR_SIZENESW:
106 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW);
108 case wxCURSOR_SIZEWE:
109 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE);
111 case wxCURSOR_SIZENS:
112 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS);
116 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
121 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
124 case wxCURSOR_BULLSEYE:
126 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
129 case wxCURSOR_PENCIL:
131 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
134 case wxCURSOR_MAGNIFIER:
136 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
139 case wxCURSOR_NO_ENTRY:
141 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
144 case wxCURSOR_LEFT_BUTTON:
146 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
149 case wxCURSOR_RIGHT_BUTTON:
151 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
154 case wxCURSOR_MIDDLE_BUTTON:
156 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
159 case wxCURSOR_SIZING:
161 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
166 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
169 case wxCURSOR_SPRAYCAN:
171 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
174 case wxCURSOR_PAINT_BRUSH:
176 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
179 case wxCURSOR_POINT_LEFT:
181 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
184 case wxCURSOR_POINT_RIGHT:
186 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
189 case wxCURSOR_QUESTION_ARROW:
191 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
196 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
201 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
207 wxCursor::~wxCursor(void)
209 // FreeResource(TRUE);
212 bool wxCursor::FreeResource(bool WXUNUSED(force
))
214 // if (M_CURSORDATA && M_CURSORDATA->m_hCursor && M_CURSORDATA->m_destroyCursor)
216 // DestroyCursor((HCURSOR) M_CURSORDATA->m_hCursor);
217 // M_CURSORDATA->m_hCursor = 0;
222 void wxCursor::SetHCURSOR(WXHCURSOR cursor
)
225 m_refData
= new wxCursorRefData
;
227 M_CURSORDATA
->m_hCursor
= cursor
;
230 // Global cursor setting
231 void wxSetCursor(const wxCursor
& cursor
)
233 extern wxCursor
*g_globalCursor
;
235 if ( cursor
.Ok() && cursor
.GetHCURSOR() )
237 // ::SetCursor((HCURSOR) cursor.GetHCURSOR());
239 if ( g_globalCursor
)
240 (*g_globalCursor
) = cursor
;