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