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