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"
20 #include "wx/toplevel.h"
25 #include "wx/apptrait.h"
28 #include "wx/mac/uma.h"
38 #include "MoreFilesX.h"
46 #if TARGET_API_MAC_OSX
47 #include <CoreServices/CoreServices.h>
49 #include <DriverServices.h>
50 #include <Multiprocessing.h>
54 #include <Carbon/Carbon.h>
56 #include <ATSUnicode.h>
57 #include <TextCommon.h>
58 #include <TextEncodingConverter.h>
62 #include "wx/mac/private.h"
64 #if defined(__MWERKS__) && wxUSE_UNICODE
65 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
70 // ---------------------------------------------------------------------------
71 // code used in both base and GUI compilation
72 // ---------------------------------------------------------------------------
74 // our OS version is the same in non GUI and GUI cases
75 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
79 // are there x-platform conventions ?
81 Gestalt(gestaltSystemVersion
, &theSystem
);
83 *minorVsn
= (theSystem
& 0xFF);
86 *majorVsn
= (theSystem
>> 8);
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
104 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
106 #ifndef __MetroNubUtils__
107 #include "MetroNubUtils.h"
114 #if TARGET_API_MAC_CARBON
116 #include <CodeFragments.h>
118 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
120 ProcPtr gCallUniversalProc_Proc
= NULL
;
124 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
126 static long fRunOnce
= false;
129 Boolean
IsMetroNubInstalled()
136 gMetroNubEntry
= NULL
;
138 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
140 // look for MetroNub's Gestalt selector
141 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
143 #if TARGET_API_MAC_CARBON
144 if (gCallUniversalProc_Proc
== NULL
)
146 CFragConnectionID connectionID
;
149 ProcPtr symbolAddress
;
151 CFragSymbolClass symbolClass
;
153 symbolAddress
= NULL
;
154 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
155 &connectionID
, &mainAddress
, errorString
);
159 gCallUniversalProc_Proc
= NULL
;
163 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
164 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
168 gCallUniversalProc_Proc
= NULL
;
175 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
177 // make sure the version of the API is compatible
178 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
179 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
182 gMetroNubEntry
= block
;
191 #if TARGET_API_MAC_CARBON
192 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
194 return (gMetroNubEntry
!= NULL
);
198 Boolean
IsMWDebuggerRunning()
200 if (IsMetroNubInstalled())
201 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
206 Boolean
AmIBeingMWDebugged()
208 if (IsMetroNubInstalled())
209 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
214 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
216 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
221 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
226 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
230 // defined in unix/utilsunx.cpp for Mac OS X
232 // get full hostname (with domain name if possible)
233 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
235 return wxGetHostName(buf
, maxSize
);
238 // Get user ID e.g. jacs
239 bool wxGetUserId(wxChar
*buf
, int maxSize
)
241 return wxGetUserName( buf
, maxSize
);
244 const wxChar
* wxGetHomeDir(wxString
*pstr
)
246 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
247 return pstr
->c_str();
250 // Get hostname only (without domain name)
251 bool wxGetHostName(wxChar
*buf
, int maxSize
)
253 // Gets Chooser name of user by examining a System resource.
256 const short kComputerNameID
= -16413;
258 short oldResFile
= CurResFile();
260 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
261 UseResFile(oldResFile
);
263 if (chooserName
&& *chooserName
)
265 HLock( (Handle
) chooserName
);
266 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
267 HUnlock( (Handle
) chooserName
);
268 ReleaseResource( (Handle
) chooserName
);
269 wxStrncpy( buf
, name
, maxSize
- 1 );
275 // Get user name e.g. Stefan Csomor
276 bool wxGetUserName(wxChar
*buf
, int maxSize
)
278 // Gets Chooser name of user by examining a System resource.
281 const short kChooserNameID
= -16096;
283 short oldResFile
= CurResFile();
285 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
286 UseResFile(oldResFile
);
288 if (chooserName
&& *chooserName
)
290 HLock( (Handle
) chooserName
);
291 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
292 HUnlock( (Handle
) chooserName
);
293 ReleaseResource( (Handle
) chooserName
);
294 wxStrncpy( buf
, name
, maxSize
- 1 );
300 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
306 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
308 // TODO : under classic there is no environement support, under X yes
312 // set the env var name to the given value, return true on success
313 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
315 // TODO : under classic there is no environement support, under X yes
319 // Execute a program in an Interactive Shell
320 bool wxShell(const wxString
& command
)
326 // Shutdown or reboot the PC
327 bool wxShutdown(wxShutdownFlags wFlags
)
333 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
334 wxMemorySize
wxGetFreeMemory()
336 return (wxMemorySize
)FreeMem();
341 void wxMicroSleep(unsigned long microseconds
)
343 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
344 MPDelayUntil( & wakeup
);
347 void wxMilliSleep(unsigned long milliseconds
)
349 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
350 MPDelayUntil( & wakeup
);
353 void wxSleep(int nSecs
)
355 wxMilliSleep(1000*nSecs
);
360 // Consume all events until no more left
365 #endif // !__DARWIN__
373 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
375 static wxToolkitInfo info
;
377 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
378 info
.name
= _T("wxBase");
387 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
389 static wxToolkitInfo info
;
391 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
392 info
.shortName
= _T("mac");
393 info
.name
= _T("wxMac");
395 #ifdef __WXUNIVERSAL__
396 info
.shortName
<< _T("univ");
397 info
.name
<< _T("/wxUniversal");
403 // Reading and writing resources (eg WIN.INI, .Xdefaults)
405 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
411 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
414 buf
.Printf(wxT("%.4f"), value
);
416 return wxWriteResource(section
, entry
, buf
, file
);
419 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
422 buf
.Printf(wxT("%ld"), value
);
424 return wxWriteResource(section
, entry
, buf
, file
);
427 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
430 buf
.Printf(wxT("%d"), value
);
432 return wxWriteResource(section
, entry
, buf
, file
);
435 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
441 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
444 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
447 *value
= (float)strtod(s
, NULL
);
454 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
457 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
460 *value
= strtol(s
, NULL
, 10);
467 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
470 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
473 *value
= (int)strtol(s
, NULL
, 10);
479 #endif // wxUSE_RESOURCES
481 int gs_wxBusyCursorCount
= 0;
482 extern wxCursor gMacCurrentCursor
;
483 wxCursor gMacStoredActiveCursor
;
485 // Set the cursor to the busy cursor for all windows
486 void wxBeginBusyCursor(const wxCursor
*cursor
)
488 if (gs_wxBusyCursorCount
++ == 0)
490 gMacStoredActiveCursor
= gMacCurrentCursor
;
491 cursor
->MacInstall();
493 //else: nothing to do, already set
496 // Restore cursor to normal
497 void wxEndBusyCursor()
499 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
500 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
502 if (--gs_wxBusyCursorCount
== 0)
504 gMacStoredActiveCursor
.MacInstall();
505 gMacStoredActiveCursor
= wxNullCursor
;
509 // true if we're between the above two calls
512 return (gs_wxBusyCursorCount
> 0);
519 wxString
wxMacFindFolderNoSeparator( short vol
,
521 Boolean createFolder
)
526 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
528 strDir
= wxMacFSRefToPath( &fsRef
);
534 wxString
wxMacFindFolder( short vol
,
536 Boolean createFolder
)
538 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
545 // Check whether this window wants to process messages, e.g. Stop button
546 // in long calculations.
547 bool wxCheckForInterrupt(wxWindow
*wnd
)
553 void wxGetMousePosition( int* x
, int* y
)
558 LocalToGlobal( &pt
);
563 // Return true if we have a colour display
564 bool wxColourDisplay()
569 // Returns depth of screen
573 SetRect(&globRect
, -32760, -32760, 32760, 32760);
574 GDHandle theMaxDevice
;
577 theMaxDevice
= GetMaxDevice(&globRect
);
578 if (theMaxDevice
!= NULL
)
579 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
584 // Get size of display
585 void wxDisplaySize(int *width
, int *height
)
588 GetQDGlobalsScreenBits( &screenBits
);
591 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
594 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
597 void wxDisplaySizeMM(int *width
, int *height
)
599 wxDisplaySize(width
, height
);
600 // on mac 72 is fixed (at least now;-)
601 float cvPt2Mm
= 25.4 / 72;
604 *width
= int( *width
* cvPt2Mm
);
607 *height
= int( *height
* cvPt2Mm
);
610 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
614 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
620 *width
= r
.right
- r
.left
;
622 *height
= r
.bottom
- r
.top
;
625 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
627 return wxGenericFindWindowAtPoint(pt
);
634 wxString
wxGetOsDescription()
636 #ifdef WXWIN_OS_DESCRIPTION
637 // use configure generated description if available
638 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
640 return wxT("MacOS"); //TODO:define further
645 wxChar
*wxGetUserHome (const wxString
& user
)
651 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
660 int pos
= p
.Find(':');
661 if ( pos
!= wxNOT_FOUND
)
669 err
= wxMacPathToFSRef( p
, &fsRef
);
672 FSVolumeRefNum vRefNum
;
673 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
676 UInt64 freeBytes
, totalBytes
;
677 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
681 *pTotal
= wxDiskspaceSize_t( totalBytes
);
683 *pFree
= wxDiskspaceSize_t( freeBytes
);
690 #endif // !__DARWIN__
692 //---------------------------------------------------------------------------
693 // wxMac Specific utility functions
694 //---------------------------------------------------------------------------
696 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
698 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
699 int len
= strlen(buf
);
704 memcpy( (char*) &to
[1] , buf
, len
);
707 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
709 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
712 // ----------------------------------------------------------------------------
713 // Common Event Support
714 // ----------------------------------------------------------------------------
716 extern ProcessSerialNumber gAppProcess
;
720 ProcessSerialNumber psn
;
722 psn
.highLongOfPSN
= 0;
723 psn
.lowLongOfPSN
= kCurrentProcess
;
724 SameProcess( &gAppProcess
, &psn
, &isSame
);
728 OSStatus err
= noErr
;
731 // lead sometimes to race conditions, although all calls used should be thread safe ...
732 static wxMacCarbonEvent s_wakeupEvent
;
733 if ( !s_wakeupEvent
.IsValid() )
735 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
736 kEventAttributeNone
);
741 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
743 s_wakeupEvent
.SetCurrentTime();
744 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
745 kEventPriorityHigh
);
748 wxMacCarbonEvent wakeupEvent
;
749 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
750 kEventAttributeNone
);
751 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
752 kEventPriorityHigh
);
755 PostEvent( nullEvent
, 0 );
760 WakeUpProcess( &gAppProcess
);
768 // ----------------------------------------------------------------------------
769 // Native Struct Conversions
770 // ----------------------------------------------------------------------------
772 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
776 n
->right
= wx
->x
+ wx
->width
;
777 n
->bottom
= wx
->y
+ wx
->height
;
780 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
784 wx
->width
= n
->right
- n
->left
;
785 wx
->height
= n
->bottom
- n
->top
;
788 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
794 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
800 // ----------------------------------------------------------------------------
801 // Carbon Event Support
802 // ----------------------------------------------------------------------------
804 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
806 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
809 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
811 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
814 // ----------------------------------------------------------------------------
815 // Control Access Support
816 // ----------------------------------------------------------------------------
818 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
822 m_isRootControl
= isRootControl
;
825 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
829 m_controlRef
= control
;
832 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
836 m_controlRef
= (ControlRef
) control
;
839 wxMacControl::~wxMacControl()
843 void wxMacControl::Init()
847 m_needsFocusRect
= false;
848 m_isRootControl
= false;
851 void wxMacControl::Dispose()
853 ::DisposeControl( m_controlRef
);
857 void wxMacControl::SetReference( SInt32 data
)
859 SetControlReference( m_controlRef
, data
);
862 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
864 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
867 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
869 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
872 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
874 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
877 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
879 #if TARGET_API_MAC_OSX
880 return SendEventToEventTargetWithOptions( event
,
881 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
883 #pragma unused(inOptions)
884 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
888 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
890 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
892 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
894 return SendEvent( event
, inOptions
);
897 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
901 memset( &command
, 0 , sizeof(command
) );
902 command
.commandID
= commandID
;
903 return SendHICommand( command
, inOptions
);
906 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
908 unsigned long finalTicks
;
910 HiliteControl( m_controlRef
, part
);
911 Delay( ticks
, &finalTicks
);
912 HiliteControl( m_controlRef
, kControlNoPart
);
915 SInt32
wxMacControl::GetValue() const
917 return ::GetControl32BitValue( m_controlRef
);
920 SInt32
wxMacControl::GetMaximum() const
922 return ::GetControl32BitMaximum( m_controlRef
);
925 SInt32
wxMacControl::GetMinimum() const
927 return ::GetControl32BitMinimum( m_controlRef
);
930 void wxMacControl::SetValue( SInt32 v
)
932 ::SetControl32BitValue( m_controlRef
, v
);
935 void wxMacControl::SetMinimum( SInt32 v
)
937 ::SetControl32BitMinimum( m_controlRef
, v
);
940 void wxMacControl::SetMaximum( SInt32 v
)
942 ::SetControl32BitMaximum( m_controlRef
, v
);
945 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
947 ::SetControl32BitMinimum( m_controlRef
, minimum
);
948 ::SetControl32BitMaximum( m_controlRef
, maximum
);
949 ::SetControl32BitValue( m_controlRef
, value
);
952 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
954 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
957 bool wxMacControl::HasFocus() const
960 GetKeyboardFocus( GetUserFocusWindow() , &control
);
961 return control
== m_controlRef
;
964 void wxMacControl::SetNeedsFocusRect( bool needs
)
966 m_needsFocusRect
= needs
;
969 bool wxMacControl::NeedsFocusRect() const
971 return m_needsFocusRect
;
974 void wxMacControl::VisibilityChanged(bool shown
)
978 void wxMacControl::SuperChangedPosition()
982 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
985 ControlFontStyleRec fontStyle
;
986 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
988 switch ( font
.MacGetThemeFontID() )
990 case kThemeSmallSystemFont
:
991 fontStyle
.font
= kControlFontSmallSystemFont
;
994 case 109 : // mini font
998 case kThemeSystemFont
:
999 fontStyle
.font
= kControlFontBigSystemFont
;
1003 fontStyle
.font
= kControlFontBigSystemFont
;
1007 fontStyle
.flags
= kControlUseFontMask
;
1011 fontStyle
.font
= font
.MacGetFontNum();
1012 fontStyle
.style
= font
.MacGetFontStyle();
1013 fontStyle
.size
= font
.MacGetFontSize();
1014 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1017 fontStyle
.just
= teJustLeft
;
1018 fontStyle
.flags
|= kControlUseJustMask
;
1019 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1020 fontStyle
.just
= teJustCenter
;
1021 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1022 fontStyle
.just
= teJustRight
;
1025 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1026 // won't get grayed out by the system anymore
1028 if ( foreground
!= *wxBLACK
)
1030 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
1031 fontStyle
.flags
|= kControlUseForeColorMask
;
1034 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1037 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1040 // setting up a color proc is not recommended anymore
1043 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1045 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1046 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1049 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1051 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1054 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1056 SetControlAction( m_controlRef
, actionProc
);
1059 void wxMacControl::SetViewSize( SInt32 viewSize
)
1061 SetControlViewSize(m_controlRef
, viewSize
);
1064 SInt32
wxMacControl::GetViewSize() const
1066 return GetControlViewSize( m_controlRef
);
1069 bool wxMacControl::IsVisible() const
1071 return IsControlVisible( m_controlRef
);
1074 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1076 SetControlVisibility( m_controlRef
, visible
, redraw
);
1079 bool wxMacControl::IsEnabled() const
1081 #if TARGET_API_MAC_OSX
1082 return IsControlEnabled( m_controlRef
);
1084 return IsControlActive( m_controlRef
);
1088 bool wxMacControl::IsActive() const
1090 return IsControlActive( m_controlRef
);
1093 void wxMacControl::Enable( bool enable
)
1096 EnableControl( m_controlRef
);
1098 DisableControl( m_controlRef
);
1101 void wxMacControl::SetDrawingEnabled( bool enable
)
1103 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1106 bool wxMacControl::GetNeedsDisplay() const
1108 return HIViewGetNeedsDisplay( m_controlRef
);
1111 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1116 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1119 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1124 if ( where
!= NULL
)
1126 RgnHandle update
= NewRgn();
1127 RectRgn( update
, where
);
1128 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1129 DisposeRgn( update
);
1132 HIViewSetNeedsDisplay( m_controlRef
, true );
1135 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1141 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1142 pt
->x
= (int)hiPoint
.x
;
1143 pt
->y
= (int)hiPoint
.y
;
1146 void wxMacControl::SetRect( Rect
*r
)
1148 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1149 //CGPoint and CGSize, which have two floats each
1150 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1151 HIViewSetFrame ( m_controlRef
, &hir
);
1152 // eventuall we might have to do a SetVisibility( false , true );
1153 // before and a SetVisibility( true , true ); after
1156 void wxMacControl::GetRect( Rect
*r
)
1158 GetControlBounds( m_controlRef
, r
);
1161 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1163 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1166 void wxMacControl::GetBestRect( Rect
*r
)
1168 short baselineoffset
;
1170 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1173 void wxMacControl::SetLabel( const wxString
&title
)
1175 wxFontEncoding encoding
;
1178 encoding
= m_font
.GetEncoding();
1180 encoding
= wxFont::GetDefaultEncoding();
1182 UMASetControlTitle( m_controlRef
, title
, encoding
);
1185 void wxMacControl::GetFeatures( UInt32
* features
)
1187 GetControlFeatures( m_controlRef
, features
);
1190 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1192 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1196 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1198 #if TARGET_API_MAC_OSX
1199 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1200 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1206 #if TARGET_API_MAC_OSX
1207 // SetNeedsDisplay would not invalidate the children
1208 static void InvalidateControlAndChildren( HIViewRef control
)
1210 HIViewSetNeedsDisplay( control
, true );
1211 UInt16 childrenCount
= 0;
1212 OSStatus err
= CountSubControls( control
, &childrenCount
);
1213 if ( err
== errControlIsNotEmbedder
)
1216 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1218 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1222 err
= GetIndexedSubControl( control
, i
, & child
);
1223 if ( err
== errControlIsNotEmbedder
)
1226 InvalidateControlAndChildren( child
);
1231 void wxMacControl::InvalidateWithChildren()
1233 #if TARGET_API_MAC_OSX
1234 InvalidateControlAndChildren( m_controlRef
);
1238 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1240 wxASSERT( r
!= NULL
);
1242 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1243 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1246 OSType wxMacCreator
= 'WXMC';
1247 OSType wxMacControlProperty
= 'MCCT';
1249 void wxMacControl::SetReferenceInNativeControl()
1252 verify_noerr( SetControlProperty ( m_controlRef
,
1253 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1256 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1258 wxMacControl
* ctl
= NULL
;
1260 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1261 &actualSize
, &ctl
) == noErr
)
1268 // ============================================================================
1269 // DataBrowser Wrapper
1270 // ============================================================================
1272 // basing on DataBrowserItemIDs
1275 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1277 DataBrowserItemID itemID
,
1278 DataBrowserItemNotification message
,
1279 DataBrowserItemDataRef itemData
)
1281 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1284 ctl
->ItemNotification(itemID
, message
, itemData
);
1288 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1290 DataBrowserItemID itemID
,
1291 DataBrowserPropertyID property
,
1292 DataBrowserItemDataRef itemData
,
1293 Boolean changeValue
)
1295 OSStatus err
= errDataBrowserPropertyNotSupported
;
1297 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1300 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1305 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1307 DataBrowserItemID itemOneID
,
1308 DataBrowserItemID itemTwoID
,
1309 DataBrowserPropertyID sortProperty
)
1311 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1314 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1319 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1320 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1321 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1323 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1325 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1326 OSStatus err
= ::CreateDataBrowserControl(
1327 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1328 &bounds
, kDataBrowserListView
, &m_controlRef
);
1329 SetReferenceInNativeControl();
1330 verify_noerr( err
);
1331 if ( gDataBrowserItemCompareUPP
== NULL
)
1332 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1333 if ( gDataBrowserItemDataUPP
== NULL
)
1334 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1335 if ( gDataBrowserItemNotificationUPP
== NULL
)
1337 gDataBrowserItemNotificationUPP
=
1338 #if TARGET_API_MAC_OSX
1339 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1341 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1345 DataBrowserCallbacks callbacks
;
1346 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1348 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1349 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1350 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1351 SetCallbacks( &callbacks
);
1355 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1357 DataBrowserItemState state
,
1358 UInt32
*numItems
) const
1360 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1363 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1365 DataBrowserItemState state
,
1368 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1371 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1373 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1376 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1377 DataBrowserTableViewColumnIndex position
)
1379 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1382 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1384 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1387 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1389 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1392 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1394 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1397 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1399 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1402 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1404 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1407 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1409 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1412 OSStatus
wxMacDataBrowserControl::UpdateItems(
1413 DataBrowserItemID container
,
1415 const DataBrowserItemID
*items
,
1416 DataBrowserPropertyID preSortProperty
,
1417 DataBrowserPropertyID propertyID
) const
1419 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1422 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1424 return IsDataBrowserItemSelected( m_controlRef
, item
);
1427 OSStatus
wxMacDataBrowserControl::AddItems(
1428 DataBrowserItemID container
,
1430 const DataBrowserItemID
*items
,
1431 DataBrowserPropertyID preSortProperty
)
1433 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1436 OSStatus
wxMacDataBrowserControl::RemoveItems(
1437 DataBrowserItemID container
,
1439 const DataBrowserItemID
*items
,
1440 DataBrowserPropertyID preSortProperty
)
1442 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1445 OSStatus
wxMacDataBrowserControl::RevealItem(
1446 DataBrowserItemID item
,
1447 DataBrowserPropertyID propertyID
,
1448 DataBrowserRevealOptions options
) const
1450 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1453 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1455 const DataBrowserItemID
*items
,
1456 DataBrowserSetOption operation
)
1458 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1461 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1463 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1466 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1468 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1471 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1473 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1476 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1478 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1481 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1483 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1486 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1488 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1491 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1493 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1496 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1498 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1501 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1503 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1506 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1508 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1511 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1513 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1516 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1518 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1521 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1522 UInt32
*position
) const
1524 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1527 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, UInt32 position
)
1529 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1532 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1534 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1537 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1539 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1542 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1544 return GetDataBrowserSortProperty( m_controlRef
, column
);
1547 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1549 return SetDataBrowserSortProperty( m_controlRef
, column
);
1552 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1554 return GetDataBrowserSortOrder( m_controlRef
, order
);
1557 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1559 return SetDataBrowserSortOrder( m_controlRef
, order
);
1562 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1563 DataBrowserPropertyFlags
*flags
) const
1565 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1568 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1569 DataBrowserPropertyFlags flags
)
1571 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1574 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1575 DataBrowserListViewHeaderDesc
*desc
) const
1577 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1580 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1581 DataBrowserListViewHeaderDesc
*desc
)
1583 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1586 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1587 Boolean expandableRows
)
1589 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1592 // ============================================================================
1593 // Higher-level Databrowser
1594 // ============================================================================
1596 // basing on data item objects
1599 wxMacDataItem::wxMacDataItem()
1603 wxMacDataItem::~wxMacDataItem()
1607 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1608 const wxMacDataItem
*,
1609 DataBrowserPropertyID property
) const
1614 OSStatus
wxMacDataItem::GetSetData(wxMacDataItemBrowserControl
*owner
,
1615 DataBrowserPropertyID property
,
1616 DataBrowserItemDataRef itemData
,
1619 return errDataBrowserPropertyNotSupported
;
1622 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1623 DataBrowserItemNotification message
,
1624 DataBrowserItemDataRef itemData
) const
1629 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1630 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1632 m_suppressSelection
= false;
1635 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1637 m_former
= browser
->SuppressSelection(true);
1638 m_browser
= browser
;
1641 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1643 m_browser
->SuppressSelection(m_former
);
1646 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1648 bool former
= m_suppressSelection
;
1649 m_suppressSelection
= suppress
;
1654 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1655 DataBrowserItemID itemTwoID
,
1656 DataBrowserPropertyID sortProperty
)
1658 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1659 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1660 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1663 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1664 const wxMacDataItem
* itemTwo
,
1665 DataBrowserPropertyID sortProperty
)
1667 Boolean retval
= false;
1668 if ( itemOne
!= NULL
)
1669 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1673 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1674 DataBrowserItemID itemID
,
1675 DataBrowserPropertyID property
,
1676 DataBrowserItemDataRef itemData
,
1677 Boolean changeValue
)
1679 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1680 return GetSetItemData(item
, property
, itemData
, changeValue
);
1683 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1684 wxMacDataItem
* item
,
1685 DataBrowserPropertyID property
,
1686 DataBrowserItemDataRef itemData
,
1687 Boolean changeValue
)
1689 OSStatus err
= errDataBrowserPropertyNotSupported
;
1692 case kDataBrowserContainerIsClosableProperty
:
1693 case kDataBrowserContainerIsSortableProperty
:
1694 case kDataBrowserContainerIsOpenableProperty
:
1695 // right now default behaviour on these
1699 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1706 void wxMacDataItemBrowserControl::ItemNotification(
1707 DataBrowserItemID itemID
,
1708 DataBrowserItemNotification message
,
1709 DataBrowserItemDataRef itemData
)
1711 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1712 ItemNotification( item
, message
, itemData
);
1715 void wxMacDataItemBrowserControl::ItemNotification(
1716 const wxMacDataItem
* item
,
1717 DataBrowserItemNotification message
,
1718 DataBrowserItemDataRef itemData
)
1721 item
->Notification( this, message
, itemData
);
1724 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1725 bool recurse
, DataBrowserItemState state
) const
1727 UInt32 numItems
= 0;
1728 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1729 recurse
, state
, &numItems
) );
1733 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1734 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1736 Handle handle
= NewHandle(0);
1737 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1738 recurse
, state
, handle
) );
1740 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1742 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1743 for ( int i
= 0; i
< itemCount
; ++i
)
1745 items
.Add(itemsArray
[i
]);
1748 DisposeHandle( handle
);
1751 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1753 DataBrowserTableViewRowIndex row
;
1754 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1755 wxASSERT( err
== noErr
);
1759 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1761 DataBrowserItemID id
;
1762 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1763 wxASSERT( err
== noErr
);
1764 return (wxMacDataItem
*) id
;
1767 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1768 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1770 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1771 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1774 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1775 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1777 unsigned int noItems
= itemArray
.GetCount();
1778 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1779 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1780 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1782 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1783 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1787 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1789 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1790 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1793 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1795 unsigned int noItems
= itemArray
.GetCount();
1796 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1797 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1798 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1800 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1801 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1805 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1807 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1808 (UInt32
*) &item
, kDataBrowserItemNoProperty
);
1809 verify_noerr( err
);
1812 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1814 unsigned int noItems
= itemArray
.GetCount();
1815 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1816 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1817 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1819 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1820 (UInt32
*) items
, kDataBrowserItemNoProperty
);
1821 verify_noerr( err
);
1825 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1827 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1828 verify_noerr( err
);
1831 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1833 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1836 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1838 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1841 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1843 unsigned int noItems
= itemArray
.GetCount();
1844 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1845 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1846 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1848 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1852 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1854 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1857 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1859 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1862 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1864 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1873 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1875 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
1882 #ifdef __WXMAC_OSX__
1883 // snippets from Sketch Sample from Apple :
1885 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
1888 This function locates, opens, and returns the profile reference for the calibrated
1889 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
1890 with the profile reference this function returns.
1892 CMProfileRef
wxMacOpenGenericProfile()
1894 static CMProfileRef cachedRGBProfileRef
= NULL
;
1896 // we only create the profile reference once
1897 if (cachedRGBProfileRef
== NULL
)
1899 CMProfileLocation loc
;
1901 loc
.locType
= cmPathBasedProfile
;
1902 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
1904 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
1907 // clone the profile reference so that the caller has their own reference, not our cached one
1908 if (cachedRGBProfileRef
)
1909 CMCloneProfileRef(cachedRGBProfileRef
);
1911 return cachedRGBProfileRef
;
1915 Return the generic RGB color space. This is a 'get' function and the caller should
1916 not release the returned value unless the caller retains it first. Usually callers
1917 of this routine will immediately use the returned colorspace with CoreGraphics
1918 so they typically do not need to retain it themselves.
1920 This function creates the generic RGB color space once and hangs onto it so it can
1921 return it whenever this function is called.
1924 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
1926 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
1928 if (genericRGBColorSpace
== NULL
)
1930 if ( UMAGetSystemVersion() >= 0x1040 )
1932 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
1936 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
1938 if (genericRGBProfile
)
1940 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
1942 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
1944 // we opened the profile so it is up to us to close it
1945 CMCloseProfile(genericRGBProfile
);
1950 return genericRGBColorSpace
;
1954 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
1956 ::GetPort( &m_port
);
1960 wxMacPortSaver::~wxMacPortSaver()
1962 ::SetPort( m_port
);