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