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