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