]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cursor.cpp | |
3 | // Purpose: wxCursor class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
6bf57206 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
0d0512bd VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
0d0512bd | 21 | #pragma implementation "cursor.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
0d0512bd | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
0d0512bd VZ |
32 | #include "wx/list.h" |
33 | #include "wx/utils.h" | |
34 | #include "wx/app.h" | |
fef15b42 | 35 | #include "wx/bitmap.h" |
0d0512bd | 36 | #include "wx/icon.h" |
fef15b42 | 37 | #include "wx/cursor.h" |
2bda0e17 KB |
38 | #endif |
39 | ||
40 | #include "wx/msw/private.h" | |
41 | #include "wx/msw/dib.h" | |
42 | ||
47d67540 | 43 | #if wxUSE_RESOURCE_LOADING_IN_MSW |
0d0512bd VZ |
44 | #include "wx/msw/curico.h" |
45 | #include "wx/msw/curicop.h" | |
2bda0e17 KB |
46 | #endif |
47 | ||
0d0512bd VZ |
48 | // ---------------------------------------------------------------------------- |
49 | // wxWin macros | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
bfbd6dc1 VZ |
52 | IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxCursorBase) |
53 | ||
54 | // ---------------------------------------------------------------------------- | |
55 | // globals | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | // Current cursor, in order to hang on to cursor handle when setting the cursor | |
59 | // globally | |
60 | static wxCursor *gs_globalCursor = NULL; | |
61 | ||
62 | // ---------------------------------------------------------------------------- | |
63 | // private classes | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
66 | class wxCursorModule : public wxModule | |
67 | { | |
68 | public: | |
69 | virtual bool OnInit() | |
70 | { | |
71 | gs_globalCursor = new wxCursor; | |
72 | ||
73 | return TRUE; | |
74 | } | |
75 | ||
76 | virtual void OnExit() | |
77 | { | |
78 | delete gs_globalCursor; | |
79 | gs_globalCursor = (wxCursor *)NULL; | |
80 | } | |
81 | }; | |
82 | ||
83 | // ============================================================================ | |
84 | // implementation | |
85 | // ============================================================================ | |
2bda0e17 | 86 | |
0d0512bd VZ |
87 | // ---------------------------------------------------------------------------- |
88 | // wxCursorRefData | |
89 | // ---------------------------------------------------------------------------- | |
90 | ||
91 | wxCursorRefData::wxCursorRefData() | |
2bda0e17 | 92 | { |
0d0512bd VZ |
93 | m_width = 32; |
94 | m_height = 32; | |
95 | ||
2bda0e17 KB |
96 | m_destroyCursor = FALSE; |
97 | } | |
98 | ||
0d0512bd | 99 | void wxCursorRefData::Free() |
2bda0e17 | 100 | { |
032af30f VZ |
101 | if ( m_hCursor ) |
102 | { | |
103 | if ( m_destroyCursor ) | |
104 | ::DestroyCursor((HCURSOR)m_hCursor); | |
105 | ||
106 | m_hCursor = 0; | |
107 | } | |
2bda0e17 KB |
108 | } |
109 | ||
0d0512bd | 110 | // ---------------------------------------------------------------------------- |
2bda0e17 | 111 | // Cursors |
0d0512bd VZ |
112 | // ---------------------------------------------------------------------------- |
113 | ||
114 | wxCursor::wxCursor() | |
2bda0e17 KB |
115 | { |
116 | } | |
117 | ||
0d0512bd VZ |
118 | wxCursor::wxCursor(const char WXUNUSED(bits)[], |
119 | int WXUNUSED(width), | |
120 | int WXUNUSED(height), | |
121 | int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), | |
122 | const char WXUNUSED(maskBits)[]) | |
2bda0e17 KB |
123 | { |
124 | } | |
125 | ||
0d0512bd VZ |
126 | wxCursor::wxCursor(const wxString& cursor_file, |
127 | long flags, | |
128 | int hotSpotX, int hotSpotY) | |
2bda0e17 | 129 | { |
0d0512bd VZ |
130 | wxCursorRefData *refData = new wxCursorRefData; |
131 | m_refData = refData; | |
2bda0e17 | 132 | |
0d0512bd VZ |
133 | refData->m_destroyCursor = FALSE; |
134 | ||
135 | if (flags == wxBITMAP_TYPE_CUR_RESOURCE) | |
136 | { | |
2f851133 | 137 | #ifdef __WIN95__ |
0d0512bd | 138 | refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, 0); |
2f851133 | 139 | #else |
0d0512bd | 140 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), cursor_file); |
2f851133 | 141 | #endif |
0d0512bd VZ |
142 | } |
143 | else if (flags == wxBITMAP_TYPE_CUR) | |
144 | { | |
2f851133 | 145 | #ifdef __WIN95__ |
0d0512bd | 146 | refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE); |
2f851133 | 147 | #else |
47d67540 | 148 | #if wxUSE_RESOURCE_LOADING_IN_MSW |
0d0512bd VZ |
149 | refData->m_hCursor = (WXHCURSOR) ReadCursorFile(WXSTRINGCAST cursor_file, wxGetInstance(), &refData->m_width, &refData->m_height); |
150 | refData->m_destroyCursor = TRUE; | |
2f851133 | 151 | #endif |
2bda0e17 | 152 | #endif |
0d0512bd VZ |
153 | } |
154 | else if (flags == wxBITMAP_TYPE_ICO) | |
155 | { | |
47d67540 | 156 | #if wxUSE_RESOURCE_LOADING_IN_MSW |
0d0512bd VZ |
157 | refData->m_hCursor = (WXHCURSOR) IconToCursor(WXSTRINGCAST cursor_file, wxGetInstance(), hotSpotX, hotSpotY, &refData->m_width, &refData->m_height); |
158 | refData->m_destroyCursor = TRUE; | |
2bda0e17 | 159 | #endif |
0d0512bd VZ |
160 | } |
161 | else if (flags == wxBITMAP_TYPE_BMP) | |
162 | { | |
47d67540 | 163 | #if wxUSE_RESOURCE_LOADING_IN_MSW |
0d0512bd VZ |
164 | HBITMAP hBitmap = 0; |
165 | HPALETTE hPalette = 0; | |
166 | bool success = wxReadDIB(WXSTRINGCAST cursor_file, &hBitmap, &hPalette) != 0; | |
167 | if (!success) | |
168 | return; | |
169 | if (hPalette) | |
170 | DeleteObject(hPalette); | |
171 | POINT pnt; | |
172 | pnt.x = hotSpotX; | |
173 | pnt.y = hotSpotY; | |
174 | refData->m_hCursor = (WXHCURSOR) MakeCursorFromBitmap(wxGetInstance(), hBitmap, &pnt); | |
175 | refData->m_destroyCursor = TRUE; | |
176 | DeleteObject(hBitmap); | |
2bda0e17 | 177 | #endif |
0d0512bd VZ |
178 | } |
179 | ||
180 | #if WXWIN_COMPATIBILITY_2 | |
181 | refData->SetOk(); | |
182 | #endif // WXWIN_COMPATIBILITY_2 | |
2bda0e17 KB |
183 | } |
184 | ||
185 | // Cursors by stock number | |
debe6624 | 186 | wxCursor::wxCursor(int cursor_type) |
2bda0e17 | 187 | { |
0d0512bd VZ |
188 | wxCursorRefData *refData = new wxCursorRefData; |
189 | m_refData = refData; | |
2bda0e17 KB |
190 | |
191 | switch (cursor_type) | |
192 | { | |
193 | case wxCURSOR_WAIT: | |
0d0512bd | 194 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT); |
2bda0e17 KB |
195 | break; |
196 | case wxCURSOR_IBEAM: | |
0d0512bd | 197 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM); |
2bda0e17 KB |
198 | break; |
199 | case wxCURSOR_CROSS: | |
0d0512bd | 200 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS); |
2bda0e17 KB |
201 | break; |
202 | case wxCURSOR_SIZENWSE: | |
0d0512bd | 203 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE); |
2bda0e17 KB |
204 | break; |
205 | case wxCURSOR_SIZENESW: | |
0d0512bd | 206 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW); |
2bda0e17 KB |
207 | break; |
208 | case wxCURSOR_SIZEWE: | |
0d0512bd | 209 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE); |
2bda0e17 KB |
210 | break; |
211 | case wxCURSOR_SIZENS: | |
0d0512bd | 212 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS); |
2bda0e17 KB |
213 | break; |
214 | case wxCURSOR_CHAR: | |
215 | { | |
0d0512bd | 216 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); |
2bda0e17 KB |
217 | break; |
218 | } | |
219 | case wxCURSOR_HAND: | |
220 | { | |
0d0512bd | 221 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND")); |
2bda0e17 KB |
222 | break; |
223 | } | |
224 | case wxCURSOR_BULLSEYE: | |
225 | { | |
0d0512bd | 226 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE")); |
2bda0e17 KB |
227 | break; |
228 | } | |
229 | case wxCURSOR_PENCIL: | |
230 | { | |
0d0512bd | 231 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL")); |
2bda0e17 KB |
232 | break; |
233 | } | |
234 | case wxCURSOR_MAGNIFIER: | |
235 | { | |
0d0512bd | 236 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER")); |
2bda0e17 KB |
237 | break; |
238 | } | |
239 | case wxCURSOR_NO_ENTRY: | |
240 | { | |
0d0512bd | 241 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY")); |
2bda0e17 KB |
242 | break; |
243 | } | |
244 | case wxCURSOR_LEFT_BUTTON: | |
245 | { | |
0d0512bd | 246 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); |
2bda0e17 KB |
247 | break; |
248 | } | |
249 | case wxCURSOR_RIGHT_BUTTON: | |
250 | { | |
0d0512bd | 251 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); |
2bda0e17 KB |
252 | break; |
253 | } | |
254 | case wxCURSOR_MIDDLE_BUTTON: | |
255 | { | |
0d0512bd | 256 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); |
2bda0e17 KB |
257 | break; |
258 | } | |
259 | case wxCURSOR_SIZING: | |
260 | { | |
0d0512bd | 261 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING")); |
2bda0e17 KB |
262 | break; |
263 | } | |
264 | case wxCURSOR_WATCH: | |
265 | { | |
0d0512bd | 266 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH")); |
2bda0e17 KB |
267 | break; |
268 | } | |
269 | case wxCURSOR_SPRAYCAN: | |
270 | { | |
0d0512bd | 271 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER")); |
2bda0e17 KB |
272 | break; |
273 | } | |
274 | case wxCURSOR_PAINT_BRUSH: | |
275 | { | |
0d0512bd | 276 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH")); |
2bda0e17 KB |
277 | break; |
278 | } | |
279 | case wxCURSOR_POINT_LEFT: | |
280 | { | |
0d0512bd | 281 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT")); |
2bda0e17 KB |
282 | break; |
283 | } | |
284 | case wxCURSOR_POINT_RIGHT: | |
285 | { | |
0d0512bd | 286 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT")); |
2bda0e17 KB |
287 | break; |
288 | } | |
289 | case wxCURSOR_QUESTION_ARROW: | |
290 | { | |
0d0512bd | 291 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW")); |
2bda0e17 KB |
292 | break; |
293 | } | |
294 | case wxCURSOR_BLANK: | |
295 | { | |
0d0512bd | 296 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK")); |
2bda0e17 KB |
297 | break; |
298 | } | |
299 | default: | |
300 | case wxCURSOR_ARROW: | |
0d0512bd | 301 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); |
2bda0e17 KB |
302 | break; |
303 | } | |
304 | } | |
305 | ||
0d0512bd | 306 | wxCursor::~wxCursor() |
2bda0e17 | 307 | { |
2bda0e17 KB |
308 | } |
309 | ||
0d0512bd | 310 | // ---------------------------------------------------------------------------- |
2bda0e17 | 311 | // Global cursor setting |
0d0512bd VZ |
312 | // ---------------------------------------------------------------------------- |
313 | ||
bfbd6dc1 | 314 | const wxCursor *wxGetGlobalCursor() |
2bda0e17 | 315 | { |
bfbd6dc1 VZ |
316 | return gs_globalCursor; |
317 | } | |
2bda0e17 | 318 | |
bfbd6dc1 VZ |
319 | void wxSetCursor(const wxCursor& cursor) |
320 | { | |
321 | if ( cursor.Ok() ) | |
6bf57206 | 322 | { |
bfbd6dc1 | 323 | ::SetCursor(GetHcursorOf(cursor)); |
6bf57206 | 324 | |
bfbd6dc1 VZ |
325 | if ( gs_globalCursor ) |
326 | *gs_globalCursor = cursor; | |
6bf57206 | 327 | } |
2bda0e17 KB |
328 | } |
329 | ||
330 |