]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/utils.cpp
fixing PPI bugs in printer dcs
[wxWidgets.git] / src / mac / carbon / utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/utils.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/utils.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/app.h"
19 #if wxUSE_GUI
20 #include "wx/toplevel.h"
21 #include "wx/font.h"
22 #endif
23 #endif
24
25 #include "wx/apptrait.h"
26
27 #if wxUSE_GUI
28 #include "wx/mac/uma.h"
29 #endif
30
31 #include <ctype.h>
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdarg.h>
37
38 #include "MoreFilesX.h"
39
40 #ifndef __DARWIN__
41 #include <Threads.h>
42 #include <Sound.h>
43 #endif
44
45 #if wxUSE_GUI
46 #if TARGET_API_MAC_OSX
47 #include <CoreServices/CoreServices.h>
48 #else
49 #include <DriverServices.h>
50 #include <Multiprocessing.h>
51 #endif
52
53 #ifdef __DARWIN__
54 #include <Carbon/Carbon.h>
55 #else
56 #include <ATSUnicode.h>
57 #include <TextCommon.h>
58 #include <TextEncodingConverter.h>
59 #endif
60 #endif // wxUSE_GUI
61
62 #include "wx/mac/private.h"
63
64 #if defined(__MWERKS__) && wxUSE_UNICODE
65 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
66 #include <wtime.h>
67 #endif
68 #endif
69
70 // ---------------------------------------------------------------------------
71 // code used in both base and GUI compilation
72 // ---------------------------------------------------------------------------
73
74 // our OS version is the same in non GUI and GUI cases
75 static int DoGetOSVersion(int *majorVsn, int *minorVsn)
76 {
77 long theSystem;
78
79 // are there x-platform conventions ?
80
81 Gestalt(gestaltSystemVersion, &theSystem);
82 if (minorVsn != NULL)
83 *minorVsn = (theSystem & 0xFF);
84
85 if (majorVsn != NULL)
86 *majorVsn = (theSystem >> 8);
87
88 #ifdef __DARWIN__
89 return wxMAC_DARWIN;
90 #else
91 return wxMAC;
92 #endif
93 }
94
95
96 #if wxUSE_BASE
97
98 // ----------------------------------------------------------------------------
99 // debugging support
100 // ----------------------------------------------------------------------------
101
102 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
103
104 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
105
106 #ifndef __MetroNubUtils__
107 #include "MetroNubUtils.h"
108 #endif
109
110 #ifndef __GESTALT__
111 #include <Gestalt.h>
112 #endif
113
114 #if TARGET_API_MAC_CARBON
115
116 #include <CodeFragments.h>
117
118 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
119
120 ProcPtr gCallUniversalProc_Proc = NULL;
121
122 #endif
123
124 static MetroNubUserEntryBlock* gMetroNubEntry = NULL;
125
126 static long fRunOnce = false;
127
128
129 Boolean IsMetroNubInstalled()
130 {
131 if (!fRunOnce)
132 {
133 long result, value;
134
135 fRunOnce = true;
136 gMetroNubEntry = NULL;
137
138 if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000)
139 {
140 // look for MetroNub's Gestalt selector
141 if (Gestalt(kMetroNubUserSignature, &result) == noErr)
142 {
143 #if TARGET_API_MAC_CARBON
144 if (gCallUniversalProc_Proc == NULL)
145 {
146 CFragConnectionID connectionID;
147 Ptr mainAddress;
148 Str255 errorString;
149 ProcPtr symbolAddress;
150 OSErr err;
151 CFragSymbolClass symbolClass;
152
153 symbolAddress = NULL;
154 err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag,
155 &connectionID, &mainAddress, errorString);
156
157 if (err != noErr)
158 {
159 gCallUniversalProc_Proc = NULL;
160 goto end;
161 }
162
163 err = FindSymbol(connectionID, "\pCallUniversalProc",
164 (Ptr *) &gCallUniversalProc_Proc, &symbolClass);
165
166 if (err != noErr)
167 {
168 gCallUniversalProc_Proc = NULL;
169 goto end;
170 }
171 }
172 #endif
173
174 {
175 MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result;
176
177 // make sure the version of the API is compatible
178 if (block->apiLowVersion <= kMetroNubUserAPIVersion &&
179 kMetroNubUserAPIVersion <= block->apiHiVersion)
180 {
181 // success!
182 gMetroNubEntry = block;
183 }
184 }
185 }
186 }
187 }
188
189 end:
190
191 #if TARGET_API_MAC_CARBON
192 return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL);
193 #else
194 return (gMetroNubEntry != NULL);
195 #endif
196 }
197
198 Boolean IsMWDebuggerRunning()
199 {
200 if (IsMetroNubInstalled())
201 return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning);
202
203 return false;
204 }
205
206 Boolean AmIBeingMWDebugged()
207 {
208 if (IsMetroNubInstalled())
209 return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged);
210
211 return false;
212 }
213
214 extern bool WXDLLEXPORT wxIsDebuggerRunning()
215 {
216 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
217 }
218
219 #else
220
221 extern bool WXDLLEXPORT wxIsDebuggerRunning()
222 {
223 return false;
224 }
225
226 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
227
228
229 #ifndef __DARWIN__
230 // defined in unix/utilsunx.cpp for Mac OS X
231
232 // get full hostname (with domain name if possible)
233 bool wxGetFullHostName(wxChar *buf, int maxSize)
234 {
235 return wxGetHostName(buf, maxSize);
236 }
237
238 // Get user ID e.g. jacs
239 bool wxGetUserId(wxChar *buf, int maxSize)
240 {
241 return wxGetUserName( buf , maxSize );
242 }
243
244 const wxChar* wxGetHomeDir(wxString *pstr)
245 {
246 *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder );
247 return pstr->c_str();
248 }
249
250 // Get hostname only (without domain name)
251 bool wxGetHostName(wxChar *buf, int maxSize)
252 {
253 // Gets Chooser name of user by examining a System resource.
254 buf[0] = 0;
255
256 const short kComputerNameID = -16413;
257
258 short oldResFile = CurResFile();
259 UseResFile(0);
260 StringHandle chooserName = (StringHandle)::GetString(kComputerNameID);
261 UseResFile(oldResFile);
262
263 if (chooserName && *chooserName)
264 {
265 HLock( (Handle) chooserName );
266 wxString name = wxMacMakeStringFromPascal( *chooserName );
267 HUnlock( (Handle) chooserName );
268 ReleaseResource( (Handle) chooserName );
269 wxStrncpy( buf , name , maxSize - 1 );
270 }
271
272 return true;
273 }
274
275 // Get user name e.g. Stefan Csomor
276 bool wxGetUserName(wxChar *buf, int maxSize)
277 {
278 // Gets Chooser name of user by examining a System resource.
279 buf[0] = 0;
280
281 const short kChooserNameID = -16096;
282
283 short oldResFile = CurResFile();
284 UseResFile(0);
285 StringHandle chooserName = (StringHandle)::GetString(kChooserNameID);
286 UseResFile(oldResFile);
287
288 if (chooserName && *chooserName)
289 {
290 HLock( (Handle) chooserName );
291 wxString name = wxMacMakeStringFromPascal( *chooserName );
292 HUnlock( (Handle) chooserName );
293 ReleaseResource( (Handle) chooserName );
294 wxStrncpy( buf , name , maxSize - 1 );
295 }
296
297 return true;
298 }
299
300 int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags)
301 {
302 // TODO
303 return 0;
304 }
305
306 WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value)
307 {
308 // TODO : under classic there is no environement support, under X yes
309 return false;
310 }
311
312 // set the env var name to the given value, return true on success
313 WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value)
314 {
315 // TODO : under classic there is no environement support, under X yes
316 return false;
317 }
318
319 // Execute a program in an Interactive Shell
320 bool wxShell(const wxString& command)
321 {
322 // TODO
323 return false;
324 }
325
326 // Shutdown or reboot the PC
327 bool wxShutdown(wxShutdownFlags wFlags)
328 {
329 // TODO
330 return false;
331 }
332
333 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
334 wxMemorySize wxGetFreeMemory()
335 {
336 return (wxMemorySize)FreeMem();
337 }
338
339 #ifndef __DARWIN__
340
341 void wxMicroSleep(unsigned long microseconds)
342 {
343 AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime());
344 MPDelayUntil( & wakeup);
345 }
346
347 void wxMilliSleep(unsigned long milliseconds)
348 {
349 AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime());
350 MPDelayUntil( & wakeup);
351 }
352
353 void wxSleep(int nSecs)
354 {
355 wxMilliSleep(1000*nSecs);
356 }
357
358 #endif
359
360 // Consume all events until no more left
361 void wxFlushEvents()
362 {
363 }
364
365 #endif // !__DARWIN__
366
367 // Emit a beeeeeep
368 void wxBell()
369 {
370 SysBeep(30);
371 }
372
373 wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo()
374 {
375 static wxToolkitInfo info;
376
377 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
378 info.name = _T("wxBase");
379
380 return info;
381 }
382
383 #endif // wxUSE_BASE
384
385 #if wxUSE_GUI
386
387 wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
388 {
389 static wxToolkitInfo info;
390
391 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
392 info.shortName = _T("mac");
393 info.name = _T("wxMac");
394
395 #ifdef __WXUNIVERSAL__
396 info.shortName << _T("univ");
397 info.name << _T("/wxUniversal");
398 #endif
399
400 return info;
401 }
402
403 // Reading and writing resources (eg WIN.INI, .Xdefaults)
404 #if wxUSE_RESOURCES
405 bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
406 {
407 // TODO
408 return false;
409 }
410
411 bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
412 {
413 wxString buf;
414 buf.Printf(wxT("%.4f"), value);
415
416 return wxWriteResource(section, entry, buf, file);
417 }
418
419 bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
420 {
421 wxString buf;
422 buf.Printf(wxT("%ld"), value);
423
424 return wxWriteResource(section, entry, buf, file);
425 }
426
427 bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
428 {
429 wxString buf;
430 buf.Printf(wxT("%d"), value);
431
432 return wxWriteResource(section, entry, buf, file);
433 }
434
435 bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
436 {
437 // TODO
438 return false;
439 }
440
441 bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
442 {
443 char *s = NULL;
444 bool succ = wxGetResource(section, entry, (char **)&s, file);
445 if (succ)
446 {
447 *value = (float)strtod(s, NULL);
448 delete[] s;
449 }
450
451 return succ;
452 }
453
454 bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
455 {
456 char *s = NULL;
457 bool succ = wxGetResource(section, entry, (char **)&s, file);
458 if (succ)
459 {
460 *value = strtol(s, NULL, 10);
461 delete[] s;
462 }
463
464 return succ;
465 }
466
467 bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
468 {
469 char *s = NULL;
470 bool succ = wxGetResource(section, entry, (char **)&s, file);
471 if (succ)
472 {
473 *value = (int)strtol(s, NULL, 10);
474 delete[] s;
475 }
476
477 return succ;
478 }
479 #endif // wxUSE_RESOURCES
480
481 int gs_wxBusyCursorCount = 0;
482 extern wxCursor gMacCurrentCursor;
483 wxCursor gMacStoredActiveCursor;
484
485 // Set the cursor to the busy cursor for all windows
486 void wxBeginBusyCursor(const wxCursor *cursor)
487 {
488 if (gs_wxBusyCursorCount++ == 0)
489 {
490 gMacStoredActiveCursor = gMacCurrentCursor;
491 cursor->MacInstall();
492 }
493 //else: nothing to do, already set
494 }
495
496 // Restore cursor to normal
497 void wxEndBusyCursor()
498 {
499 wxCHECK_RET( gs_wxBusyCursorCount > 0,
500 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
501
502 if (--gs_wxBusyCursorCount == 0)
503 {
504 gMacStoredActiveCursor.MacInstall();
505 gMacStoredActiveCursor = wxNullCursor;
506 }
507 }
508
509 // true if we're between the above two calls
510 bool wxIsBusy()
511 {
512 return (gs_wxBusyCursorCount > 0);
513 }
514
515 #endif // wxUSE_GUI
516
517 #if wxUSE_BASE
518
519 wxString wxMacFindFolderNoSeparator( short vol,
520 OSType folderType,
521 Boolean createFolder)
522 {
523 FSRef fsRef;
524 wxString strDir;
525
526 if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr)
527 {
528 strDir = wxMacFSRefToPath( &fsRef );
529 }
530
531 return strDir;
532 }
533
534 wxString wxMacFindFolder( short vol,
535 OSType folderType,
536 Boolean createFolder)
537 {
538 return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH;
539 }
540
541 #endif // wxUSE_BASE
542
543 #if wxUSE_GUI
544
545 // Check whether this window wants to process messages, e.g. Stop button
546 // in long calculations.
547 bool wxCheckForInterrupt(wxWindow *wnd)
548 {
549 // TODO
550 return false;
551 }
552
553 void wxGetMousePosition( int* x, int* y )
554 {
555 Point pt;
556
557 GetMouse( &pt );
558 LocalToGlobal( &pt );
559 *x = pt.h;
560 *y = pt.v;
561 };
562
563 // Return true if we have a colour display
564 bool wxColourDisplay()
565 {
566 return true;
567 }
568
569 // Returns depth of screen
570 int wxDisplayDepth()
571 {
572 Rect globRect;
573 SetRect(&globRect, -32760, -32760, 32760, 32760);
574 GDHandle theMaxDevice;
575
576 int theDepth = 8;
577 theMaxDevice = GetMaxDevice(&globRect);
578 if (theMaxDevice != NULL)
579 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
580
581 return theDepth;
582 }
583
584 // Get size of display
585 void wxDisplaySize(int *width, int *height)
586 {
587 BitMap screenBits;
588 GetQDGlobalsScreenBits( &screenBits );
589
590 if (width != NULL)
591 *width = screenBits.bounds.right - screenBits.bounds.left;
592
593 if (height != NULL)
594 *height = screenBits.bounds.bottom - screenBits.bounds.top;
595 }
596
597 void wxDisplaySizeMM(int *width, int *height)
598 {
599 wxDisplaySize(width, height);
600 // on mac 72 is fixed (at least now;-)
601 float cvPt2Mm = 25.4 / 72;
602
603 if (width != NULL)
604 *width = int( *width * cvPt2Mm );
605
606 if (height != NULL)
607 *height = int( *height * cvPt2Mm );
608 }
609
610 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
611 {
612 Rect r;
613
614 GetAvailableWindowPositioningBounds( GetMainDevice() , &r );
615 if ( x )
616 *x = r.left;
617 if ( y )
618 *y = r.top;
619 if ( width )
620 *width = r.right - r.left;
621 if ( height )
622 *height = r.bottom - r.top;
623 }
624
625 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
626 {
627 return wxGenericFindWindowAtPoint(pt);
628 }
629
630 #endif // wxUSE_GUI
631
632 #if wxUSE_BASE
633
634 wxString wxGetOsDescription()
635 {
636 #ifdef WXWIN_OS_DESCRIPTION
637 // use configure generated description if available
638 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")"));
639 #else
640 return wxT("MacOS"); //TODO:define further
641 #endif
642 }
643
644 #ifndef __DARWIN__
645 wxChar *wxGetUserHome (const wxString& user)
646 {
647 // TODO
648 return NULL;
649 }
650
651 bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree)
652 {
653 if ( path.empty() )
654 return false;
655
656 wxString p = path;
657 if (p[0u] == ':' )
658 p = wxGetCwd() + p;
659
660 int pos = p.Find(':');
661 if ( pos != wxNOT_FOUND )
662 p = p.Mid(1,pos);
663
664 p = p + wxT(":");
665
666 OSErr err = noErr;
667
668 FSRef fsRef;
669 err = wxMacPathToFSRef( p , &fsRef );
670 if ( noErr == err )
671 {
672 FSVolumeRefNum vRefNum;
673 err = FSGetVRefNum( &fsRef , &vRefNum );
674 if ( noErr == err )
675 {
676 UInt64 freeBytes , totalBytes;
677 err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes );
678 if ( noErr == err )
679 {
680 if ( pTotal )
681 *pTotal = wxDiskspaceSize_t( totalBytes );
682 if ( pFree )
683 *pFree = wxDiskspaceSize_t( freeBytes );
684 }
685 }
686 }
687
688 return err == noErr;
689 }
690 #endif // !__DARWIN__
691
692 //---------------------------------------------------------------------------
693 // wxMac Specific utility functions
694 //---------------------------------------------------------------------------
695
696 void wxMacStringToPascal( const wxString&from , StringPtr to )
697 {
698 wxCharBuffer buf = from.mb_str( wxConvLocal );
699 int len = strlen(buf);
700
701 if ( len > 255 )
702 len = 255;
703 to[0] = len;
704 memcpy( (char*) &to[1] , buf , len );
705 }
706
707 wxString wxMacMakeStringFromPascal( ConstStringPtr from )
708 {
709 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
710 }
711
712 // ----------------------------------------------------------------------------
713 // Common Event Support
714 // ----------------------------------------------------------------------------
715
716 extern ProcessSerialNumber gAppProcess;
717
718 void wxMacWakeUp()
719 {
720 ProcessSerialNumber psn;
721 Boolean isSame;
722 psn.highLongOfPSN = 0;
723 psn.lowLongOfPSN = kCurrentProcess;
724 SameProcess( &gAppProcess , &psn , &isSame );
725 if ( isSame )
726 {
727 #if TARGET_CARBON
728 OSStatus err = noErr;
729
730 #if 0
731 // lead sometimes to race conditions, although all calls used should be thread safe ...
732 static wxMacCarbonEvent s_wakeupEvent;
733 if ( !s_wakeupEvent.IsValid() )
734 {
735 err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
736 kEventAttributeNone );
737 }
738 if ( err == noErr )
739 {
740
741 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) )
742 return;
743 s_wakeupEvent.SetCurrentTime();
744 err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent,
745 kEventPriorityHigh );
746 }
747 #else
748 wxMacCarbonEvent wakeupEvent;
749 wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
750 kEventAttributeNone );
751 err = PostEventToQueue(GetMainEventQueue(), wakeupEvent,
752 kEventPriorityHigh );
753 #endif
754 #else
755 PostEvent( nullEvent , 0 );
756 #endif
757 }
758 else
759 {
760 WakeUpProcess( &gAppProcess );
761 }
762 }
763
764 #endif // wxUSE_BASE
765
766 #if wxUSE_GUI
767
768 // ----------------------------------------------------------------------------
769 // Native Struct Conversions
770 // ----------------------------------------------------------------------------
771
772 void wxMacRectToNative( const wxRect *wx , Rect *n )
773 {
774 n->left = wx->x;
775 n->top = wx->y;
776 n->right = wx->x + wx->width;
777 n->bottom = wx->y + wx->height;
778 }
779
780 void wxMacNativeToRect( const Rect *n , wxRect* wx )
781 {
782 wx->x = n->left;
783 wx->y = n->top;
784 wx->width = n->right - n->left;
785 wx->height = n->bottom - n->top;
786 }
787
788 void wxMacPointToNative( const wxPoint* wx , Point *n )
789 {
790 n->h = wx->x;
791 n->v = wx->y;
792 }
793
794 void wxMacNativeToPoint( const Point *n , wxPoint* wx )
795 {
796 wx->x = n->h;
797 wx->y = n->v;
798 }
799
800 // ----------------------------------------------------------------------------
801 // Carbon Event Support
802 // ----------------------------------------------------------------------------
803
804 OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
805 {
806 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData );
807 }
808
809 OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
810 {
811 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData );
812 }
813
814 // ----------------------------------------------------------------------------
815 // Control Access Support
816 // ----------------------------------------------------------------------------
817
818 wxMacControl::wxMacControl(wxWindow* peer , bool isRootControl )
819 {
820 Init();
821 m_peer = peer;
822 m_isRootControl = isRootControl;
823 m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing();
824 }
825
826 wxMacControl::wxMacControl( wxWindow* peer , ControlRef control )
827 {
828 Init();
829 m_peer = peer;
830 m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing();
831 m_controlRef = control;
832 }
833
834 wxMacControl::wxMacControl( wxWindow* peer , WXWidget control )
835 {
836 Init();
837 m_peer = peer;
838 m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing();
839 m_controlRef = (ControlRef) control;
840 }
841
842 wxMacControl::~wxMacControl()
843 {
844 }
845
846 void wxMacControl::Init()
847 {
848 m_peer = NULL;
849 m_controlRef = NULL;
850 m_needsFocusRect = false;
851 m_isCompositing = false;
852 m_isRootControl = false;
853 }
854
855 void wxMacControl::Dispose()
856 {
857 ::DisposeControl( m_controlRef );
858 m_controlRef = NULL;
859 }
860
861 void wxMacControl::SetReference( SInt32 data )
862 {
863 SetControlReference( m_controlRef , data );
864 }
865
866 OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const
867 {
868 return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize );
869 }
870
871 OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const
872 {
873 return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize );
874 }
875
876 OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
877 {
878 return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData );
879 }
880
881 OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions )
882 {
883 #if TARGET_API_MAC_OSX
884 return SendEventToEventTargetWithOptions( event,
885 HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions );
886 #else
887 #pragma unused(inOptions)
888 return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) );
889 #endif
890 }
891
892 OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions )
893 {
894 wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess );
895
896 event.SetParameter<HICommand>(kEventParamDirectObject,command);
897
898 return SendEvent( event , inOptions );
899 }
900
901 OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions )
902 {
903 HICommand command;
904
905 memset( &command, 0 , sizeof(command) );
906 command.commandID = commandID;
907 return SendHICommand( command , inOptions );
908 }
909
910 void wxMacControl::Flash( ControlPartCode part , UInt32 ticks )
911 {
912 unsigned long finalTicks;
913
914 HiliteControl( m_controlRef , part );
915 Delay( ticks , &finalTicks );
916 HiliteControl( m_controlRef , kControlNoPart );
917 }
918
919 SInt32 wxMacControl::GetValue() const
920 {
921 return ::GetControl32BitValue( m_controlRef );
922 }
923
924 SInt32 wxMacControl::GetMaximum() const
925 {
926 return ::GetControl32BitMaximum( m_controlRef );
927 }
928
929 SInt32 wxMacControl::GetMinimum() const
930 {
931 return ::GetControl32BitMinimum( m_controlRef );
932 }
933
934 void wxMacControl::SetValue( SInt32 v )
935 {
936 ::SetControl32BitValue( m_controlRef , v );
937 }
938
939 void wxMacControl::SetMinimum( SInt32 v )
940 {
941 ::SetControl32BitMinimum( m_controlRef , v );
942 }
943
944 void wxMacControl::SetMaximum( SInt32 v )
945 {
946 ::SetControl32BitMaximum( m_controlRef , v );
947 }
948
949 void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum )
950 {
951 ::SetControl32BitMinimum( m_controlRef , minimum );
952 ::SetControl32BitMaximum( m_controlRef , maximum );
953 ::SetControl32BitValue( m_controlRef , value );
954 }
955
956 OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart )
957 {
958 return SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, focusPart );
959 }
960
961 bool wxMacControl::HasFocus() const
962 {
963 ControlRef control;
964 GetKeyboardFocus( GetUserFocusWindow() , &control );
965 return control == m_controlRef;
966 }
967
968 void wxMacControl::SetNeedsFocusRect( bool needs )
969 {
970 m_needsFocusRect = needs;
971 }
972
973 bool wxMacControl::NeedsFocusRect() const
974 {
975 return m_needsFocusRect;
976 }
977
978 void wxMacControl::VisibilityChanged(bool shown)
979 {
980 }
981
982 void wxMacControl::SuperChangedPosition()
983 {
984 }
985
986 void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle )
987 {
988 m_font = font;
989 ControlFontStyleRec fontStyle;
990 if ( font.MacGetThemeFontID() != kThemeCurrentPortFont )
991 {
992 switch ( font.MacGetThemeFontID() )
993 {
994 case kThemeSmallSystemFont :
995 fontStyle.font = kControlFontSmallSystemFont;
996 break;
997
998 case 109 : // mini font
999 fontStyle.font = -5;
1000 break;
1001
1002 case kThemeSystemFont :
1003 fontStyle.font = kControlFontBigSystemFont;
1004 break;
1005
1006 default :
1007 fontStyle.font = kControlFontBigSystemFont;
1008 break;
1009 }
1010
1011 fontStyle.flags = kControlUseFontMask;
1012 }
1013 else
1014 {
1015 fontStyle.font = font.MacGetFontNum();
1016 fontStyle.style = font.MacGetFontStyle();
1017 fontStyle.size = font.MacGetFontSize();
1018 fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask;
1019 }
1020
1021 fontStyle.just = teJustLeft;
1022 fontStyle.flags |= kControlUseJustMask;
1023 if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
1024 fontStyle.just = teJustCenter;
1025 else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
1026 fontStyle.just = teJustRight;
1027
1028
1029 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1030 // won't get grayed out by the system anymore
1031
1032 if ( foreground != *wxBLACK )
1033 {
1034 fontStyle.foreColor = MAC_WXCOLORREF( foreground.GetPixel() );
1035 fontStyle.flags |= kControlUseForeColorMask;
1036 }
1037
1038 ::SetControlFontStyle( m_controlRef , &fontStyle );
1039 }
1040
1041 void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) )
1042 {
1043 // TODO
1044 // setting up a color proc is not recommended anymore
1045 }
1046
1047 void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
1048 {
1049 ::SetControl32BitMinimum( m_controlRef , minimum );
1050 ::SetControl32BitMaximum( m_controlRef , maximum );
1051 }
1052
1053 short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers )
1054 {
1055 return HandleControlKey( m_controlRef , keyCode , charCode , modifiers );
1056 }
1057
1058 void wxMacControl::SetActionProc( ControlActionUPP actionProc )
1059 {
1060 SetControlAction( m_controlRef , actionProc );
1061 }
1062
1063 void wxMacControl::SetViewSize( SInt32 viewSize )
1064 {
1065 SetControlViewSize(m_controlRef , viewSize );
1066 }
1067
1068 SInt32 wxMacControl::GetViewSize() const
1069 {
1070 return GetControlViewSize( m_controlRef );
1071 }
1072
1073 bool wxMacControl::IsVisible() const
1074 {
1075 return IsControlVisible( m_controlRef );
1076 }
1077
1078 void wxMacControl::SetVisibility( bool visible , bool redraw )
1079 {
1080 SetControlVisibility( m_controlRef , visible , redraw );
1081 }
1082
1083 bool wxMacControl::IsEnabled() const
1084 {
1085 #if TARGET_API_MAC_OSX
1086 return IsControlEnabled( m_controlRef );
1087 #else
1088 return IsControlActive( m_controlRef );
1089 #endif
1090 }
1091
1092 bool wxMacControl::IsActive() const
1093 {
1094 return IsControlActive( m_controlRef );
1095 }
1096
1097 void wxMacControl::Enable( bool enable )
1098 {
1099 #if TARGET_API_MAC_OSX
1100 if ( enable )
1101 EnableControl( m_controlRef );
1102 else
1103 DisableControl( m_controlRef );
1104 #else
1105 if ( enable )
1106 ActivateControl( m_controlRef );
1107 else
1108 DeactivateControl( m_controlRef );
1109 #endif
1110 }
1111
1112 void wxMacControl::SetDrawingEnabled( bool enable )
1113 {
1114 #if TARGET_API_MAC_OSX
1115 HIViewSetDrawingEnabled( m_controlRef , enable );
1116 #endif
1117 }
1118
1119 #if TARGET_API_MAC_OSX
1120 bool wxMacControl::GetNeedsDisplay() const
1121 {
1122 #if TARGET_API_MAC_OSX
1123 if ( m_isCompositing )
1124 {
1125 return HIViewGetNeedsDisplay( m_controlRef );
1126 }
1127 else
1128 #endif
1129 {
1130 if ( !IsVisible() )
1131 return false;
1132
1133 Rect controlBounds;
1134 GetControlBounds( m_controlRef, &controlBounds );
1135 RgnHandle rgn = NewRgn();
1136 GetWindowRegion ( GetControlOwner( m_controlRef ) , kWindowUpdateRgn , rgn );
1137 Boolean intersect = RectInRgn ( &controlBounds , rgn );
1138 DisposeRgn( rgn );
1139
1140 return intersect;
1141 }
1142 }
1143 #endif
1144
1145 void wxMacControl::SetNeedsDisplay( RgnHandle where )
1146 {
1147 if ( !IsVisible() )
1148 return;
1149
1150 #if TARGET_API_MAC_OSX
1151 if ( m_isCompositing )
1152 {
1153 HIViewSetNeedsDisplayInRegion( m_controlRef , where , true );
1154 }
1155 else
1156 #endif
1157 {
1158 Rect controlBounds;
1159 GetControlBounds( m_controlRef, &controlBounds );
1160 RgnHandle update = NewRgn();
1161 CopyRgn( where , update );
1162 OffsetRgn( update , controlBounds.left , controlBounds.top );
1163 InvalWindowRgn( GetControlOwner( m_controlRef) , update );
1164 }
1165 }
1166
1167 void wxMacControl::SetNeedsDisplay( Rect* where )
1168 {
1169 if ( !IsVisible() )
1170 return;
1171
1172 #if TARGET_API_MAC_OSX
1173 if ( m_isCompositing )
1174 {
1175 if ( where != NULL )
1176 {
1177 RgnHandle update = NewRgn();
1178 RectRgn( update , where );
1179 HIViewSetNeedsDisplayInRegion( m_controlRef , update , true );
1180 DisposeRgn( update );
1181 }
1182 else
1183 HIViewSetNeedsDisplay( m_controlRef , true );
1184 }
1185 else
1186 #endif
1187 {
1188 Rect controlBounds;
1189
1190 GetControlBounds( m_controlRef, &controlBounds );
1191 if ( where )
1192 {
1193 Rect whereLocal = *where;
1194 OffsetRect( &whereLocal , controlBounds.left , controlBounds.top );
1195 SectRect( &controlBounds , &whereLocal, &controlBounds );
1196 }
1197
1198 InvalWindowRect( GetControlOwner( m_controlRef) , &controlBounds );
1199 }
1200 }
1201
1202 void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to )
1203 {
1204 #if TARGET_API_MAC_OSX
1205 if ( from->m_peer->MacGetTopLevelWindow()->MacUsesCompositing() )
1206 {
1207 HIPoint hiPoint;
1208
1209 hiPoint.x = pt->x;
1210 hiPoint.y = pt->y;
1211 HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef );
1212 pt->x = (int)hiPoint.x;
1213 pt->y = (int)hiPoint.y;
1214 }
1215 else
1216 #endif
1217 {
1218 Rect fromRect, toRect;
1219
1220 GetControlBounds( from->m_controlRef , &fromRect );
1221 GetControlBounds( to->m_controlRef , &toRect );
1222 if ( from->m_isRootControl )
1223 fromRect.left = fromRect.top = 0;
1224 if ( to->m_isRootControl )
1225 toRect.left = toRect.top = 0;
1226
1227 pt->x = pt->x + fromRect.left - toRect.left;
1228 pt->y = pt->y + fromRect.top - toRect.top;
1229 }
1230 }
1231
1232 void wxMacControl::SetRect( Rect *r )
1233 {
1234 #if TARGET_API_MAC_OSX
1235 if ( m_isCompositing )
1236 {
1237 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1238 //CGPoint and CGSize, which have two floats each
1239 HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } };
1240 HIViewSetFrame ( m_controlRef , &hir );
1241 // eventuall we might have to do a SetVisibility( false , true );
1242 // before and a SetVisibility( true , true ); after
1243 }
1244 else
1245 #endif
1246 {
1247 bool vis = IsVisible();
1248 if ( vis )
1249 {
1250 Rect former;
1251 GetControlBounds( m_controlRef , &former );
1252 InvalWindowRect( GetControlOwner( m_controlRef ) , &former );
1253 }
1254
1255 Rect controlBounds = *r;
1256
1257 // since the rect passed in is always (even in non-compositing) relative
1258 // to the (native) parent, we have to adjust to window relative here
1259 wxMacControl* parent = m_peer->GetParent()->GetPeer();
1260 if ( !parent->m_isRootControl )
1261 {
1262 Rect superRect;
1263 GetControlBounds( parent->m_controlRef , &superRect );
1264 OffsetRect( &controlBounds , superRect.left , superRect.top );
1265 }
1266
1267 SetControlBounds( m_controlRef , &controlBounds );
1268 if ( vis )
1269 InvalWindowRect( GetControlOwner( m_controlRef ) , &controlBounds );
1270 }
1271 }
1272
1273 void wxMacControl::GetRect( Rect *r )
1274 {
1275 GetControlBounds( m_controlRef , r );
1276 if ( !m_isCompositing )
1277 {
1278 // correct the case of the root control
1279 if ( m_isRootControl )
1280 {
1281 WindowRef wr = GetControlOwner( m_controlRef );
1282 GetWindowBounds( wr , kWindowContentRgn , r );
1283 r->right -= r->left;
1284 r->bottom -= r->top;
1285 r->left = 0;
1286 r->top = 0;
1287 }
1288 else
1289 {
1290 wxMacControl* parent = m_peer->GetParent()->GetPeer();
1291 if ( !parent->m_isRootControl )
1292 {
1293 Rect superRect;
1294 GetControlBounds( parent->m_controlRef , &superRect );
1295 OffsetRect( r , -superRect.left , -superRect.top );
1296 }
1297 }
1298 }
1299 }
1300
1301 void wxMacControl::GetRectInWindowCoords( Rect *r )
1302 {
1303 UMAGetControlBoundsInWindowCoords( m_controlRef , r );
1304 }
1305
1306 void wxMacControl::GetBestRect( Rect *r )
1307 {
1308 short baselineoffset;
1309
1310 GetBestControlRect( m_controlRef , r , &baselineoffset );
1311 }
1312
1313 void wxMacControl::SetLabel( const wxString &title )
1314 {
1315 wxFontEncoding encoding;
1316
1317 if ( m_font.Ok() )
1318 encoding = m_font.GetEncoding();
1319 else
1320 encoding = wxFont::GetDefaultEncoding();
1321
1322 UMASetControlTitle( m_controlRef , title , encoding );
1323 }
1324
1325 void wxMacControl::GetFeatures( UInt32 * features )
1326 {
1327 GetControlFeatures( m_controlRef , features );
1328 }
1329
1330 OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region )
1331 {
1332 OSStatus err = GetControlRegion( m_controlRef , partCode , region );
1333 if ( !m_isCompositing )
1334 {
1335 if ( !m_isRootControl )
1336 {
1337 Rect r;
1338
1339 GetControlBounds(m_controlRef, &r );
1340 if ( !EmptyRgn( region ) )
1341 OffsetRgn( region , -r.left , -r.top );
1342 }
1343 }
1344
1345 return err;
1346 }
1347
1348 OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other )
1349 {
1350 #if TARGET_API_MAC_OSX
1351 return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow,
1352 (other != NULL) ? other->m_controlRef : NULL);
1353 #else
1354 return 0;
1355 #endif
1356 }
1357
1358 #if TARGET_API_MAC_OSX
1359 // SetNeedsDisplay would not invalidate the children
1360 static void InvalidateControlAndChildren( HIViewRef control )
1361 {
1362 HIViewSetNeedsDisplay( control , true );
1363 UInt16 childrenCount = 0;
1364 OSStatus err = CountSubControls( control , &childrenCount );
1365 if ( err == errControlIsNotEmbedder )
1366 return;
1367
1368 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") );
1369
1370 for ( UInt16 i = childrenCount; i >=1; --i )
1371 {
1372 HIViewRef child;
1373
1374 err = GetIndexedSubControl( control , i , & child );
1375 if ( err == errControlIsNotEmbedder )
1376 return;
1377
1378 InvalidateControlAndChildren( child );
1379 }
1380 }
1381 #endif
1382
1383 void wxMacControl::InvalidateWithChildren()
1384 {
1385 #if TARGET_API_MAC_OSX
1386 InvalidateControlAndChildren( m_controlRef );
1387 #endif
1388 }
1389
1390 void wxMacControl::ScrollRect( wxRect *r , int dx , int dy )
1391 {
1392 wxASSERT( r != NULL );
1393
1394 #if TARGET_API_MAC_OSX
1395 if ( m_isCompositing )
1396 {
1397 HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height);
1398 HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy );
1399 }
1400 else
1401 #endif
1402 {
1403 Rect bounds;
1404
1405 GetControlBounds( m_controlRef , &bounds );
1406 bounds.left += r->x;
1407 bounds.top += r->y;
1408 bounds.bottom = bounds.top + r->height;
1409 bounds.right = bounds.left + r->width;
1410 wxMacWindowClipper clip( m_peer );
1411 RgnHandle updateRgn = NewRgn();
1412 ::ScrollRect( &bounds , dx , dy , updateRgn );
1413 InvalWindowRgn( GetControlOwner( m_controlRef ) , updateRgn );
1414 DisposeRgn( updateRgn );
1415 }
1416 }
1417
1418 OSType wxMacCreator = 'WXMC';
1419 OSType wxMacControlProperty = 'MCCT';
1420
1421 void wxMacControl::SetReferenceInNativeControl()
1422 {
1423 void * data = this;
1424 verify_noerr( SetControlProperty ( m_controlRef ,
1425 wxMacCreator,wxMacControlProperty, sizeof(data), &data ) );
1426 }
1427
1428 wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control)
1429 {
1430 wxMacControl* ctl = NULL;
1431 UInt32 actualSize;
1432 if ( GetControlProperty( control ,wxMacCreator,wxMacControlProperty, sizeof(ctl) ,
1433 &actualSize , &ctl ) == noErr )
1434 {
1435 return ctl;
1436 }
1437 return NULL;
1438 }
1439
1440 // ============================================================================
1441 // DataBrowser Wrapper
1442 // ============================================================================
1443 //
1444 // basing on DataBrowserItemIDs
1445 //
1446
1447 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1448 ControlRef browser,
1449 DataBrowserItemID itemID,
1450 DataBrowserItemNotification message,
1451 DataBrowserItemDataRef itemData )
1452 {
1453 wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1454 if ( ctl != 0 )
1455 {
1456 ctl->ItemNotification(itemID, message, itemData);
1457 }
1458 }
1459
1460 pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1461 ControlRef browser,
1462 DataBrowserItemID itemID,
1463 DataBrowserPropertyID property,
1464 DataBrowserItemDataRef itemData,
1465 Boolean changeValue )
1466 {
1467 OSStatus err = errDataBrowserPropertyNotSupported;
1468
1469 wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1470 if ( ctl != 0 )
1471 {
1472 err = ctl->GetSetItemData(itemID, property, itemData, changeValue);
1473 }
1474 return err;
1475 }
1476
1477 pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc(
1478 ControlRef browser,
1479 DataBrowserItemID itemOneID,
1480 DataBrowserItemID itemTwoID,
1481 DataBrowserPropertyID sortProperty)
1482 {
1483 wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1484 if ( ctl != 0 )
1485 {
1486 return ctl->CompareItems(itemOneID, itemTwoID, sortProperty);
1487 }
1488 return false;
1489 }
1490
1491 DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL;
1492 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL;
1493 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL;
1494
1495 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style) : wxMacControl( peer )
1496 {
1497 Rect bounds = wxMacGetBoundsForControl( peer, pos, size );
1498 OSStatus err = ::CreateDataBrowserControl(
1499 MAC_WXHWND(peer->MacGetTopLevelWindowRef()),
1500 &bounds, kDataBrowserListView, &m_controlRef );
1501 SetReferenceInNativeControl();
1502 verify_noerr( err );
1503 if ( gDataBrowserItemCompareUPP == NULL )
1504 gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc);
1505 if ( gDataBrowserItemDataUPP == NULL )
1506 gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc);
1507 if ( gDataBrowserItemNotificationUPP == NULL )
1508 {
1509 gDataBrowserItemNotificationUPP =
1510 #if TARGET_API_MAC_OSX
1511 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc);
1512 #else
1513 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc);
1514 #endif
1515 }
1516
1517 DataBrowserCallbacks callbacks;
1518 InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks );
1519
1520 callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP;
1521 callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP;
1522 callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP;
1523 SetCallbacks( &callbacks );
1524
1525 }
1526
1527 OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container,
1528 Boolean recurse,
1529 DataBrowserItemState state,
1530 UInt32 *numItems) const
1531 {
1532 return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems );
1533 }
1534
1535 OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container,
1536 Boolean recurse,
1537 DataBrowserItemState state,
1538 Handle items) const
1539 {
1540 return GetDataBrowserItems( m_controlRef, container, recurse, state, items );
1541 }
1542
1543 OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options )
1544 {
1545 return SetDataBrowserSelectionFlags( m_controlRef, options );
1546 }
1547
1548 OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc,
1549 DataBrowserTableViewColumnIndex position )
1550 {
1551 return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position );
1552 }
1553
1554 OSStatus wxMacDataBrowserControl::AutoSizeColumns()
1555 {
1556 return AutoSizeDataBrowserListViewColumns(m_controlRef);
1557 }
1558
1559 OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert )
1560 {
1561 return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert );
1562 }
1563
1564 OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
1565 {
1566 return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle );
1567 }
1568
1569 OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height)
1570 {
1571 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
1572 }
1573
1574 OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height)
1575 {
1576 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
1577 }
1578
1579 OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks)
1580 {
1581 return SetDataBrowserCallbacks( m_controlRef, callbacks );
1582 }
1583
1584 OSStatus wxMacDataBrowserControl::UpdateItems(
1585 DataBrowserItemID container,
1586 UInt32 numItems,
1587 const DataBrowserItemID *items,
1588 DataBrowserPropertyID preSortProperty,
1589 DataBrowserPropertyID propertyID ) const
1590 {
1591 return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID );
1592 }
1593
1594 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const
1595 {
1596 return IsDataBrowserItemSelected( m_controlRef, item );
1597 }
1598
1599 OSStatus wxMacDataBrowserControl::AddItems(
1600 DataBrowserItemID container,
1601 UInt32 numItems,
1602 const DataBrowserItemID *items,
1603 DataBrowserPropertyID preSortProperty )
1604 {
1605 return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
1606 }
1607
1608 OSStatus wxMacDataBrowserControl::RemoveItems(
1609 DataBrowserItemID container,
1610 UInt32 numItems,
1611 const DataBrowserItemID *items,
1612 DataBrowserPropertyID preSortProperty )
1613 {
1614 return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
1615 }
1616
1617 OSStatus wxMacDataBrowserControl::RevealItem(
1618 DataBrowserItemID item,
1619 DataBrowserPropertyID propertyID,
1620 DataBrowserRevealOptions options ) const
1621 {
1622 return RevealDataBrowserItem( m_controlRef, item, propertyID, options );
1623 }
1624
1625 OSStatus wxMacDataBrowserControl::SetSelectedItems(
1626 UInt32 numItems,
1627 const DataBrowserItemID *items,
1628 DataBrowserSetOption operation )
1629 {
1630 return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation );
1631 }
1632
1633 OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const
1634 {
1635 return GetDataBrowserSelectionAnchor( m_controlRef, first, last );
1636 }
1637
1638 OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
1639 {
1640 return GetDataBrowserTableViewItemID( m_controlRef, row, item );
1641 }
1642
1643 OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const
1644 {
1645 return GetDataBrowserTableViewItemRow( m_controlRef, item, row );
1646 }
1647
1648 OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height )
1649 {
1650 return SetDataBrowserTableViewRowHeight( m_controlRef , height );
1651 }
1652
1653 OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const
1654 {
1655 return GetDataBrowserTableViewRowHeight( m_controlRef, height );
1656 }
1657
1658 OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height)
1659 {
1660 return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height );
1661 }
1662
1663 OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const
1664 {
1665 return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height);
1666 }
1667
1668 OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const
1669 {
1670 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
1671 }
1672
1673 OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width )
1674 {
1675 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
1676 }
1677
1678 OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const
1679 {
1680 return GetDataBrowserTableViewColumnWidth( m_controlRef , width );
1681 }
1682
1683 OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width )
1684 {
1685 return SetDataBrowserTableViewColumnWidth( m_controlRef , width );
1686 }
1687
1688 OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const
1689 {
1690 return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns);
1691 }
1692
1693 OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column,
1694 UInt32 *position) const
1695 {
1696 return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
1697 }
1698
1699 OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, UInt32 position)
1700 {
1701 return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
1702 }
1703
1704 OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
1705 {
1706 return GetDataBrowserScrollPosition( m_controlRef , top , left );
1707 }
1708
1709 OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left )
1710 {
1711 return SetDataBrowserScrollPosition( m_controlRef , top , left );
1712 }
1713
1714 OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const
1715 {
1716 return GetDataBrowserSortProperty( m_controlRef , column );
1717 }
1718
1719 OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column )
1720 {
1721 return SetDataBrowserSortProperty( m_controlRef , column );
1722 }
1723
1724 OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const
1725 {
1726 return GetDataBrowserSortOrder( m_controlRef , order );
1727 }
1728
1729 OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order )
1730 {
1731 return SetDataBrowserSortOrder( m_controlRef , order );
1732 }
1733
1734 OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property,
1735 DataBrowserPropertyFlags *flags ) const
1736 {
1737 return GetDataBrowserPropertyFlags( m_controlRef , property , flags );
1738 }
1739
1740 OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property,
1741 DataBrowserPropertyFlags flags )
1742 {
1743 return SetDataBrowserPropertyFlags( m_controlRef , property , flags );
1744 }
1745
1746 OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property,
1747 DataBrowserListViewHeaderDesc *desc ) const
1748 {
1749 return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
1750 }
1751
1752 OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property,
1753 DataBrowserListViewHeaderDesc *desc )
1754 {
1755 return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
1756 }
1757
1758 OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property ,
1759 Boolean expandableRows )
1760 {
1761 return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows);
1762 }
1763
1764 // ============================================================================
1765 // Higher-level Databrowser
1766 // ============================================================================
1767 //
1768 // basing on data item objects
1769 //
1770
1771 wxMacDataItem::wxMacDataItem()
1772 {
1773 }
1774
1775 wxMacDataItem::~wxMacDataItem()
1776 {
1777 }
1778
1779 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *owner ,
1780 const wxMacDataItem*,
1781 DataBrowserPropertyID property) const
1782 {
1783 return false;
1784 }
1785
1786 OSStatus wxMacDataItem::GetSetData(wxMacDataItemBrowserControl *owner ,
1787 DataBrowserPropertyID property,
1788 DataBrowserItemDataRef itemData,
1789 bool changeValue )
1790 {
1791 return errDataBrowserPropertyNotSupported;
1792 }
1793
1794 void wxMacDataItem::Notification(wxMacDataItemBrowserControl *owner ,
1795 DataBrowserItemNotification message,
1796 DataBrowserItemDataRef itemData ) const
1797 {
1798 }
1799
1800
1801 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) :
1802 wxMacDataBrowserControl( peer, pos, size, style )
1803 {
1804 m_suppressSelection = false;
1805 }
1806
1807 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser)
1808 {
1809 m_former = browser->SuppressSelection(true);
1810 m_browser = browser;
1811 }
1812
1813 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1814 {
1815 m_browser->SuppressSelection(m_former);
1816 }
1817
1818 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress )
1819 {
1820 bool former = m_suppressSelection;
1821 m_suppressSelection = suppress;
1822
1823 return former;
1824 }
1825
1826 Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID,
1827 DataBrowserItemID itemTwoID,
1828 DataBrowserPropertyID sortProperty)
1829 {
1830 wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID;
1831 wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID;
1832 return CompareItems( itemOne , itemTwo , sortProperty );
1833 }
1834
1835 Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne,
1836 const wxMacDataItem* itemTwo,
1837 DataBrowserPropertyID sortProperty)
1838 {
1839 Boolean retval = false;
1840 if ( itemOne != NULL )
1841 retval = itemOne->IsLessThan( this , itemTwo , sortProperty);
1842 return retval;
1843 }
1844
1845 OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1846 DataBrowserItemID itemID,
1847 DataBrowserPropertyID property,
1848 DataBrowserItemDataRef itemData,
1849 Boolean changeValue )
1850 {
1851 wxMacDataItem* item = (wxMacDataItem*) itemID;
1852 return GetSetItemData(item, property, itemData , changeValue );
1853 }
1854
1855 OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1856 wxMacDataItem* item,
1857 DataBrowserPropertyID property,
1858 DataBrowserItemDataRef itemData,
1859 Boolean changeValue )
1860 {
1861 OSStatus err = errDataBrowserPropertyNotSupported;
1862 switch( property )
1863 {
1864 case kDataBrowserContainerIsClosableProperty :
1865 case kDataBrowserContainerIsSortableProperty :
1866 case kDataBrowserContainerIsOpenableProperty :
1867 // right now default behaviour on these
1868 break;
1869 default :
1870 if ( item != NULL )
1871 err = item->GetSetData( this, property , itemData , changeValue );
1872 break;
1873
1874 }
1875 return err;
1876 }
1877
1878 void wxMacDataItemBrowserControl::ItemNotification(
1879 DataBrowserItemID itemID,
1880 DataBrowserItemNotification message,
1881 DataBrowserItemDataRef itemData)
1882 {
1883 wxMacDataItem* item = (wxMacDataItem*) itemID;
1884 ItemNotification( item , message, itemData);
1885 }
1886
1887 void wxMacDataItemBrowserControl::ItemNotification(
1888 const wxMacDataItem* item,
1889 DataBrowserItemNotification message,
1890 DataBrowserItemDataRef itemData)
1891 {
1892 if (item != NULL)
1893 item->Notification( this, message, itemData);
1894 }
1895
1896 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container,
1897 bool recurse , DataBrowserItemState state) const
1898 {
1899 UInt32 numItems = 0;
1900 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container,
1901 recurse, state, &numItems ) );
1902 return numItems;
1903 }
1904
1905 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container,
1906 bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const
1907 {
1908 Handle handle = NewHandle(0);
1909 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container ,
1910 recurse , state, handle) );
1911
1912 int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID);
1913 HLock( handle );
1914 wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle;
1915 for ( int i = 0; i < itemCount; ++i)
1916 {
1917 items.Add(itemsArray[i]);
1918 }
1919 HUnlock( handle );
1920 DisposeHandle( handle );
1921 }
1922
1923 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const
1924 {
1925 DataBrowserTableViewRowIndex row;
1926 OSStatus err = GetItemRow( (DataBrowserItemID) item , &row);
1927 wxASSERT( err == noErr);
1928 return row;
1929 }
1930
1931 wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const
1932 {
1933 DataBrowserItemID id;
1934 OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id);
1935 wxASSERT( err == noErr);
1936 return (wxMacDataItem*) id;
1937 }
1938
1939 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container,
1940 const wxMacDataItem *item , DataBrowserPropertyID property) const
1941 {
1942 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1,
1943 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) );
1944 }
1945
1946 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container,
1947 wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const
1948 {
1949 unsigned int noItems = itemArray.GetCount();
1950 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1951 for ( unsigned int i = 0; i < noItems; ++i )
1952 items[i] = (DataBrowserItemID) itemArray[i];
1953
1954 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems,
1955 items, kDataBrowserItemNoProperty /* notSorted */, property ) );
1956 delete [] items;
1957 }
1958
1959 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item)
1960 {
1961 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1,
1962 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) );
1963 }
1964
1965 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray )
1966 {
1967 unsigned int noItems = itemArray.GetCount();
1968 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1969 for ( unsigned int i = 0; i < noItems; ++i )
1970 items[i] = (DataBrowserItemID) itemArray[i];
1971
1972 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems,
1973 (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) );
1974 delete [] items;
1975 }
1976
1977 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item)
1978 {
1979 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1,
1980 (UInt32*) &item, kDataBrowserItemNoProperty );
1981 verify_noerr( err );
1982 }
1983
1984 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray)
1985 {
1986 unsigned int noItems = itemArray.GetCount();
1987 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1988 for ( unsigned int i = 0; i < noItems; ++i )
1989 items[i] = (DataBrowserItemID) itemArray[i];
1990
1991 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems,
1992 (UInt32*) items, kDataBrowserItemNoProperty );
1993 verify_noerr( err );
1994 delete [] items;
1995 }
1996
1997 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container)
1998 {
1999 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty );
2000 verify_noerr( err );
2001 }
2002
2003 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option)
2004 {
2005 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option ));
2006 }
2007
2008 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option)
2009 {
2010 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option ));
2011 }
2012
2013 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option)
2014 {
2015 unsigned int noItems = itemArray.GetCount();
2016 DataBrowserItemID *items = new DataBrowserItemID[noItems];
2017 for ( unsigned int i = 0; i < noItems; ++i )
2018 items[i] = (DataBrowserItemID) itemArray[i];
2019
2020 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option ));
2021 delete [] items;
2022 }
2023
2024 Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const
2025 {
2026 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item);
2027 }
2028
2029 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options)
2030 {
2031 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) );
2032 }
2033
2034 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const
2035 {
2036 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) );
2037 }
2038
2039
2040
2041 //
2042 // Tab Control
2043 //
2044
2045 OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable )
2046 {
2047 return ::SetTabEnabled( m_controlRef , tabNo , enable );
2048 }
2049
2050 //
2051 // Quartz Support
2052 //
2053
2054 #ifdef __WXMAC_OSX__
2055 // snippets from Sketch Sample from Apple :
2056
2057 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2058
2059 /*
2060 This function locates, opens, and returns the profile reference for the calibrated
2061 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2062 with the profile reference this function returns.
2063 */
2064 CMProfileRef wxMacOpenGenericProfile()
2065 {
2066 static CMProfileRef cachedRGBProfileRef = NULL;
2067
2068 // we only create the profile reference once
2069 if (cachedRGBProfileRef == NULL)
2070 {
2071 CMProfileLocation loc;
2072
2073 loc.locType = cmPathBasedProfile;
2074 strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr);
2075
2076 verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) );
2077 }
2078
2079 // clone the profile reference so that the caller has their own reference, not our cached one
2080 if (cachedRGBProfileRef)
2081 CMCloneProfileRef(cachedRGBProfileRef);
2082
2083 return cachedRGBProfileRef;
2084 }
2085
2086 /*
2087 Return the generic RGB color space. This is a 'get' function and the caller should
2088 not release the returned value unless the caller retains it first. Usually callers
2089 of this routine will immediately use the returned colorspace with CoreGraphics
2090 so they typically do not need to retain it themselves.
2091
2092 This function creates the generic RGB color space once and hangs onto it so it can
2093 return it whenever this function is called.
2094 */
2095
2096 CGColorSpaceRef wxMacGetGenericRGBColorSpace()
2097 {
2098 static wxMacCFRefHolder<CGColorSpaceRef> genericRGBColorSpace;
2099
2100 if (genericRGBColorSpace == NULL)
2101 {
2102 if ( UMAGetSystemVersion() >= 0x1040 )
2103 {
2104 genericRGBColorSpace.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2105 }
2106 else
2107 {
2108 CMProfileRef genericRGBProfile = wxMacOpenGenericProfile();
2109
2110 if (genericRGBProfile)
2111 {
2112 genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) );
2113
2114 wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") );
2115
2116 // we opened the profile so it is up to us to close it
2117 CMCloseProfile(genericRGBProfile);
2118 }
2119 }
2120 }
2121
2122 return genericRGBColorSpace;
2123 }
2124 #endif
2125
2126 wxMacPortSaver::wxMacPortSaver( GrafPtr port )
2127 {
2128 ::GetPort( &m_port );
2129 ::SetPort( port );
2130 }
2131
2132 wxMacPortSaver::~wxMacPortSaver()
2133 {
2134 ::SetPort( m_port );
2135 }
2136
2137 #endif // wxUSE_GUI