]> git.saurik.com Git - wxWidgets.git/blame - src/msw/cursor.cpp
wxInputConsumer
[wxWidgets.git] / src / msw / cursor.cpp
CommitLineData
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
2b0b4c55 40#include "wx/module.h"
2bda0e17 41#include "wx/msw/private.h"
04ef50df 42#ifndef __WXMICROWIN__
2bda0e17 43#include "wx/msw/dib.h"
04ef50df 44#endif
2bda0e17 45
47d67540 46#if wxUSE_RESOURCE_LOADING_IN_MSW
0d0512bd
VZ
47 #include "wx/msw/curico.h"
48 #include "wx/msw/curicop.h"
2bda0e17
KB
49#endif
50
0d0512bd
VZ
51// ----------------------------------------------------------------------------
52// wxWin macros
53// ----------------------------------------------------------------------------
54
bfbd6dc1
VZ
55IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxCursorBase)
56
57// ----------------------------------------------------------------------------
58// globals
59// ----------------------------------------------------------------------------
60
61// Current cursor, in order to hang on to cursor handle when setting the cursor
62// globally
63static wxCursor *gs_globalCursor = NULL;
64
65// ----------------------------------------------------------------------------
66// private classes
67// ----------------------------------------------------------------------------
68
69class wxCursorModule : public wxModule
70{
71public:
72 virtual bool OnInit()
73 {
74 gs_globalCursor = new wxCursor;
75
76 return TRUE;
77 }
78
79 virtual void OnExit()
80 {
81 delete gs_globalCursor;
82 gs_globalCursor = (wxCursor *)NULL;
83 }
84};
85
86// ============================================================================
87// implementation
88// ============================================================================
2bda0e17 89
0d0512bd
VZ
90// ----------------------------------------------------------------------------
91// wxCursorRefData
92// ----------------------------------------------------------------------------
93
94wxCursorRefData::wxCursorRefData()
2bda0e17 95{
0d0512bd
VZ
96 m_width = 32;
97 m_height = 32;
98
2bda0e17
KB
99 m_destroyCursor = FALSE;
100}
101
0d0512bd 102void wxCursorRefData::Free()
2bda0e17 103{
032af30f
VZ
104 if ( m_hCursor )
105 {
04ef50df 106#ifndef __WXMICROWIN__
032af30f
VZ
107 if ( m_destroyCursor )
108 ::DestroyCursor((HCURSOR)m_hCursor);
04ef50df 109#endif
032af30f
VZ
110
111 m_hCursor = 0;
112 }
2bda0e17
KB
113}
114
0d0512bd 115// ----------------------------------------------------------------------------
2bda0e17 116// Cursors
0d0512bd
VZ
117// ----------------------------------------------------------------------------
118
119wxCursor::wxCursor()
2bda0e17
KB
120{
121}
122
0d0512bd
VZ
123wxCursor::wxCursor(const char WXUNUSED(bits)[],
124 int WXUNUSED(width),
125 int WXUNUSED(height),
126 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY),
127 const char WXUNUSED(maskBits)[])
2bda0e17
KB
128{
129}
130
0d0512bd
VZ
131wxCursor::wxCursor(const wxString& cursor_file,
132 long flags,
133 int hotSpotX, int hotSpotY)
2bda0e17 134{
04ef50df
JS
135#ifdef __WXMICROWIN__
136 m_refData = NULL;
137#else
0d0512bd
VZ
138 wxCursorRefData *refData = new wxCursorRefData;
139 m_refData = refData;
2bda0e17 140
0d0512bd
VZ
141 refData->m_destroyCursor = FALSE;
142
143 if (flags == wxBITMAP_TYPE_CUR_RESOURCE)
144 {
2f851133 145#ifdef __WIN95__
0d0512bd 146 refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, 0);
2f851133 147#else
0d0512bd 148 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), cursor_file);
2f851133 149#endif
0d0512bd
VZ
150 }
151 else if (flags == wxBITMAP_TYPE_CUR)
152 {
2f851133 153#ifdef __WIN95__
0d0512bd 154 refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
2f851133 155#else
47d67540 156#if wxUSE_RESOURCE_LOADING_IN_MSW
0d0512bd
VZ
157 refData->m_hCursor = (WXHCURSOR) ReadCursorFile(WXSTRINGCAST cursor_file, wxGetInstance(), &refData->m_width, &refData->m_height);
158 refData->m_destroyCursor = TRUE;
2f851133 159#endif
2bda0e17 160#endif
0d0512bd
VZ
161 }
162 else if (flags == wxBITMAP_TYPE_ICO)
163 {
47d67540 164#if wxUSE_RESOURCE_LOADING_IN_MSW
0d0512bd
VZ
165 refData->m_hCursor = (WXHCURSOR) IconToCursor(WXSTRINGCAST cursor_file, wxGetInstance(), hotSpotX, hotSpotY, &refData->m_width, &refData->m_height);
166 refData->m_destroyCursor = TRUE;
2bda0e17 167#endif
0d0512bd
VZ
168 }
169 else if (flags == wxBITMAP_TYPE_BMP)
170 {
47d67540 171#if wxUSE_RESOURCE_LOADING_IN_MSW
0d0512bd
VZ
172 HBITMAP hBitmap = 0;
173 HPALETTE hPalette = 0;
174 bool success = wxReadDIB(WXSTRINGCAST cursor_file, &hBitmap, &hPalette) != 0;
175 if (!success)
176 return;
177 if (hPalette)
178 DeleteObject(hPalette);
179 POINT pnt;
180 pnt.x = hotSpotX;
181 pnt.y = hotSpotY;
182 refData->m_hCursor = (WXHCURSOR) MakeCursorFromBitmap(wxGetInstance(), hBitmap, &pnt);
183 refData->m_destroyCursor = TRUE;
184 DeleteObject(hBitmap);
2bda0e17 185#endif
0d0512bd
VZ
186 }
187
188#if WXWIN_COMPATIBILITY_2
189 refData->SetOk();
190#endif // WXWIN_COMPATIBILITY_2
04ef50df
JS
191
192#endif
2bda0e17
KB
193}
194
195// Cursors by stock number
debe6624 196wxCursor::wxCursor(int cursor_type)
2bda0e17 197{
04ef50df
JS
198#ifdef __WXMICROWIN__
199 m_refData = NULL;
200#else
0d0512bd
VZ
201 wxCursorRefData *refData = new wxCursorRefData;
202 m_refData = refData;
2bda0e17
KB
203
204 switch (cursor_type)
205 {
83f96286 206 case wxCURSOR_ARROWWAIT:
788722ac 207#ifndef __WIN16__
83f96286
RD
208 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_APPSTARTING);
209 break;
788722ac 210#endif
2bda0e17 211 case wxCURSOR_WAIT:
0d0512bd 212 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT);
2bda0e17
KB
213 break;
214 case wxCURSOR_IBEAM:
0d0512bd 215 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM);
2bda0e17
KB
216 break;
217 case wxCURSOR_CROSS:
0d0512bd 218 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS);
2bda0e17
KB
219 break;
220 case wxCURSOR_SIZENWSE:
0d0512bd 221 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE);
2bda0e17
KB
222 break;
223 case wxCURSOR_SIZENESW:
0d0512bd 224 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW);
2bda0e17
KB
225 break;
226 case wxCURSOR_SIZEWE:
0d0512bd 227 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE);
2bda0e17
KB
228 break;
229 case wxCURSOR_SIZENS:
0d0512bd 230 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS);
2bda0e17
KB
231 break;
232 case wxCURSOR_CHAR:
233 {
0d0512bd 234 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
235 break;
236 }
237 case wxCURSOR_HAND:
238 {
0d0512bd 239 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
2bda0e17
KB
240 break;
241 }
242 case wxCURSOR_BULLSEYE:
243 {
0d0512bd 244 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
2bda0e17
KB
245 break;
246 }
247 case wxCURSOR_PENCIL:
248 {
0d0512bd 249 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
2bda0e17
KB
250 break;
251 }
252 case wxCURSOR_MAGNIFIER:
253 {
0d0512bd 254 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
2bda0e17
KB
255 break;
256 }
257 case wxCURSOR_NO_ENTRY:
258 {
0d0512bd 259 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
2bda0e17
KB
260 break;
261 }
262 case wxCURSOR_LEFT_BUTTON:
263 {
0d0512bd 264 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
265 break;
266 }
267 case wxCURSOR_RIGHT_BUTTON:
268 {
0d0512bd 269 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
270 break;
271 }
272 case wxCURSOR_MIDDLE_BUTTON:
273 {
0d0512bd 274 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
275 break;
276 }
277 case wxCURSOR_SIZING:
278 {
0d0512bd 279 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
2bda0e17
KB
280 break;
281 }
282 case wxCURSOR_WATCH:
283 {
0d0512bd 284 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
2bda0e17
KB
285 break;
286 }
287 case wxCURSOR_SPRAYCAN:
288 {
0d0512bd 289 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
2bda0e17
KB
290 break;
291 }
292 case wxCURSOR_PAINT_BRUSH:
293 {
0d0512bd 294 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
2bda0e17
KB
295 break;
296 }
297 case wxCURSOR_POINT_LEFT:
298 {
0d0512bd 299 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
2bda0e17
KB
300 break;
301 }
302 case wxCURSOR_POINT_RIGHT:
303 {
0d0512bd 304 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
2bda0e17
KB
305 break;
306 }
307 case wxCURSOR_QUESTION_ARROW:
308 {
b96340e6 309// refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), wxT("wxCURSOR_QARROW"), IMAGE_CURSOR, 16, 16, LR_MONOCHROME);
0d0512bd 310 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
2bda0e17
KB
311 break;
312 }
313 case wxCURSOR_BLANK:
314 {
0d0512bd 315 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
2bda0e17
KB
316 break;
317 }
318 default:
319 case wxCURSOR_ARROW:
0d0512bd 320 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
321 break;
322 }
04ef50df 323#endif
2bda0e17
KB
324}
325
0d0512bd 326wxCursor::~wxCursor()
2bda0e17 327{
2bda0e17
KB
328}
329
0d0512bd 330// ----------------------------------------------------------------------------
2bda0e17 331// Global cursor setting
0d0512bd
VZ
332// ----------------------------------------------------------------------------
333
bfbd6dc1 334const wxCursor *wxGetGlobalCursor()
2bda0e17 335{
bfbd6dc1
VZ
336 return gs_globalCursor;
337}
2bda0e17 338
bfbd6dc1
VZ
339void wxSetCursor(const wxCursor& cursor)
340{
341 if ( cursor.Ok() )
6bf57206 342 {
04ef50df 343#ifndef __WXMICROWIN__
bfbd6dc1 344 ::SetCursor(GetHcursorOf(cursor));
04ef50df 345#endif
6bf57206 346
bfbd6dc1
VZ
347 if ( gs_globalCursor )
348 *gs_globalCursor = cursor;
6bf57206 349 }
2bda0e17
KB
350}
351
352