1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/carbon/utils.cpp 
   3 // Purpose:     Various utilities 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  21 #include "wx/apptrait.h" 
  24     #include "wx/mac/uma.h" 
  26     #include "wx/toplevel.h" 
  36 #include "MoreFilesX.h" 
  44 #if TARGET_API_MAC_OSX 
  45     #include <CoreServices/CoreServices.h> 
  47     #include <DriverServices.h> 
  48     #include <Multiprocessing.h> 
  52     #include <Carbon/Carbon.h> 
  54     #include <ATSUnicode.h> 
  55     #include <TextCommon.h> 
  56     #include <TextEncodingConverter.h> 
  60 #include "wx/mac/private.h" 
  62 #if defined(__MWERKS__) && wxUSE_UNICODE 
  63 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__) 
  68 // --------------------------------------------------------------------------- 
  69 // code used in both base and GUI compilation 
  70 // --------------------------------------------------------------------------- 
  72 // our OS version is the same in non GUI and GUI cases 
  73 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
) 
  77     // are there x-platform conventions ? 
  79     Gestalt(gestaltSystemVersion
, &theSystem
); 
  81         *minorVsn 
= (theSystem 
& 0xFF); 
  84         *majorVsn 
= (theSystem 
>> 8); 
  96 // ---------------------------------------------------------------------------- 
  98 // ---------------------------------------------------------------------------- 
 100 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) 
 102 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... 
 104 #ifndef __MetroNubUtils__ 
 105 #include "MetroNubUtils.h" 
 112 #if TARGET_API_MAC_CARBON 
 114 #include <CodeFragments.h> 
 116 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...); 
 118 ProcPtr gCallUniversalProc_Proc 
= NULL
; 
 122 static MetroNubUserEntryBlock
*    gMetroNubEntry 
= NULL
; 
 124 static long fRunOnce 
= false; 
 127 Boolean 
IsMetroNubInstalled() 
 134         gMetroNubEntry 
= NULL
; 
 136         if (Gestalt(gestaltSystemVersion
, &value
) == noErr 
&& value 
< 0x1000) 
 138             // look for MetroNub's Gestalt selector 
 139             if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
) 
 141 #if TARGET_API_MAC_CARBON 
 142                 if (gCallUniversalProc_Proc 
== NULL
) 
 144                     CFragConnectionID   connectionID
; 
 147                     ProcPtr             symbolAddress
; 
 149                     CFragSymbolClass    symbolClass
; 
 151                     symbolAddress 
= NULL
; 
 152                     err 
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
, 
 153                                            &connectionID
, &mainAddress
, errorString
); 
 157                         gCallUniversalProc_Proc 
= NULL
; 
 161                     err 
= FindSymbol(connectionID
, "\pCallUniversalProc", 
 162                                     (Ptr 
*) &gCallUniversalProc_Proc
, &symbolClass
); 
 166                         gCallUniversalProc_Proc 
= NULL
; 
 173                     MetroNubUserEntryBlock
* block 
= (MetroNubUserEntryBlock 
*)result
; 
 175                     // make sure the version of the API is compatible 
 176                     if (block
->apiLowVersion 
<= kMetroNubUserAPIVersion 
&& 
 177                         kMetroNubUserAPIVersion 
<= block
->apiHiVersion
) 
 180                         gMetroNubEntry 
= block
; 
 189 #if TARGET_API_MAC_CARBON 
 190     return (gMetroNubEntry 
!= NULL 
&& gCallUniversalProc_Proc 
!= NULL
); 
 192     return (gMetroNubEntry 
!= NULL
); 
 196 Boolean 
IsMWDebuggerRunning() 
 198     if (IsMetroNubInstalled()) 
 199         return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
); 
 204 Boolean 
AmIBeingMWDebugged() 
 206     if (IsMetroNubInstalled()) 
 207         return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
); 
 212 extern bool WXDLLEXPORT 
wxIsDebuggerRunning() 
 214     return IsMWDebuggerRunning() && AmIBeingMWDebugged(); 
 219 extern bool WXDLLEXPORT 
wxIsDebuggerRunning() 
 224 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) 
 228 // defined in unix/utilsunx.cpp for Mac OS X 
 230 // get full hostname (with domain name if possible) 
 231 bool wxGetFullHostName(wxChar 
*buf
, int maxSize
) 
 233     return wxGetHostName(buf
, maxSize
); 
 236 // Get user ID e.g. jacs 
 237 bool wxGetUserId(wxChar 
*buf
, int maxSize
) 
 239     return wxGetUserName( buf 
, maxSize 
); 
 242 const wxChar
* wxGetHomeDir(wxString 
*pstr
) 
 244     *pstr 
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder 
); 
 245     return pstr
->c_str(); 
 248 // Get hostname only (without domain name) 
 249 bool wxGetHostName(wxChar 
*buf
, int maxSize
) 
 251     // Gets Chooser name of user by examining a System resource. 
 254     const short kComputerNameID 
= -16413; 
 256     short oldResFile 
= CurResFile(); 
 258     StringHandle chooserName 
= (StringHandle
)::GetString(kComputerNameID
); 
 259     UseResFile(oldResFile
); 
 261     if (chooserName 
&& *chooserName
) 
 263         HLock( (Handle
) chooserName 
); 
 264         wxString name 
= wxMacMakeStringFromPascal( *chooserName 
); 
 265         HUnlock( (Handle
) chooserName 
); 
 266         ReleaseResource( (Handle
) chooserName 
); 
 267         wxStrncpy( buf 
, name 
, maxSize 
- 1 ); 
 273 // Get user name e.g. Stefan Csomor 
 274 bool wxGetUserName(wxChar 
*buf
, int maxSize
) 
 276     // Gets Chooser name of user by examining a System resource. 
 279     const short kChooserNameID 
= -16096; 
 281     short oldResFile 
= CurResFile(); 
 283     StringHandle chooserName 
= (StringHandle
)::GetString(kChooserNameID
); 
 284     UseResFile(oldResFile
); 
 286     if (chooserName 
&& *chooserName
) 
 288         HLock( (Handle
) chooserName 
); 
 289         wxString name 
= wxMacMakeStringFromPascal( *chooserName 
); 
 290         HUnlock( (Handle
) chooserName 
); 
 291         ReleaseResource( (Handle
) chooserName 
); 
 292         wxStrncpy( buf 
, name 
, maxSize 
- 1 ); 
 298 int wxKill(long pid
, wxSignal sig 
, wxKillError 
*rc
, int flags
) 
 304 WXDLLEXPORT 
bool wxGetEnv(const wxString
& var
, wxString 
*value
) 
 306     // TODO : under classic there is no environement support, under X yes 
 310 // set the env var name to the given value, return true on success 
 311 WXDLLEXPORT 
bool wxSetEnv(const wxString
& var
, const wxChar 
*value
) 
 313     // TODO : under classic there is no environement support, under X yes 
 317 // Execute a program in an Interactive Shell 
 318 bool wxShell(const wxString
& command
) 
 324 // Shutdown or reboot the PC 
 325 bool wxShutdown(wxShutdownFlags wFlags
) 
 331 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) 
 332 wxMemorySize 
wxGetFreeMemory() 
 334     return (wxMemorySize
)FreeMem(); 
 339 void wxMicroSleep(unsigned long microseconds
) 
 341     AbsoluteTime wakeup 
= AddDurationToAbsolute( microseconds 
* durationMicrosecond 
, UpTime()); 
 342     MPDelayUntil( & wakeup
); 
 345 void wxMilliSleep(unsigned long milliseconds
) 
 347     AbsoluteTime wakeup 
= AddDurationToAbsolute( milliseconds
, UpTime()); 
 348     MPDelayUntil( & wakeup
); 
 351 void wxSleep(int nSecs
) 
 353     wxMilliSleep(1000*nSecs
); 
 358 // Consume all events until no more left 
 363 #endif // !__DARWIN__ 
 371 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo() 
 373     static wxToolkitInfo info
; 
 375     info
.os 
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
); 
 376     info
.name 
= _T("wxBase"); 
 385 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo() 
 387     static wxToolkitInfo info
; 
 389     info
.os 
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
); 
 390     info
.shortName 
= _T("mac"); 
 391     info
.name 
= _T("wxMac"); 
 393 #ifdef __WXUNIVERSAL__ 
 394     info
.shortName 
<< _T("univ"); 
 395     info
.name 
<< _T("/wxUniversal"); 
 401 // Reading and writing resources (eg WIN.INI, .Xdefaults) 
 403 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
) 
 409 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
) 
 412     buf
.Printf(wxT("%.4f"), value
); 
 414     return wxWriteResource(section
, entry
, buf
, file
); 
 417 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
) 
 420     buf
.Printf(wxT("%ld"), value
); 
 422     return wxWriteResource(section
, entry
, buf
, file
); 
 425 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
) 
 428     buf
.Printf(wxT("%d"), value
); 
 430     return wxWriteResource(section
, entry
, buf
, file
); 
 433 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
) 
 439 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
) 
 442     bool succ 
= wxGetResource(section
, entry
, (char **)&s
, file
); 
 445         *value 
= (float)strtod(s
, NULL
); 
 452 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
) 
 455     bool succ 
= wxGetResource(section
, entry
, (char **)&s
, file
); 
 458         *value 
= strtol(s
, NULL
, 10); 
 465 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
) 
 468     bool succ 
= wxGetResource(section
, entry
, (char **)&s
, file
); 
 471         *value 
= (int)strtol(s
, NULL
, 10); 
 477 #endif // wxUSE_RESOURCES 
 479 int gs_wxBusyCursorCount 
= 0; 
 480 extern wxCursor    gMacCurrentCursor
; 
 481 wxCursor        gMacStoredActiveCursor
; 
 483 // Set the cursor to the busy cursor for all windows 
 484 void wxBeginBusyCursor(const wxCursor 
*cursor
) 
 486     if (gs_wxBusyCursorCount
++ == 0) 
 488         gMacStoredActiveCursor 
= gMacCurrentCursor
; 
 489         cursor
->MacInstall(); 
 491     //else: nothing to do, already set 
 494 // Restore cursor to normal 
 495 void wxEndBusyCursor() 
 497     wxCHECK_RET( gs_wxBusyCursorCount 
> 0, 
 498         wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") ); 
 500     if (--gs_wxBusyCursorCount 
== 0) 
 502         gMacStoredActiveCursor
.MacInstall(); 
 503         gMacStoredActiveCursor 
= wxNullCursor
; 
 507 // true if we're between the above two calls 
 510     return (gs_wxBusyCursorCount 
> 0); 
 517 wxString 
wxMacFindFolderNoSeparator( short        vol
, 
 519               Boolean      createFolder
) 
 524     if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
) 
 526         strDir 
= wxMacFSRefToPath( &fsRef 
); 
 532 wxString 
wxMacFindFolder( short        vol
, 
 534               Boolean      createFolder
) 
 536     return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
; 
 543 // Check whether this window wants to process messages, e.g. Stop button 
 544 // in long calculations. 
 545 bool wxCheckForInterrupt(wxWindow 
*wnd
) 
 551 void wxGetMousePosition( int* x
, int* y 
) 
 556     LocalToGlobal( &pt 
); 
 561 // Return true if we have a colour display 
 562 bool wxColourDisplay() 
 567 // Returns depth of screen 
 571     SetRect(&globRect
, -32760, -32760, 32760, 32760); 
 572     GDHandle    theMaxDevice
; 
 575     theMaxDevice 
= GetMaxDevice(&globRect
); 
 576     if (theMaxDevice 
!= NULL
) 
 577         theDepth 
= (**(**theMaxDevice
).gdPMap
).pixelSize
; 
 582 // Get size of display 
 583 void wxDisplaySize(int *width
, int *height
) 
 586     GetQDGlobalsScreenBits( &screenBits 
); 
 589         *width 
= screenBits
.bounds
.right 
- screenBits
.bounds
.left
; 
 592         *height 
= screenBits
.bounds
.bottom 
- screenBits
.bounds
.top
; 
 595 void wxDisplaySizeMM(int *width
, int *height
) 
 597     wxDisplaySize(width
, height
); 
 598     // on mac 72 is fixed (at least now;-) 
 599     float cvPt2Mm 
= 25.4 / 72; 
 602         *width 
= int( *width 
* cvPt2Mm 
); 
 605         *height 
= int( *height 
* cvPt2Mm 
); 
 608 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
) 
 612     GetAvailableWindowPositioningBounds( GetMainDevice() , &r 
); 
 618         *width 
= r
.right 
- r
.left
; 
 620         *height 
= r
.bottom 
- r
.top
; 
 623 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
) 
 625     return wxGenericFindWindowAtPoint(pt
); 
 632 wxString 
wxGetOsDescription() 
 634 #ifdef WXWIN_OS_DESCRIPTION 
 635     // use configure generated description if available 
 636     return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")")); 
 638     return wxT("MacOS"); //TODO:define further 
 643 wxChar 
*wxGetUserHome (const wxString
& user
) 
 649 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t 
*pTotal
, wxDiskspaceSize_t 
*pFree
) 
 658     int pos 
= p
.Find(':'); 
 659     if ( pos 
!= wxNOT_FOUND 
) 
 667     err 
= wxMacPathToFSRef( p 
, &fsRef 
); 
 670         FSVolumeRefNum vRefNum
; 
 671         err 
= FSGetVRefNum( &fsRef 
, &vRefNum 
); 
 674             UInt64 freeBytes 
, totalBytes
; 
 675             err 
= FSGetVInfo( vRefNum 
, NULL 
, &freeBytes 
, &totalBytes 
); 
 679                     *pTotal 
= wxDiskspaceSize_t( totalBytes 
); 
 681                     *pFree 
= wxDiskspaceSize_t( freeBytes 
); 
 688 #endif // !__DARWIN__ 
 690 //--------------------------------------------------------------------------- 
 691 // wxMac Specific utility functions 
 692 //--------------------------------------------------------------------------- 
 694 void wxMacStringToPascal( const wxString
&from 
, StringPtr to 
) 
 696     wxCharBuffer buf 
= from
.mb_str( wxConvLocal 
); 
 697     int len 
= strlen(buf
); 
 702     memcpy( (char*) &to
[1] , buf 
, len 
); 
 705 wxString 
wxMacMakeStringFromPascal( ConstStringPtr from 
) 
 707     return wxString( (char*) &from
[1] , wxConvLocal 
, from
[0] ); 
 710 // ---------------------------------------------------------------------------- 
 711 // Common Event Support 
 712 // ---------------------------------------------------------------------------- 
 714 extern ProcessSerialNumber gAppProcess
; 
 718     ProcessSerialNumber psn
; 
 720     psn
.highLongOfPSN 
= 0; 
 721     psn
.lowLongOfPSN 
= kCurrentProcess
; 
 722     SameProcess( &gAppProcess 
, &psn 
, &isSame 
); 
 726         OSStatus err 
= noErr
; 
 729         // lead sometimes to race conditions, although all calls used should be thread safe ... 
 730         static wxMacCarbonEvent s_wakeupEvent
; 
 731         if ( !s_wakeupEvent
.IsValid() ) 
 733            err 
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), 
 734                         kEventAttributeNone 
); 
 739             if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent 
) ) 
 741             s_wakeupEvent
.SetCurrentTime(); 
 742             err 
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
, 
 743                                   kEventPriorityHigh 
); 
 746         wxMacCarbonEvent wakeupEvent
; 
 747         wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), 
 748                             kEventAttributeNone 
); 
 749         err 
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
, 
 750                                kEventPriorityHigh 
); 
 753         PostEvent( nullEvent 
, 0 ); 
 758         WakeUpProcess( &gAppProcess 
); 
 766 // ---------------------------------------------------------------------------- 
 767 // Native Struct Conversions 
 768 // ---------------------------------------------------------------------------- 
 770 void wxMacRectToNative( const wxRect 
*wx 
, Rect 
*n 
) 
 774     n
->right 
= wx
->x 
+ wx
->width
; 
 775     n
->bottom 
= wx
->y 
+ wx
->height
; 
 778 void wxMacNativeToRect( const Rect 
*n 
, wxRect
* wx 
) 
 782     wx
->width 
= n
->right 
- n
->left
; 
 783     wx
->height 
= n
->bottom 
- n
->top
; 
 786 void wxMacPointToNative( const wxPoint
* wx 
, Point 
*n 
) 
 792 void wxMacNativeToPoint( const Point 
*n 
, wxPoint
* wx 
) 
 798 // ---------------------------------------------------------------------------- 
 799 // Carbon Event Support 
 800 // ---------------------------------------------------------------------------- 
 802 OSStatus 
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
) 
 804     return ::GetEventParameter( m_eventRef 
, inName 
, inDesiredType 
, NULL 
, inBufferSize 
, NULL 
, outData 
); 
 807 OSStatus 
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
) 
 809     return ::SetEventParameter( m_eventRef 
, inName 
, inType 
, inBufferSize 
, inData 
); 
 812 // ---------------------------------------------------------------------------- 
 813 // Control Access Support 
 814 // ---------------------------------------------------------------------------- 
 816 wxMacControl::wxMacControl(wxWindow
* peer 
, bool isRootControl 
) 
 820     m_isRootControl 
= isRootControl
; 
 821     m_isCompositing 
= peer
->MacGetTopLevelWindow()->MacUsesCompositing(); 
 824 wxMacControl::wxMacControl( wxWindow
* peer 
, ControlRef control 
) 
 828     m_isCompositing 
= peer
->MacGetTopLevelWindow()->MacUsesCompositing(); 
 829     m_controlRef 
= control
; 
 832 wxMacControl::wxMacControl( wxWindow
* peer 
, WXWidget control 
) 
 836     m_isCompositing 
= peer
->MacGetTopLevelWindow()->MacUsesCompositing(); 
 837     m_controlRef 
= (ControlRef
) control
; 
 840 wxMacControl::~wxMacControl() 
 844 void wxMacControl::Init() 
 848     m_needsFocusRect 
= false; 
 849     m_isCompositing 
= false; 
 850     m_isRootControl 
= false; 
 853 void wxMacControl::Dispose() 
 855     ::DisposeControl( m_controlRef 
); 
 859 void wxMacControl::SetReference( SInt32 data 
) 
 861     SetControlReference( m_controlRef 
, data 
); 
 864 OSStatus 
wxMacControl::GetData(ControlPartCode inPartCode 
, ResType inTag 
, Size inBufferSize 
, void * inOutBuffer 
, Size 
* outActualSize 
) const 
 866     return ::GetControlData( m_controlRef 
, inPartCode 
, inTag 
, inBufferSize 
, inOutBuffer 
, outActualSize 
); 
 869 OSStatus 
wxMacControl::GetDataSize(ControlPartCode inPartCode 
, ResType inTag 
, Size 
* outActualSize 
) const 
 871     return ::GetControlDataSize( m_controlRef 
, inPartCode 
, inTag 
, outActualSize 
); 
 874 OSStatus 
wxMacControl::SetData(ControlPartCode inPartCode 
, ResType inTag 
, Size inSize 
, const void * inData
) 
 876     return ::SetControlData( m_controlRef 
, inPartCode 
, inTag 
, inSize 
, inData 
); 
 879 OSStatus 
wxMacControl::SendEvent( EventRef event 
, OptionBits inOptions 
) 
 881 #if TARGET_API_MAC_OSX 
 882     return SendEventToEventTargetWithOptions( event
, 
 883         HIObjectGetEventTarget( (HIObjectRef
) m_controlRef 
), inOptions 
); 
 885     #pragma unused(inOptions) 
 886     return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef 
) ); 
 890 OSStatus 
wxMacControl::SendHICommand( HICommand 
&command 
, OptionBits inOptions 
) 
 892     wxMacCarbonEvent 
event( kEventClassCommand 
, kEventCommandProcess 
); 
 894     event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
); 
 896     return SendEvent( event 
, inOptions 
); 
 899 OSStatus 
wxMacControl::SendHICommand( UInt32 commandID 
, OptionBits inOptions  
) 
 903     memset( &command
, 0 , sizeof(command
) ); 
 904     command
.commandID 
= commandID
; 
 905     return SendHICommand( command 
, inOptions 
); 
 908 void wxMacControl::Flash( ControlPartCode part 
, UInt32 ticks 
) 
 910     unsigned long finalTicks
; 
 912     HiliteControl( m_controlRef 
, part 
); 
 913     Delay( ticks 
, &finalTicks 
); 
 914     HiliteControl( m_controlRef 
, kControlNoPart 
); 
 917 SInt32 
wxMacControl::GetValue() const 
 919     return ::GetControl32BitValue( m_controlRef 
); 
 922 SInt32 
wxMacControl::GetMaximum() const 
 924     return ::GetControl32BitMaximum( m_controlRef 
); 
 927 SInt32 
wxMacControl::GetMinimum() const 
 929     return ::GetControl32BitMinimum( m_controlRef 
); 
 932 void wxMacControl::SetValue( SInt32 v 
) 
 934     ::SetControl32BitValue( m_controlRef 
, v 
); 
 937 void wxMacControl::SetMinimum( SInt32 v 
) 
 939     ::SetControl32BitMinimum( m_controlRef 
, v 
); 
 942 void wxMacControl::SetMaximum( SInt32 v 
) 
 944     ::SetControl32BitMaximum( m_controlRef 
, v 
); 
 947 void wxMacControl::SetValueAndRange( SInt32 value 
, SInt32 minimum 
, SInt32 maximum 
) 
 949     ::SetControl32BitMinimum( m_controlRef 
, minimum 
); 
 950     ::SetControl32BitMaximum( m_controlRef 
, maximum 
); 
 951     ::SetControl32BitValue( m_controlRef 
, value 
); 
 954 OSStatus 
wxMacControl::SetFocus( ControlFocusPart focusPart 
) 
 956     return SetKeyboardFocus( GetControlOwner( m_controlRef 
), m_controlRef
, focusPart 
); 
 959 bool wxMacControl::HasFocus() const 
 962     GetKeyboardFocus( GetUserFocusWindow() , &control 
); 
 963     return control 
== m_controlRef
; 
 966 void wxMacControl::SetNeedsFocusRect( bool needs 
) 
 968     m_needsFocusRect 
= needs
; 
 971 bool wxMacControl::NeedsFocusRect() const 
 973     return m_needsFocusRect
; 
 976 void wxMacControl::VisibilityChanged(bool shown
) 
 980 void wxMacControl::SuperChangedPosition() 
 984 void wxMacControl::SetFont( const wxFont 
& font 
, const wxColour
& foreground 
, long windowStyle 
) 
 987     ControlFontStyleRec fontStyle
; 
 988     if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont 
) 
 990         switch ( font
.MacGetThemeFontID() ) 
 992             case kThemeSmallSystemFont 
: 
 993                 fontStyle
.font 
= kControlFontSmallSystemFont
; 
 996             case 109 : // mini font 
1000             case kThemeSystemFont 
: 
1001                 fontStyle
.font 
= kControlFontBigSystemFont
; 
1005                 fontStyle
.font 
= kControlFontBigSystemFont
; 
1009         fontStyle
.flags 
= kControlUseFontMask
; 
1013         fontStyle
.font 
= font
.MacGetFontNum(); 
1014         fontStyle
.style 
= font
.MacGetFontStyle(); 
1015         fontStyle
.size 
= font
.MacGetFontSize(); 
1016         fontStyle
.flags 
= kControlUseFontMask 
| kControlUseFaceMask 
| kControlUseSizeMask
; 
1019     fontStyle
.just 
= teJustLeft
; 
1020     fontStyle
.flags 
|= kControlUseJustMask
; 
1021     if ( ( windowStyle 
& wxALIGN_MASK 
) & wxALIGN_CENTER_HORIZONTAL 
) 
1022         fontStyle
.just 
= teJustCenter
; 
1023     else if ( ( windowStyle 
& wxALIGN_MASK 
) & wxALIGN_RIGHT 
) 
1024         fontStyle
.just 
= teJustRight
; 
1027     // we only should do this in case of a non-standard color, as otherwise 'disabled' controls 
1028     // won't get grayed out by the system anymore 
1030     if ( foreground 
!= *wxBLACK 
) 
1032         fontStyle
.foreColor 
= MAC_WXCOLORREF( foreground
.GetPixel() ); 
1033         fontStyle
.flags 
|= kControlUseForeColorMask
; 
1036     ::SetControlFontStyle( m_controlRef 
, &fontStyle 
); 
1039 void wxMacControl::SetBackground( const wxBrush 
&WXUNUSED(brush
) ) 
1042     // setting up a color proc is not recommended anymore 
1045 void wxMacControl::SetRange( SInt32 minimum 
, SInt32 maximum 
) 
1047     ::SetControl32BitMinimum( m_controlRef 
, minimum 
); 
1048     ::SetControl32BitMaximum( m_controlRef 
, maximum 
); 
1051 short wxMacControl::HandleKey( SInt16 keyCode
,  SInt16 charCode
, EventModifiers modifiers 
) 
1053     return HandleControlKey( m_controlRef 
, keyCode 
, charCode 
, modifiers 
); 
1056 void wxMacControl::SetActionProc( ControlActionUPP   actionProc 
) 
1058     SetControlAction( m_controlRef 
, actionProc 
); 
1061 void wxMacControl::SetViewSize( SInt32 viewSize 
) 
1063     SetControlViewSize(m_controlRef 
, viewSize 
); 
1066 SInt32 
wxMacControl::GetViewSize() const 
1068     return GetControlViewSize( m_controlRef 
); 
1071 bool wxMacControl::IsVisible() const 
1073     return IsControlVisible( m_controlRef 
); 
1076 void wxMacControl::SetVisibility( bool visible 
, bool redraw 
) 
1078     SetControlVisibility( m_controlRef 
, visible 
, redraw 
); 
1081 bool wxMacControl::IsEnabled() const 
1083 #if TARGET_API_MAC_OSX 
1084     return IsControlEnabled( m_controlRef 
); 
1086     return IsControlActive( m_controlRef 
); 
1090 bool wxMacControl::IsActive() const 
1092     return IsControlActive( m_controlRef 
); 
1095 void wxMacControl::Enable( bool enable 
) 
1097 #if TARGET_API_MAC_OSX 
1099         EnableControl( m_controlRef 
); 
1101         DisableControl( m_controlRef 
); 
1104         ActivateControl( m_controlRef 
); 
1106         DeactivateControl( m_controlRef 
); 
1110 void wxMacControl::SetDrawingEnabled( bool enable 
) 
1112 #if TARGET_API_MAC_OSX 
1113     HIViewSetDrawingEnabled( m_controlRef 
, enable 
); 
1117 #if TARGET_API_MAC_OSX 
1118 bool wxMacControl::GetNeedsDisplay() const 
1120 #if TARGET_API_MAC_OSX 
1121     if ( m_isCompositing 
) 
1123         return HIViewGetNeedsDisplay( m_controlRef 
); 
1132         GetControlBounds( m_controlRef
, &controlBounds 
); 
1133         RgnHandle rgn 
= NewRgn(); 
1134         GetWindowRegion ( GetControlOwner( m_controlRef 
) , kWindowUpdateRgn 
, rgn 
); 
1135         Boolean intersect 
= RectInRgn ( &controlBounds 
, rgn 
); 
1143 void wxMacControl::SetNeedsDisplay( RgnHandle where 
) 
1148 #if TARGET_API_MAC_OSX 
1149     if ( m_isCompositing 
) 
1151         HIViewSetNeedsDisplayInRegion( m_controlRef 
, where 
, true ); 
1157         GetControlBounds( m_controlRef
, &controlBounds 
); 
1158         RgnHandle update 
= NewRgn(); 
1159         CopyRgn( where 
, update 
); 
1160         OffsetRgn( update 
, controlBounds
.left 
, controlBounds
.top 
); 
1161         InvalWindowRgn( GetControlOwner( m_controlRef
) , update 
); 
1165 void wxMacControl::SetNeedsDisplay( Rect
* where 
) 
1170 #if TARGET_API_MAC_OSX 
1171     if ( m_isCompositing 
) 
1173         if ( where 
!= NULL 
) 
1175             RgnHandle update 
= NewRgn(); 
1176             RectRgn( update 
, where 
); 
1177             HIViewSetNeedsDisplayInRegion( m_controlRef 
, update 
, true ); 
1178             DisposeRgn( update 
); 
1181             HIViewSetNeedsDisplay( m_controlRef 
, true ); 
1188         GetControlBounds( m_controlRef
, &controlBounds 
); 
1191             Rect whereLocal 
= *where
; 
1192             OffsetRect( &whereLocal 
, controlBounds
.left 
, controlBounds
.top 
); 
1193             SectRect( &controlBounds 
, &whereLocal
, &controlBounds 
); 
1196         InvalWindowRect( GetControlOwner( m_controlRef
) , &controlBounds 
); 
1200 void  wxMacControl::Convert( wxPoint 
*pt 
, wxMacControl 
*from 
, wxMacControl 
*to 
) 
1202 #if TARGET_API_MAC_OSX 
1203     if ( from
->m_peer
->MacGetTopLevelWindow()->MacUsesCompositing() ) 
1209         HIViewConvertPoint( &hiPoint 
, from
->m_controlRef 
, to
->m_controlRef  
); 
1210         pt
->x 
= (int)hiPoint
.x
; 
1211         pt
->y 
= (int)hiPoint
.y
; 
1216         Rect fromRect
, toRect
; 
1218         GetControlBounds( from
->m_controlRef 
, &fromRect 
); 
1219         GetControlBounds( to
->m_controlRef 
, &toRect 
); 
1220         if ( from
->m_isRootControl 
) 
1221             fromRect
.left 
= fromRect
.top 
= 0; 
1222         if ( to
->m_isRootControl 
) 
1223             toRect
.left 
= toRect
.top 
= 0; 
1225         pt
->x 
= pt
->x 
+ fromRect
.left 
- toRect
.left
; 
1226         pt
->y 
= pt
->y 
+ fromRect
.top 
- toRect
.top
; 
1230 void wxMacControl::SetRect( Rect 
*r 
) 
1232 #if TARGET_API_MAC_OSX 
1233     if ( m_isCompositing 
) 
1235         //A HIRect is actually a CGRect on OSX - which consists of two structures - 
1236         //CGPoint and CGSize, which have two floats each 
1237         HIRect hir 
= { { r
->left 
, r
->top 
}, { r
->right 
- r
->left 
, r
->bottom 
- r
->top 
} }; 
1238         HIViewSetFrame ( m_controlRef 
, &hir 
); 
1239         // eventuall we might have to do a SetVisibility( false , true ); 
1240         // before and a SetVisibility( true , true ); after 
1245         bool vis 
= IsVisible(); 
1249             GetControlBounds( m_controlRef 
, &former 
); 
1250             InvalWindowRect( GetControlOwner( m_controlRef 
) , &former 
); 
1253         Rect controlBounds 
= *r
; 
1255         // since the rect passed in is always (even in non-compositing) relative 
1256         // to the (native) parent, we have to adjust to window relative here 
1257         wxMacControl
* parent 
= m_peer
->GetParent()->GetPeer(); 
1258         if ( !parent
->m_isRootControl 
) 
1261             GetControlBounds( parent
->m_controlRef 
, &superRect 
); 
1262             OffsetRect( &controlBounds 
, superRect
.left 
, superRect
.top 
); 
1265         SetControlBounds( m_controlRef 
, &controlBounds 
); 
1267             InvalWindowRect( GetControlOwner( m_controlRef 
) , &controlBounds 
); 
1271 void wxMacControl::GetRect( Rect 
*r 
) 
1273     GetControlBounds( m_controlRef 
, r 
); 
1274     if ( !m_isCompositing 
) 
1276         // correct the case of the root control 
1277         if ( m_isRootControl 
) 
1279             WindowRef wr 
= GetControlOwner( m_controlRef 
); 
1280             GetWindowBounds( wr 
, kWindowContentRgn 
, r 
); 
1281             r
->right 
-= r
->left
; 
1282             r
->bottom 
-= r
->top
; 
1288             wxMacControl
* parent 
= m_peer
->GetParent()->GetPeer(); 
1289             if ( !parent
->m_isRootControl 
) 
1292                 GetControlBounds( parent
->m_controlRef 
, &superRect 
); 
1293                 OffsetRect( r 
, -superRect
.left 
, -superRect
.top 
); 
1299 void wxMacControl::GetRectInWindowCoords( Rect 
*r 
) 
1301     UMAGetControlBoundsInWindowCoords( m_controlRef 
, r 
); 
1304 void wxMacControl::GetBestRect( Rect 
*r 
) 
1306     short   baselineoffset
; 
1308     GetBestControlRect( m_controlRef 
, r 
, &baselineoffset 
); 
1311 void wxMacControl::SetLabel( const wxString 
&title 
) 
1313     wxFontEncoding encoding
; 
1316         encoding 
= m_font
.GetEncoding(); 
1318         encoding 
= wxFont::GetDefaultEncoding(); 
1320     UMASetControlTitle( m_controlRef 
, title 
, encoding 
); 
1323 void wxMacControl::GetFeatures( UInt32 
* features 
) 
1325     GetControlFeatures( m_controlRef 
, features 
); 
1328 OSStatus 
wxMacControl::GetRegion( ControlPartCode partCode 
, RgnHandle region 
) 
1330     OSStatus err 
= GetControlRegion( m_controlRef 
, partCode 
, region 
); 
1331     if ( !m_isCompositing 
) 
1333         if ( !m_isRootControl 
) 
1337             GetControlBounds(m_controlRef
, &r 
); 
1338             if ( !EmptyRgn( region 
) ) 
1339                 OffsetRgn( region 
, -r
.left 
, -r
.top 
); 
1346 OSStatus 
wxMacControl::SetZOrder( bool above 
, wxMacControl
* other 
) 
1348 #if TARGET_API_MAC_OSX 
1349     return HIViewSetZOrder( m_controlRef
,above 
? kHIViewZOrderAbove 
: kHIViewZOrderBelow
, 
1350        (other 
!= NULL
) ? other
->m_controlRef 
: NULL
); 
1356 #if TARGET_API_MAC_OSX 
1357 // SetNeedsDisplay would not invalidate the children 
1358 static void InvalidateControlAndChildren( HIViewRef control 
) 
1360     HIViewSetNeedsDisplay( control 
, true ); 
1361     UInt16 childrenCount 
= 0; 
1362     OSStatus err 
= CountSubControls( control 
, &childrenCount 
); 
1363     if ( err 
== errControlIsNotEmbedder 
) 
1366     wxASSERT_MSG( err 
== noErr 
, wxT("Unexpected error when accessing subcontrols") ); 
1368     for ( UInt16 i 
= childrenCount
; i 
>=1; --i 
) 
1372         err 
= GetIndexedSubControl( control 
, i 
, & child 
); 
1373         if ( err 
== errControlIsNotEmbedder 
) 
1376         InvalidateControlAndChildren( child 
); 
1381 void wxMacControl::InvalidateWithChildren() 
1383 #if TARGET_API_MAC_OSX 
1384     InvalidateControlAndChildren( m_controlRef 
); 
1388 void wxMacControl::ScrollRect( wxRect 
*r 
, int dx 
, int dy 
) 
1390     wxASSERT( r 
!= NULL 
); 
1392 #if TARGET_API_MAC_OSX 
1393     if ( m_isCompositing 
) 
1395         HIRect scrollarea 
= CGRectMake( r
->x 
, r
->y 
, r
->width 
, r
->height
); 
1396         HIViewScrollRect ( m_controlRef 
, &scrollarea 
, dx 
,dy 
); 
1403         GetControlBounds( m_controlRef 
, &bounds 
); 
1404         bounds
.left 
+= r
->x
; 
1406         bounds
.bottom 
= bounds
.top 
+ r
->height
; 
1407         bounds
.right 
= bounds
.left 
+ r
->width
; 
1408         wxMacWindowClipper 
clip( m_peer 
); 
1409         RgnHandle updateRgn 
= NewRgn(); 
1410         ::ScrollRect( &bounds 
, dx 
, dy 
, updateRgn 
); 
1411         InvalWindowRgn( GetControlOwner( m_controlRef 
) , updateRgn 
); 
1412         DisposeRgn( updateRgn 
); 
1416 OSType wxMacCreator 
= 'WXMC'; 
1417 OSType wxMacControlProperty 
= 'MCCT'; 
1419 void wxMacControl::SetReferenceInNativeControl() 
1422     verify_noerr( SetControlProperty ( m_controlRef 
, 
1423         wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data 
) ); 
1426 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
) 
1428     wxMacControl
* ctl 
= NULL
; 
1430     if ( GetControlProperty( control 
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) , 
1431         &actualSize 
, &ctl 
) == noErr 
) 
1438 // ============================================================================ 
1439 // DataBrowser Wrapper 
1440 // ============================================================================ 
1442 // basing on DataBrowserItemIDs 
1445 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc( 
1447     DataBrowserItemID itemID
, 
1448     DataBrowserItemNotification message
, 
1449     DataBrowserItemDataRef itemData 
) 
1451     wxMacDataBrowserControl
* ctl 
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser 
) ); 
1454         ctl
->ItemNotification(itemID
, message
, itemData
); 
1458 pascal OSStatus 
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc( 
1460     DataBrowserItemID itemID
, 
1461     DataBrowserPropertyID property
, 
1462     DataBrowserItemDataRef itemData
, 
1463     Boolean changeValue 
) 
1465     OSStatus err 
= errDataBrowserPropertyNotSupported
; 
1467     wxMacDataBrowserControl
* ctl 
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser 
) ); 
1470         err 
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
); 
1475 pascal Boolean 
wxMacDataBrowserControl::DataBrowserCompareProc( 
1477     DataBrowserItemID itemOneID
, 
1478     DataBrowserItemID itemTwoID
, 
1479     DataBrowserPropertyID sortProperty
) 
1481     wxMacDataBrowserControl
* ctl 
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser 
) ); 
1484         return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
); 
1489 DataBrowserItemDataUPP gDataBrowserItemDataUPP 
= NULL
; 
1490 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP 
= NULL
; 
1491 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP 
= NULL
; 
1493 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer 
) 
1495     Rect bounds 
= wxMacGetBoundsForControl( peer
, pos
, size 
); 
1496     OSStatus err 
= ::CreateDataBrowserControl( 
1497         MAC_WXHWND(peer
->MacGetTopLevelWindowRef()), 
1498         &bounds
, kDataBrowserListView
, &m_controlRef 
); 
1499     SetReferenceInNativeControl(); 
1500     verify_noerr( err 
); 
1501     if ( gDataBrowserItemCompareUPP 
== NULL 
) 
1502         gDataBrowserItemCompareUPP 
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
); 
1503     if ( gDataBrowserItemDataUPP 
== NULL 
) 
1504         gDataBrowserItemDataUPP 
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
); 
1505     if ( gDataBrowserItemNotificationUPP 
== NULL 
) 
1507         gDataBrowserItemNotificationUPP 
= 
1508 #if TARGET_API_MAC_OSX 
1509             (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
); 
1511             NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
); 
1515     DataBrowserCallbacks callbacks
; 
1516     InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks 
); 
1518     callbacks
.u
.v1
.itemDataCallback 
= gDataBrowserItemDataUPP
; 
1519     callbacks
.u
.v1
.itemCompareCallback 
= gDataBrowserItemCompareUPP
; 
1520     callbacks
.u
.v1
.itemNotificationCallback 
= gDataBrowserItemNotificationUPP
; 
1521     SetCallbacks( &callbacks 
); 
1525 OSStatus 
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
, 
1527     DataBrowserItemState state
, 
1528     UInt32 
*numItems
) const 
1530     return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems 
); 
1533 OSStatus 
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
, 
1535     DataBrowserItemState state
, 
1538     return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items 
); 
1541 OSStatus 
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options 
) 
1543     return SetDataBrowserSelectionFlags( m_controlRef
, options 
); 
1546 OSStatus 
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc 
*columnDesc
, 
1547         DataBrowserTableViewColumnIndex position 
) 
1549     return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position 
); 
1552 OSStatus 
wxMacDataBrowserControl::AutoSizeColumns() 
1554     return AutoSizeDataBrowserListViewColumns(m_controlRef
); 
1557 OSStatus 
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert 
) 
1559     return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert 
); 
1562 OSStatus 
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle 
) 
1564     return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle 
); 
1567 OSStatus 
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
) 
1569     return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height 
); 
1572 OSStatus 
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 
*height
) 
1574     return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height 
); 
1577 OSStatus 
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks 
*callbacks
) 
1579     return SetDataBrowserCallbacks( m_controlRef
, callbacks 
); 
1582 OSStatus 
wxMacDataBrowserControl::UpdateItems( 
1583     DataBrowserItemID container
, 
1585     const DataBrowserItemID 
*items
, 
1586     DataBrowserPropertyID preSortProperty
, 
1587     DataBrowserPropertyID propertyID 
) const 
1589     return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID 
); 
1592 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item 
) const 
1594     return IsDataBrowserItemSelected( m_controlRef
, item 
); 
1597 OSStatus 
wxMacDataBrowserControl::AddItems( 
1598     DataBrowserItemID container
, 
1600     const DataBrowserItemID 
*items
, 
1601     DataBrowserPropertyID preSortProperty 
) 
1603     return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty 
); 
1606 OSStatus 
wxMacDataBrowserControl::RemoveItems( 
1607     DataBrowserItemID container
, 
1609     const DataBrowserItemID 
*items
, 
1610     DataBrowserPropertyID preSortProperty 
) 
1612     return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty 
); 
1615 OSStatus 
wxMacDataBrowserControl::RevealItem( 
1616     DataBrowserItemID item
, 
1617     DataBrowserPropertyID propertyID
, 
1618     DataBrowserRevealOptions options 
) const 
1620     return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options 
); 
1623 OSStatus 
wxMacDataBrowserControl::SetSelectedItems( 
1625     const DataBrowserItemID 
*items
, 
1626     DataBrowserSetOption operation 
) 
1628     return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation 
); 
1631 OSStatus 
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID 
*first
, DataBrowserItemID 
*last 
) const 
1633     return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last 
); 
1636 OSStatus 
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID 
* item 
) const 
1638     return GetDataBrowserTableViewItemID( m_controlRef
, row
, item 
); 
1641 OSStatus 
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex 
* row 
) const 
1643     return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row 
); 
1646 OSStatus 
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height 
) 
1648     return SetDataBrowserTableViewRowHeight( m_controlRef 
, height 
); 
1651 OSStatus 
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 
* height 
) const 
1653     return GetDataBrowserTableViewRowHeight( m_controlRef
, height 
); 
1656 OSStatus 
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item 
, UInt16 height
) 
1658     return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item 
, height 
); 
1661 OSStatus 
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item 
, UInt16 
*height
) const 
1663     return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item 
, height
); 
1666 OSStatus 
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column 
, UInt16 
*width 
) const 
1668     return GetDataBrowserTableViewNamedColumnWidth( m_controlRef 
, column 
, width 
); 
1671 OSStatus 
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column 
, UInt16 width 
) 
1673     return SetDataBrowserTableViewNamedColumnWidth( m_controlRef 
, column 
, width 
); 
1676 OSStatus 
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 
*width 
) const 
1678     return GetDataBrowserTableViewColumnWidth( m_controlRef 
, width 
); 
1681 OSStatus 
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width 
) 
1683     return SetDataBrowserTableViewColumnWidth( m_controlRef 
, width 
); 
1686 OSStatus 
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const 
1688     return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
); 
1691 OSStatus 
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
, 
1692     UInt32 
*position
) const 
1694     return GetDataBrowserTableViewColumnPosition( m_controlRef 
, column 
, position
); 
1697 OSStatus 
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, UInt32 position
) 
1699     return SetDataBrowserTableViewColumnPosition( m_controlRef 
, column 
, position
); 
1702 OSStatus 
wxMacDataBrowserControl::GetScrollPosition( UInt32 
*top 
, UInt32 
*left 
) const 
1704     return GetDataBrowserScrollPosition( m_controlRef 
, top 
, left 
); 
1707 OSStatus 
wxMacDataBrowserControl::SetScrollPosition( UInt32 top 
, UInt32 left 
) 
1709     return SetDataBrowserScrollPosition( m_controlRef 
, top 
, left 
); 
1712 OSStatus 
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID 
*column 
) const 
1714     return GetDataBrowserSortProperty( m_controlRef 
, column 
); 
1717 OSStatus 
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column 
) 
1719     return SetDataBrowserSortProperty( m_controlRef 
, column 
); 
1722 OSStatus 
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder 
*order 
) const 
1724     return GetDataBrowserSortOrder( m_controlRef 
, order 
); 
1727 OSStatus 
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order 
) 
1729     return SetDataBrowserSortOrder( m_controlRef 
, order 
); 
1732 OSStatus 
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
, 
1733     DataBrowserPropertyFlags 
*flags 
) const 
1735     return GetDataBrowserPropertyFlags( m_controlRef 
, property 
, flags 
); 
1738 OSStatus 
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
, 
1739     DataBrowserPropertyFlags flags 
) 
1741     return SetDataBrowserPropertyFlags( m_controlRef 
, property 
, flags 
); 
1744 OSStatus 
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
, 
1745     DataBrowserListViewHeaderDesc 
*desc 
) const 
1747     return GetDataBrowserListViewHeaderDesc( m_controlRef 
, property 
, desc 
); 
1750 OSStatus 
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
, 
1751     DataBrowserListViewHeaderDesc 
*desc 
) 
1753     return SetDataBrowserListViewHeaderDesc( m_controlRef 
, property 
, desc 
); 
1756 OSStatus 
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property 
, 
1757     Boolean expandableRows 
) 
1759     return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
); 
1762 // ============================================================================ 
1763 // Higher-level Databrowser 
1764 // ============================================================================ 
1766 // basing on data item objects 
1769 wxMacDataItem::wxMacDataItem() 
1773 wxMacDataItem::~wxMacDataItem() 
1777 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl 
*owner 
, 
1778     const wxMacDataItem
*, 
1779     DataBrowserPropertyID property
) const 
1784 OSStatus 
wxMacDataItem::GetSetData(wxMacDataItemBrowserControl 
*owner 
, 
1785     DataBrowserPropertyID property
, 
1786     DataBrowserItemDataRef itemData
, 
1789     return errDataBrowserPropertyNotSupported
; 
1792 void wxMacDataItem::Notification(wxMacDataItemBrowserControl 
*owner 
, 
1793     DataBrowserItemNotification message
, 
1794     DataBrowserItemDataRef itemData 
) const 
1799 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer 
, const wxPoint
& pos
, const wxSize
& size
, long style
) : 
1800     wxMacDataBrowserControl( peer
, pos
, size
, style 
) 
1802     m_suppressSelection 
= false; 
1805 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl 
*browser
) 
1807     m_former 
= browser
->SuppressSelection(true); 
1808     m_browser 
= browser
; 
1811 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor() 
1813     m_browser
->SuppressSelection(m_former
); 
1816 bool  wxMacDataItemBrowserControl::SuppressSelection( bool suppress 
) 
1818     bool former 
= m_suppressSelection
; 
1819     m_suppressSelection 
= suppress
; 
1824 Boolean 
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
, 
1825     DataBrowserItemID itemTwoID
, 
1826     DataBrowserPropertyID sortProperty
) 
1828     wxMacDataItem
* itemOne 
= (wxMacDataItem
*) itemOneID
; 
1829     wxMacDataItem
* itemTwo 
= (wxMacDataItem
*) itemTwoID
; 
1830     return CompareItems( itemOne 
, itemTwo 
, sortProperty 
); 
1833 Boolean 
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
*  itemOne
, 
1834     const wxMacDataItem
*  itemTwo
, 
1835     DataBrowserPropertyID sortProperty
) 
1837     Boolean retval 
= false; 
1838     if ( itemOne 
!= NULL 
) 
1839         retval 
= itemOne
->IsLessThan( this , itemTwo 
, sortProperty
); 
1843 OSStatus 
wxMacDataItemBrowserControl::GetSetItemData( 
1844     DataBrowserItemID itemID
, 
1845     DataBrowserPropertyID property
, 
1846     DataBrowserItemDataRef itemData
, 
1847     Boolean changeValue 
) 
1849     wxMacDataItem
* item 
= (wxMacDataItem
*) itemID
; 
1850     return GetSetItemData(item
, property
, itemData 
, changeValue 
); 
1853 OSStatus 
wxMacDataItemBrowserControl::GetSetItemData( 
1854     wxMacDataItem
* item
, 
1855     DataBrowserPropertyID property
, 
1856     DataBrowserItemDataRef itemData
, 
1857     Boolean changeValue 
) 
1859     OSStatus err 
= errDataBrowserPropertyNotSupported
; 
1862         case kDataBrowserContainerIsClosableProperty 
: 
1863         case kDataBrowserContainerIsSortableProperty 
: 
1864         case kDataBrowserContainerIsOpenableProperty 
: 
1865             // right now default behaviour on these 
1869                 err 
= item
->GetSetData( this, property 
, itemData 
, changeValue 
); 
1876 void wxMacDataItemBrowserControl::ItemNotification( 
1877     DataBrowserItemID itemID
, 
1878     DataBrowserItemNotification message
, 
1879     DataBrowserItemDataRef itemData
) 
1881     wxMacDataItem
* item 
= (wxMacDataItem
*) itemID
; 
1882     ItemNotification( item 
, message
, itemData
); 
1885 void wxMacDataItemBrowserControl::ItemNotification( 
1886     const wxMacDataItem
* item
, 
1887     DataBrowserItemNotification message
, 
1888     DataBrowserItemDataRef itemData
) 
1891         item
->Notification( this, message
, itemData
); 
1894 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
, 
1895         bool recurse 
, DataBrowserItemState state
) const 
1897     UInt32 numItems 
= 0; 
1898     verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
, 
1899         recurse
, state
, &numItems 
) ); 
1903 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
, 
1904     bool recurse 
, DataBrowserItemState state
, wxArrayMacDataItemPtr 
&items
) const 
1906     Handle handle 
= NewHandle(0); 
1907     verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container 
, 
1908         recurse 
, state
, handle
) ); 
1910     int itemCount 
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
); 
1912     wxMacDataItemPtr
* itemsArray 
= (wxMacDataItemPtr
*) *handle
; 
1913     for ( int i 
= 0; i 
< itemCount
; ++i
) 
1915         items
.Add(itemsArray
[i
]); 
1918     DisposeHandle( handle 
); 
1921 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const 
1923     DataBrowserTableViewRowIndex row
; 
1924     OSStatus err 
= GetItemRow( (DataBrowserItemID
) item 
, &row
); 
1925     wxASSERT( err 
== noErr
); 
1929 wxMacDataItem
*  wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const 
1931     DataBrowserItemID id
; 
1932     OSStatus err 
=  GetItemID( (DataBrowserTableViewRowIndex
) n 
, &id
); 
1933     wxASSERT( err 
== noErr
); 
1934     return (wxMacDataItem
*) id
; 
1937 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem 
*container
, 
1938         const wxMacDataItem 
*item 
, DataBrowserPropertyID property
) const 
1940     verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1, 
1941         (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty 
/* notSorted */, property 
) ); 
1944 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem 
*container
, 
1945         wxArrayMacDataItemPtr 
&itemArray 
, DataBrowserPropertyID property
) const 
1947     unsigned int noItems 
= itemArray
.GetCount(); 
1948     DataBrowserItemID 
*items 
= new DataBrowserItemID
[noItems
]; 
1949     for ( unsigned int i 
= 0; i 
< noItems
; ++i 
) 
1950         items
[i
] = (DataBrowserItemID
) itemArray
[i
]; 
1952     verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
, 
1953         items
, kDataBrowserItemNoProperty 
/* notSorted */, property 
) ); 
1957 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem 
*container
, wxMacDataItem 
*item
) 
1959     verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1, 
1960         (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty 
) ); 
1963 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem 
*container
, wxArrayMacDataItemPtr 
&itemArray 
) 
1965     unsigned int noItems 
= itemArray
.GetCount(); 
1966     DataBrowserItemID 
*items 
= new DataBrowserItemID
[noItems
]; 
1967     for ( unsigned int i 
= 0; i 
< noItems
; ++i 
) 
1968         items
[i
] = (DataBrowserItemID
) itemArray
[i
]; 
1970     verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
, 
1971         (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty 
) ); 
1975 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem 
*container
, wxMacDataItem
* item
) 
1977     OSStatus err 
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1, 
1978         (UInt32
*) &item
, kDataBrowserItemNoProperty 
); 
1979     verify_noerr( err 
); 
1982 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem 
*container
, wxArrayMacDataItemPtr 
&itemArray
) 
1984     unsigned int noItems 
= itemArray
.GetCount(); 
1985     DataBrowserItemID 
*items 
= new DataBrowserItemID
[noItems
]; 
1986     for ( unsigned int i 
= 0; i 
< noItems
; ++i 
) 
1987         items
[i
] = (DataBrowserItemID
) itemArray
[i
]; 
1989     OSStatus err 
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
, 
1990         (UInt32
*) items
, kDataBrowserItemNoProperty 
); 
1991     verify_noerr( err 
); 
1995 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem 
*container
) 
1997     OSStatus err 
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL 
, kDataBrowserItemNoProperty 
); 
1998     verify_noerr( err 
); 
2001 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item 
, DataBrowserSetOption option
) 
2003     verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option 
)); 
2006 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
) 
2008     verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL 
, option 
)); 
2011 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr 
&itemArray 
, DataBrowserSetOption option
) 
2013     unsigned int noItems 
= itemArray
.GetCount(); 
2014     DataBrowserItemID 
*items 
= new DataBrowserItemID
[noItems
]; 
2015     for ( unsigned int i 
= 0; i 
< noItems
; ++i 
) 
2016         items
[i
] = (DataBrowserItemID
) itemArray
[i
]; 
2018     verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option 
)); 
2022 Boolean 
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const 
2024     return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
); 
2027 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
) 
2029     verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem 
, options 
) ); 
2032 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first 
, wxMacDataItemPtr
* last
) const 
2034     verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) ); 
2043 OSStatus 
wxMacControl::SetTabEnabled( SInt16 tabNo 
, bool enable 
) 
2045     return ::SetTabEnabled( m_controlRef 
, tabNo 
, enable 
); 
2052 #ifdef __WXMAC_OSX__ 
2053 // snippets from Sketch Sample from Apple : 
2055 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc" 
2058     This function locates, opens, and returns the profile reference for the calibrated 
2059     Generic RGB color space. It is up to the caller to call CMCloseProfile when done 
2060     with the profile reference this function returns. 
2062 CMProfileRef 
wxMacOpenGenericProfile() 
2064     static CMProfileRef cachedRGBProfileRef 
= NULL
; 
2066     // we only create the profile reference once 
2067     if (cachedRGBProfileRef 
== NULL
) 
2069         CMProfileLocation loc
; 
2071         loc
.locType 
= cmPathBasedProfile
; 
2072         strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
); 
2074         verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) ); 
2077     // clone the profile reference so that the caller has their own reference, not our cached one 
2078     if (cachedRGBProfileRef
) 
2079         CMCloneProfileRef(cachedRGBProfileRef
); 
2081     return cachedRGBProfileRef
; 
2085     Return the generic RGB color space. This is a 'get' function and the caller should 
2086     not release the returned value unless the caller retains it first. Usually callers 
2087     of this routine will immediately use the returned colorspace with CoreGraphics 
2088     so they typically do not need to retain it themselves. 
2090     This function creates the generic RGB color space once and hangs onto it so it can 
2091     return it whenever this function is called. 
2094 CGColorSpaceRef 
wxMacGetGenericRGBColorSpace() 
2096     static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
; 
2098     if (genericRGBColorSpace 
== NULL
) 
2100         if ( UMAGetSystemVersion() >= 0x1040 ) 
2102             genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) ); 
2106             CMProfileRef genericRGBProfile 
= wxMacOpenGenericProfile(); 
2108             if (genericRGBProfile
) 
2110                 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) ); 
2112                 wxASSERT_MSG( genericRGBColorSpace 
!= NULL
, wxT("couldn't create the generic RGB color space") ); 
2114                 // we opened the profile so it is up to us to close it 
2115                 CMCloseProfile(genericRGBProfile
); 
2120     return genericRGBColorSpace
; 
2124 wxMacPortSaver::wxMacPortSaver( GrafPtr port 
) 
2126     ::GetPort( &m_port 
); 
2130 wxMacPortSaver::~wxMacPortSaver() 
2132     ::SetPort( m_port 
);