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