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