]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cursor.cpp | |
3 | // Purpose: wxCursor class | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "cursor.h" | |
14 | #endif | |
15 | ||
0e13e965 GD |
16 | #include "wx/defs.h" |
17 | ||
18 | #include "wx/app.h" | |
e9576ca5 SC |
19 | #include "wx/cursor.h" |
20 | #include "wx/icon.h" | |
c6a071d2 | 21 | #include "wx/image.h" |
c5e59178 SC |
22 | #include "wx/xpmdecod.h" |
23 | ||
76a5e5d2 | 24 | #include "wx/mac/private.h" |
e9576ca5 | 25 | |
2f1ae414 | 26 | #if !USE_SHARED_LIBRARIES |
e9576ca5 | 27 | IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) |
2f1ae414 | 28 | #endif |
e9576ca5 | 29 | |
dd05f811 SC |
30 | const short kwxCursorBullseye = 0 ; |
31 | const short kwxCursorBlank = 1 ; | |
32 | const short kwxCursorPencil = 2 ; | |
33 | const short kwxCursorMagnifier = 3 ; | |
34 | const short kwxCursorNoEntry = 4 ; | |
35 | const short kwxCursorPaintBrush = 5 ; | |
36 | const short kwxCursorPointRight = 6 ; | |
37 | const short kwxCursorPointLeft = 7 ; | |
38 | const short kwxCursorQuestionArrow = 8 ; | |
39 | const short kwxCursorRightArrow = 9 ; | |
40 | const short kwxCursorSizeNS = 10 ; | |
41 | const short kwxCursorSize = 11 ; | |
42 | const short kwxCursorSizeNESW = 12 ; | |
43 | const short kwxCursorSizeNWSE = 13 ; | |
44 | const short kwxCursorRoller = 14 ; | |
45 | const short kwxCursorLast = kwxCursorRoller ; | |
46 | ||
47 | Cursor gMacCursors[kwxCursorLast+1] = | |
48 | { | |
699e27dc | 49 | |
dd05f811 | 50 | { |
699e27dc RN |
51 | {0x0000, 0x03E0, 0x0630, 0x0808, 0x1004, 0x31C6, 0x2362, 0x2222, |
52 | 0x2362, 0x31C6, 0x1004, 0x0808, 0x0630, 0x03E0, 0x0000, 0x0000}, | |
53 | {0x0000, 0x03E0, 0x07F0, 0x0FF8, 0x1FFC, 0x3FFE, 0x3FFE, 0x3FFE, | |
54 | 0x3FFE, 0x3FFE, 0x1FFC, 0x0FF8, 0x07F0, 0x03E0, 0x0000, 0x0000}, | |
55 | {0x0007, 0x0008} | |
dd05f811 SC |
56 | }, |
57 | ||
58 | { | |
699e27dc RN |
59 | {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
60 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, | |
61 | {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | |
62 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, | |
63 | {0x0000, 0x0000} | |
dd05f811 SC |
64 | }, |
65 | ||
66 | { | |
699e27dc RN |
67 | {0x00F0, 0x0088, 0x0108, 0x0190, 0x0270, 0x0220, 0x0440, 0x0440, |
68 | 0x0880, 0x0880, 0x1100, 0x1E00, 0x1C00, 0x1800, 0x1000, 0x0000}, | |
69 | {0x00F0, 0x00F8, 0x01F8, 0x01F0, 0x03F0, 0x03E0, 0x07C0, 0x07C0, | |
70 | 0x0F80, 0x0F80, 0x1F00, 0x1E00, 0x1C00, 0x1800, 0x1000, 0x0000}, | |
71 | {0x000E, 0x0003} | |
dd05f811 SC |
72 | }, |
73 | ||
74 | { | |
699e27dc RN |
75 | {0x0000, 0x1E00, 0x2100, 0x4080, 0x4080, 0x4080, 0x4080, 0x2180, |
76 | 0x1FC0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x0006, 0x0000}, | |
77 | {0x3F00, 0x7F80, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0x7FC0, | |
78 | 0x3FE0, 0x1FF0, 0x00F8, 0x007C, 0x003E, 0x001F, 0x000F, 0x0007}, | |
79 | {0x0004, 0x0004} | |
dd05f811 SC |
80 | }, |
81 | ||
82 | { | |
699e27dc RN |
83 | {0x0000, 0x07E0, 0x1FF0, 0x3838, 0x3C0C, 0x6E0E, 0x6706, 0x6386, |
84 | 0x61C6, 0x60E6, 0x7076, 0x303C, 0x1C1C, 0x0FF8, 0x07E0, 0x0000}, | |
85 | {0x0540, 0x0FF0, 0x3FF8, 0x3C3C, 0x7E0E, 0xFF0F, 0x6F86, 0xE7C7, | |
86 | 0x63E6, 0xE1F7, 0x70FE, 0x707E, 0x3C3C, 0x1FFC, 0x0FF0, 0x0540}, | |
87 | {0x0007, 0x0007} | |
dd05f811 SC |
88 | }, |
89 | ||
90 | { | |
699e27dc RN |
91 | {0x0000, 0x0380, 0x0380, 0x0380, 0x0380, 0x0380, 0x0380, 0x0FE0, |
92 | 0x1FF0, 0x1FF0, 0x0000, 0x1FF0, 0x1FF0, 0x1550, 0x1550, 0x1550}, | |
93 | {0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x0FE0, 0x1FF0, | |
94 | 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8}, | |
95 | {0x000B, 0x0007} | |
dd05f811 SC |
96 | }, |
97 | ||
98 | { | |
699e27dc RN |
99 | {0x00C0, 0x0140, 0x0640, 0x08C0, 0x3180, 0x47FE, 0x8001, 0x8001, |
100 | 0x81FE, 0x8040, 0x01C0, 0x0040, 0x03C0, 0xC080, 0x3F80, 0x0000}, | |
101 | {0x00C0, 0x01C0, 0x07C0, 0x0FC0, 0x3F80, 0x7FFE, 0xFFFF, 0xFFFF, | |
102 | 0xFFFE, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFF80, 0x3F80, 0x0000}, | |
103 | {0x0006, 0x000F} | |
dd05f811 SC |
104 | }, |
105 | ||
106 | { | |
699e27dc RN |
107 | {0x0100, 0x0280, 0x0260, 0x0310, 0x018C, 0x7FE3, 0x8000, 0x8000, |
108 | 0x7F80, 0x0200, 0x0380, 0x0200, 0x03C0, 0x0107, 0x01F8, 0x0000}, | |
109 | {0x0100, 0x0380, 0x03E0, 0x03F0, 0x01FC, 0x7FFF, 0xFFFF, 0xFFFF, | |
110 | 0xFFFF, 0x03FF, 0x03FF, 0x03FF, 0x03FF, 0x01FF, 0x01F8, 0x0000}, | |
111 | {0x0006, 0x0000} | |
dd05f811 SC |
112 | }, |
113 | ||
114 | { | |
699e27dc RN |
115 | {0x0000, 0x4078, 0x60FC, 0x71CE, 0x7986, 0x7C06, 0x7E0E, 0x7F1C, |
116 | 0x7FB8, 0x7C30, 0x6C30, 0x4600, 0x0630, 0x0330, 0x0300, 0x0000}, | |
117 | {0xC078, 0xE0FC, 0xF1FE, 0xFBFF, 0xFFCF, 0xFF8F, 0xFF1F, 0xFFBE, | |
118 | 0xFFFC, 0xFE78, 0xFF78, 0xEFF8, 0xCFF8, 0x87F8, 0x07F8, 0x0300}, | |
119 | {0x0001, 0x0001} | |
dd05f811 SC |
120 | }, |
121 | ||
122 | { | |
699e27dc RN |
123 | {0x0000, 0x0002, 0x0006, 0x000E, 0x001E, 0x003E, 0x007E, 0x00FE, |
124 | 0x01FE, 0x003E, 0x0036, 0x0062, 0x0060, 0x00C0, 0x00C0, 0x0000}, | |
125 | {0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, | |
126 | 0x03FF, 0x07FF, 0x007F, 0x00F7, 0x00F3, 0x01E1, 0x01E0, 0x01C0}, | |
127 | {0x0001, 0x000E} | |
dd05f811 SC |
128 | }, |
129 | ||
130 | { | |
699e27dc RN |
131 | {0x0000, 0x0080, 0x01C0, 0x03E0, 0x0080, 0x0080, 0x0080, 0x1FFC, |
132 | 0x1FFC, 0x0080, 0x0080, 0x0080, 0x03E0, 0x01C0, 0x0080, 0x0000}, | |
133 | {0x0080, 0x01C0, 0x03E0, 0x07F0, 0x0FF8, 0x01C0, 0x3FFE, 0x3FFE, | |
134 | 0x3FFE, 0x3FFE, 0x01C0, 0x0FF8, 0x07F0, 0x03E0, 0x01C0, 0x0080}, | |
135 | {0x0007, 0x0008} | |
dd05f811 SC |
136 | }, |
137 | ||
138 | { | |
699e27dc RN |
139 | {0x0000, 0x0080, 0x01C0, 0x03E0, 0x0080, 0x0888, 0x188C, 0x3FFE, |
140 | 0x188C, 0x0888, 0x0080, 0x03E0, 0x01C0, 0x0080, 0x0000, 0x0000}, | |
141 | {0x0080, 0x01C0, 0x03E0, 0x07F0, 0x0BE8, 0x1DDC, 0x3FFE, 0x7FFF, | |
142 | 0x3FFE, 0x1DDC, 0x0BE8, 0x07F0, 0x03E0, 0x01C0, 0x0080, 0x0000}, | |
143 | {0x0007, 0x0008} | |
dd05f811 SC |
144 | }, |
145 | ||
146 | { | |
699e27dc RN |
147 | {0x0000, 0x001E, 0x000E, 0x060E, 0x0712, 0x03A0, 0x01C0, 0x00E0, |
148 | 0x0170, 0x1238, 0x1C18, 0x1C00, 0x1E00, 0x0000, 0x0000, 0x0000}, | |
149 | {0x007F, 0x003F, 0x0E1F, 0x0F0F, 0x0F97, 0x07E3, 0x03E1, 0x21F0, | |
150 | 0x31F8, 0x3A7C, 0x3C3C, 0x3E1C, 0x3F00, 0x3F80, 0x0000, 0x0000}, | |
151 | {0x0006, 0x0009} | |
dd05f811 SC |
152 | }, |
153 | ||
154 | { | |
699e27dc RN |
155 | {0x0000, 0x7800, 0x7000, 0x7060, 0x48E0, 0x05C0, 0x0380, 0x0700, |
156 | 0x0E80, 0x1C48, 0x1838, 0x0038, 0x0078, 0x0000, 0x0000, 0x0000}, | |
157 | {0xFE00, 0xFC00, 0xF870, 0xF0F0, 0xE9F0, 0xC7E0, 0x87C0, 0x0F84, | |
158 | 0x1F8C, 0x3E5C, 0x3C3C, 0x387C, 0x00FC, 0x01FC, 0x0000, 0x0000}, | |
159 | {0x0006, 0x0006} | |
dd05f811 SC |
160 | }, |
161 | ||
162 | { | |
699e27dc RN |
163 | {0x0006, 0x000E, 0x001C, 0x0018, 0x0020, 0x0040, 0x00F8, 0x0004, |
164 | 0x1FF4, 0x200C, 0x2AA8, 0x1FF0, 0x1F80, 0x3800, 0x6000, 0x8000}, | |
165 | {0x000F, 0x001F, 0x003E, 0x007C, 0x0070, 0x00E0, 0x01FC, 0x3FF6, | |
166 | 0x7FF6, 0x7FFE, 0x7FFC, 0x7FF8, 0x3FF0, 0x7FC0, 0xF800, 0xE000}, | |
167 | {0x000A, 0x0006} | |
168 | }, | |
169 | ||
170 | } ; | |
c6a071d2 | 171 | |
e40298d5 | 172 | wxCursor gMacCurrentCursor ; |
519cb848 | 173 | |
dd05f811 SC |
174 | CursHandle wxGetStockCursor( int number ) |
175 | { | |
176 | wxASSERT_MSG( number >= 0 && number <=kwxCursorLast , wxT("invalid stock cursor id") ) ; | |
177 | CursHandle c = (CursHandle) NewHandle( sizeof(Cursor) ) ; | |
178 | memcpy( *c , &gMacCursors[number] , sizeof( Cursor ) ) ; | |
179 | return c ; | |
180 | } | |
181 | ||
e9576ca5 SC |
182 | wxCursorRefData::wxCursorRefData() |
183 | { | |
c6a071d2 SC |
184 | m_width = 16; |
185 | m_height = 16; | |
519cb848 | 186 | m_hCursor = NULL ; |
c6a071d2 SC |
187 | m_disposeHandle = false ; |
188 | m_releaseHandle = false ; | |
189 | m_isColorCursor = false ; | |
190 | m_themeCursor = -1 ; | |
e9576ca5 SC |
191 | } |
192 | ||
193 | wxCursorRefData::~wxCursorRefData() | |
194 | { | |
c6a071d2 SC |
195 | if ( m_isColorCursor ) |
196 | { | |
197 | ::DisposeCCursor( (CCrsrHandle) m_hCursor ) ; | |
198 | } | |
e40298d5 JS |
199 | else if ( m_disposeHandle ) |
200 | { | |
201 | ::DisposeHandle( (Handle ) m_hCursor ) ; | |
202 | } | |
203 | else if ( m_releaseHandle ) | |
204 | { | |
205 | // we don't release the resource since it may already | |
206 | // be in use again | |
207 | } | |
e9576ca5 SC |
208 | } |
209 | ||
210 | // Cursors | |
211 | wxCursor::wxCursor() | |
212 | { | |
213 | } | |
214 | ||
215 | wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height), | |
216 | int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[]) | |
217 | { | |
218 | } | |
219 | ||
c6a071d2 SC |
220 | wxCursor::wxCursor( const wxImage &image ) |
221 | { | |
ce72eadb | 222 | CreateFromImage( image ) ; |
c6a071d2 SC |
223 | } |
224 | ||
c5e59178 SC |
225 | wxCursor::wxCursor(const char **bits) |
226 | { | |
227 | (void) CreateFromXpm(bits); | |
228 | } | |
229 | ||
230 | wxCursor::wxCursor(char **bits) | |
231 | { | |
232 | (void) CreateFromXpm((const char **)bits); | |
233 | } | |
234 | ||
235 | bool wxCursor::CreateFromXpm(const char **bits) | |
236 | { | |
237 | wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid cursor data") ) | |
238 | wxXPMDecoder decoder; | |
239 | wxImage img = decoder.ReadData(bits); | |
240 | wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid cursor data") ) | |
241 | CreateFromImage( img ) ; | |
242 | return TRUE; | |
243 | } | |
244 | ||
245 | short GetCTabIndex( CTabHandle colors , RGBColor *col ) | |
246 | { | |
247 | short retval = 0 ; | |
248 | unsigned long bestdiff = 0xFFFF ; | |
249 | for ( int i = 0 ; i < (**colors).ctSize ; ++i ) | |
250 | { | |
251 | unsigned long diff = abs(col->red - (**colors).ctTable[i].rgb.red ) + | |
252 | abs(col->green - (**colors).ctTable[i].rgb.green ) + | |
253 | abs(col->blue - (**colors).ctTable[i].rgb.blue ) ; | |
254 | if ( diff < bestdiff ) | |
255 | { | |
256 | bestdiff = diff ; | |
257 | retval = (**colors).ctTable[i].value ; | |
258 | } | |
259 | } | |
260 | return retval ; | |
261 | } | |
262 | ||
ce72eadb | 263 | void wxCursor::CreateFromImage(const wxImage & image) |
c6a071d2 SC |
264 | { |
265 | m_refData = new wxCursorRefData; | |
266 | ||
267 | wxImage image16 = image.Scale(16,16) ; | |
e40298d5 | 268 | unsigned char * rgbBits = image16.GetData(); |
c6a071d2 | 269 | |
e40298d5 | 270 | |
c6a071d2 SC |
271 | int w = image16.GetWidth() ; |
272 | int h = image16.GetHeight() ; | |
273 | bool bHasMask = image16.HasMask() ; | |
274 | ||
1a81dc12 MB |
275 | int hotSpotX = image16.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X); |
276 | int hotSpotY = image16.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y); | |
c6a071d2 SC |
277 | if (hotSpotX < 0 || hotSpotX >= w) |
278 | hotSpotX = 0; | |
279 | if (hotSpotY < 0 || hotSpotY >= h) | |
280 | hotSpotY = 0; | |
281 | ||
c5e59178 SC |
282 | PixMapHandle pm = (PixMapHandle) NewHandleClear( sizeof (PixMap)) ; |
283 | short extent = 16 ; | |
284 | short bytesPerPixel = 1 ; | |
285 | short depth = 8 ; | |
286 | Rect bounds = { 0 , 0 , extent , extent } ; | |
287 | CCrsrHandle ch = (CCrsrHandle) NewHandleClear ( sizeof( CCrsr ) ) ; | |
288 | CTabHandle newColors = GetCTable( 8 ) ; | |
289 | HandToHand((Handle *) &newColors); | |
290 | // set the values to the indices | |
291 | for ( int i = 0 ; i < (**newColors).ctSize ; ++i ) | |
292 | { | |
293 | (**newColors).ctTable[i].value = i ; | |
294 | } | |
295 | HLock( (Handle) ch) ; | |
296 | (**ch).crsrType = 0x8001 ; // color cursors | |
297 | (**ch).crsrMap = pm ; | |
298 | short bytesPerRow = bytesPerPixel * extent ; | |
299 | ||
300 | (**pm).baseAddr = 0; | |
301 | (**pm).rowBytes = bytesPerRow | 0x8000; | |
302 | (**pm).bounds = bounds; | |
303 | (**pm).pmVersion = 0; | |
304 | (**pm).packType = 0; | |
305 | (**pm).packSize = 0; | |
306 | (**pm).hRes = 0x00480000; /* 72 DPI default res */ | |
307 | (**pm).vRes = 0x00480000; /* 72 DPI default res */ | |
308 | (**pm).pixelSize = depth; | |
309 | (**pm).pixelType = 0; | |
310 | (**pm).cmpCount = 1; | |
311 | (**pm).cmpSize = depth; | |
312 | (**pm).pmTable = newColors; | |
313 | ||
314 | (**ch).crsrData = NewHandleClear( extent * bytesPerRow ) ; | |
315 | (**ch).crsrXData = NULL ; | |
316 | (**ch).crsrXValid = 0; | |
317 | (**ch).crsrXHandle = NULL; | |
318 | ||
319 | (**ch).crsrHotSpot.h = hotSpotX ; | |
320 | (**ch).crsrHotSpot.v = hotSpotY ; | |
321 | (**ch).crsrXTable = NULL ; | |
322 | (**ch).crsrID = GetCTSeed() ; | |
323 | ||
324 | memset( (**ch).crsr1Data , 0 , sizeof( Bits16 ) ) ; | |
325 | memset( (**ch).crsrMask , 0 , sizeof( Bits16 ) ) ; | |
326 | ||
327 | unsigned char mr = image16.GetMaskRed() ; | |
328 | unsigned char mg = image16.GetMaskGreen() ; | |
329 | unsigned char mb = image16.GetMaskBlue() ; | |
330 | for ( int y = 0 ; y < h ; ++y ) | |
331 | { | |
332 | short rowbits = 0 ; | |
333 | short maskbits = 0 ; | |
334 | ||
335 | for ( int x = 0 ; x < w ; ++x ) | |
336 | { | |
337 | long pos = (y * w + x) * 3; | |
338 | ||
339 | unsigned char r = rgbBits[pos] ; | |
340 | unsigned char g = rgbBits[pos+1] ; | |
341 | unsigned char b = rgbBits[pos+2] ; | |
342 | RGBColor col = { 0xFFFF ,0xFFFF, 0xFFFF } ; | |
343 | ||
344 | if ( bHasMask && r==mr && g==mg && b==mb ) | |
345 | { | |
346 | // masked area, does not appear anywhere | |
347 | } | |
348 | else | |
349 | { | |
350 | if ( (int)r + (int)g + (int)b < 0x0200 ) | |
351 | { | |
352 | rowbits |= ( 1 << (15-x) ) ; | |
353 | } | |
354 | maskbits |= ( 1 << (15-x) ) ; | |
355 | ||
356 | col = *((RGBColor*) wxColor( r , g , b ).GetPixel()) ; | |
357 | } | |
358 | *((*(**ch).crsrData) + y * bytesPerRow + x) = | |
359 | GetCTabIndex( newColors , &col) ; | |
360 | } | |
361 | (**ch).crsr1Data[y] = rowbits ; | |
362 | (**ch).crsrMask[y] = maskbits ; | |
363 | } | |
364 | if ( !bHasMask ) | |
365 | { | |
366 | memcpy( (**ch).crsrMask , (**ch).crsr1Data , sizeof( Bits16) ) ; | |
367 | } | |
368 | ||
369 | HUnlock((Handle) ch) ; | |
370 | M_CURSORDATA->m_hCursor = ch ; | |
371 | M_CURSORDATA->m_isColorCursor = true ; | |
c6a071d2 SC |
372 | } |
373 | ||
e9576ca5 SC |
374 | wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY) |
375 | { | |
376 | m_refData = new wxCursorRefData; | |
c6a071d2 SC |
377 | if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE ) |
378 | { | |
e40298d5 | 379 | Str255 theName ; |
427ff662 | 380 | wxMacStringToPascal( cursor_file , theName ) ; |
e40298d5 | 381 | |
e40298d5 JS |
382 | Handle resHandle = ::GetNamedResource( 'crsr' , theName ) ; |
383 | if ( resHandle ) | |
384 | { | |
385 | short theId = -1 ; | |
386 | OSType theType ; | |
387 | GetResInfo( resHandle , &theId , &theType , theName ) ; | |
388 | ReleaseResource( resHandle ) ; | |
389 | M_CURSORDATA->m_hCursor = GetCCursor( theId ) ; | |
390 | if ( M_CURSORDATA->m_hCursor ) | |
391 | M_CURSORDATA->m_isColorCursor = true ; | |
392 | } | |
393 | else | |
394 | { | |
395 | Handle resHandle = ::GetNamedResource( 'CURS' , theName ) ; | |
396 | if ( resHandle ) | |
397 | { | |
398 | short theId = -1 ; | |
399 | OSType theType ; | |
400 | GetResInfo( resHandle , &theId , &theType , theName ) ; | |
401 | ReleaseResource( resHandle ) ; | |
402 | M_CURSORDATA->m_hCursor = GetCursor( theId ) ; | |
403 | if ( M_CURSORDATA->m_hCursor ) | |
404 | M_CURSORDATA->m_releaseHandle = true ; | |
405 | } | |
c6a071d2 SC |
406 | } |
407 | } | |
408 | else | |
409 | { | |
410 | wxImage image ; | |
411 | image.LoadFile( cursor_file , flags ) ; | |
412 | if( image.Ok() ) | |
413 | { | |
1a81dc12 MB |
414 | image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X,hotSpotX ) ; |
415 | image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y,hotSpotY ) ; | |
c6a071d2 | 416 | delete m_refData ; |
ce72eadb | 417 | CreateFromImage(image) ; |
c6a071d2 SC |
418 | } |
419 | } | |
e9576ca5 SC |
420 | } |
421 | ||
422 | // Cursors by stock number | |
423 | wxCursor::wxCursor(int cursor_type) | |
424 | { | |
e40298d5 JS |
425 | m_refData = new wxCursorRefData; |
426 | ||
427 | switch (cursor_type) | |
428 | { | |
c5e59178 SC |
429 | case wxCURSOR_COPY_ARROW: |
430 | M_CURSORDATA->m_themeCursor = kThemeCopyArrowCursor ; | |
431 | break; | |
e9576ca5 | 432 | case wxCURSOR_WAIT: |
e40298d5 JS |
433 | M_CURSORDATA->m_themeCursor = kThemeWatchCursor ; |
434 | break; | |
e9576ca5 | 435 | case wxCURSOR_IBEAM: |
e40298d5 JS |
436 | M_CURSORDATA->m_themeCursor = kThemeIBeamCursor ; |
437 | break; | |
e9576ca5 | 438 | case wxCURSOR_CROSS: |
e40298d5 JS |
439 | M_CURSORDATA->m_themeCursor = kThemeCrossCursor; |
440 | break; | |
e9576ca5 | 441 | case wxCURSOR_SIZENWSE: |
e40298d5 | 442 | { |
dd05f811 | 443 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSizeNWSE); |
e40298d5 JS |
444 | } |
445 | break; | |
e9576ca5 | 446 | case wxCURSOR_SIZENESW: |
e40298d5 | 447 | { |
dd05f811 | 448 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSizeNESW); |
e40298d5 JS |
449 | } |
450 | break; | |
e9576ca5 | 451 | case wxCURSOR_SIZEWE: |
e40298d5 JS |
452 | { |
453 | M_CURSORDATA->m_themeCursor = kThemeResizeLeftRightCursor; | |
454 | } | |
455 | break; | |
e9576ca5 | 456 | case wxCURSOR_SIZENS: |
e40298d5 | 457 | { |
dd05f811 | 458 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSizeNS); |
e40298d5 JS |
459 | } |
460 | break; | |
461 | case wxCURSOR_SIZING: | |
462 | { | |
dd05f811 | 463 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSize); |
e40298d5 JS |
464 | } |
465 | break; | |
e9576ca5 | 466 | case wxCURSOR_HAND: |
e40298d5 JS |
467 | { |
468 | M_CURSORDATA->m_themeCursor = kThemePointingHandCursor; | |
469 | } | |
470 | break; | |
e9576ca5 | 471 | case wxCURSOR_BULLSEYE: |
fe3fcb05 | 472 | { |
dd05f811 | 473 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorBullseye); |
fe3fcb05 SC |
474 | } |
475 | break; | |
e9576ca5 | 476 | case wxCURSOR_PENCIL: |
fe3fcb05 | 477 | { |
dd05f811 | 478 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorPencil); |
fe3fcb05 SC |
479 | } |
480 | break; | |
e9576ca5 | 481 | case wxCURSOR_MAGNIFIER: |
fe3fcb05 | 482 | { |
dd05f811 | 483 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorMagnifier); |
fe3fcb05 SC |
484 | } |
485 | break; | |
e9576ca5 | 486 | case wxCURSOR_NO_ENTRY: |
fe3fcb05 | 487 | { |
dd05f811 | 488 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorNoEntry); |
fe3fcb05 SC |
489 | } |
490 | break; | |
e9576ca5 | 491 | case wxCURSOR_WATCH: |
e40298d5 JS |
492 | { |
493 | M_CURSORDATA->m_themeCursor = kThemeWatchCursor; | |
494 | break; | |
495 | } | |
e9576ca5 | 496 | case wxCURSOR_PAINT_BRUSH: |
e40298d5 | 497 | { |
dd05f811 | 498 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorPaintBrush); |
e40298d5 JS |
499 | break; |
500 | } | |
e9576ca5 | 501 | case wxCURSOR_POINT_LEFT: |
e40298d5 | 502 | { |
dd05f811 | 503 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorPointLeft); |
e40298d5 JS |
504 | break; |
505 | } | |
e9576ca5 | 506 | case wxCURSOR_POINT_RIGHT: |
e40298d5 | 507 | { |
dd05f811 | 508 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorPointRight); |
e40298d5 JS |
509 | break; |
510 | } | |
e9576ca5 | 511 | case wxCURSOR_QUESTION_ARROW: |
e40298d5 | 512 | { |
dd05f811 | 513 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorQuestionArrow); |
e40298d5 JS |
514 | break; |
515 | } | |
e9576ca5 | 516 | case wxCURSOR_BLANK: |
e40298d5 | 517 | { |
dd05f811 | 518 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorBlank); |
e40298d5 JS |
519 | break; |
520 | } | |
c6a071d2 | 521 | case wxCURSOR_RIGHT_ARROW: |
e40298d5 | 522 | { |
dd05f811 | 523 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorRightArrow); |
e40298d5 JS |
524 | break; |
525 | } | |
c6a071d2 | 526 | case wxCURSOR_SPRAYCAN: |
e40298d5 | 527 | { |
dd05f811 | 528 | M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorRoller); |
e40298d5 JS |
529 | break; |
530 | } | |
c6a071d2 | 531 | case wxCURSOR_CHAR: |
e9576ca5 | 532 | case wxCURSOR_ARROW: |
c6a071d2 SC |
533 | case wxCURSOR_LEFT_BUTTON: |
534 | case wxCURSOR_RIGHT_BUTTON: | |
535 | case wxCURSOR_MIDDLE_BUTTON: | |
e40298d5 JS |
536 | default: |
537 | M_CURSORDATA->m_themeCursor = kThemeArrowCursor ; | |
538 | break; | |
539 | } | |
540 | if ( M_CURSORDATA->m_themeCursor == -1 ) | |
541 | M_CURSORDATA->m_releaseHandle = true ; | |
519cb848 | 542 | } |
e9576ca5 | 543 | |
519cb848 SC |
544 | void wxCursor::MacInstall() const |
545 | { | |
e40298d5 JS |
546 | gMacCurrentCursor = *this ; |
547 | if ( m_refData && M_CURSORDATA->m_themeCursor != -1 ) | |
548 | { | |
549 | SetThemeCursor( M_CURSORDATA->m_themeCursor ) ; | |
550 | } | |
551 | else if ( m_refData && M_CURSORDATA->m_hCursor ) | |
552 | { | |
553 | if ( M_CURSORDATA->m_isColorCursor ) | |
554 | ::SetCCursor( (CCrsrHandle) M_CURSORDATA->m_hCursor ) ; | |
555 | else | |
556 | ::SetCursor( * (CursHandle) M_CURSORDATA->m_hCursor ) ; | |
557 | } | |
558 | else | |
559 | { | |
560 | SetThemeCursor( kThemeArrowCursor ) ; | |
561 | } | |
e9576ca5 SC |
562 | } |
563 | ||
564 | wxCursor::~wxCursor() | |
565 | { | |
566 | } | |
567 | ||
568 | // Global cursor setting | |
569 | void wxSetCursor(const wxCursor& cursor) | |
570 | { | |
e40298d5 | 571 | cursor.MacInstall() ; |
e9576ca5 SC |
572 | } |
573 | ||
574 |