]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/cursor.cpp
Don't use DDEExec registry key in wxMSW wxExecute() if it's empty.
[wxWidgets.git] / src / osx / carbon / cursor.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/cursor.cpp
3 // Purpose: wxCursor class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #include "wx/cursor.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/app.h"
17 #include "wx/icon.h"
18 #include "wx/image.h"
19 #endif // WX_PRECOMP
20
21 #include "wx/xpmdecod.h"
22
23 #include "wx/osx/private.h"
24
25
26 IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxGDIObject)
27
28
29 class WXDLLEXPORT wxCursorRefData: public wxGDIRefData
30 {
31 public:
32 wxCursorRefData();
33 wxCursorRefData(const wxCursorRefData& cursor);
34 virtual ~wxCursorRefData();
35
36 virtual bool IsOk() const
37 {
38 #if wxOSX_USE_COCOA_OR_CARBON
39 if ( m_hCursor != NULL )
40 return true;
41 #if wxOSX_USE_CARBON
42 if ( m_themeCursor != -1 )
43 return true;
44 #endif
45
46 return false;
47 #else
48 // in order to avoid asserts, always claim to have a valid cursor
49 return true;
50 #endif
51 }
52
53 protected:
54 #if wxOSX_USE_COCOA
55 WX_NSCursor m_hCursor;
56 #elif wxOSX_USE_CARBON
57 WXHCURSOR m_hCursor;
58 bool m_disposeHandle;
59 bool m_releaseHandle;
60 bool m_isColorCursor;
61 long m_themeCursor;
62 #elif wxOSX_USE_IPHONE
63 void* m_hCursor;
64 #endif
65
66 friend class wxCursor;
67
68 wxDECLARE_NO_ASSIGN_CLASS(wxCursorRefData);
69 };
70
71 #define M_CURSORDATA static_cast<wxCursorRefData*>(m_refData)
72
73 #if wxOSX_USE_COCOA_OR_CARBON
74
75 ClassicCursor gMacCursors[kwxCursorLast+1] =
76 {
77
78 {
79 {0x0000, 0x03E0, 0x0630, 0x0808, 0x1004, 0x31C6, 0x2362, 0x2222,
80 0x2362, 0x31C6, 0x1004, 0x0808, 0x0630, 0x03E0, 0x0000, 0x0000},
81 {0x0000, 0x03E0, 0x07F0, 0x0FF8, 0x1FFC, 0x3FFE, 0x3FFE, 0x3FFE,
82 0x3FFE, 0x3FFE, 0x1FFC, 0x0FF8, 0x07F0, 0x03E0, 0x0000, 0x0000},
83 {0x0007, 0x0008}
84 },
85
86 {
87 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
88 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
89 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
90 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
91 {0x0000, 0x0000}
92 },
93
94 {
95 {0x00F0, 0x0088, 0x0108, 0x0190, 0x0270, 0x0220, 0x0440, 0x0440,
96 0x0880, 0x0880, 0x1100, 0x1E00, 0x1C00, 0x1800, 0x1000, 0x0000},
97 {0x00F0, 0x00F8, 0x01F8, 0x01F0, 0x03F0, 0x03E0, 0x07C0, 0x07C0,
98 0x0F80, 0x0F80, 0x1F00, 0x1E00, 0x1C00, 0x1800, 0x1000, 0x0000},
99 {0x000E, 0x0003}
100 },
101
102 {
103 {0x0000, 0x1E00, 0x2100, 0x4080, 0x4080, 0x4080, 0x4080, 0x2180,
104 0x1FC0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x0006, 0x0000},
105 {0x3F00, 0x7F80, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0x7FC0,
106 0x3FE0, 0x1FF0, 0x00F8, 0x007C, 0x003E, 0x001F, 0x000F, 0x0007},
107 {0x0004, 0x0004}
108 },
109
110 {
111 {0x0000, 0x07E0, 0x1FF0, 0x3838, 0x3C0C, 0x6E0E, 0x6706, 0x6386,
112 0x61C6, 0x60E6, 0x7076, 0x303C, 0x1C1C, 0x0FF8, 0x07E0, 0x0000},
113 {0x0540, 0x0FF0, 0x3FF8, 0x3C3C, 0x7E0E, 0xFF0F, 0x6F86, 0xE7C7,
114 0x63E6, 0xE1F7, 0x70FE, 0x707E, 0x3C3C, 0x1FFC, 0x0FF0, 0x0540},
115 {0x0007, 0x0007}
116 },
117
118 {
119 {0x0000, 0x0380, 0x0380, 0x0380, 0x0380, 0x0380, 0x0380, 0x0FE0,
120 0x1FF0, 0x1FF0, 0x0000, 0x1FF0, 0x1FF0, 0x1550, 0x1550, 0x1550},
121 {0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x0FE0, 0x1FF0,
122 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8},
123 {0x000B, 0x0007}
124 },
125
126 {
127 {0x00C0, 0x0140, 0x0640, 0x08C0, 0x3180, 0x47FE, 0x8001, 0x8001,
128 0x81FE, 0x8040, 0x01C0, 0x0040, 0x03C0, 0xC080, 0x3F80, 0x0000},
129 {0x00C0, 0x01C0, 0x07C0, 0x0FC0, 0x3F80, 0x7FFE, 0xFFFF, 0xFFFF,
130 0xFFFE, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFF80, 0x3F80, 0x0000},
131 {0x0006, 0x000F}
132 },
133
134 {
135 {0x0100, 0x0280, 0x0260, 0x0310, 0x018C, 0x7FE3, 0x8000, 0x8000,
136 0x7F80, 0x0200, 0x0380, 0x0200, 0x03C0, 0x0107, 0x01F8, 0x0000},
137 {0x0100, 0x0380, 0x03E0, 0x03F0, 0x01FC, 0x7FFF, 0xFFFF, 0xFFFF,
138 0xFFFF, 0x03FF, 0x03FF, 0x03FF, 0x03FF, 0x01FF, 0x01F8, 0x0000},
139 {0x0006, 0x0000}
140 },
141
142 {
143 {0x0000, 0x4078, 0x60FC, 0x71CE, 0x7986, 0x7C06, 0x7E0E, 0x7F1C,
144 0x7FB8, 0x7C30, 0x6C30, 0x4600, 0x0630, 0x0330, 0x0300, 0x0000},
145 {0xC078, 0xE0FC, 0xF1FE, 0xFBFF, 0xFFCF, 0xFF8F, 0xFF1F, 0xFFBE,
146 0xFFFC, 0xFE78, 0xFF78, 0xEFF8, 0xCFF8, 0x87F8, 0x07F8, 0x0300},
147 {0x0001, 0x0001}
148 },
149
150 {
151 {0x0000, 0x0002, 0x0006, 0x000E, 0x001E, 0x003E, 0x007E, 0x00FE,
152 0x01FE, 0x003E, 0x0036, 0x0062, 0x0060, 0x00C0, 0x00C0, 0x0000},
153 {0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF,
154 0x03FF, 0x07FF, 0x007F, 0x00F7, 0x00F3, 0x01E1, 0x01E0, 0x01C0},
155 {0x0001, 0x000E}
156 },
157
158 {
159 {0x0000, 0x0080, 0x01C0, 0x03E0, 0x0080, 0x0080, 0x0080, 0x1FFC,
160 0x1FFC, 0x0080, 0x0080, 0x0080, 0x03E0, 0x01C0, 0x0080, 0x0000},
161 {0x0080, 0x01C0, 0x03E0, 0x07F0, 0x0FF8, 0x01C0, 0x3FFE, 0x3FFE,
162 0x3FFE, 0x3FFE, 0x01C0, 0x0FF8, 0x07F0, 0x03E0, 0x01C0, 0x0080},
163 {0x0007, 0x0008}
164 },
165
166 {
167 {0x0000, 0x0080, 0x01C0, 0x03E0, 0x0080, 0x0888, 0x188C, 0x3FFE,
168 0x188C, 0x0888, 0x0080, 0x03E0, 0x01C0, 0x0080, 0x0000, 0x0000},
169 {0x0080, 0x01C0, 0x03E0, 0x07F0, 0x0BE8, 0x1DDC, 0x3FFE, 0x7FFF,
170 0x3FFE, 0x1DDC, 0x0BE8, 0x07F0, 0x03E0, 0x01C0, 0x0080, 0x0000},
171 {0x0007, 0x0008}
172 },
173
174 {
175 {0x0000, 0x001E, 0x000E, 0x060E, 0x0712, 0x03A0, 0x01C0, 0x00E0,
176 0x0170, 0x1238, 0x1C18, 0x1C00, 0x1E00, 0x0000, 0x0000, 0x0000},
177 {0x007F, 0x003F, 0x0E1F, 0x0F0F, 0x0F97, 0x07E3, 0x03E1, 0x21F0,
178 0x31F8, 0x3A7C, 0x3C3C, 0x3E1C, 0x3F00, 0x3F80, 0x0000, 0x0000},
179 {0x0006, 0x0009}
180 },
181
182 {
183 {0x0000, 0x7800, 0x7000, 0x7060, 0x48E0, 0x05C0, 0x0380, 0x0700,
184 0x0E80, 0x1C48, 0x1838, 0x0038, 0x0078, 0x0000, 0x0000, 0x0000},
185 {0xFE00, 0xFC00, 0xF870, 0xF0F0, 0xE9F0, 0xC7E0, 0x87C0, 0x0F84,
186 0x1F8C, 0x3E5C, 0x3C3C, 0x387C, 0x00FC, 0x01FC, 0x0000, 0x0000},
187 {0x0006, 0x0006}
188 },
189
190 {
191 {0x0006, 0x000E, 0x001C, 0x0018, 0x0020, 0x0040, 0x00F8, 0x0004,
192 0x1FF4, 0x200C, 0x2AA8, 0x1FF0, 0x1F80, 0x3800, 0x6000, 0x8000},
193 {0x000F, 0x001F, 0x003E, 0x007C, 0x0070, 0x00E0, 0x01FC, 0x3FF6,
194 0x7FF6, 0x7FFE, 0x7FFC, 0x7FF8, 0x3FF0, 0x7FC0, 0xF800, 0xE000},
195 {0x000A, 0x0006}
196 },
197
198 {
199 {0x07E0, 0x07E0, 0x07E0, 0x07E0, 0x0810, 0x1088, 0x1088, 0x1088,
200 0x1388, 0x1008, 0x1008, 0x0810, 0x07E0, 0x07E0, 0x07E0, 0x07E0},
201 {0x07E0, 0x07E0, 0x07E0, 0x07E0, 0x0FF0, 0x1FF8, 0x1FF8, 0x1FF8,
202 0x1FF8, 0x1FF8, 0x1FF8, 0x0FF0, 0x07E0, 0x07E0, 0x07E0, 0x07E0},
203 {0x0008, 0x0008}
204 },
205
206 };
207
208 #endif
209
210 wxCursor gMacCurrentCursor ;
211
212 #if wxOSX_USE_CARBON
213 CursHandle wxGetStockCursor( int number )
214 {
215 wxASSERT_MSG( number >= 0 && number <=kwxCursorLast , wxT("invalid stock cursor id") ) ;
216 CursHandle c = (CursHandle) NewHandle( sizeof(Cursor) ) ;
217 memcpy( *c, &gMacCursors[number], sizeof(Cursor) ) ;
218
219 #ifndef WORDS_BIGENDIAN
220 short *sptr = (short*) *c ;
221 for ( int i = 0 ; i < 2 * 16 /* image and mask */ ; ++i, ++sptr )
222 {
223 *sptr = CFSwapInt16( *sptr ) ;
224 }
225 #endif
226 return c ;
227 }
228 #endif
229
230 wxCursorRefData::wxCursorRefData()
231 {
232 m_hCursor = NULL;
233 #if wxOSX_USE_CARBON
234 m_disposeHandle = false;
235 m_releaseHandle = false;
236 m_isColorCursor = false;
237 m_themeCursor = -1;
238 #endif
239 }
240
241 wxCursorRefData::wxCursorRefData(const wxCursorRefData& cursor) : wxGDIRefData()
242 {
243 m_hCursor = NULL;
244
245 #if wxOSX_USE_COCOA
246 m_hCursor = (WX_NSCursor) wxMacCocoaRetain(cursor.m_hCursor);
247 #elif wxOSX_USE_CARBON
248 // FIXME: need to copy the cursor
249 m_disposeHandle = false;
250 m_releaseHandle = false;
251 m_isColorCursor = cursor.m_isColorCursor;
252 m_themeCursor = cursor.m_themeCursor;
253 #endif
254 }
255
256 wxCursorRefData::~wxCursorRefData()
257 {
258 #if wxOSX_USE_COCOA
259 if ( m_hCursor )
260 wxMacCocoaRelease(m_hCursor);
261 #elif wxOSX_USE_CARBON
262 if ( m_isColorCursor )
263 {
264 #ifndef __LP64__
265 ::DisposeCCursor( (CCrsrHandle) m_hCursor ) ;
266 #endif
267 }
268 else if ( m_disposeHandle )
269 {
270 ::DisposeHandle( (Handle ) m_hCursor ) ;
271 }
272 else if ( m_releaseHandle )
273 {
274 // we don't release the resource since it may already
275 // be in use again
276 }
277 #endif
278 }
279
280 wxCursor::wxCursor()
281 {
282 }
283
284 wxCursor::wxCursor( const wxImage &image )
285 {
286 #if wxUSE_IMAGE
287 CreateFromImage( image ) ;
288 #endif
289 }
290
291 wxGDIRefData *wxCursor::CreateGDIRefData() const
292 {
293 return new wxCursorRefData;
294 }
295
296 wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const
297 {
298 return new wxCursorRefData(*static_cast<const wxCursorRefData *>(data));
299 }
300
301 WXHCURSOR wxCursor::GetHCURSOR() const
302 {
303 return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0);
304 }
305
306 #if wxOSX_USE_CARBON
307 short GetCTabIndex( CTabHandle colors , RGBColor *col )
308 {
309 short retval = 0 ;
310 unsigned long bestdiff = 0xFFFF ;
311
312 for ( int i = 0 ; i < (**colors).ctSize ; ++i )
313 {
314 unsigned long diff = abs(col->red - (**colors).ctTable[i].rgb.red ) +
315 abs(col->green - (**colors).ctTable[i].rgb.green ) +
316 abs(col->blue - (**colors).ctTable[i].rgb.blue ) ;
317
318 if ( diff < bestdiff )
319 {
320 bestdiff = diff ;
321 retval = (**colors).ctTable[i].value ;
322 }
323 }
324
325 return retval ;
326 }
327 #endif
328
329 #if wxUSE_IMAGE
330
331 void wxCursor::CreateFromImage(const wxImage & image)
332 {
333 m_refData = new wxCursorRefData;
334 int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
335 int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
336 #if wxOSX_USE_COCOA
337 wxBitmap bmp( image );
338 CGImageRef cgimage = wxMacCreateCGImageFromBitmap(bmp);
339 if ( cgimage )
340 {
341 M_CURSORDATA->m_hCursor = wxMacCocoaCreateCursorFromCGImage( cgimage, hotSpotX, hotSpotY );
342 CFRelease( cgimage );
343 }
344 #elif wxOSX_USE_CARBON
345 #ifndef __LP64__
346 int w = 16;
347 int h = 16;
348
349 int image_w = image.GetWidth();
350 int image_h = image.GetHeight();
351
352 wxASSERT_MSG( hotSpotX >= 0 && hotSpotX < image_w &&
353 hotSpotY >= 0 && hotSpotY < image_h,
354 wxT("invalid cursor hot spot coordinates") );
355
356 wxImage image16(image); // final image of correct size
357
358 // if image is too small then place it in the center, resize it if too big
359 if ((w > image_w) && (h > image_h))
360 {
361 wxPoint offset((w - image_w) / 2, (h - image_h) / 2);
362 hotSpotX = hotSpotX + offset.x;
363 hotSpotY = hotSpotY + offset.y;
364
365 image16 = image.Size(wxSize(w, h), offset);
366 }
367 else if ((w != image_w) || (h != image_h))
368 {
369 hotSpotX = int(hotSpotX * double(w) / double(image_w));
370 hotSpotY = int(hotSpotY * double(h) / double(image_h));
371
372 image16 = image.Scale(w, h);
373 }
374
375 unsigned char * rgbBits = image16.GetData();
376 bool bHasMask = image16.HasMask() ;
377
378 PixMapHandle pm = (PixMapHandle) NewHandleClear( sizeof(PixMap) ) ;
379 short extent = 16 ;
380 short bytesPerPixel = 1 ;
381 short depth = 8 ;
382 Rect bounds = { 0 , 0 , extent , extent } ;
383 CCrsrHandle ch = (CCrsrHandle) NewHandleClear( sizeof(CCrsr) ) ;
384 CTabHandle newColors = GetCTable( 8 ) ;
385 HandToHand( (Handle *) &newColors );
386
387 // set the values to the indices
388 for ( int i = 0 ; i < (**newColors).ctSize ; ++i )
389 {
390 (**newColors).ctTable[i].value = i ;
391 }
392
393 HLock( (Handle)ch );
394 (**ch).crsrType = 0x8001; // color cursors
395 (**ch).crsrMap = pm;
396 short bytesPerRow = bytesPerPixel * extent;
397
398 (**pm).baseAddr = 0;
399 (**pm).rowBytes = bytesPerRow | 0x8000;
400 (**pm).bounds = bounds;
401 (**pm).pmVersion = 0;
402 (**pm).packType = 0;
403 (**pm).packSize = 0;
404 (**pm).hRes = 0x00480000; // 72 DPI default res
405 (**pm).vRes = 0x00480000; // 72 DPI default res
406 (**pm).pixelSize = depth;
407 (**pm).pixelType = 0;
408 (**pm).cmpCount = 1;
409 (**pm).cmpSize = depth;
410 (**pm).pmTable = newColors;
411
412 (**ch).crsrData = NewHandleClear( extent * bytesPerRow ) ;
413 (**ch).crsrXData = NULL ;
414 (**ch).crsrXValid = 0;
415 (**ch).crsrXHandle = NULL;
416
417 (**ch).crsrHotSpot.h = hotSpotX ;
418 (**ch).crsrHotSpot.v = hotSpotY ;
419 (**ch).crsrXTable = 0 ;
420 (**ch).crsrID = GetCTSeed() ;
421
422 memset( (**ch).crsr1Data , 0 , sizeof( Bits16 ) ) ;
423 memset( (**ch).crsrMask , 0 , sizeof( Bits16 ) ) ;
424
425 unsigned char mr = image16.GetMaskRed() ;
426 unsigned char mg = image16.GetMaskGreen() ;
427 unsigned char mb = image16.GetMaskBlue() ;
428
429 for ( int y = 0 ; y < h ; ++y )
430 {
431 short rowbits = 0, maskbits = 0 ;
432
433 for ( int x = 0 ; x < w ; ++x )
434 {
435 long pos = (y * w + x) * 3;
436
437 unsigned char r = rgbBits[pos] ;
438 unsigned char g = rgbBits[pos + 1] ;
439 unsigned char b = rgbBits[pos + 2] ;
440 RGBColor col = { 0xFFFF, 0xFFFF, 0xFFFF } ;
441
442 if ( bHasMask && r == mr && g == mg && b == mb )
443 {
444 // masked area, does not appear anywhere
445 }
446 else
447 {
448 if ( (int)r + (int)g + (int)b < 0x0200 )
449 rowbits |= ( 1 << (15 - x) ) ;
450
451 maskbits |= ( 1 << (15 - x) ) ;
452
453 wxColor( r , g , b ).GetRGBColor( &col );
454 }
455
456 *((*(**ch).crsrData) + y * bytesPerRow + x) =
457 GetCTabIndex( newColors , &col) ;
458 }
459 #ifdef WORDS_BIGENDIAN
460 (**ch).crsr1Data[y] = rowbits ;
461 (**ch).crsrMask[y] = maskbits ;
462 #else
463 (**ch).crsr1Data[y] = CFSwapInt16(rowbits) ;
464 (**ch).crsrMask[y] = CFSwapInt16(maskbits) ;
465 #endif
466 }
467
468 if ( !bHasMask )
469 memcpy( (**ch).crsrMask , (**ch).crsr1Data , sizeof( Bits16) ) ;
470
471 HUnlock( (Handle)ch ) ;
472 M_CURSORDATA->m_hCursor = ch ;
473 M_CURSORDATA->m_isColorCursor = true ;
474 #endif
475 #endif
476 }
477
478 #endif //wxUSE_IMAGE
479
480 wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX, int hotSpotY)
481 {
482 m_refData = new wxCursorRefData;
483 if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )
484 {
485 #if wxOSX_USE_COCOA
486 wxFAIL_MSG( wxT("Not implemented") );
487 #elif wxOSX_USE_CARBON
488 #ifndef __LP64__
489 Str255 theName ;
490 wxMacStringToPascal( cursor_file , theName ) ;
491
492 Handle resHandle = ::GetNamedResource( 'crsr' , theName ) ;
493 if ( resHandle )
494 {
495 short theId = -1 ;
496 OSType theType ;
497
498 GetResInfo( resHandle , &theId , &theType , theName ) ;
499 ReleaseResource( resHandle ) ;
500
501 M_CURSORDATA->m_hCursor = GetCCursor( theId ) ;
502 if ( M_CURSORDATA->m_hCursor )
503 M_CURSORDATA->m_isColorCursor = true ;
504 }
505 else
506 {
507 Handle resHandle = ::GetNamedResource( 'CURS' , theName ) ;
508 if ( resHandle )
509 {
510 short theId = -1 ;
511 OSType theType ;
512
513 GetResInfo( resHandle , &theId , &theType , theName ) ;
514 ReleaseResource( resHandle ) ;
515
516 M_CURSORDATA->m_hCursor = GetCursor( theId ) ;
517 if ( M_CURSORDATA->m_hCursor )
518 M_CURSORDATA->m_releaseHandle = true ;
519 }
520 }
521 #endif
522 #endif
523 }
524 else
525 {
526 #if wxUSE_IMAGE
527 wxImage image ;
528 image.LoadFile( cursor_file, flags ) ;
529 if ( image.IsOk() )
530 {
531 image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotX ) ;
532 image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotSpotY ) ;
533 m_refData->DecRef() ;
534 m_refData = NULL ;
535 CreateFromImage( image ) ;
536 }
537 #endif
538 }
539 }
540
541 // Cursors by stock number
542 void wxCursor::InitFromStock(wxStockCursor cursor_type)
543 {
544 m_refData = new wxCursorRefData;
545 #if wxOSX_USE_COCOA
546 M_CURSORDATA->m_hCursor = wxMacCocoaCreateStockCursor( cursor_type );
547 #elif wxOSX_USE_CARBON
548 switch (cursor_type)
549 {
550 case wxCURSOR_COPY_ARROW:
551 M_CURSORDATA->m_themeCursor = kThemeCopyArrowCursor;
552 break;
553
554 case wxCURSOR_WAIT:
555 M_CURSORDATA->m_themeCursor = kThemeWatchCursor;
556 break;
557
558 case wxCURSOR_IBEAM:
559 M_CURSORDATA->m_themeCursor = kThemeIBeamCursor;
560 break;
561
562 case wxCURSOR_CROSS:
563 M_CURSORDATA->m_themeCursor = kThemeCrossCursor;
564 break;
565
566 case wxCURSOR_SIZENWSE:
567 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSizeNWSE);
568 break;
569
570 case wxCURSOR_SIZENESW:
571 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSizeNESW);
572 break;
573
574 case wxCURSOR_SIZEWE:
575 M_CURSORDATA->m_themeCursor = kThemeResizeLeftRightCursor;
576 break;
577
578 case wxCURSOR_SIZENS:
579 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSizeNS);
580 break;
581
582 case wxCURSOR_SIZING:
583 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSize);
584 break;
585
586 case wxCURSOR_HAND:
587 M_CURSORDATA->m_themeCursor = kThemePointingHandCursor;
588 break;
589
590 case wxCURSOR_BULLSEYE:
591 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorBullseye);
592 break;
593
594 case wxCURSOR_PENCIL:
595 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorPencil);
596 break;
597
598 case wxCURSOR_MAGNIFIER:
599 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorMagnifier);
600 break;
601
602 case wxCURSOR_NO_ENTRY:
603 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorNoEntry);
604 break;
605
606 case wxCURSOR_WATCH:
607 M_CURSORDATA->m_themeCursor = kThemeWatchCursor;
608 break;
609
610 case wxCURSOR_PAINT_BRUSH:
611 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorPaintBrush);
612 break;
613
614 case wxCURSOR_POINT_LEFT:
615 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorPointLeft);
616 break;
617
618 case wxCURSOR_POINT_RIGHT:
619 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorPointRight);
620 break;
621
622 case wxCURSOR_QUESTION_ARROW:
623 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorQuestionArrow);
624 break;
625
626 case wxCURSOR_BLANK:
627 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorBlank);
628 break;
629
630 case wxCURSOR_RIGHT_ARROW:
631 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorRightArrow);
632 break;
633
634 case wxCURSOR_SPRAYCAN:
635 M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorRoller);
636 break;
637
638 case wxCURSOR_OPEN_HAND:
639 M_CURSORDATA->m_themeCursor = kThemeOpenHandCursor;
640 break;
641
642 case wxCURSOR_CLOSED_HAND:
643 M_CURSORDATA->m_themeCursor = kThemeClosedHandCursor;
644 break;
645
646 case wxCURSOR_CHAR:
647 case wxCURSOR_ARROW:
648 case wxCURSOR_LEFT_BUTTON:
649 case wxCURSOR_RIGHT_BUTTON:
650 case wxCURSOR_MIDDLE_BUTTON:
651 default:
652 M_CURSORDATA->m_themeCursor = kThemeArrowCursor;
653 break;
654 }
655
656 if ( M_CURSORDATA->m_themeCursor == -1 )
657 M_CURSORDATA->m_releaseHandle = true;
658 #endif
659 }
660
661 void wxCursor::MacInstall() const
662 {
663 gMacCurrentCursor = *this ;
664 #if wxOSX_USE_COCOA
665 if ( IsOk() )
666 wxMacCocoaSetCursor( M_CURSORDATA->m_hCursor );
667 #elif wxOSX_USE_CARBON
668 if ( m_refData && M_CURSORDATA->m_themeCursor != -1 )
669 {
670 SetThemeCursor( M_CURSORDATA->m_themeCursor ) ;
671 }
672 else if ( m_refData && M_CURSORDATA->m_hCursor )
673 {
674 #ifndef __LP64__
675 if ( M_CURSORDATA->m_isColorCursor )
676 ::SetCCursor( (CCrsrHandle) M_CURSORDATA->m_hCursor ) ;
677 else
678 ::SetCursor( * (CursHandle) M_CURSORDATA->m_hCursor ) ;
679 #endif
680 }
681 else
682 {
683 SetThemeCursor( kThemeArrowCursor ) ;
684 }
685 #endif
686 }
687
688 wxCursor::~wxCursor()
689 {
690 }
691
692 // Global cursor setting
693 wxCursor gGlobalCursor;
694 void wxSetCursor(const wxCursor& cursor)
695 {
696 cursor.MacInstall() ;
697 gGlobalCursor = cursor;
698 }