]> git.saurik.com Git - wxWidgets.git/blame - src/msw/cursor.cpp
dllwidget demo updates
[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 if (flags == wxBITMAP_TYPE_CUR_RESOURCE)
142 {
2f851133 143#ifdef __WIN95__
0d0512bd 144 refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, 0);
2f851133 145#else
0d0512bd 146 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), cursor_file);
2f851133 147#endif
3fe03e47 148 refData->m_destroyCursor = FALSE;
0d0512bd
VZ
149 }
150 else if (flags == wxBITMAP_TYPE_CUR)
151 {
2f851133 152#ifdef __WIN95__
0d0512bd 153 refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
2f851133 154#else
47d67540 155#if wxUSE_RESOURCE_LOADING_IN_MSW
0d0512bd 156 refData->m_hCursor = (WXHCURSOR) ReadCursorFile(WXSTRINGCAST cursor_file, wxGetInstance(), &refData->m_width, &refData->m_height);
2f851133 157#endif
2bda0e17 158#endif
0d0512bd
VZ
159 }
160 else if (flags == wxBITMAP_TYPE_ICO)
161 {
47d67540 162#if wxUSE_RESOURCE_LOADING_IN_MSW
0d0512bd 163 refData->m_hCursor = (WXHCURSOR) IconToCursor(WXSTRINGCAST cursor_file, wxGetInstance(), hotSpotX, hotSpotY, &refData->m_width, &refData->m_height);
2bda0e17 164#endif
0d0512bd
VZ
165 }
166 else if (flags == wxBITMAP_TYPE_BMP)
167 {
47d67540 168#if wxUSE_RESOURCE_LOADING_IN_MSW
0d0512bd
VZ
169 HBITMAP hBitmap = 0;
170 HPALETTE hPalette = 0;
171 bool success = wxReadDIB(WXSTRINGCAST cursor_file, &hBitmap, &hPalette) != 0;
172 if (!success)
173 return;
174 if (hPalette)
175 DeleteObject(hPalette);
176 POINT pnt;
177 pnt.x = hotSpotX;
178 pnt.y = hotSpotY;
179 refData->m_hCursor = (WXHCURSOR) MakeCursorFromBitmap(wxGetInstance(), hBitmap, &pnt);
0d0512bd 180 DeleteObject(hBitmap);
2bda0e17 181#endif
0d0512bd
VZ
182 }
183
184#if WXWIN_COMPATIBILITY_2
185 refData->SetOk();
186#endif // WXWIN_COMPATIBILITY_2
04ef50df
JS
187
188#endif
2bda0e17
KB
189}
190
191// Cursors by stock number
debe6624 192wxCursor::wxCursor(int cursor_type)
2bda0e17 193{
04ef50df
JS
194#ifdef __WXMICROWIN__
195 m_refData = NULL;
196#else
0d0512bd
VZ
197 wxCursorRefData *refData = new wxCursorRefData;
198 m_refData = refData;
2bda0e17
KB
199
200 switch (cursor_type)
201 {
83f96286 202 case wxCURSOR_ARROWWAIT:
788722ac 203#ifndef __WIN16__
83f96286
RD
204 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_APPSTARTING);
205 break;
788722ac 206#endif
2bda0e17 207 case wxCURSOR_WAIT:
0d0512bd 208 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT);
2bda0e17
KB
209 break;
210 case wxCURSOR_IBEAM:
0d0512bd 211 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM);
2bda0e17
KB
212 break;
213 case wxCURSOR_CROSS:
0d0512bd 214 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS);
2bda0e17
KB
215 break;
216 case wxCURSOR_SIZENWSE:
0d0512bd 217 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE);
2bda0e17
KB
218 break;
219 case wxCURSOR_SIZENESW:
0d0512bd 220 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW);
2bda0e17
KB
221 break;
222 case wxCURSOR_SIZEWE:
0d0512bd 223 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE);
2bda0e17
KB
224 break;
225 case wxCURSOR_SIZENS:
0d0512bd 226 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS);
2bda0e17
KB
227 break;
228 case wxCURSOR_CHAR:
229 {
0d0512bd 230 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
231 break;
232 }
233 case wxCURSOR_HAND:
234 {
0d0512bd 235 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
2bda0e17
KB
236 break;
237 }
238 case wxCURSOR_BULLSEYE:
239 {
0d0512bd 240 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
2bda0e17
KB
241 break;
242 }
243 case wxCURSOR_PENCIL:
244 {
0d0512bd 245 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
2bda0e17
KB
246 break;
247 }
248 case wxCURSOR_MAGNIFIER:
249 {
0d0512bd 250 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
2bda0e17
KB
251 break;
252 }
253 case wxCURSOR_NO_ENTRY:
254 {
0d0512bd 255 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
2bda0e17
KB
256 break;
257 }
258 case wxCURSOR_LEFT_BUTTON:
259 {
0d0512bd 260 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
261 break;
262 }
263 case wxCURSOR_RIGHT_BUTTON:
264 {
0d0512bd 265 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
266 break;
267 }
268 case wxCURSOR_MIDDLE_BUTTON:
269 {
0d0512bd 270 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
271 break;
272 }
273 case wxCURSOR_SIZING:
274 {
0d0512bd 275 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
2bda0e17
KB
276 break;
277 }
278 case wxCURSOR_WATCH:
279 {
0d0512bd 280 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
2bda0e17
KB
281 break;
282 }
283 case wxCURSOR_SPRAYCAN:
284 {
0d0512bd 285 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
2bda0e17
KB
286 break;
287 }
288 case wxCURSOR_PAINT_BRUSH:
289 {
0d0512bd 290 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
2bda0e17
KB
291 break;
292 }
293 case wxCURSOR_POINT_LEFT:
294 {
0d0512bd 295 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
2bda0e17
KB
296 break;
297 }
298 case wxCURSOR_POINT_RIGHT:
299 {
0d0512bd 300 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
2bda0e17
KB
301 break;
302 }
303 case wxCURSOR_QUESTION_ARROW:
304 {
b96340e6 305// refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), wxT("wxCURSOR_QARROW"), IMAGE_CURSOR, 16, 16, LR_MONOCHROME);
0d0512bd 306 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
2bda0e17
KB
307 break;
308 }
309 case wxCURSOR_BLANK:
310 {
0d0512bd 311 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
2bda0e17
KB
312 break;
313 }
314 default:
315 case wxCURSOR_ARROW:
0d0512bd 316 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
317 break;
318 }
04ef50df 319#endif
2bda0e17
KB
320}
321
0d0512bd 322wxCursor::~wxCursor()
2bda0e17 323{
2bda0e17
KB
324}
325
0d0512bd 326// ----------------------------------------------------------------------------
2bda0e17 327// Global cursor setting
0d0512bd
VZ
328// ----------------------------------------------------------------------------
329
bfbd6dc1 330const wxCursor *wxGetGlobalCursor()
2bda0e17 331{
bfbd6dc1
VZ
332 return gs_globalCursor;
333}
2bda0e17 334
bfbd6dc1
VZ
335void wxSetCursor(const wxCursor& cursor)
336{
337 if ( cursor.Ok() )
6bf57206 338 {
04ef50df 339#ifndef __WXMICROWIN__
bfbd6dc1 340 ::SetCursor(GetHcursorOf(cursor));
04ef50df 341#endif
6bf57206 342
bfbd6dc1
VZ
343 if ( gs_globalCursor )
344 *gs_globalCursor = cursor;
6bf57206 345 }
2bda0e17
KB
346}
347
348