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