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 wxOperatingSystemId
wxGetOsVersion(int *verMaj
, int *verMin
)
79 // are there x-platform conventions ?
81 Gestalt(gestaltSystemVersion
, &theSystem
);
83 *minorVsn
= (theSystem
& 0xFF);
86 *majorVsn
= (theSystem
>> 8);
88 #if defined( __DARWIN__ )
89 return wxOS_MAC_OSX_DARWIN
;
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
105 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
107 #ifndef __MetroNubUtils__
108 #include "MetroNubUtils.h"
115 #if TARGET_API_MAC_CARBON
117 #include <CodeFragments.h>
119 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
121 ProcPtr gCallUniversalProc_Proc
= NULL
;
125 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
127 static long fRunOnce
= false;
130 Boolean
IsMetroNubInstalled()
137 gMetroNubEntry
= NULL
;
139 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
141 // look for MetroNub's Gestalt selector
142 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
144 #if TARGET_API_MAC_CARBON
145 if (gCallUniversalProc_Proc
== NULL
)
147 CFragConnectionID connectionID
;
150 ProcPtr symbolAddress
;
152 CFragSymbolClass symbolClass
;
154 symbolAddress
= NULL
;
155 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
156 &connectionID
, &mainAddress
, errorString
);
160 gCallUniversalProc_Proc
= NULL
;
164 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
165 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
169 gCallUniversalProc_Proc
= NULL
;
176 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
178 // make sure the version of the API is compatible
179 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
180 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
183 gMetroNubEntry
= block
;
192 #if TARGET_API_MAC_CARBON
193 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
195 return (gMetroNubEntry
!= NULL
);
199 Boolean
IsMWDebuggerRunning()
201 if (IsMetroNubInstalled())
202 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
207 Boolean
AmIBeingMWDebugged()
209 if (IsMetroNubInstalled())
210 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
215 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
217 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
222 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
227 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
231 // defined in unix/utilsunx.cpp for Mac OS X
233 // get full hostname (with domain name if possible)
234 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
236 return wxGetHostName(buf
, maxSize
);
239 // Get user ID e.g. jacs
240 bool wxGetUserId(wxChar
*buf
, int maxSize
)
242 return wxGetUserName( buf
, maxSize
);
245 const wxChar
* wxGetHomeDir(wxString
*pstr
)
247 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
248 return pstr
->c_str();
251 // Get hostname only (without domain name)
252 bool wxGetHostName(wxChar
*buf
, int maxSize
)
254 // Gets Chooser name of user by examining a System resource.
257 const short kComputerNameID
= -16413;
259 short oldResFile
= CurResFile();
261 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
262 UseResFile(oldResFile
);
264 if (chooserName
&& *chooserName
)
266 HLock( (Handle
) chooserName
);
267 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
268 HUnlock( (Handle
) chooserName
);
269 ReleaseResource( (Handle
) chooserName
);
270 wxStrncpy( buf
, name
, maxSize
- 1 );
276 // Get user name e.g. Stefan Csomor
277 bool wxGetUserName(wxChar
*buf
, int maxSize
)
279 // Gets Chooser name of user by examining a System resource.
282 const short kChooserNameID
= -16096;
284 short oldResFile
= CurResFile();
286 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
287 UseResFile(oldResFile
);
289 if (chooserName
&& *chooserName
)
291 HLock( (Handle
) chooserName
);
292 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
293 HUnlock( (Handle
) chooserName
);
294 ReleaseResource( (Handle
) chooserName
);
295 wxStrncpy( buf
, name
, maxSize
- 1 );
301 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
307 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
309 // TODO : under classic there is no environement support, under X yes
313 // set the env var name to the given value, return true on success
314 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
316 // TODO : under classic there is no environement support, under X yes
320 // Execute a program in an Interactive Shell
321 bool wxShell(const wxString
& command
)
327 // Shutdown or reboot the PC
328 bool wxShutdown(wxShutdownFlags wFlags
)
334 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
335 wxMemorySize
wxGetFreeMemory()
337 return (wxMemorySize
)FreeMem();
342 void wxMicroSleep(unsigned long microseconds
)
344 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
345 MPDelayUntil( & wakeup
);
348 void wxMilliSleep(unsigned long milliseconds
)
350 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
351 MPDelayUntil( & wakeup
);
354 void wxSleep(int nSecs
)
356 wxMilliSleep(1000*nSecs
);
361 // Consume all events until no more left
366 #endif // !__DARWIN__
379 wxPortId wxGUIAppTraits
::GetToolkitVersion(int *verMaj
, int *verMin
) const
381 // We suppose that toolkit version is the same as OS version under Mac
382 wxGetOsVersion(verMaj
, verMin
);
387 // Reading and writing resources (eg WIN.INI, .Xdefaults)
389 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
395 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
398 buf
.Printf(wxT("%.4f"), value
);
400 return wxWriteResource(section
, entry
, buf
, file
);
403 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
406 buf
.Printf(wxT("%ld"), value
);
408 return wxWriteResource(section
, entry
, buf
, file
);
411 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
414 buf
.Printf(wxT("%d"), value
);
416 return wxWriteResource(section
, entry
, buf
, file
);
419 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
425 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
428 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
431 *value
= (float)strtod(s
, NULL
);
438 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
441 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
444 *value
= strtol(s
, NULL
, 10);
451 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
454 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
457 *value
= (int)strtol(s
, NULL
, 10);
463 #endif // wxUSE_RESOURCES
465 int gs_wxBusyCursorCount
= 0;
466 extern wxCursor gMacCurrentCursor
;
467 wxCursor gMacStoredActiveCursor
;
469 // Set the cursor to the busy cursor for all windows
470 void wxBeginBusyCursor(const wxCursor
*cursor
)
472 if (gs_wxBusyCursorCount
++ == 0)
474 gMacStoredActiveCursor
= gMacCurrentCursor
;
475 cursor
->MacInstall();
477 //else: nothing to do, already set
480 // Restore cursor to normal
481 void wxEndBusyCursor()
483 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
484 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
486 if (--gs_wxBusyCursorCount
== 0)
488 gMacStoredActiveCursor
.MacInstall();
489 gMacStoredActiveCursor
= wxNullCursor
;
493 // true if we're between the above two calls
496 return (gs_wxBusyCursorCount
> 0);
503 wxString
wxMacFindFolderNoSeparator( short vol
,
505 Boolean createFolder
)
510 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
512 strDir
= wxMacFSRefToPath( &fsRef
);
518 wxString
wxMacFindFolder( short vol
,
520 Boolean createFolder
)
522 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
529 // Check whether this window wants to process messages, e.g. Stop button
530 // in long calculations.
531 bool wxCheckForInterrupt(wxWindow
*wnd
)
537 void wxGetMousePosition( int* x
, int* y
)
542 LocalToGlobal( &pt
);
547 // Return true if we have a colour display
548 bool wxColourDisplay()
553 // Returns depth of screen
557 SetRect(&globRect
, -32760, -32760, 32760, 32760);
558 GDHandle theMaxDevice
;
561 theMaxDevice
= GetMaxDevice(&globRect
);
562 if (theMaxDevice
!= NULL
)
563 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
568 // Get size of display
569 void wxDisplaySize(int *width
, int *height
)
572 GetQDGlobalsScreenBits( &screenBits
);
575 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
578 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
581 void wxDisplaySizeMM(int *width
, int *height
)
583 wxDisplaySize(width
, height
);
584 // on mac 72 is fixed (at least now;-)
585 float cvPt2Mm
= 25.4 / 72;
588 *width
= int( *width
* cvPt2Mm
);
591 *height
= int( *height
* cvPt2Mm
);
594 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
598 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
604 *width
= r
.right
- r
.left
;
606 *height
= r
.bottom
- r
.top
;
609 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
611 return wxGenericFindWindowAtPoint(pt
);
618 wxString
wxGetOsDescription()
620 #ifdef WXWIN_OS_DESCRIPTION
621 // use configure generated description if available
622 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
624 return wxT("MacOS"); //TODO:define further
629 wxChar
*wxGetUserHome (const wxString
& user
)
635 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
644 int pos
= p
.Find(':');
645 if ( pos
!= wxNOT_FOUND
)
653 err
= wxMacPathToFSRef( p
, &fsRef
);
656 FSVolumeRefNum vRefNum
;
657 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
660 UInt64 freeBytes
, totalBytes
;
661 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
665 *pTotal
= wxDiskspaceSize_t( totalBytes
);
667 *pFree
= wxDiskspaceSize_t( freeBytes
);
674 #endif // !__DARWIN__
676 //---------------------------------------------------------------------------
677 // wxMac Specific utility functions
678 //---------------------------------------------------------------------------
680 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
682 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
683 int len
= strlen(buf
);
688 memcpy( (char*) &to
[1] , buf
, len
);
691 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
693 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
696 // ----------------------------------------------------------------------------
697 // Common Event Support
698 // ----------------------------------------------------------------------------
700 extern ProcessSerialNumber gAppProcess
;
704 ProcessSerialNumber psn
;
706 psn
.highLongOfPSN
= 0;
707 psn
.lowLongOfPSN
= kCurrentProcess
;
708 SameProcess( &gAppProcess
, &psn
, &isSame
);
712 OSStatus err
= noErr
;
715 // lead sometimes to race conditions, although all calls used should be thread safe ...
716 static wxMacCarbonEvent s_wakeupEvent
;
717 if ( !s_wakeupEvent
.IsValid() )
719 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
720 kEventAttributeNone
);
725 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
727 s_wakeupEvent
.SetCurrentTime();
728 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
729 kEventPriorityHigh
);
732 wxMacCarbonEvent wakeupEvent
;
733 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
734 kEventAttributeNone
);
735 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
736 kEventPriorityHigh
);
739 PostEvent( nullEvent
, 0 );
744 WakeUpProcess( &gAppProcess
);
752 // ----------------------------------------------------------------------------
753 // Native Struct Conversions
754 // ----------------------------------------------------------------------------
756 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
760 n
->right
= wx
->x
+ wx
->width
;
761 n
->bottom
= wx
->y
+ wx
->height
;
764 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
768 wx
->width
= n
->right
- n
->left
;
769 wx
->height
= n
->bottom
- n
->top
;
772 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
778 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
784 // ----------------------------------------------------------------------------
785 // Carbon Event Support
786 // ----------------------------------------------------------------------------
788 OSStatus wxMacCarbonEvent
::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
790 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
793 OSStatus wxMacCarbonEvent
::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
795 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
798 // ----------------------------------------------------------------------------
799 // Control Access Support
800 // ----------------------------------------------------------------------------
802 wxMacControl
::wxMacControl(wxWindow
* peer
, bool isRootControl
)
806 m_isRootControl
= isRootControl
;
809 wxMacControl
::wxMacControl( wxWindow
* peer
, ControlRef control
)
813 m_controlRef
= control
;
816 wxMacControl
::wxMacControl( wxWindow
* peer
, WXWidget control
)
820 m_controlRef
= (ControlRef
) control
;
823 wxMacControl
::~wxMacControl()
827 void wxMacControl
::Init()
831 m_needsFocusRect
= false;
832 m_isRootControl
= false;
835 void wxMacControl
::Dispose()
837 ::DisposeControl( m_controlRef
);
841 void wxMacControl
::SetReference( SInt32 data
)
843 SetControlReference( m_controlRef
, data
);
846 OSStatus wxMacControl
::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
848 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
851 OSStatus wxMacControl
::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
853 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
856 OSStatus wxMacControl
::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
858 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
861 OSStatus wxMacControl
::SendEvent( EventRef event
, OptionBits inOptions
)
863 #if TARGET_API_MAC_OSX
864 return SendEventToEventTargetWithOptions( event
,
865 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
867 #pragma unused(inOptions)
868 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
872 OSStatus wxMacControl
::SendHICommand( HICommand
&command
, OptionBits inOptions
)
874 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
876 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
878 return SendEvent( event
, inOptions
);
881 OSStatus wxMacControl
::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
885 memset( &command
, 0 , sizeof(command
) );
886 command
.commandID
= commandID
;
887 return SendHICommand( command
, inOptions
);
890 void wxMacControl
::Flash( ControlPartCode part
, UInt32 ticks
)
892 unsigned long finalTicks
;
894 HiliteControl( m_controlRef
, part
);
895 Delay( ticks
, &finalTicks
);
896 HiliteControl( m_controlRef
, kControlNoPart
);
899 SInt32 wxMacControl
::GetValue() const
901 return ::GetControl32BitValue( m_controlRef
);
904 SInt32 wxMacControl
::GetMaximum() const
906 return ::GetControl32BitMaximum( m_controlRef
);
909 SInt32 wxMacControl
::GetMinimum() const
911 return ::GetControl32BitMinimum( m_controlRef
);
914 void wxMacControl
::SetValue( SInt32 v
)
916 ::SetControl32BitValue( m_controlRef
, v
);
919 void wxMacControl
::SetMinimum( SInt32 v
)
921 ::SetControl32BitMinimum( m_controlRef
, v
);
924 void wxMacControl
::SetMaximum( SInt32 v
)
926 ::SetControl32BitMaximum( m_controlRef
, v
);
929 void wxMacControl
::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
931 ::SetControl32BitMinimum( m_controlRef
, minimum
);
932 ::SetControl32BitMaximum( m_controlRef
, maximum
);
933 ::SetControl32BitValue( m_controlRef
, value
);
936 OSStatus wxMacControl
::SetFocus( ControlFocusPart focusPart
)
938 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
941 bool wxMacControl
::HasFocus() const
944 GetKeyboardFocus( GetUserFocusWindow() , &control
);
945 return control
== m_controlRef
;
948 void wxMacControl
::SetNeedsFocusRect( bool needs
)
950 m_needsFocusRect
= needs
;
953 bool wxMacControl
::NeedsFocusRect() const
955 return m_needsFocusRect
;
958 void wxMacControl
::VisibilityChanged(bool shown
)
962 void wxMacControl
::SuperChangedPosition()
966 void wxMacControl
::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
969 ControlFontStyleRec fontStyle
;
970 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
972 switch ( font
.MacGetThemeFontID() )
974 case kThemeSmallSystemFont
:
975 fontStyle
.font
= kControlFontSmallSystemFont
;
978 case 109 : // mini font
982 case kThemeSystemFont
:
983 fontStyle
.font
= kControlFontBigSystemFont
;
987 fontStyle
.font
= kControlFontBigSystemFont
;
991 fontStyle
.flags
= kControlUseFontMask
;
995 fontStyle
.font
= font
.MacGetFontNum();
996 fontStyle
.style
= font
.MacGetFontStyle();
997 fontStyle
.size
= font
.MacGetFontSize();
998 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1001 fontStyle
.just
= teJustLeft
;
1002 fontStyle
.flags
|= kControlUseJustMask
;
1003 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1004 fontStyle
.just
= teJustCenter
;
1005 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1006 fontStyle
.just
= teJustRight
;
1009 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1010 // won't get grayed out by the system anymore
1012 if ( foreground
!= *wxBLACK
)
1014 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
1015 fontStyle
.flags
|= kControlUseForeColorMask
;
1018 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1021 void wxMacControl
::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1024 // setting up a color proc is not recommended anymore
1027 void wxMacControl
::SetRange( SInt32 minimum
, SInt32 maximum
)
1029 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1030 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1033 short wxMacControl
::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1035 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1038 void wxMacControl
::SetActionProc( ControlActionUPP actionProc
)
1040 SetControlAction( m_controlRef
, actionProc
);
1043 void wxMacControl
::SetViewSize( SInt32 viewSize
)
1045 SetControlViewSize(m_controlRef
, viewSize
);
1048 SInt32 wxMacControl
::GetViewSize() const
1050 return GetControlViewSize( m_controlRef
);
1053 bool wxMacControl
::IsVisible() const
1055 return IsControlVisible( m_controlRef
);
1058 void wxMacControl
::SetVisibility( bool visible
, bool redraw
)
1060 SetControlVisibility( m_controlRef
, visible
, redraw
);
1063 bool wxMacControl
::IsEnabled() const
1065 #if TARGET_API_MAC_OSX
1066 return IsControlEnabled( m_controlRef
);
1068 return IsControlActive( m_controlRef
);
1072 bool wxMacControl
::IsActive() const
1074 return IsControlActive( m_controlRef
);
1077 void wxMacControl
::Enable( bool enable
)
1080 EnableControl( m_controlRef
);
1082 DisableControl( m_controlRef
);
1085 void wxMacControl
::SetDrawingEnabled( bool enable
)
1087 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1090 bool wxMacControl
::GetNeedsDisplay() const
1092 return HIViewGetNeedsDisplay( m_controlRef
);
1095 void wxMacControl
::SetNeedsDisplay( RgnHandle where
)
1100 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1103 void wxMacControl
::SetNeedsDisplay( Rect
* where
)
1108 if ( where
!= NULL
)
1110 RgnHandle update
= NewRgn();
1111 RectRgn( update
, where
);
1112 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1113 DisposeRgn( update
);
1116 HIViewSetNeedsDisplay( m_controlRef
, true );
1119 void wxMacControl
::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1125 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1126 pt
->x
= (int)hiPoint
.x
;
1127 pt
->y
= (int)hiPoint
.y
;
1130 void wxMacControl
::SetRect( Rect
*r
)
1132 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1133 //CGPoint and CGSize, which have two floats each
1134 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1135 HIViewSetFrame ( m_controlRef
, &hir
);
1136 // eventuall we might have to do a SetVisibility( false , true );
1137 // before and a SetVisibility( true , true ); after
1140 void wxMacControl
::GetRect( Rect
*r
)
1142 GetControlBounds( m_controlRef
, r
);
1145 void wxMacControl
::GetRectInWindowCoords( Rect
*r
)
1147 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1150 void wxMacControl
::GetBestRect( Rect
*r
)
1152 short baselineoffset
;
1154 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1157 void wxMacControl
::SetLabel( const wxString
&title
)
1159 wxFontEncoding encoding
;
1162 encoding
= m_font
.GetEncoding();
1164 encoding
= wxFont
::GetDefaultEncoding();
1166 UMASetControlTitle( m_controlRef
, title
, encoding
);
1169 void wxMacControl
::GetFeatures( UInt32
* features
)
1171 GetControlFeatures( m_controlRef
, features
);
1174 OSStatus wxMacControl
::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1176 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1180 OSStatus wxMacControl
::SetZOrder( bool above
, wxMacControl
* other
)
1182 #if TARGET_API_MAC_OSX
1183 return HIViewSetZOrder( m_controlRef
,above ? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1184 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1190 #if TARGET_API_MAC_OSX
1191 // SetNeedsDisplay would not invalidate the children
1192 static void InvalidateControlAndChildren( HIViewRef control
)
1194 HIViewSetNeedsDisplay( control
, true );
1195 UInt16 childrenCount
= 0;
1196 OSStatus err
= CountSubControls( control
, &childrenCount
);
1197 if ( err
== errControlIsNotEmbedder
)
1200 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1202 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1206 err
= GetIndexedSubControl( control
, i
, & child
);
1207 if ( err
== errControlIsNotEmbedder
)
1210 InvalidateControlAndChildren( child
);
1215 void wxMacControl
::InvalidateWithChildren()
1217 #if TARGET_API_MAC_OSX
1218 InvalidateControlAndChildren( m_controlRef
);
1222 void wxMacControl
::ScrollRect( wxRect
*r
, int dx
, int dy
)
1224 wxASSERT( r
!= NULL
);
1226 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1227 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1230 OSType wxMacCreator
= 'WXMC';
1231 OSType wxMacControlProperty
= 'MCCT';
1233 void wxMacControl
::SetReferenceInNativeControl()
1236 verify_noerr( SetControlProperty ( m_controlRef
,
1237 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1240 wxMacControl
* wxMacControl
::GetReferenceFromNativeControl(ControlRef control
)
1242 wxMacControl
* ctl
= NULL
;
1244 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1245 &actualSize
, &ctl
) == noErr
)
1252 // ============================================================================
1253 // DataBrowser Wrapper
1254 // ============================================================================
1256 // basing on DataBrowserItemIDs
1259 pascal void wxMacDataBrowserControl
::DataBrowserItemNotificationProc(
1261 DataBrowserItemID itemID
,
1262 DataBrowserItemNotification message
,
1263 DataBrowserItemDataRef itemData
)
1265 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl
::GetReferenceFromNativeControl( browser
) );
1268 ctl
->ItemNotification(itemID
, message
, itemData
);
1272 pascal OSStatus wxMacDataBrowserControl
::DataBrowserGetSetItemDataProc(
1274 DataBrowserItemID itemID
,
1275 DataBrowserPropertyID property
,
1276 DataBrowserItemDataRef itemData
,
1277 Boolean changeValue
)
1279 OSStatus err
= errDataBrowserPropertyNotSupported
;
1281 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl
::GetReferenceFromNativeControl( browser
) );
1284 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1289 pascal Boolean wxMacDataBrowserControl
::DataBrowserCompareProc(
1291 DataBrowserItemID itemOneID
,
1292 DataBrowserItemID itemTwoID
,
1293 DataBrowserPropertyID sortProperty
)
1295 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl
::GetReferenceFromNativeControl( browser
) );
1298 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1303 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1304 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1305 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1307 wxMacDataBrowserControl
::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1309 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1310 OSStatus err
= ::CreateDataBrowserControl(
1311 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1312 &bounds
, kDataBrowserListView
, &m_controlRef
);
1313 SetReferenceInNativeControl();
1314 verify_noerr( err
);
1315 if ( gDataBrowserItemCompareUPP
== NULL
)
1316 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1317 if ( gDataBrowserItemDataUPP
== NULL
)
1318 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1319 if ( gDataBrowserItemNotificationUPP
== NULL
)
1321 gDataBrowserItemNotificationUPP
=
1322 #if TARGET_API_MAC_OSX
1323 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1325 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1329 DataBrowserCallbacks callbacks
;
1330 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1332 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1333 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1334 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1335 SetCallbacks( &callbacks
);
1339 OSStatus wxMacDataBrowserControl
::GetItemCount( DataBrowserItemID container
,
1341 DataBrowserItemState state
,
1342 UInt32
*numItems
) const
1344 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1347 OSStatus wxMacDataBrowserControl
::GetItems( DataBrowserItemID container
,
1349 DataBrowserItemState state
,
1352 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1355 OSStatus wxMacDataBrowserControl
::SetSelectionFlags( DataBrowserSelectionFlags options
)
1357 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1360 OSStatus wxMacDataBrowserControl
::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1361 DataBrowserTableViewColumnIndex position
)
1363 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1366 OSStatus wxMacDataBrowserControl
::AutoSizeColumns()
1368 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1371 OSStatus wxMacDataBrowserControl
::SetHasScrollBars( bool horiz
, bool vert
)
1373 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1376 OSStatus wxMacDataBrowserControl
::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1378 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1381 OSStatus wxMacDataBrowserControl
::SetHeaderButtonHeight(UInt16 height
)
1383 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1386 OSStatus wxMacDataBrowserControl
::GetHeaderButtonHeight(UInt16
*height
)
1388 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1391 OSStatus wxMacDataBrowserControl
::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1393 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1396 OSStatus wxMacDataBrowserControl
::UpdateItems(
1397 DataBrowserItemID container
,
1399 const DataBrowserItemID
*items
,
1400 DataBrowserPropertyID preSortProperty
,
1401 DataBrowserPropertyID propertyID
) const
1403 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1406 bool wxMacDataBrowserControl
::IsItemSelected( DataBrowserItemID item
) const
1408 return IsDataBrowserItemSelected( m_controlRef
, item
);
1411 OSStatus wxMacDataBrowserControl
::AddItems(
1412 DataBrowserItemID container
,
1414 const DataBrowserItemID
*items
,
1415 DataBrowserPropertyID preSortProperty
)
1417 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1420 OSStatus wxMacDataBrowserControl
::RemoveItems(
1421 DataBrowserItemID container
,
1423 const DataBrowserItemID
*items
,
1424 DataBrowserPropertyID preSortProperty
)
1426 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1429 OSStatus wxMacDataBrowserControl
::RevealItem(
1430 DataBrowserItemID item
,
1431 DataBrowserPropertyID propertyID
,
1432 DataBrowserRevealOptions options
) const
1434 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1437 OSStatus wxMacDataBrowserControl
::SetSelectedItems(
1439 const DataBrowserItemID
*items
,
1440 DataBrowserSetOption operation
)
1442 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1445 OSStatus wxMacDataBrowserControl
::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1447 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1450 OSStatus wxMacDataBrowserControl
::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1452 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1455 OSStatus wxMacDataBrowserControl
::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1457 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1460 OSStatus wxMacDataBrowserControl
::SetDefaultRowHeight( UInt16 height
)
1462 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1465 OSStatus wxMacDataBrowserControl
::GetDefaultRowHeight( UInt16
* height
) const
1467 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1470 OSStatus wxMacDataBrowserControl
::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1472 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1475 OSStatus wxMacDataBrowserControl
::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1477 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1480 OSStatus wxMacDataBrowserControl
::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1482 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1485 OSStatus wxMacDataBrowserControl
::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1487 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1490 OSStatus wxMacDataBrowserControl
::GetDefaultColumnWidth( UInt16
*width
) const
1492 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1495 OSStatus wxMacDataBrowserControl
::SetDefaultColumnWidth( UInt16 width
)
1497 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1500 OSStatus wxMacDataBrowserControl
::GetColumnCount(UInt32
* numColumns
) const
1502 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1505 OSStatus wxMacDataBrowserControl
::GetColumnPosition( DataBrowserPropertyID column
,
1506 UInt32
*position
) const
1508 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1511 OSStatus wxMacDataBrowserControl
::SetColumnPosition( DataBrowserPropertyID column
, UInt32 position
)
1513 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1516 OSStatus wxMacDataBrowserControl
::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1518 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1521 OSStatus wxMacDataBrowserControl
::SetScrollPosition( UInt32 top
, UInt32 left
)
1523 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1526 OSStatus wxMacDataBrowserControl
::GetSortProperty( DataBrowserPropertyID
*column
) const
1528 return GetDataBrowserSortProperty( m_controlRef
, column
);
1531 OSStatus wxMacDataBrowserControl
::SetSortProperty( DataBrowserPropertyID column
)
1533 return SetDataBrowserSortProperty( m_controlRef
, column
);
1536 OSStatus wxMacDataBrowserControl
::GetSortOrder( DataBrowserSortOrder
*order
) const
1538 return GetDataBrowserSortOrder( m_controlRef
, order
);
1541 OSStatus wxMacDataBrowserControl
::SetSortOrder( DataBrowserSortOrder order
)
1543 return SetDataBrowserSortOrder( m_controlRef
, order
);
1546 OSStatus wxMacDataBrowserControl
::GetPropertyFlags( DataBrowserPropertyID property
,
1547 DataBrowserPropertyFlags
*flags
) const
1549 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1552 OSStatus wxMacDataBrowserControl
::SetPropertyFlags( DataBrowserPropertyID property
,
1553 DataBrowserPropertyFlags flags
)
1555 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1558 OSStatus wxMacDataBrowserControl
::GetHeaderDesc( DataBrowserPropertyID property
,
1559 DataBrowserListViewHeaderDesc
*desc
) const
1561 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1564 OSStatus wxMacDataBrowserControl
::SetHeaderDesc( DataBrowserPropertyID property
,
1565 DataBrowserListViewHeaderDesc
*desc
)
1567 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1570 OSStatus wxMacDataBrowserControl
::SetDisclosureColumn( DataBrowserPropertyID property
,
1571 Boolean expandableRows
)
1573 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1576 // ============================================================================
1577 // Higher-level Databrowser
1578 // ============================================================================
1580 // basing on data item objects
1583 wxMacDataItem
::wxMacDataItem()
1587 wxMacDataItem
::~wxMacDataItem()
1591 bool wxMacDataItem
::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1592 const wxMacDataItem
*,
1593 DataBrowserPropertyID property
) const
1598 OSStatus wxMacDataItem
::GetSetData(wxMacDataItemBrowserControl
*owner
,
1599 DataBrowserPropertyID property
,
1600 DataBrowserItemDataRef itemData
,
1603 return errDataBrowserPropertyNotSupported
;
1606 void wxMacDataItem
::Notification(wxMacDataItemBrowserControl
*owner
,
1607 DataBrowserItemNotification message
,
1608 DataBrowserItemDataRef itemData
) const
1613 wxMacDataItemBrowserControl
::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1614 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1616 m_suppressSelection
= false;
1619 wxMacDataItemBrowserSelectionSuppressor
::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1621 m_former
= browser
->SuppressSelection(true);
1622 m_browser
= browser
;
1625 wxMacDataItemBrowserSelectionSuppressor
::~wxMacDataItemBrowserSelectionSuppressor()
1627 m_browser
->SuppressSelection(m_former
);
1630 bool wxMacDataItemBrowserControl
::SuppressSelection( bool suppress
)
1632 bool former
= m_suppressSelection
;
1633 m_suppressSelection
= suppress
;
1638 Boolean wxMacDataItemBrowserControl
::CompareItems(DataBrowserItemID itemOneID
,
1639 DataBrowserItemID itemTwoID
,
1640 DataBrowserPropertyID sortProperty
)
1642 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1643 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1644 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1647 Boolean wxMacDataItemBrowserControl
::CompareItems(const wxMacDataItem
* itemOne
,
1648 const wxMacDataItem
* itemTwo
,
1649 DataBrowserPropertyID sortProperty
)
1651 Boolean retval
= false;
1652 if ( itemOne
!= NULL
)
1653 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1657 OSStatus wxMacDataItemBrowserControl
::GetSetItemData(
1658 DataBrowserItemID itemID
,
1659 DataBrowserPropertyID property
,
1660 DataBrowserItemDataRef itemData
,
1661 Boolean changeValue
)
1663 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1664 return GetSetItemData(item
, property
, itemData
, changeValue
);
1667 OSStatus wxMacDataItemBrowserControl
::GetSetItemData(
1668 wxMacDataItem
* item
,
1669 DataBrowserPropertyID property
,
1670 DataBrowserItemDataRef itemData
,
1671 Boolean changeValue
)
1673 OSStatus err
= errDataBrowserPropertyNotSupported
;
1676 case kDataBrowserContainerIsClosableProperty
:
1677 case kDataBrowserContainerIsSortableProperty
:
1678 case kDataBrowserContainerIsOpenableProperty
:
1679 // right now default behaviour on these
1683 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1690 void wxMacDataItemBrowserControl
::ItemNotification(
1691 DataBrowserItemID itemID
,
1692 DataBrowserItemNotification message
,
1693 DataBrowserItemDataRef itemData
)
1695 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1696 ItemNotification( item
, message
, itemData
);
1699 void wxMacDataItemBrowserControl
::ItemNotification(
1700 const wxMacDataItem
* item
,
1701 DataBrowserItemNotification message
,
1702 DataBrowserItemDataRef itemData
)
1705 item
->Notification( this, message
, itemData
);
1708 unsigned int wxMacDataItemBrowserControl
::GetItemCount(const wxMacDataItem
* container
,
1709 bool recurse
, DataBrowserItemState state
) const
1711 UInt32 numItems
= 0;
1712 verify_noerr( wxMacDataBrowserControl
::GetItemCount( (DataBrowserItemID
)container
,
1713 recurse
, state
, &numItems
) );
1717 void wxMacDataItemBrowserControl
::GetItems(const wxMacDataItem
* container
,
1718 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1720 Handle handle
= NewHandle(0);
1721 verify_noerr( wxMacDataBrowserControl
::GetItems( (DataBrowserItemID
)container
,
1722 recurse
, state
, handle
) );
1724 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1726 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1727 for ( int i
= 0; i
< itemCount
; ++i
)
1729 items
.Add(itemsArray
[i
]);
1732 DisposeHandle( handle
);
1735 unsigned int wxMacDataItemBrowserControl
::GetLineFromItem(const wxMacDataItem
* item
) const
1737 DataBrowserTableViewRowIndex row
;
1738 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1739 wxASSERT( err
== noErr
);
1743 wxMacDataItem
* wxMacDataItemBrowserControl
::GetItemFromLine(unsigned int n
) const
1745 DataBrowserItemID id
;
1746 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1747 wxASSERT( err
== noErr
);
1748 return (wxMacDataItem
*) id
;
1751 void wxMacDataItemBrowserControl
::UpdateItem(const wxMacDataItem
*container
,
1752 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1754 verify_noerr( wxMacDataBrowserControl
::UpdateItems((DataBrowserItemID
)container
, 1,
1755 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1758 void wxMacDataItemBrowserControl
::UpdateItems(const wxMacDataItem
*container
,
1759 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1761 unsigned int noItems
= itemArray
.GetCount();
1762 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1763 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1764 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1766 verify_noerr( wxMacDataBrowserControl
::UpdateItems((DataBrowserItemID
)container
, noItems
,
1767 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1771 void wxMacDataItemBrowserControl
::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1773 verify_noerr( wxMacDataBrowserControl
::AddItems( (DataBrowserItemID
)container
, 1,
1774 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1777 void wxMacDataItemBrowserControl
::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1779 unsigned int noItems
= itemArray
.GetCount();
1780 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1781 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1782 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1784 verify_noerr( wxMacDataBrowserControl
::AddItems( (DataBrowserItemID
)container
, noItems
,
1785 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1789 void wxMacDataItemBrowserControl
::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1791 OSStatus err
= wxMacDataBrowserControl
::RemoveItems( (DataBrowserItemID
)container
, 1,
1792 (UInt32
*) &item
, kDataBrowserItemNoProperty
);
1793 verify_noerr( err
);
1796 void wxMacDataItemBrowserControl
::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1798 unsigned int noItems
= itemArray
.GetCount();
1799 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1800 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1801 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1803 OSStatus err
= wxMacDataBrowserControl
::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1804 (UInt32
*) items
, kDataBrowserItemNoProperty
);
1805 verify_noerr( err
);
1809 void wxMacDataItemBrowserControl
::RemoveAllItems(wxMacDataItem
*container
)
1811 OSStatus err
= wxMacDataBrowserControl
::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1812 verify_noerr( err
);
1815 void wxMacDataItemBrowserControl
::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1817 verify_noerr(wxMacDataBrowserControl
::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1820 void wxMacDataItemBrowserControl
::SetSelectedAllItems(DataBrowserSetOption option
)
1822 verify_noerr(wxMacDataBrowserControl
::SetSelectedItems( 0 , NULL
, option
));
1825 void wxMacDataItemBrowserControl
::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1827 unsigned int noItems
= itemArray
.GetCount();
1828 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1829 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1830 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1832 verify_noerr(wxMacDataBrowserControl
::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1836 Boolean wxMacDataItemBrowserControl
::IsItemSelected( const wxMacDataItem
* item
) const
1838 return wxMacDataBrowserControl
::IsItemSelected( (DataBrowserItemID
) item
);
1841 void wxMacDataItemBrowserControl
::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1843 verify_noerr(wxMacDataBrowserControl
::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1846 void wxMacDataItemBrowserControl
::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1848 verify_noerr(wxMacDataBrowserControl
::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1857 OSStatus wxMacControl
::SetTabEnabled( SInt16 tabNo
, bool enable
)
1859 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
1866 #ifdef __WXMAC_OSX__
1867 // snippets from Sketch Sample from Apple :
1869 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
1872 This function locates, opens, and returns the profile reference for the calibrated
1873 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
1874 with the profile reference this function returns.
1876 CMProfileRef
wxMacOpenGenericProfile()
1878 static CMProfileRef cachedRGBProfileRef
= NULL
;
1880 // we only create the profile reference once
1881 if (cachedRGBProfileRef
== NULL
)
1883 CMProfileLocation loc
;
1885 loc
.locType
= cmPathBasedProfile
;
1886 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
1888 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
1891 // clone the profile reference so that the caller has their own reference, not our cached one
1892 if (cachedRGBProfileRef
)
1893 CMCloneProfileRef(cachedRGBProfileRef
);
1895 return cachedRGBProfileRef
;
1899 Return the generic RGB color space. This is a 'get' function and the caller should
1900 not release the returned value unless the caller retains it first. Usually callers
1901 of this routine will immediately use the returned colorspace with CoreGraphics
1902 so they typically do not need to retain it themselves.
1904 This function creates the generic RGB color space once and hangs onto it so it can
1905 return it whenever this function is called.
1908 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
1910 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
1912 if (genericRGBColorSpace
== NULL
)
1914 if ( UMAGetSystemVersion() >= 0x1040 )
1916 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
1920 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
1922 if (genericRGBProfile
)
1924 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
1926 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
1928 // we opened the profile so it is up to us to close it
1929 CMCloseProfile(genericRGBProfile
);
1934 return genericRGBColorSpace
;
1938 wxMacPortSaver
::wxMacPortSaver( GrafPtr port
)
1940 ::GetPort( &m_port
);
1944 wxMacPortSaver
::~wxMacPortSaver()
1946 ::SetPort( m_port
);