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