]>
Commit | Line | Data |
---|---|---|
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 ) | |
71 | { | |
72 | if ( m_destroyCursor ) | |
73 | ::DestroyCursor((HCURSOR)m_hCursor); | |
74 | ||
75 | m_hCursor = 0; | |
76 | } | |
77 | } | |
78 | ||
79 | // ---------------------------------------------------------------------------- | |
80 | // Cursors | |
81 | // ---------------------------------------------------------------------------- | |
82 | ||
83 | wxCursor::wxCursor() | |
84 | { | |
85 | } | |
86 | ||
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)[]) | |
92 | { | |
93 | } | |
94 | ||
95 | wxCursor::wxCursor(const wxString& cursor_file, | |
96 | long flags, | |
97 | int hotSpotX, int hotSpotY) | |
98 | { | |
99 | wxCursorRefData *refData = new wxCursorRefData; | |
100 | m_refData = refData; | |
101 | ||
102 | refData->m_destroyCursor = FALSE; | |
103 | ||
104 | if (flags == wxBITMAP_TYPE_CUR_RESOURCE) | |
105 | { | |
106 | #ifdef __WIN95__ | |
107 | refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, 0); | |
108 | #else | |
109 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), cursor_file); | |
110 | #endif | |
111 | } | |
112 | else if (flags == wxBITMAP_TYPE_CUR) | |
113 | { | |
114 | #ifdef __WIN95__ | |
115 | refData->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE); | |
116 | #else | |
117 | #if wxUSE_RESOURCE_LOADING_IN_MSW | |
118 | refData->m_hCursor = (WXHCURSOR) ReadCursorFile(WXSTRINGCAST cursor_file, wxGetInstance(), &refData->m_width, &refData->m_height); | |
119 | refData->m_destroyCursor = TRUE; | |
120 | #endif | |
121 | #endif | |
122 | } | |
123 | else if (flags == wxBITMAP_TYPE_ICO) | |
124 | { | |
125 | #if wxUSE_RESOURCE_LOADING_IN_MSW | |
126 | refData->m_hCursor = (WXHCURSOR) IconToCursor(WXSTRINGCAST cursor_file, wxGetInstance(), hotSpotX, hotSpotY, &refData->m_width, &refData->m_height); | |
127 | refData->m_destroyCursor = TRUE; | |
128 | #endif | |
129 | } | |
130 | else if (flags == wxBITMAP_TYPE_BMP) | |
131 | { | |
132 | #if wxUSE_RESOURCE_LOADING_IN_MSW | |
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); | |
146 | #endif | |
147 | } | |
148 | ||
149 | #if WXWIN_COMPATIBILITY_2 | |
150 | refData->SetOk(); | |
151 | #endif // WXWIN_COMPATIBILITY_2 | |
152 | } | |
153 | ||
154 | // Cursors by stock number | |
155 | wxCursor::wxCursor(int cursor_type) | |
156 | { | |
157 | wxCursorRefData *refData = new wxCursorRefData; | |
158 | m_refData = refData; | |
159 | ||
160 | switch (cursor_type) | |
161 | { | |
162 | case wxCURSOR_WAIT: | |
163 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT); | |
164 | break; | |
165 | case wxCURSOR_IBEAM: | |
166 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM); | |
167 | break; | |
168 | case wxCURSOR_CROSS: | |
169 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS); | |
170 | break; | |
171 | case wxCURSOR_SIZENWSE: | |
172 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE); | |
173 | break; | |
174 | case wxCURSOR_SIZENESW: | |
175 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW); | |
176 | break; | |
177 | case wxCURSOR_SIZEWE: | |
178 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE); | |
179 | break; | |
180 | case wxCURSOR_SIZENS: | |
181 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS); | |
182 | break; | |
183 | case wxCURSOR_CHAR: | |
184 | { | |
185 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); | |
186 | break; | |
187 | } | |
188 | case wxCURSOR_HAND: | |
189 | { | |
190 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND")); | |
191 | break; | |
192 | } | |
193 | case wxCURSOR_BULLSEYE: | |
194 | { | |
195 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE")); | |
196 | break; | |
197 | } | |
198 | case wxCURSOR_PENCIL: | |
199 | { | |
200 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL")); | |
201 | break; | |
202 | } | |
203 | case wxCURSOR_MAGNIFIER: | |
204 | { | |
205 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER")); | |
206 | break; | |
207 | } | |
208 | case wxCURSOR_NO_ENTRY: | |
209 | { | |
210 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY")); | |
211 | break; | |
212 | } | |
213 | case wxCURSOR_LEFT_BUTTON: | |
214 | { | |
215 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); | |
216 | break; | |
217 | } | |
218 | case wxCURSOR_RIGHT_BUTTON: | |
219 | { | |
220 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); | |
221 | break; | |
222 | } | |
223 | case wxCURSOR_MIDDLE_BUTTON: | |
224 | { | |
225 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); | |
226 | break; | |
227 | } | |
228 | case wxCURSOR_SIZING: | |
229 | { | |
230 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING")); | |
231 | break; | |
232 | } | |
233 | case wxCURSOR_WATCH: | |
234 | { | |
235 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH")); | |
236 | break; | |
237 | } | |
238 | case wxCURSOR_SPRAYCAN: | |
239 | { | |
240 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER")); | |
241 | break; | |
242 | } | |
243 | case wxCURSOR_PAINT_BRUSH: | |
244 | { | |
245 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH")); | |
246 | break; | |
247 | } | |
248 | case wxCURSOR_POINT_LEFT: | |
249 | { | |
250 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT")); | |
251 | break; | |
252 | } | |
253 | case wxCURSOR_POINT_RIGHT: | |
254 | { | |
255 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT")); | |
256 | break; | |
257 | } | |
258 | case wxCURSOR_QUESTION_ARROW: | |
259 | { | |
260 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW")); | |
261 | break; | |
262 | } | |
263 | case wxCURSOR_BLANK: | |
264 | { | |
265 | refData->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK")); | |
266 | break; | |
267 | } | |
268 | default: | |
269 | case wxCURSOR_ARROW: | |
270 | refData->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW); | |
271 | break; | |
272 | } | |
273 | } | |
274 | ||
275 | wxCursor::~wxCursor() | |
276 | { | |
277 | } | |
278 | ||
279 | // ---------------------------------------------------------------------------- | |
280 | // Global cursor setting | |
281 | // ---------------------------------------------------------------------------- | |
282 | ||
283 | void wxSetCursor(const wxCursor& cursor) | |
284 | { | |
285 | extern wxCursor *g_globalCursor; | |
286 | ||
287 | if ( cursor.Ok() && cursor.GetHCURSOR() ) | |
288 | { | |
289 | ::SetCursor((HCURSOR) cursor.GetHCURSOR()); | |
290 | ||
291 | if ( g_globalCursor ) | |
292 | (*g_globalCursor) = cursor; | |
293 | } | |
294 | } | |
295 | ||
296 |