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