]> git.saurik.com Git - wxWidgets.git/blame - src/msw/cursor.cpp
wxSpinCtrl
[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
12#ifdef __GNUG__
13#pragma implementation "cursor.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include <stdio.h>
25#include "wx/setup.h"
26#include "wx/list.h"
27#include "wx/utils.h"
28#include "wx/app.h"
29#include "wx/cursor.h"
0c589ad0 30#include "wx/icon.h"
2bda0e17
KB
31#endif
32
33#include "wx/msw/private.h"
34#include "wx/msw/dib.h"
35
36#include "assert.h"
37
47d67540 38#if wxUSE_RESOURCE_LOADING_IN_MSW
2bda0e17
KB
39#include "wx/msw/curico.h"
40#include "wx/msw/curicop.h"
41#endif
42
43#if !USE_SHARED_LIBRARIES
44IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
45#endif
46
47wxCursorRefData::wxCursorRefData(void)
48{
49 m_width = 32; m_height = 32;
50 m_hCursor = 0 ;
51 m_destroyCursor = FALSE;
52}
53
54wxCursorRefData::~wxCursorRefData(void)
55{
6bf57206 56 if ( m_hCursor && m_destroyCursor)
5ea105e0
RR
57#ifdef __WXWINE__
58 ::DestroyCursor((HCURSOR) m_hCursor);
59#else
6bf57206 60 ::DestroyCursor((HICON) m_hCursor);
5ea105e0 61#endif
2bda0e17
KB
62}
63
64// Cursors
65wxCursor::wxCursor(void)
66{
67}
68
debe6624
JS
69wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height),
70 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[])
2bda0e17
KB
71{
72}
73
debe6624 74wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY)
2bda0e17 75{
5360828d 76 m_refData = new wxCursorRefData;
2bda0e17
KB
77
78 M_CURSORDATA->m_destroyCursor = FALSE;
79 M_CURSORDATA->m_hCursor = 0;
80 M_CURSORDATA->m_ok = FALSE;
81 if (flags & wxBITMAP_TYPE_CUR_RESOURCE)
82 {
2f851133
JS
83#ifdef __WIN95__
84 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, 0);
85#else
2bda0e17 86 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), cursor_file);
2f851133 87#endif
2bda0e17
KB
88 if (M_CURSORDATA->m_hCursor)
89 M_CURSORDATA->m_ok = TRUE;
90 else
91 M_CURSORDATA->m_ok = FALSE;
92 }
93 else if (flags & wxBITMAP_TYPE_CUR)
94 {
2f851133
JS
95#ifdef __WIN95__
96 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
97#else
47d67540 98#if wxUSE_RESOURCE_LOADING_IN_MSW
837e5743 99 M_CURSORDATA->m_hCursor = (WXHCURSOR) ReadCursorFile(WXSTRINGCAST cursor_file, wxGetInstance(), &M_CURSORDATA->m_width, &M_CURSORDATA->m_height);
6bf57206 100 M_CURSORDATA->m_destroyCursor = TRUE;
2f851133 101#endif
2bda0e17
KB
102#endif
103 }
104 else if (flags & wxBITMAP_TYPE_ICO)
105 {
47d67540 106#if wxUSE_RESOURCE_LOADING_IN_MSW
837e5743 107 M_CURSORDATA->m_hCursor = (WXHCURSOR) IconToCursor(WXSTRINGCAST cursor_file, wxGetInstance(), hotSpotX, hotSpotY, &M_CURSORDATA->m_width, &M_CURSORDATA->m_height);
6bf57206 108 M_CURSORDATA->m_destroyCursor = TRUE;
2bda0e17
KB
109#endif
110 }
111 else if (flags & wxBITMAP_TYPE_BMP)
112 {
47d67540 113#if wxUSE_RESOURCE_LOADING_IN_MSW
2bda0e17
KB
114 HBITMAP hBitmap = 0;
115 HPALETTE hPalette = 0;
ef3ab009 116 bool success = wxReadDIB(WXSTRINGCAST cursor_file, &hBitmap, &hPalette) != 0;
2bda0e17
KB
117 if (!success)
118 return;
119 if (hPalette)
120 DeleteObject(hPalette);
121 POINT pnt;
122 pnt.x = hotSpotX;
123 pnt.y = hotSpotY;
124 M_CURSORDATA->m_hCursor = (WXHCURSOR) MakeCursorFromBitmap(wxGetInstance(), hBitmap, &pnt);
6bf57206 125 M_CURSORDATA->m_destroyCursor = TRUE;
2bda0e17
KB
126 DeleteObject(hBitmap);
127 if (M_CURSORDATA->m_hCursor)
128 M_CURSORDATA->m_ok = TRUE;
129#endif
130 }
131}
132
133// Cursors by stock number
debe6624 134wxCursor::wxCursor(int cursor_type)
2bda0e17 135{
5360828d 136 m_refData = new wxCursorRefData;
2bda0e17
KB
137
138 switch (cursor_type)
139 {
140 case wxCURSOR_WAIT:
57c208c5 141 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT);
2bda0e17
KB
142 break;
143 case wxCURSOR_IBEAM:
57c208c5 144 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM);
2bda0e17
KB
145 break;
146 case wxCURSOR_CROSS:
57c208c5 147 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS);
2bda0e17
KB
148 break;
149 case wxCURSOR_SIZENWSE:
57c208c5 150 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE);
2bda0e17
KB
151 break;
152 case wxCURSOR_SIZENESW:
57c208c5 153 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW);
2bda0e17
KB
154 break;
155 case wxCURSOR_SIZEWE:
57c208c5 156 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE);
2bda0e17
KB
157 break;
158 case wxCURSOR_SIZENS:
57c208c5 159 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS);
2bda0e17
KB
160 break;
161 case wxCURSOR_CHAR:
162 {
57c208c5 163 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
164 break;
165 }
166 case wxCURSOR_HAND:
167 {
223d09f6 168 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
2bda0e17
KB
169 break;
170 }
171 case wxCURSOR_BULLSEYE:
172 {
223d09f6 173 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
2bda0e17
KB
174 break;
175 }
176 case wxCURSOR_PENCIL:
177 {
223d09f6 178 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
2bda0e17
KB
179 break;
180 }
181 case wxCURSOR_MAGNIFIER:
182 {
223d09f6 183 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
2bda0e17
KB
184 break;
185 }
186 case wxCURSOR_NO_ENTRY:
187 {
223d09f6 188 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
2bda0e17
KB
189 break;
190 }
191 case wxCURSOR_LEFT_BUTTON:
192 {
57c208c5 193 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
194 break;
195 }
196 case wxCURSOR_RIGHT_BUTTON:
197 {
57c208c5 198 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
199 break;
200 }
201 case wxCURSOR_MIDDLE_BUTTON:
202 {
57c208c5 203 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
204 break;
205 }
206 case wxCURSOR_SIZING:
207 {
223d09f6 208 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
2bda0e17
KB
209 break;
210 }
211 case wxCURSOR_WATCH:
212 {
223d09f6 213 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
2bda0e17
KB
214 break;
215 }
216 case wxCURSOR_SPRAYCAN:
217 {
223d09f6 218 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
2bda0e17
KB
219 break;
220 }
221 case wxCURSOR_PAINT_BRUSH:
222 {
223d09f6 223 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
2bda0e17
KB
224 break;
225 }
226 case wxCURSOR_POINT_LEFT:
227 {
223d09f6 228 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
2bda0e17
KB
229 break;
230 }
231 case wxCURSOR_POINT_RIGHT:
232 {
223d09f6 233 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
2bda0e17
KB
234 break;
235 }
236 case wxCURSOR_QUESTION_ARROW:
237 {
223d09f6 238 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
2bda0e17
KB
239 break;
240 }
241 case wxCURSOR_BLANK:
242 {
223d09f6 243 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
2bda0e17
KB
244 break;
245 }
246 default:
247 case wxCURSOR_ARROW:
57c208c5 248 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
2bda0e17
KB
249 break;
250 }
251}
252
253wxCursor::~wxCursor(void)
254{
6bf57206 255// FreeResource(TRUE);
2bda0e17
KB
256}
257
57c208c5 258bool wxCursor::FreeResource(bool WXUNUSED(force))
2bda0e17
KB
259{
260 if (M_CURSORDATA && M_CURSORDATA->m_hCursor && M_CURSORDATA->m_destroyCursor)
261 {
262 DestroyCursor((HCURSOR) M_CURSORDATA->m_hCursor);
6bf57206 263 M_CURSORDATA->m_hCursor = 0;
2bda0e17
KB
264 }
265 return TRUE;
266}
267
268void wxCursor::SetHCURSOR(WXHCURSOR cursor)
269{
270 if ( !M_CURSORDATA )
6bf57206 271 m_refData = new wxCursorRefData;
2bda0e17
KB
272
273 M_CURSORDATA->m_hCursor = cursor;
274}
275
276// Global cursor setting
277void wxSetCursor(const wxCursor& cursor)
278{
6bf57206 279 extern wxCursor *g_globalCursor;
2bda0e17 280
6bf57206
VZ
281 if ( cursor.Ok() && cursor.GetHCURSOR() )
282 {
283 ::SetCursor((HCURSOR) cursor.GetHCURSOR());
284
285 if ( g_globalCursor )
286 (*g_globalCursor) = cursor;
287 }
2bda0e17
KB
288}
289
290