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