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>
61 #include "wx/mac/private/timer.h"
64 #include "wx/evtloop.h"
65 #include "wx/mac/private.h"
67 #if defined(__MWERKS__) && wxUSE_UNICODE
68 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
75 // our OS version is the same in non GUI and GUI cases
76 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
79 Gestalt(gestaltSystemVersion
, &theSystem
);
81 if ( majorVsn
!= NULL
)
82 *majorVsn
= (theSystem
>> 8);
84 if ( minorVsn
!= NULL
)
85 *minorVsn
= (theSystem
& 0xFF);
87 #if defined( __DARWIN__ )
88 return wxOS_MAC_OSX_DARWIN
;
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
100 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
102 #ifndef __MetroNubUtils__
103 #include "MetroNubUtils.h"
110 #if TARGET_API_MAC_CARBON
112 #include <CodeFragments.h>
114 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
116 ProcPtr gCallUniversalProc_Proc
= NULL
;
120 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
122 static long fRunOnce
= false;
125 Boolean
IsMetroNubInstalled()
132 gMetroNubEntry
= NULL
;
134 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
136 // look for MetroNub's Gestalt selector
137 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
139 #if TARGET_API_MAC_CARBON
140 if (gCallUniversalProc_Proc
== NULL
)
142 CFragConnectionID connectionID
;
145 ProcPtr symbolAddress
;
147 CFragSymbolClass symbolClass
;
149 symbolAddress
= NULL
;
150 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
151 &connectionID
, &mainAddress
, errorString
);
155 gCallUniversalProc_Proc
= NULL
;
159 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
160 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
164 gCallUniversalProc_Proc
= NULL
;
171 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
173 // make sure the version of the API is compatible
174 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
175 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
178 gMetroNubEntry
= block
;
187 #if TARGET_API_MAC_CARBON
188 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
190 return (gMetroNubEntry
!= NULL
);
194 Boolean
IsMWDebuggerRunning()
196 if (IsMetroNubInstalled())
197 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
202 Boolean
AmIBeingMWDebugged()
204 if (IsMetroNubInstalled())
205 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
210 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
212 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
217 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
222 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
226 // defined in unix/utilsunx.cpp for Mac OS X
228 // get full hostname (with domain name if possible)
229 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
231 return wxGetHostName(buf
, maxSize
);
234 // Get user ID e.g. jacs
235 bool wxGetUserId(wxChar
*buf
, int maxSize
)
237 return wxGetUserName( buf
, maxSize
);
240 const wxChar
* wxGetHomeDir(wxString
*pstr
)
242 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
243 return pstr
->c_str();
246 // Get hostname only (without domain name)
247 bool wxGetHostName(wxChar
*buf
, int maxSize
)
249 // Gets Chooser name of user by examining a System resource.
252 const short kComputerNameID
= -16413;
254 short oldResFile
= CurResFile();
256 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
257 UseResFile(oldResFile
);
259 if (chooserName
&& *chooserName
)
261 HLock( (Handle
) chooserName
);
262 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
263 HUnlock( (Handle
) chooserName
);
264 ReleaseResource( (Handle
) chooserName
);
265 wxStrncpy( buf
, name
, maxSize
- 1 );
271 // Get user name e.g. Stefan Csomor
272 bool wxGetUserName(wxChar
*buf
, int maxSize
)
274 // Gets Chooser name of user by examining a System resource.
277 const short kChooserNameID
= -16096;
279 short oldResFile
= CurResFile();
281 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
282 UseResFile(oldResFile
);
284 if (chooserName
&& *chooserName
)
286 HLock( (Handle
) chooserName
);
287 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
288 HUnlock( (Handle
) chooserName
);
289 ReleaseResource( (Handle
) chooserName
);
290 wxStrncpy( buf
, name
, maxSize
- 1 );
296 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
302 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
304 // TODO : under classic there is no environement support, under X yes
308 // set the env var name to the given value, return true on success
309 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
311 // TODO : under classic there is no environement support, under X yes
315 // Execute a program in an Interactive Shell
316 bool wxShell(const wxString
& command
)
322 // Shutdown or reboot the PC
323 bool wxShutdown(wxShutdownFlags wFlags
)
329 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
330 wxMemorySize
wxGetFreeMemory()
332 return (wxMemorySize
)FreeMem();
337 void wxMicroSleep(unsigned long microseconds
)
339 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
340 MPDelayUntil( & wakeup
);
343 void wxMilliSleep(unsigned long milliseconds
)
345 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
346 MPDelayUntil( & wakeup
);
349 void wxSleep(int nSecs
)
351 wxMilliSleep(1000*nSecs
);
356 // Consume all events until no more left
361 #endif // !__DARWIN__
376 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
378 // We suppose that toolkit version is the same as OS version under Mac
379 wxGetOsVersion(verMaj
, verMin
);
384 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
386 return new wxEventLoop
;
389 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
391 return new wxCarbonTimerImpl(timer
);
394 int gs_wxBusyCursorCount
= 0;
395 extern wxCursor gMacCurrentCursor
;
396 wxCursor gMacStoredActiveCursor
;
398 // Set the cursor to the busy cursor for all windows
399 void wxBeginBusyCursor(const wxCursor
*cursor
)
401 if (gs_wxBusyCursorCount
++ == 0)
403 gMacStoredActiveCursor
= gMacCurrentCursor
;
404 cursor
->MacInstall();
406 //else: nothing to do, already set
409 // Restore cursor to normal
410 void wxEndBusyCursor()
412 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
413 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
415 if (--gs_wxBusyCursorCount
== 0)
417 gMacStoredActiveCursor
.MacInstall();
418 gMacStoredActiveCursor
= wxNullCursor
;
422 // true if we're between the above two calls
425 return (gs_wxBusyCursorCount
> 0);
432 wxString
wxMacFindFolderNoSeparator( short vol
,
434 Boolean createFolder
)
439 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
441 strDir
= wxMacFSRefToPath( &fsRef
);
447 wxString
wxMacFindFolder( short vol
,
449 Boolean createFolder
)
451 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
458 // Check whether this window wants to process messages, e.g. Stop button
459 // in long calculations.
460 bool wxCheckForInterrupt(wxWindow
*wnd
)
466 void wxGetMousePosition( int* x
, int* y
)
469 #if wxMAC_USE_CORE_GRAPHICS
473 LocalToGlobal( &pt
);
479 // Return true if we have a colour display
480 bool wxColourDisplay()
485 // Returns depth of screen
489 #if wxMAC_USE_CORE_GRAPHICS
490 theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
493 SetRect(&globRect
, -32760, -32760, 32760, 32760);
494 GDHandle theMaxDevice
;
496 theMaxDevice
= GetMaxDevice(&globRect
);
497 if (theMaxDevice
!= NULL
)
498 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
503 // Get size of display
504 void wxDisplaySize(int *width
, int *height
)
506 #if wxMAC_USE_CORE_GRAPHICS
507 // TODO adapt for multi-displays
508 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
510 *width
= (int)bounds
.size
.width
;
512 *height
= (int)bounds
.size
.height
;
515 GetQDGlobalsScreenBits( &screenBits
);
518 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
521 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
525 void wxDisplaySizeMM(int *width
, int *height
)
527 wxDisplaySize(width
, height
);
528 // on mac 72 is fixed (at least now;-)
529 float cvPt2Mm
= 25.4 / 72;
532 *width
= int( *width
* cvPt2Mm
);
535 *height
= int( *height
* cvPt2Mm
);
538 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
540 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
542 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
545 *x
= bounds
.origin
.x
;
547 *y
= bounds
.origin
.y
;
549 *width
= bounds
.size
.width
;
551 *height
= bounds
.size
.height
;
554 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
560 *width
= r
.right
- r
.left
;
562 *height
= r
.bottom
- r
.top
;
566 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
568 return wxGenericFindWindowAtPoint(pt
);
575 wxString
wxGetOsDescription()
577 #ifdef WXWIN_OS_DESCRIPTION
578 // use configure generated description if available
579 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
581 return wxT("MacOS"); //TODO:define further
586 wxChar
*wxGetUserHome (const wxString
& user
)
592 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
601 int pos
= p
.Find(':');
602 if ( pos
!= wxNOT_FOUND
)
610 err
= wxMacPathToFSRef( p
, &fsRef
);
613 FSVolumeRefNum vRefNum
;
614 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
617 UInt64 freeBytes
, totalBytes
;
618 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
622 *pTotal
= wxDiskspaceSize_t( totalBytes
);
624 *pFree
= wxDiskspaceSize_t( freeBytes
);
631 #endif // !__DARWIN__
633 //---------------------------------------------------------------------------
634 // wxMac Specific utility functions
635 //---------------------------------------------------------------------------
637 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
639 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
640 int len
= strlen(buf
);
645 memcpy( (char*) &to
[1] , buf
, len
);
648 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
650 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
653 // ----------------------------------------------------------------------------
654 // Common Event Support
655 // ----------------------------------------------------------------------------
657 extern ProcessSerialNumber gAppProcess
;
661 ProcessSerialNumber psn
;
663 psn
.highLongOfPSN
= 0;
664 psn
.lowLongOfPSN
= kCurrentProcess
;
665 SameProcess( &gAppProcess
, &psn
, &isSame
);
669 OSStatus err
= noErr
;
672 // lead sometimes to race conditions, although all calls used should be thread safe ...
673 static wxMacCarbonEvent s_wakeupEvent
;
674 if ( !s_wakeupEvent
.IsValid() )
676 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
677 kEventAttributeNone
);
682 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
684 s_wakeupEvent
.SetCurrentTime();
685 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
686 kEventPriorityHigh
);
689 wxMacCarbonEvent wakeupEvent
;
690 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
691 kEventAttributeNone
);
692 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
693 kEventPriorityHigh
);
696 PostEvent( nullEvent
, 0 );
701 WakeUpProcess( &gAppProcess
);
709 // ----------------------------------------------------------------------------
710 // Native Struct Conversions
711 // ----------------------------------------------------------------------------
713 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
717 n
->right
= wx
->x
+ wx
->width
;
718 n
->bottom
= wx
->y
+ wx
->height
;
721 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
725 wx
->width
= n
->right
- n
->left
;
726 wx
->height
= n
->bottom
- n
->top
;
729 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
735 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
741 // ----------------------------------------------------------------------------
742 // Carbon Event Support
743 // ----------------------------------------------------------------------------
745 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
747 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
750 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
752 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
755 // ----------------------------------------------------------------------------
756 // Control Access Support
757 // ----------------------------------------------------------------------------
759 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
761 wxMacControl::wxMacControl()
766 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
770 m_isRootControl
= isRootControl
;
773 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
777 m_controlRef
= control
;
780 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
784 m_controlRef
= (ControlRef
) control
;
787 wxMacControl::~wxMacControl()
791 void wxMacControl::Init()
795 m_needsFocusRect
= false;
796 m_isRootControl
= false;
799 void wxMacControl::Dispose()
801 wxASSERT_MSG( m_controlRef
!= NULL
, wxT("Control Handle already NULL, Dispose called twice ?") );
802 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
804 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
805 // we can have situations when being embedded, where the control gets deleted behind our back, so only
806 // CFRelease if we are safe
807 if ( IsValidControlHandle(m_controlRef
) )
808 CFRelease(m_controlRef
);
812 void wxMacControl::SetReference( URefCon data
)
814 SetControlReference( m_controlRef
, data
);
817 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
819 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
822 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
824 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
827 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
829 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
832 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
834 #if TARGET_API_MAC_OSX
835 return SendEventToEventTargetWithOptions( event
,
836 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
838 #pragma unused(inOptions)
839 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
843 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
845 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
847 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
849 return SendEvent( event
, inOptions
);
852 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
856 memset( &command
, 0 , sizeof(command
) );
857 command
.commandID
= commandID
;
858 return SendHICommand( command
, inOptions
);
861 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
863 unsigned long finalTicks
;
865 HiliteControl( m_controlRef
, part
);
866 Delay( ticks
, &finalTicks
);
867 HiliteControl( m_controlRef
, kControlNoPart
);
870 SInt32
wxMacControl::GetValue() const
872 return ::GetControl32BitValue( m_controlRef
);
875 SInt32
wxMacControl::GetMaximum() const
877 return ::GetControl32BitMaximum( m_controlRef
);
880 SInt32
wxMacControl::GetMinimum() const
882 return ::GetControl32BitMinimum( m_controlRef
);
885 void wxMacControl::SetValue( SInt32 v
)
887 ::SetControl32BitValue( m_controlRef
, v
);
890 void wxMacControl::SetMinimum( SInt32 v
)
892 ::SetControl32BitMinimum( m_controlRef
, v
);
895 void wxMacControl::SetMaximum( SInt32 v
)
897 ::SetControl32BitMaximum( m_controlRef
, v
);
900 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
902 ::SetControl32BitMinimum( m_controlRef
, minimum
);
903 ::SetControl32BitMaximum( m_controlRef
, maximum
);
904 ::SetControl32BitValue( m_controlRef
, value
);
907 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
909 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
912 bool wxMacControl::HasFocus() const
915 GetKeyboardFocus( GetUserFocusWindow() , &control
);
916 return control
== m_controlRef
;
919 void wxMacControl::SetNeedsFocusRect( bool needs
)
921 m_needsFocusRect
= needs
;
924 bool wxMacControl::NeedsFocusRect() const
926 return m_needsFocusRect
;
929 void wxMacControl::VisibilityChanged(bool shown
)
933 void wxMacControl::SuperChangedPosition()
937 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
940 ControlFontStyleRec fontStyle
;
941 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
943 switch ( font
.MacGetThemeFontID() )
945 case kThemeSmallSystemFont
:
946 fontStyle
.font
= kControlFontSmallSystemFont
;
949 case 109 : // mini font
953 case kThemeSystemFont
:
954 fontStyle
.font
= kControlFontBigSystemFont
;
958 fontStyle
.font
= kControlFontBigSystemFont
;
962 fontStyle
.flags
= kControlUseFontMask
;
966 fontStyle
.font
= font
.MacGetFontNum();
967 fontStyle
.style
= font
.MacGetFontStyle();
968 fontStyle
.size
= font
.MacGetFontSize();
969 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
972 fontStyle
.just
= teJustLeft
;
973 fontStyle
.flags
|= kControlUseJustMask
;
974 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
975 fontStyle
.just
= teJustCenter
;
976 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
977 fontStyle
.just
= teJustRight
;
980 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
981 // won't get grayed out by the system anymore
983 if ( foreground
!= *wxBLACK
)
985 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
986 fontStyle
.flags
|= kControlUseForeColorMask
;
989 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
992 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
995 // setting up a color proc is not recommended anymore
998 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1000 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1001 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1004 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1007 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1013 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1015 SetControlAction( m_controlRef
, actionProc
);
1018 void wxMacControl::SetViewSize( SInt32 viewSize
)
1020 SetControlViewSize(m_controlRef
, viewSize
);
1023 SInt32
wxMacControl::GetViewSize() const
1025 return GetControlViewSize( m_controlRef
);
1028 bool wxMacControl::IsVisible() const
1030 return IsControlVisible( m_controlRef
);
1033 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1035 SetControlVisibility( m_controlRef
, visible
, redraw
);
1038 bool wxMacControl::IsEnabled() const
1040 #if TARGET_API_MAC_OSX
1041 return IsControlEnabled( m_controlRef
);
1043 return IsControlActive( m_controlRef
);
1047 bool wxMacControl::IsActive() const
1049 return IsControlActive( m_controlRef
);
1052 void wxMacControl::Enable( bool enable
)
1055 EnableControl( m_controlRef
);
1057 DisableControl( m_controlRef
);
1060 void wxMacControl::SetDrawingEnabled( bool enable
)
1062 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1065 bool wxMacControl::GetNeedsDisplay() const
1067 return HIViewGetNeedsDisplay( m_controlRef
);
1070 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1075 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1078 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1083 if ( where
!= NULL
)
1085 RgnHandle update
= NewRgn();
1086 RectRgn( update
, where
);
1087 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1088 DisposeRgn( update
);
1091 HIViewSetNeedsDisplay( m_controlRef
, true );
1094 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1100 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1101 pt
->x
= (int)hiPoint
.x
;
1102 pt
->y
= (int)hiPoint
.y
;
1105 void wxMacControl::SetRect( Rect
*r
)
1107 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1108 //CGPoint and CGSize, which have two floats each
1109 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1110 HIViewSetFrame ( m_controlRef
, &hir
);
1111 // eventuall we might have to do a SetVisibility( false , true );
1112 // before and a SetVisibility( true , true ); after
1115 void wxMacControl::GetRect( Rect
*r
)
1117 GetControlBounds( m_controlRef
, r
);
1120 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1122 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1125 void wxMacControl::GetBestRect( Rect
*r
)
1127 short baselineoffset
;
1129 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1132 void wxMacControl::SetLabel( const wxString
&title
)
1134 wxFontEncoding encoding
;
1137 encoding
= m_font
.GetEncoding();
1139 encoding
= wxFont::GetDefaultEncoding();
1141 UMASetControlTitle( m_controlRef
, title
, encoding
);
1144 void wxMacControl::GetFeatures( UInt32
* features
)
1146 GetControlFeatures( m_controlRef
, features
);
1149 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1151 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1155 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1157 #if TARGET_API_MAC_OSX
1158 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1159 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1165 #if TARGET_API_MAC_OSX
1166 // SetNeedsDisplay would not invalidate the children
1167 static void InvalidateControlAndChildren( HIViewRef control
)
1169 HIViewSetNeedsDisplay( control
, true );
1170 UInt16 childrenCount
= 0;
1171 OSStatus err
= CountSubControls( control
, &childrenCount
);
1172 if ( err
== errControlIsNotEmbedder
)
1175 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1177 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1181 err
= GetIndexedSubControl( control
, i
, & child
);
1182 if ( err
== errControlIsNotEmbedder
)
1185 InvalidateControlAndChildren( child
);
1190 void wxMacControl::InvalidateWithChildren()
1192 #if TARGET_API_MAC_OSX
1193 InvalidateControlAndChildren( m_controlRef
);
1197 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1199 wxASSERT( r
!= NULL
);
1201 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1202 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1205 OSType wxMacCreator
= 'WXMC';
1206 OSType wxMacControlProperty
= 'MCCT';
1208 void wxMacControl::SetReferenceInNativeControl()
1211 verify_noerr( SetControlProperty ( m_controlRef
,
1212 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1215 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1217 wxMacControl
* ctl
= NULL
;
1218 ByteCount actualSize
;
1219 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1220 &actualSize
, &ctl
) == noErr
)
1227 // ============================================================================
1228 // DataBrowser Wrapper
1229 // ============================================================================
1231 // basing on DataBrowserItemIDs
1234 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
1236 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1238 DataBrowserItemID itemID
,
1239 DataBrowserItemNotification message
,
1240 DataBrowserItemDataRef itemData
)
1242 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1245 ctl
->ItemNotification(itemID
, message
, itemData
);
1249 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1251 DataBrowserItemID itemID
,
1252 DataBrowserPropertyID property
,
1253 DataBrowserItemDataRef itemData
,
1254 Boolean changeValue
)
1256 OSStatus err
= errDataBrowserPropertyNotSupported
;
1257 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1260 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1265 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1267 DataBrowserItemID itemOneID
,
1268 DataBrowserItemID itemTwoID
,
1269 DataBrowserPropertyID sortProperty
)
1271 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1274 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1279 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1280 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1281 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1283 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1285 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1286 OSStatus err
= ::CreateDataBrowserControl(
1287 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1288 &bounds
, kDataBrowserListView
, &m_controlRef
);
1289 SetReferenceInNativeControl();
1290 verify_noerr( err
);
1291 if ( gDataBrowserItemCompareUPP
== NULL
)
1292 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1293 if ( gDataBrowserItemDataUPP
== NULL
)
1294 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1295 if ( gDataBrowserItemNotificationUPP
== NULL
)
1297 gDataBrowserItemNotificationUPP
=
1298 #if TARGET_API_MAC_OSX
1299 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1301 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1305 DataBrowserCallbacks callbacks
;
1306 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1308 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1309 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1310 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1311 SetCallbacks( &callbacks
);
1315 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1317 DataBrowserItemState state
,
1318 ItemCount
*numItems
) const
1320 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1323 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1325 DataBrowserItemState state
,
1328 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1331 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1333 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1336 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1337 DataBrowserTableViewColumnIndex position
)
1339 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1342 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1343 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1346 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1348 DataBrowserTableViewColumnID id
;
1349 GetColumnIDFromIndex( position
, &id
);
1350 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1353 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1355 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1358 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1360 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1363 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1365 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1368 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1370 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1373 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1375 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1378 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1380 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1383 OSStatus
wxMacDataBrowserControl::UpdateItems(
1384 DataBrowserItemID container
,
1386 const DataBrowserItemID
*items
,
1387 DataBrowserPropertyID preSortProperty
,
1388 DataBrowserPropertyID propertyID
) const
1390 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1393 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1395 return IsDataBrowserItemSelected( m_controlRef
, item
);
1398 OSStatus
wxMacDataBrowserControl::AddItems(
1399 DataBrowserItemID container
,
1401 const DataBrowserItemID
*items
,
1402 DataBrowserPropertyID preSortProperty
)
1404 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1407 OSStatus
wxMacDataBrowserControl::RemoveItems(
1408 DataBrowserItemID container
,
1410 const DataBrowserItemID
*items
,
1411 DataBrowserPropertyID preSortProperty
)
1413 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1416 OSStatus
wxMacDataBrowserControl::RevealItem(
1417 DataBrowserItemID item
,
1418 DataBrowserPropertyID propertyID
,
1419 DataBrowserRevealOptions options
) const
1421 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1424 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1426 const DataBrowserItemID
*items
,
1427 DataBrowserSetOption operation
)
1429 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1432 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1434 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1437 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1439 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1442 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1444 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1447 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1449 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1452 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1454 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1457 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1459 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1462 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1464 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1467 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1469 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1472 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1474 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1477 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1479 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1482 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1484 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1487 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1489 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1492 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1493 DataBrowserTableViewColumnIndex
*position
) const
1495 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1498 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1500 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1503 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1505 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1508 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1510 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1513 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1515 return GetDataBrowserSortProperty( m_controlRef
, column
);
1518 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1520 return SetDataBrowserSortProperty( m_controlRef
, column
);
1523 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1525 return GetDataBrowserSortOrder( m_controlRef
, order
);
1528 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1530 return SetDataBrowserSortOrder( m_controlRef
, order
);
1533 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1534 DataBrowserPropertyFlags
*flags
) const
1536 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1539 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1540 DataBrowserPropertyFlags flags
)
1542 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1545 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1546 DataBrowserListViewHeaderDesc
*desc
) const
1548 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1551 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1552 DataBrowserListViewHeaderDesc
*desc
)
1554 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1557 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1558 Boolean expandableRows
)
1560 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1563 // ============================================================================
1564 // Higher-level Databrowser
1565 // ============================================================================
1567 // basing on data item objects
1570 wxMacDataItem::wxMacDataItem()
1575 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1578 wxMacDataItem::~wxMacDataItem()
1582 void wxMacDataItem::SetOrder( SInt32 order
)
1587 SInt32
wxMacDataItem::GetOrder() const
1592 void wxMacDataItem::SetData( void* data
)
1597 void* wxMacDataItem::GetData() const
1602 short wxMacDataItem::GetColumn()
1607 void wxMacDataItem::SetColumn( short col
)
1612 void wxMacDataItem::SetLabel( const wxString
& str
)
1615 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1618 const wxString
& wxMacDataItem::GetLabel() const
1623 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1624 const wxMacDataItem
* rhs
,
1625 DataBrowserPropertyID sortProperty
) const
1627 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1628 bool retval
= false;
1630 if ( sortProperty
== m_colId
){
1631 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1634 else if ( sortProperty
== kNumericOrderColumnId
)
1635 retval
= m_order
< otherItem
->m_order
;
1640 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1641 DataBrowserPropertyID property
,
1642 DataBrowserItemDataRef itemData
,
1645 OSStatus err
= errDataBrowserPropertyNotSupported
;
1648 if ( property
== m_colId
){
1649 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1652 else if ( property
== kNumericOrderColumnId
){
1653 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1663 // no editable props here
1672 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1673 DataBrowserItemNotification message
,
1674 DataBrowserItemDataRef itemData
) const
1678 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1680 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1681 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1683 m_suppressSelection
= false;
1684 m_sortOrder
= SortOrder_None
;
1685 m_clientDataItemsType
= wxClientData_None
;
1688 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1690 return new wxMacDataItem();
1693 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1695 m_former
= browser
->SuppressSelection(true);
1696 m_browser
= browser
;
1699 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1701 m_browser
->SuppressSelection(m_former
);
1704 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1706 bool former
= m_suppressSelection
;
1707 m_suppressSelection
= suppress
;
1712 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1713 DataBrowserItemID itemTwoID
,
1714 DataBrowserPropertyID sortProperty
)
1716 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1717 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1718 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1721 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1722 const wxMacDataItem
* itemTwo
,
1723 DataBrowserPropertyID sortProperty
)
1725 Boolean retval
= false;
1726 if ( itemOne
!= NULL
)
1727 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1731 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1732 DataBrowserItemID itemID
,
1733 DataBrowserPropertyID property
,
1734 DataBrowserItemDataRef itemData
,
1735 Boolean changeValue
)
1737 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1738 return GetSetItemData(item
, property
, itemData
, changeValue
);
1741 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1742 wxMacDataItem
* item
,
1743 DataBrowserPropertyID property
,
1744 DataBrowserItemDataRef itemData
,
1745 Boolean changeValue
)
1747 OSStatus err
= errDataBrowserPropertyNotSupported
;
1750 case kDataBrowserContainerIsClosableProperty
:
1751 case kDataBrowserContainerIsSortableProperty
:
1752 case kDataBrowserContainerIsOpenableProperty
:
1753 // right now default behaviour on these
1757 if ( item
!= NULL
){
1758 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1766 void wxMacDataItemBrowserControl::ItemNotification(
1767 DataBrowserItemID itemID
,
1768 DataBrowserItemNotification message
,
1769 DataBrowserItemDataRef itemData
)
1771 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1772 ItemNotification( item
, message
, itemData
);
1775 void wxMacDataItemBrowserControl::ItemNotification(
1776 const wxMacDataItem
* item
,
1777 DataBrowserItemNotification message
,
1778 DataBrowserItemDataRef itemData
)
1781 item
->Notification( this, message
, itemData
);
1784 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1785 bool recurse
, DataBrowserItemState state
) const
1787 ItemCount numItems
= 0;
1788 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1789 recurse
, state
, &numItems
) );
1793 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1794 bool recurse
) const
1796 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1800 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1801 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1803 Handle handle
= NewHandle(0);
1804 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1805 recurse
, state
, handle
) );
1807 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1809 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1810 for ( int i
= 0; i
< itemCount
; ++i
)
1812 items
.Add(itemsArray
[i
]);
1815 DisposeHandle( handle
);
1818 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1820 DataBrowserTableViewRowIndex row
;
1821 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1822 wxASSERT( err
== noErr
);
1826 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1828 DataBrowserItemID id
;
1829 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1830 wxASSERT( err
== noErr
);
1831 return (wxMacDataItem
*) id
;
1834 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1835 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1837 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1838 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1841 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1842 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1844 unsigned int noItems
= itemArray
.GetCount();
1845 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1846 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1847 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1849 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1850 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1854 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1855 const wxString
& title
, SInt16 just
, int defaultWidth
)
1857 DataBrowserListViewColumnDesc columnDesc
;
1858 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1859 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1861 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1862 kControlUseFontMask
| kControlUseJustMask
;
1864 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1865 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1866 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1867 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1869 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1870 // defined for other modes?
1873 enc
= m_font
.GetEncoding();
1875 enc
= wxLocale::GetSystemEncoding();
1876 wxMacCFStringHolder cfTitle
;
1877 cfTitle
.Assign( title
, enc
);
1878 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1880 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1881 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1883 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1884 columnDesc
.propertyDesc
.propertyType
= colType
;
1885 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1886 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1887 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1889 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1890 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1893 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1895 if (defaultWidth
> 0){
1896 SetColumnWidth(colId
, defaultWidth
);
1901 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1903 DataBrowserPropertyID id
;
1904 GetColumnIDFromIndex(colId
, &id
);
1905 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1908 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1910 DataBrowserPropertyID id
;
1911 GetColumnIDFromIndex(colId
, &id
);
1913 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1917 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1919 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1920 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1923 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1925 unsigned int noItems
= itemArray
.GetCount();
1926 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1927 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1928 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1930 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1931 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1935 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1937 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1938 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1939 verify_noerr( err
);
1942 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1944 unsigned int noItems
= itemArray
.GetCount();
1945 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1946 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1947 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1949 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1950 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1951 verify_noerr( err
);
1955 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1957 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1958 verify_noerr( err
);
1961 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1963 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1966 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1968 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1971 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1973 unsigned int noItems
= itemArray
.GetCount();
1974 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1975 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1976 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1978 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1982 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1984 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1987 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1989 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1992 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1994 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1997 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1999 return m_clientDataItemsType
;
2001 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
2003 m_clientDataItemsType
= clientDataItemsType
;
2006 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
2008 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
2011 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
2013 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
2014 RemoveItem( wxMacDataBrowserRootContainer
, item
);
2017 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxString
& text
, int column
)
2019 wxMacDataItem
* newItem
= CreateItem();
2020 newItem
->SetLabel( text
);
2022 newItem
->SetColumn( kMinColumnId
+ column
);
2024 if ( m_sortOrder
== SortOrder_None
)
2026 // increase the order of the lines to be shifted
2027 unsigned int lines
= MacGetCount();
2028 for ( unsigned int i
= n
; i
< lines
; ++i
)
2030 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2031 iter
->SetOrder( iter
->GetOrder() + 1 );
2034 SInt32 frontLineOrder
= 0;
2037 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2038 frontLineOrder
= iter
->GetOrder();
2040 newItem
->SetOrder( frontLineOrder
+ 1 );
2043 AddItem( wxMacDataBrowserRootContainer
, newItem
);
2046 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxArrayString
& items
, int column
)
2048 size_t itemsCount
= items
.GetCount();
2049 if ( itemsCount
== 0 )
2052 SInt32 frontLineOrder
= 0;
2054 if ( m_sortOrder
== SortOrder_None
)
2056 // increase the order of the lines to be shifted
2057 unsigned int lines
= MacGetCount();
2058 for ( unsigned int i
= n
; i
< lines
; ++i
)
2060 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2061 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
2065 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2066 frontLineOrder
= iter
->GetOrder();
2070 wxArrayMacDataItemPtr ids
;
2071 ids
.SetCount( itemsCount
);
2073 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
2075 wxMacDataItem
* item
= CreateItem();
2076 item
->SetLabel( items
[i
]);
2078 item
->SetColumn( kMinColumnId
+ column
);
2080 if ( m_sortOrder
== SortOrder_None
)
2081 item
->SetOrder( frontLineOrder
+ 1 + i
);
2086 AddItems( wxMacDataBrowserRootContainer
, ids
);
2089 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
2091 wxMacDataItem
* item
= CreateItem();
2092 item
->SetLabel( text
);
2093 if ( m_sortOrder
== SortOrder_None
)
2095 unsigned int lines
= MacGetCount();
2097 item
->SetOrder( 1 );
2100 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
2101 item
->SetOrder( frontItem
->GetOrder() + 1 );
2104 AddItem( wxMacDataBrowserRootContainer
, item
);
2106 return GetLineFromItem(item
);
2109 void wxMacDataItemBrowserControl::MacClear()
2111 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2112 RemoveAllItems(wxMacDataBrowserRootContainer
);
2115 void wxMacDataItemBrowserControl::MacDeselectAll()
2117 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2118 SetSelectedAllItems( kDataBrowserItemsRemove
);
2121 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
2123 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2124 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2126 if ( IsItemSelected( item
) != select
)
2129 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
2131 SetSelectedItem( item
, kDataBrowserItemsRemove
);
2137 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
2139 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2140 return IsItemSelected( item
);
2143 int wxMacDataItemBrowserControl::MacGetSelection() const
2145 wxMacDataItemPtr first
, last
;
2146 GetSelectionAnchor( &first
, &last
);
2148 if ( first
!= NULL
)
2150 return GetLineFromItem( first
);
2156 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
2158 aSelections
.Empty();
2159 wxArrayMacDataItemPtr selectedItems
;
2160 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
2162 int count
= selectedItems
.GetCount();
2164 for ( int i
= 0; i
< count
; ++i
)
2166 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
2172 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
2174 // as we don't store the strings we only have to issue a redraw
2175 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2176 item
->SetLabel( text
);
2177 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
2180 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
2182 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2183 return item
->GetLabel();
2186 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
2188 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2189 item
->SetData( data
);
2190 // not displayed, therefore no Update infos to DataBrowser
2193 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
2195 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2196 return item
->GetData();
2199 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
2201 RevealItem( GetItemFromLine( n
) , kDataBrowserRevealWithoutSelecting
);
2210 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2212 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2219 #ifdef __WXMAC_OSX__
2220 // snippets from Sketch Sample from Apple :
2222 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2225 This function locates, opens, and returns the profile reference for the calibrated
2226 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2227 with the profile reference this function returns.
2229 CMProfileRef
wxMacOpenGenericProfile()
2231 static CMProfileRef cachedRGBProfileRef
= NULL
;
2233 // we only create the profile reference once
2234 if (cachedRGBProfileRef
== NULL
)
2236 CMProfileLocation loc
;
2238 loc
.locType
= cmPathBasedProfile
;
2239 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2241 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2244 // clone the profile reference so that the caller has their own reference, not our cached one
2245 if (cachedRGBProfileRef
)
2246 CMCloneProfileRef(cachedRGBProfileRef
);
2248 return cachedRGBProfileRef
;
2252 Return the generic RGB color space. This is a 'get' function and the caller should
2253 not release the returned value unless the caller retains it first. Usually callers
2254 of this routine will immediately use the returned colorspace with CoreGraphics
2255 so they typically do not need to retain it themselves.
2257 This function creates the generic RGB color space once and hangs onto it so it can
2258 return it whenever this function is called.
2261 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2263 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2265 if (genericRGBColorSpace
== NULL
)
2267 if ( UMAGetSystemVersion() >= 0x1040 )
2269 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2273 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2275 if (genericRGBProfile
)
2277 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2279 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2281 // we opened the profile so it is up to us to close it
2282 CMCloseProfile(genericRGBProfile
);
2287 return genericRGBColorSpace
;
2293 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2295 ::GetPort( &m_port
);
2299 wxMacPortSaver::~wxMacPortSaver()
2301 ::SetPort( m_port
);
2305 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
2307 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2308 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2309 HIViewRef contentView
;
2310 // TODO check toolbar offset
2311 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2312 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
2316 QDGlobalToLocalPoint( GetWindowPort(window
), pt
) ;
2320 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
2322 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2323 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2324 HIViewRef contentView
;
2325 // TODO check toolbar offset
2326 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2327 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2331 QDLocalToGlobalPoint( GetWindowPort(window
), pt
) ;