]> git.saurik.com Git - wxWidgets.git/blob - src/msw/cursor.cpp
compilation fixes - wxGTK compiles but not links
[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 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "cursor.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/list.h"
33 #include "wx/utils.h"
34 #include "wx/app.h"
35 #include "wx/bitmap.h"
36 #include "wx/icon.h"
37 #include "wx/cursor.h"
38 #endif
39
40 #include "wx/module.h"
41 #include "wx/msw/private.h"
42 #include "wx/msw/dib.h"
43
44 #if wxUSE_RESOURCE_LOADING_IN_MSW
45 #include "wx/msw/curico.h"
46 #include "wx/msw/curicop.h"
47 #endif
48
49 // ----------------------------------------------------------------------------
50 // wxWin macros
51 // ----------------------------------------------------------------------------
52
53 IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxCursorBase)
54
55 // ----------------------------------------------------------------------------
56 // globals
57 // ----------------------------------------------------------------------------
58
59 // Current cursor, in order to hang on to cursor handle when setting the cursor
60 // globally
61 static wxCursor *gs_globalCursor = NULL;
62
63 // ----------------------------------------------------------------------------
64 // private classes
65 // ----------------------------------------------------------------------------
66
67 class wxCursorModule : public wxModule
68 {
69 public:
70 virtual bool OnInit()
71 {
72 gs_globalCursor = new wxCursor;
73
74 return TRUE;
75 }
76
77 virtual void OnExit()
78 {
79 delete gs_globalCursor;
80 gs_globalCursor = (wxCursor *)NULL;
81 }
82 };
83
84 // ============================================================================
85 // implementation
86 // ============================================================================
87
88 // ----------------------------------------------------------------------------
89 // wxCursorRefData
90 // ----------------------------------------------------------------------------
91
92 wxCursorRefData::wxCursorRefData()
93 {
94 m_width = 32;
95 m_height = 32;
96
97 m_destroyCursor = FALSE;
98 }
99
100 void wxCursorRefData::Free()
101 {
102 if ( m_hCursor )
103 {
104 if ( m_destroyCursor )
105 ::DestroyCursor((HCURSOR)m_hCursor);
106
107 m_hCursor = 0;
108 }
109 }
110
111 // ----------------------------------------------------------------------------
112 // Cursors
113 // ----------------------------------------------------------------------------
114
115 wxCursor::wxCursor()
116 {
117 }
118
119 wxCursor::wxCursor(const char WXUNUSED(bits)[],
120 int WXUNUSED(width),
121 int WXUNUSED(height),
122 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY),
123 const char WXUNUSED(maskBits)[])
124 {
125 }
126
127 wxCursor::wxCursor(const wxString& cursor_file,
128 long flags,
129 int hotSpotX, int hotSpotY)
130 {
131 wxCursorRefData *refData = new wxCursorRefData;
132 m_refData = refData;
133
134 refData->m_destroyCursor = FALSE;
135
136 if (flags == wxBITMAP_TYPE_CUR_RESOURCE)
137 {
138 #ifdef __WIN95__
139 refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, 0);
140 #else
141 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), cursor_file);
142 #endif
143 }
144 else if (flags == wxBITMAP_TYPE_CUR)
145 {
146 #ifdef __WIN95__
147 refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
148 #else
149 #if wxUSE_RESOURCE_LOADING_IN_MSW
150 refData->m_hCursor = (WXHCURSOR) ReadCursorFile(WXSTRINGCAST cursor_file, wxGetInstance(), &refData->m_width, &refData->m_height);
151 refData->m_destroyCursor = TRUE;
152 #endif
153 #endif
154 }
155 else if (flags == wxBITMAP_TYPE_ICO)
156 {
157 #if wxUSE_RESOURCE_LOADING_IN_MSW
158 refData->m_hCursor = (WXHCURSOR) IconToCursor(WXSTRINGCAST cursor_file, wxGetInstance(), hotSpotX, hotSpotY, &refData->m_width, &refData->m_height);
159 refData->m_destroyCursor = TRUE;
160 #endif
161 }
162 else if (flags == wxBITMAP_TYPE_BMP)
163 {
164 #if wxUSE_RESOURCE_LOADING_IN_MSW
165 HBITMAP hBitmap = 0;
166 HPALETTE hPalette = 0;
167 bool success = wxReadDIB(WXSTRINGCAST cursor_file, &hBitmap, &hPalette) != 0;
168 if (!success)
169 return;
170 if (hPalette)
171 DeleteObject(hPalette);
172 POINT pnt;
173 pnt.x = hotSpotX;
174 pnt.y = hotSpotY;
175 refData->m_hCursor = (WXHCURSOR) MakeCursorFromBitmap(wxGetInstance(), hBitmap, &pnt);
176 refData->m_destroyCursor = TRUE;
177 DeleteObject(hBitmap);
178 #endif
179 }
180
181 #if WXWIN_COMPATIBILITY_2
182 refData->SetOk();
183 #endif // WXWIN_COMPATIBILITY_2
184 }
185
186 // Cursors by stock number
187 wxCursor::wxCursor(int cursor_type)
188 {
189 wxCursorRefData *refData = new wxCursorRefData;
190 m_refData = refData;
191
192 switch (cursor_type)
193 {
194 case wxCURSOR_ARROWWAIT:
195 #ifndef __WIN16__
196 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_APPSTARTING);
197 break;
198 #endif
199 case wxCURSOR_WAIT:
200 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT);
201 break;
202 case wxCURSOR_IBEAM:
203 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM);
204 break;
205 case wxCURSOR_CROSS:
206 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS);
207 break;
208 case wxCURSOR_SIZENWSE:
209 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE);
210 break;
211 case wxCURSOR_SIZENESW:
212 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW);
213 break;
214 case wxCURSOR_SIZEWE:
215 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE);
216 break;
217 case wxCURSOR_SIZENS:
218 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS);
219 break;
220 case wxCURSOR_CHAR:
221 {
222 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
223 break;
224 }
225 case wxCURSOR_HAND:
226 {
227 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
228 break;
229 }
230 case wxCURSOR_BULLSEYE:
231 {
232 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
233 break;
234 }
235 case wxCURSOR_PENCIL:
236 {
237 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
238 break;
239 }
240 case wxCURSOR_MAGNIFIER:
241 {
242 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
243 break;
244 }
245 case wxCURSOR_NO_ENTRY:
246 {
247 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
248 break;
249 }
250 case wxCURSOR_LEFT_BUTTON:
251 {
252 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
253 break;
254 }
255 case wxCURSOR_RIGHT_BUTTON:
256 {
257 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
258 break;
259 }
260 case wxCURSOR_MIDDLE_BUTTON:
261 {
262 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
263 break;
264 }
265 case wxCURSOR_SIZING:
266 {
267 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
268 break;
269 }
270 case wxCURSOR_WATCH:
271 {
272 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
273 break;
274 }
275 case wxCURSOR_SPRAYCAN:
276 {
277 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
278 break;
279 }
280 case wxCURSOR_PAINT_BRUSH:
281 {
282 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
283 break;
284 }
285 case wxCURSOR_POINT_LEFT:
286 {
287 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
288 break;
289 }
290 case wxCURSOR_POINT_RIGHT:
291 {
292 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
293 break;
294 }
295 case wxCURSOR_QUESTION_ARROW:
296 {
297 // refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), wxT("wxCURSOR_QARROW"), IMAGE_CURSOR, 16, 16, LR_MONOCHROME);
298 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
299 break;
300 }
301 case wxCURSOR_BLANK:
302 {
303 refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
304 break;
305 }
306 default:
307 case wxCURSOR_ARROW:
308 refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
309 break;
310 }
311 }
312
313 wxCursor::~wxCursor()
314 {
315 }
316
317 // ----------------------------------------------------------------------------
318 // Global cursor setting
319 // ----------------------------------------------------------------------------
320
321 const wxCursor *wxGetGlobalCursor()
322 {
323 return gs_globalCursor;
324 }
325
326 void wxSetCursor(const wxCursor& cursor)
327 {
328 if ( cursor.Ok() )
329 {
330 ::SetCursor(GetHcursorOf(cursor));
331
332 if ( gs_globalCursor )
333 *gs_globalCursor = cursor;
334 }
335 }
336
337