]> git.saurik.com Git - wxWidgets.git/blob - src/msw/cursor.cpp
Fixed wxConfig (I hope) and disabled wxRegConfig::DeleteAll.
[wxWidgets.git] / src / msw / cursor.cpp
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 wxUSE_RESOURCE_LOADING_IN_MSW
38 #include "wx/msw/curico.h"
39 #include "wx/msw/curicop.h"
40 #endif
41
42 #if !USE_SHARED_LIBRARIES
43 IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
44 #endif
45
46 wxCursorRefData::wxCursorRefData(void)
47 {
48 m_width = 32; m_height = 32;
49 m_hCursor = 0 ;
50 m_destroyCursor = FALSE;
51 }
52
53 wxCursorRefData::~wxCursorRefData(void)
54 {
55 if ( m_hCursor && m_destroyCursor)
56 ::DestroyCursor((HICON) m_hCursor);
57 }
58
59 // Cursors
60 wxCursor::wxCursor(void)
61 {
62 }
63
64 wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height),
65 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[])
66 {
67 }
68
69 wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY)
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 {
86 #if wxUSE_RESOURCE_LOADING_IN_MSW
87 M_CURSORDATA->m_hCursor = (WXHCURSOR) ReadCursorFile((char *)(const char *)cursor_file, wxGetInstance(), &M_CURSORDATA->m_width, &M_CURSORDATA->m_height);
88 M_CURSORDATA->m_destroyCursor = TRUE;
89 #endif
90 }
91 else if (flags & wxBITMAP_TYPE_ICO)
92 {
93 #if wxUSE_RESOURCE_LOADING_IN_MSW
94 M_CURSORDATA->m_hCursor = (WXHCURSOR) IconToCursor((char *)(const char *)cursor_file, wxGetInstance(), hotSpotX, hotSpotY, &M_CURSORDATA->m_width, &M_CURSORDATA->m_height);
95 M_CURSORDATA->m_destroyCursor = TRUE;
96 #endif
97 }
98 else if (flags & wxBITMAP_TYPE_BMP)
99 {
100 #if wxUSE_RESOURCE_LOADING_IN_MSW
101 HBITMAP hBitmap = 0;
102 HPALETTE hPalette = 0;
103 bool success = ReadDIB((char *)(const char *)cursor_file, &hBitmap, &hPalette) != 0;
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);
112 M_CURSORDATA->m_destroyCursor = TRUE;
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
121 wxCursor::wxCursor(int cursor_type)
122 {
123 m_refData = new wxIconRefData;
124
125 switch (cursor_type)
126 {
127 case wxCURSOR_WAIT:
128 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT);
129 break;
130 case wxCURSOR_IBEAM:
131 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM);
132 break;
133 case wxCURSOR_CROSS:
134 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS);
135 break;
136 case wxCURSOR_SIZENWSE:
137 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE);
138 break;
139 case wxCURSOR_SIZENESW:
140 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW);
141 break;
142 case wxCURSOR_SIZEWE:
143 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE);
144 break;
145 case wxCURSOR_SIZENS:
146 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS);
147 break;
148 case wxCURSOR_CHAR:
149 {
150 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
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 {
180 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
181 break;
182 }
183 case wxCURSOR_RIGHT_BUTTON:
184 {
185 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
186 break;
187 }
188 case wxCURSOR_MIDDLE_BUTTON:
189 {
190 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
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:
235 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
236 break;
237 }
238 }
239
240 wxCursor::~wxCursor(void)
241 {
242 // FreeResource(TRUE);
243 }
244
245 bool wxCursor::FreeResource(bool WXUNUSED(force))
246 {
247 if (M_CURSORDATA && M_CURSORDATA->m_hCursor && M_CURSORDATA->m_destroyCursor)
248 {
249 DestroyCursor((HCURSOR) M_CURSORDATA->m_hCursor);
250 M_CURSORDATA->m_hCursor = 0;
251 }
252 return TRUE;
253 }
254
255 void wxCursor::SetHCURSOR(WXHCURSOR cursor)
256 {
257 if ( !M_CURSORDATA )
258 m_refData = new wxCursorRefData;
259
260 M_CURSORDATA->m_hCursor = cursor;
261 }
262
263 // Global cursor setting
264 void wxSetCursor(const wxCursor& cursor)
265 {
266 extern wxCursor *g_globalCursor;
267 if ( g_globalCursor )
268 (*g_globalCursor) = cursor;
269
270 if (cursor.Ok() && cursor.GetHCURSOR())
271 ::SetCursor((HCURSOR) cursor.GetHCURSOR());
272 }
273
274