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