]> git.saurik.com Git - wxWidgets.git/blame - src/msw/cursor.cpp
wxFrame::OnSize() slightly optimized (the behaviour is the same as before)
[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
9// Licence: wxWindows licence
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
37#if USE_XPM_IN_MSW
38#define FOR_MSW 1
39#include "..\..\contrib\wxxpm\libxpm.34b\lib\xpm34.h"
40#endif
41
42#if USE_RESOURCE_LOADING_IN_MSW
43#include "wx/msw/curico.h"
44#include "wx/msw/curicop.h"
45#endif
46
47#if !USE_SHARED_LIBRARIES
48IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
49#endif
50
51wxCursorRefData::wxCursorRefData(void)
52{
53 m_width = 32; m_height = 32;
54 m_hCursor = 0 ;
55 m_destroyCursor = FALSE;
56}
57
58wxCursorRefData::~wxCursorRefData(void)
59{
60 if ( m_hCursor && m_destroyCursor)
61 ::DestroyCursor((HICON) m_hCursor);
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 {
91#if USE_RESOURCE_LOADING_IN_MSW
92 M_CURSORDATA->m_hCursor = (WXHCURSOR) ReadCursorFile((char *)(const char *)cursor_file, wxGetInstance(), &M_CURSORDATA->m_width, &M_CURSORDATA->m_height);
93 M_CURSORDATA->m_destroyCursor = TRUE;
94#endif
95 }
96 else if (flags & wxBITMAP_TYPE_ICO)
97 {
98#if USE_RESOURCE_LOADING_IN_MSW
99 M_CURSORDATA->m_hCursor = (WXHCURSOR) IconToCursor((char *)(const char *)cursor_file, wxGetInstance(), hotSpotX, hotSpotY, &M_CURSORDATA->m_width, &M_CURSORDATA->m_height);
100 M_CURSORDATA->m_destroyCursor = TRUE;
101#endif
102 }
103 else if (flags & wxBITMAP_TYPE_BMP)
104 {
105#if USE_RESOURCE_LOADING_IN_MSW
106 HBITMAP hBitmap = 0;
107 HPALETTE hPalette = 0;
108 bool success = ReadDIB((char *)(const char *)cursor_file, &hBitmap, &hPalette);
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);
117 M_CURSORDATA->m_destroyCursor = TRUE;
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:
133 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_WAIT);
134 break;
135 case wxCURSOR_IBEAM:
136 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_IBEAM);
137 break;
138 case wxCURSOR_CROSS:
139 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_CROSS);
140 break;
141 case wxCURSOR_SIZENWSE:
142 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_SIZENWSE);
143 break;
144 case wxCURSOR_SIZENESW:
145 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_SIZENESW);
146 break;
147 case wxCURSOR_SIZEWE:
148 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_SIZEWE);
149 break;
150 case wxCURSOR_SIZENS:
151 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_SIZENS);
152 break;
153 case wxCURSOR_CHAR:
154 {
155 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW);
156 break;
157 }
158 case wxCURSOR_HAND:
159 {
160 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_HAND");
161 break;
162 }
163 case wxCURSOR_BULLSEYE:
164 {
165 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_BULLSEYE");
166 break;
167 }
168 case wxCURSOR_PENCIL:
169 {
170 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_PENCIL");
171 break;
172 }
173 case wxCURSOR_MAGNIFIER:
174 {
175 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_MAGNIFIER");
176 break;
177 }
178 case wxCURSOR_NO_ENTRY:
179 {
180 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_NO_ENTRY");
181 break;
182 }
183 case wxCURSOR_LEFT_BUTTON:
184 {
185 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW);
186 break;
187 }
188 case wxCURSOR_RIGHT_BUTTON:
189 {
190 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW);
191 break;
192 }
193 case wxCURSOR_MIDDLE_BUTTON:
194 {
195 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW);
196 break;
197 }
198 case wxCURSOR_SIZING:
199 {
200 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_SIZING");
201 break;
202 }
203 case wxCURSOR_WATCH:
204 {
205 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_WATCH");
206 break;
207 }
208 case wxCURSOR_SPRAYCAN:
209 {
210 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_ROLLER");
211 break;
212 }
213 case wxCURSOR_PAINT_BRUSH:
214 {
215 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_PBRUSH");
216 break;
217 }
218 case wxCURSOR_POINT_LEFT:
219 {
220 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_PLEFT");
221 break;
222 }
223 case wxCURSOR_POINT_RIGHT:
224 {
225 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_PRIGHT");
226 break;
227 }
228 case wxCURSOR_QUESTION_ARROW:
229 {
230 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_QARROW");
231 break;
232 }
233 case wxCURSOR_BLANK:
234 {
235 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_BLANK");
236 break;
237 }
238 default:
239 case wxCURSOR_ARROW:
240 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW);
241 break;
242 }
243}
244
245wxCursor::~wxCursor(void)
246{
247// FreeResource(TRUE);
248}
249
250bool wxCursor::FreeResource(bool force)
251{
252 if (M_CURSORDATA && M_CURSORDATA->m_hCursor && M_CURSORDATA->m_destroyCursor)
253 {
254 DestroyCursor((HCURSOR) M_CURSORDATA->m_hCursor);
255 M_CURSORDATA->m_hCursor = 0;
256 }
257 return TRUE;
258}
259
260void wxCursor::SetHCURSOR(WXHCURSOR cursor)
261{
262 if ( !M_CURSORDATA )
263 m_refData = new wxCursorRefData;
264
265 M_CURSORDATA->m_hCursor = cursor;
266}
267
268// Global cursor setting
269void wxSetCursor(const wxCursor& cursor)
270{
271 extern wxCursor *g_globalCursor;
272 if ( g_globalCursor )
273 (*g_globalCursor) = cursor;
274
275 if (cursor.Ok() && cursor.GetHCURSOR())
276 ::SetCursor((HCURSOR) cursor.GetHCURSOR());
277}
278
279