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 #include <CoreServices/CoreServices.h>
47 #include <Carbon/Carbon.h>
48 #include "wx/mac/private/timer.h"
51 #include "wx/evtloop.h"
52 #include "wx/mac/private.h"
54 #if defined(__MWERKS__) && wxUSE_UNICODE
55 #if __MWERKS__ < 0x4100
62 // our OS version is the same in non GUI and GUI cases
63 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
66 Gestalt(gestaltSystemVersion
, &theSystem
);
68 if ( majorVsn
!= NULL
)
69 *majorVsn
= (theSystem
>> 8);
71 if ( minorVsn
!= NULL
)
72 *minorVsn
= (theSystem
& 0xFF);
74 #if defined( __DARWIN__ )
75 return wxOS_MAC_OSX_DARWIN
;
81 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
83 // TODO : try to find out ...
100 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
102 // We suppose that toolkit version is the same as OS version under Mac
103 wxGetOsVersion(verMaj
, verMin
);
108 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
110 return new wxEventLoop
;
113 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
115 return new wxCarbonTimerImpl(timer
);
118 int gs_wxBusyCursorCount
= 0;
119 extern wxCursor gMacCurrentCursor
;
120 wxCursor gMacStoredActiveCursor
;
122 // Set the cursor to the busy cursor for all windows
123 void wxBeginBusyCursor(const wxCursor
*cursor
)
125 if (gs_wxBusyCursorCount
++ == 0)
127 gMacStoredActiveCursor
= gMacCurrentCursor
;
128 cursor
->MacInstall();
130 //else: nothing to do, already set
133 // Restore cursor to normal
134 void wxEndBusyCursor()
136 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
137 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
139 if (--gs_wxBusyCursorCount
== 0)
141 gMacStoredActiveCursor
.MacInstall();
142 gMacStoredActiveCursor
= wxNullCursor
;
146 // true if we're between the above two calls
149 return (gs_wxBusyCursorCount
> 0);
156 wxString
wxMacFindFolderNoSeparator( short vol
,
158 Boolean createFolder
)
163 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
165 strDir
= wxMacFSRefToPath( &fsRef
);
171 wxString
wxMacFindFolder( short vol
,
173 Boolean createFolder
)
175 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
182 // Check whether this window wants to process messages, e.g. Stop button
183 // in long calculations.
184 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
190 void wxGetMousePosition( int* x
, int* y
)
198 // Return true if we have a colour display
199 bool wxColourDisplay()
204 // Returns depth of screen
207 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
209 SetRect(&globRect
, -32760, -32760, 32760, 32760);
210 GDHandle theMaxDevice
;
212 theMaxDevice
= GetMaxDevice(&globRect
);
213 if (theMaxDevice
!= NULL
)
214 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
219 // Get size of display
220 void wxDisplaySize(int *width
, int *height
)
222 // TODO adapt for multi-displays
223 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
225 *width
= (int)bounds
.size
.width
;
227 *height
= (int)bounds
.size
.height
;
230 void wxDisplaySizeMM(int *width
, int *height
)
232 wxDisplaySize(width
, height
);
233 // on mac 72 is fixed (at least now;-)
234 float cvPt2Mm
= 25.4 / 72;
237 *width
= int( *width
* cvPt2Mm
);
240 *height
= int( *height
* cvPt2Mm
);
243 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
245 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
247 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
250 *x
= bounds
.origin
.x
;
252 *y
= bounds
.origin
.y
;
254 *width
= bounds
.size
.width
;
256 *height
= bounds
.size
.height
;
259 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
265 *width
= r
.right
- r
.left
;
267 *height
= r
.bottom
- r
.top
;
271 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
273 return wxGenericFindWindowAtPoint(pt
);
280 wxString
wxGetOsDescription()
282 #ifdef WXWIN_OS_DESCRIPTION
283 // use configure generated description if available
284 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
286 return wxT("MacOS"); //TODO:define further
291 wxString
wxGetUserHome (const wxString
& user
)
297 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
306 int pos
= p
.Find(':');
307 if ( pos
!= wxNOT_FOUND
)
315 err
= wxMacPathToFSRef( p
, &fsRef
);
318 FSVolumeRefNum vRefNum
;
319 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
322 UInt64 freeBytes
, totalBytes
;
323 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
327 *pTotal
= wxDiskspaceSize_t( totalBytes
);
329 *pFree
= wxDiskspaceSize_t( freeBytes
);
336 #endif // !__DARWIN__
338 //---------------------------------------------------------------------------
339 // wxMac Specific utility functions
340 //---------------------------------------------------------------------------
342 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
344 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
345 int len
= strlen(buf
);
350 memcpy( (char*) &to
[1] , buf
, len
);
353 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
355 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
358 // ----------------------------------------------------------------------------
359 // Common Event Support
360 // ----------------------------------------------------------------------------
362 extern ProcessSerialNumber gAppProcess
;
366 ProcessSerialNumber psn
;
368 psn
.highLongOfPSN
= 0;
369 psn
.lowLongOfPSN
= kCurrentProcess
;
370 SameProcess( &gAppProcess
, &psn
, &isSame
);
373 OSStatus err
= noErr
;
376 // lead sometimes to race conditions, although all calls used should be thread safe ...
377 static wxMacCarbonEvent s_wakeupEvent
;
378 if ( !s_wakeupEvent
.IsValid() )
380 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
381 kEventAttributeNone
);
386 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
388 s_wakeupEvent
.SetCurrentTime();
389 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
390 kEventPriorityHigh
);
393 wxMacCarbonEvent wakeupEvent
;
394 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
395 kEventAttributeNone
);
396 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
397 kEventPriorityHigh
);
402 WakeUpProcess( &gAppProcess
);
410 // ----------------------------------------------------------------------------
411 // Native Struct Conversions
412 // ----------------------------------------------------------------------------
414 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
418 n
->right
= wx
->x
+ wx
->width
;
419 n
->bottom
= wx
->y
+ wx
->height
;
422 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
426 wx
->width
= n
->right
- n
->left
;
427 wx
->height
= n
->bottom
- n
->top
;
430 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
436 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
442 // ----------------------------------------------------------------------------
443 // Carbon Event Support
444 // ----------------------------------------------------------------------------
446 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
448 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
451 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
453 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
456 // ----------------------------------------------------------------------------
457 // Control Access Support
458 // ----------------------------------------------------------------------------
460 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
462 wxMacControl::wxMacControl()
467 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
471 m_isRootControl
= isRootControl
;
474 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
478 m_controlRef
= control
;
481 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
485 m_controlRef
= (ControlRef
) control
;
488 wxMacControl::~wxMacControl()
492 void wxMacControl::Init()
496 m_needsFocusRect
= false;
497 m_isRootControl
= false;
500 void wxMacControl::Dispose()
502 wxASSERT_MSG( m_controlRef
!= NULL
, wxT("Control Handle already NULL, Dispose called twice ?") );
503 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
505 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
506 // we can have situations when being embedded, where the control gets deleted behind our back, so only
507 // CFRelease if we are safe
508 if ( IsValidControlHandle(m_controlRef
) )
509 CFRelease(m_controlRef
);
513 void wxMacControl::SetReference( URefCon data
)
515 SetControlReference( m_controlRef
, data
);
518 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
520 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
523 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
525 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
528 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
530 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
533 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
535 return SendEventToEventTargetWithOptions( event
,
536 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
539 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
541 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
543 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
545 return SendEvent( event
, inOptions
);
548 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
552 memset( &command
, 0 , sizeof(command
) );
553 command
.commandID
= commandID
;
554 return SendHICommand( command
, inOptions
);
557 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
559 unsigned long finalTicks
;
561 HiliteControl( m_controlRef
, part
);
562 Delay( ticks
, &finalTicks
);
563 HiliteControl( m_controlRef
, kControlNoPart
);
566 SInt32
wxMacControl::GetValue() const
568 return ::GetControl32BitValue( m_controlRef
);
571 SInt32
wxMacControl::GetMaximum() const
573 return ::GetControl32BitMaximum( m_controlRef
);
576 SInt32
wxMacControl::GetMinimum() const
578 return ::GetControl32BitMinimum( m_controlRef
);
581 void wxMacControl::SetValue( SInt32 v
)
583 ::SetControl32BitValue( m_controlRef
, v
);
586 void wxMacControl::SetMinimum( SInt32 v
)
588 ::SetControl32BitMinimum( m_controlRef
, v
);
591 void wxMacControl::SetMaximum( SInt32 v
)
593 ::SetControl32BitMaximum( m_controlRef
, v
);
596 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
598 ::SetControl32BitMinimum( m_controlRef
, minimum
);
599 ::SetControl32BitMaximum( m_controlRef
, maximum
);
600 ::SetControl32BitValue( m_controlRef
, value
);
603 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
605 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
608 bool wxMacControl::HasFocus() const
611 GetKeyboardFocus( GetUserFocusWindow() , &control
);
612 return control
== m_controlRef
;
615 void wxMacControl::SetNeedsFocusRect( bool needs
)
617 m_needsFocusRect
= needs
;
620 bool wxMacControl::NeedsFocusRect() const
622 return m_needsFocusRect
;
625 void wxMacControl::VisibilityChanged(bool WXUNUSED(shown
))
629 void wxMacControl::SuperChangedPosition()
633 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
637 ControlFontStyleRec fontStyle
;
638 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
640 switch ( font
.MacGetThemeFontID() )
642 case kThemeSmallSystemFont
:
643 fontStyle
.font
= kControlFontSmallSystemFont
;
646 case 109 : // mini font
650 case kThemeSystemFont
:
651 fontStyle
.font
= kControlFontBigSystemFont
;
655 fontStyle
.font
= kControlFontBigSystemFont
;
659 fontStyle
.flags
= kControlUseFontMask
;
663 fontStyle
.font
= font
.MacGetFontNum();
664 fontStyle
.style
= font
.MacGetFontStyle();
665 fontStyle
.size
= font
.MacGetFontSize();
666 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
669 fontStyle
.just
= teJustLeft
;
670 fontStyle
.flags
|= kControlUseJustMask
;
671 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
672 fontStyle
.just
= teJustCenter
;
673 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
674 fontStyle
.just
= teJustRight
;
677 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
678 // won't get grayed out by the system anymore
680 if ( foreground
!= *wxBLACK
)
682 foreground
.GetRGBColor( &fontStyle
.foreColor
);
683 fontStyle
.flags
|= kControlUseForeColorMask
;
686 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
690 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
693 // setting up a color proc is not recommended anymore
696 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
698 ::SetControl32BitMinimum( m_controlRef
, minimum
);
699 ::SetControl32BitMaximum( m_controlRef
, maximum
);
702 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
705 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
711 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
713 SetControlAction( m_controlRef
, actionProc
);
716 void wxMacControl::SetViewSize( SInt32 viewSize
)
718 SetControlViewSize(m_controlRef
, viewSize
);
721 SInt32
wxMacControl::GetViewSize() const
723 return GetControlViewSize( m_controlRef
);
726 bool wxMacControl::IsVisible() const
728 return IsControlVisible( m_controlRef
);
731 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
733 SetControlVisibility( m_controlRef
, visible
, redraw
);
736 bool wxMacControl::IsEnabled() const
738 #if TARGET_API_MAC_OSX
739 return IsControlEnabled( m_controlRef
);
741 return IsControlActive( m_controlRef
);
745 bool wxMacControl::IsActive() const
747 return IsControlActive( m_controlRef
);
750 void wxMacControl::Enable( bool enable
)
753 EnableControl( m_controlRef
);
755 DisableControl( m_controlRef
);
758 void wxMacControl::SetDrawingEnabled( bool enable
)
760 HIViewSetDrawingEnabled( m_controlRef
, enable
);
763 bool wxMacControl::GetNeedsDisplay() const
765 return HIViewGetNeedsDisplay( m_controlRef
);
768 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
773 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
776 void wxMacControl::SetNeedsDisplay( Rect
* where
)
783 RgnHandle update
= NewRgn();
784 RectRgn( update
, where
);
785 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
786 DisposeRgn( update
);
789 HIViewSetNeedsDisplay( m_controlRef
, true );
792 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
798 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
799 pt
->x
= (int)hiPoint
.x
;
800 pt
->y
= (int)hiPoint
.y
;
803 void wxMacControl::SetRect( Rect
*r
)
805 //A HIRect is actually a CGRect on OSX - which consists of two structures -
806 //CGPoint and CGSize, which have two floats each
807 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
808 HIViewSetFrame ( m_controlRef
, &hir
);
809 // eventuall we might have to do a SetVisibility( false , true );
810 // before and a SetVisibility( true , true ); after
813 void wxMacControl::GetRect( Rect
*r
)
815 GetControlBounds( m_controlRef
, r
);
818 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
820 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
823 void wxMacControl::GetBestRect( Rect
*r
)
825 short baselineoffset
;
827 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
830 void wxMacControl::SetLabel( const wxString
&title
)
832 wxFontEncoding encoding
;
835 encoding
= m_font
.GetEncoding();
837 encoding
= wxFont::GetDefaultEncoding();
839 UMASetControlTitle( m_controlRef
, title
, encoding
);
842 void wxMacControl::GetFeatures( UInt32
* features
)
844 GetControlFeatures( m_controlRef
, features
);
847 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
849 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
853 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
855 #if TARGET_API_MAC_OSX
856 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
857 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
863 #if TARGET_API_MAC_OSX
864 // SetNeedsDisplay would not invalidate the children
865 static void InvalidateControlAndChildren( HIViewRef control
)
867 HIViewSetNeedsDisplay( control
, true );
868 UInt16 childrenCount
= 0;
869 OSStatus err
= CountSubControls( control
, &childrenCount
);
870 if ( err
== errControlIsNotEmbedder
)
873 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
875 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
879 err
= GetIndexedSubControl( control
, i
, & child
);
880 if ( err
== errControlIsNotEmbedder
)
883 InvalidateControlAndChildren( child
);
888 void wxMacControl::InvalidateWithChildren()
890 #if TARGET_API_MAC_OSX
891 InvalidateControlAndChildren( m_controlRef
);
895 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
897 wxASSERT( r
!= NULL
);
899 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
900 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
903 OSType wxMacCreator
= 'WXMC';
904 OSType wxMacControlProperty
= 'MCCT';
906 void wxMacControl::SetReferenceInNativeControl()
909 verify_noerr( SetControlProperty ( m_controlRef
,
910 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
913 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
915 wxMacControl
* ctl
= NULL
;
916 ByteCount actualSize
;
917 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
918 &actualSize
, &ctl
) == noErr
)
925 // ============================================================================
926 // DataBrowser Wrapper
927 // ============================================================================
929 // basing on DataBrowserItemIDs
932 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
934 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
936 DataBrowserItemID itemID
,
937 DataBrowserItemNotification message
,
938 DataBrowserItemDataRef itemData
)
940 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
943 ctl
->ItemNotification(itemID
, message
, itemData
);
947 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
949 DataBrowserItemID itemID
,
950 DataBrowserPropertyID property
,
951 DataBrowserItemDataRef itemData
,
952 Boolean changeValue
)
954 OSStatus err
= errDataBrowserPropertyNotSupported
;
955 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
958 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
963 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
965 DataBrowserItemID itemOneID
,
966 DataBrowserItemID itemTwoID
,
967 DataBrowserPropertyID sortProperty
)
969 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
972 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
977 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
978 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
979 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
981 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
984 long WXUNUSED(style
))
985 : wxMacControl( peer
)
987 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
988 OSStatus err
= ::CreateDataBrowserControl(
989 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
990 &bounds
, kDataBrowserListView
, &m_controlRef
);
991 SetReferenceInNativeControl();
993 if ( gDataBrowserItemCompareUPP
== NULL
)
994 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
995 if ( gDataBrowserItemDataUPP
== NULL
)
996 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
997 if ( gDataBrowserItemNotificationUPP
== NULL
)
999 gDataBrowserItemNotificationUPP
=
1000 #if TARGET_API_MAC_OSX
1001 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1003 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1007 DataBrowserCallbacks callbacks
;
1008 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1010 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1011 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1012 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1013 SetCallbacks( &callbacks
);
1017 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1019 DataBrowserItemState state
,
1020 ItemCount
*numItems
) const
1022 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1025 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1027 DataBrowserItemState state
,
1030 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1033 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1035 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1038 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1039 DataBrowserTableViewColumnIndex position
)
1041 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1044 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1045 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1048 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1050 DataBrowserTableViewColumnID id
;
1051 GetColumnIDFromIndex( position
, &id
);
1052 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1055 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1057 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1060 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1062 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1065 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1067 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1070 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1072 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1075 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1077 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1080 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1082 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1085 OSStatus
wxMacDataBrowserControl::UpdateItems(
1086 DataBrowserItemID container
,
1088 const DataBrowserItemID
*items
,
1089 DataBrowserPropertyID preSortProperty
,
1090 DataBrowserPropertyID propertyID
) const
1092 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1095 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1097 return IsDataBrowserItemSelected( m_controlRef
, item
);
1100 OSStatus
wxMacDataBrowserControl::AddItems(
1101 DataBrowserItemID container
,
1103 const DataBrowserItemID
*items
,
1104 DataBrowserPropertyID preSortProperty
)
1106 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1109 OSStatus
wxMacDataBrowserControl::RemoveItems(
1110 DataBrowserItemID container
,
1112 const DataBrowserItemID
*items
,
1113 DataBrowserPropertyID preSortProperty
)
1115 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1118 OSStatus
wxMacDataBrowserControl::RevealItem(
1119 DataBrowserItemID item
,
1120 DataBrowserPropertyID propertyID
,
1121 DataBrowserRevealOptions options
) const
1123 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1126 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1128 const DataBrowserItemID
*items
,
1129 DataBrowserSetOption operation
)
1131 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1134 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1136 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1139 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1141 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1144 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1146 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1149 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1151 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1154 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1156 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1159 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1161 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1164 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1166 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1169 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1171 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1174 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1176 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1179 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1181 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1184 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1186 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1189 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1191 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1194 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1195 DataBrowserTableViewColumnIndex
*position
) const
1197 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1200 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1202 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1205 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1207 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1210 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1212 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1215 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1217 return GetDataBrowserSortProperty( m_controlRef
, column
);
1220 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1222 return SetDataBrowserSortProperty( m_controlRef
, column
);
1225 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1227 return GetDataBrowserSortOrder( m_controlRef
, order
);
1230 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1232 return SetDataBrowserSortOrder( m_controlRef
, order
);
1235 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1236 DataBrowserPropertyFlags
*flags
) const
1238 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1241 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1242 DataBrowserPropertyFlags flags
)
1244 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1247 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1248 DataBrowserListViewHeaderDesc
*desc
) const
1250 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1253 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1254 DataBrowserListViewHeaderDesc
*desc
)
1256 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1259 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1260 Boolean expandableRows
)
1262 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1265 // ============================================================================
1266 // Higher-level Databrowser
1267 // ============================================================================
1269 // basing on data item objects
1272 wxMacDataItem::wxMacDataItem()
1277 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1280 wxMacDataItem::~wxMacDataItem()
1284 void wxMacDataItem::SetOrder( SInt32 order
)
1289 SInt32
wxMacDataItem::GetOrder() const
1294 void wxMacDataItem::SetData( void* data
)
1299 void* wxMacDataItem::GetData() const
1304 short wxMacDataItem::GetColumn()
1309 void wxMacDataItem::SetColumn( short col
)
1314 void wxMacDataItem::SetLabel( const wxString
& str
)
1317 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1320 const wxString
& wxMacDataItem::GetLabel() const
1325 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1326 const wxMacDataItem
* rhs
,
1327 DataBrowserPropertyID sortProperty
) const
1329 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1330 bool retval
= false;
1332 if ( sortProperty
== m_colId
){
1333 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1336 else if ( sortProperty
== kNumericOrderColumnId
)
1337 retval
= m_order
< otherItem
->m_order
;
1342 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1343 DataBrowserPropertyID property
,
1344 DataBrowserItemDataRef itemData
,
1347 OSStatus err
= errDataBrowserPropertyNotSupported
;
1350 if ( property
== m_colId
){
1351 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1354 else if ( property
== kNumericOrderColumnId
){
1355 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1365 // no editable props here
1374 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1375 DataBrowserItemNotification
WXUNUSED(message
),
1376 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
1380 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1382 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1383 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1385 m_suppressSelection
= false;
1386 m_sortOrder
= SortOrder_None
;
1387 m_clientDataItemsType
= wxClientData_None
;
1390 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1392 return new wxMacDataItem();
1395 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1397 m_former
= browser
->SuppressSelection(true);
1398 m_browser
= browser
;
1401 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1403 m_browser
->SuppressSelection(m_former
);
1406 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1408 bool former
= m_suppressSelection
;
1409 m_suppressSelection
= suppress
;
1414 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1415 DataBrowserItemID itemTwoID
,
1416 DataBrowserPropertyID sortProperty
)
1418 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1419 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1420 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1423 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1424 const wxMacDataItem
* itemTwo
,
1425 DataBrowserPropertyID sortProperty
)
1427 Boolean retval
= false;
1428 if ( itemOne
!= NULL
)
1429 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1433 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1434 DataBrowserItemID itemID
,
1435 DataBrowserPropertyID property
,
1436 DataBrowserItemDataRef itemData
,
1437 Boolean changeValue
)
1439 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1440 return GetSetItemData(item
, property
, itemData
, changeValue
);
1443 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1444 wxMacDataItem
* item
,
1445 DataBrowserPropertyID property
,
1446 DataBrowserItemDataRef itemData
,
1447 Boolean changeValue
)
1449 OSStatus err
= errDataBrowserPropertyNotSupported
;
1452 case kDataBrowserContainerIsClosableProperty
:
1453 case kDataBrowserContainerIsSortableProperty
:
1454 case kDataBrowserContainerIsOpenableProperty
:
1455 // right now default behaviour on these
1459 if ( item
!= NULL
){
1460 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1468 void wxMacDataItemBrowserControl::ItemNotification(
1469 DataBrowserItemID itemID
,
1470 DataBrowserItemNotification message
,
1471 DataBrowserItemDataRef itemData
)
1473 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1474 ItemNotification( item
, message
, itemData
);
1477 void wxMacDataItemBrowserControl::ItemNotification(
1478 const wxMacDataItem
* item
,
1479 DataBrowserItemNotification message
,
1480 DataBrowserItemDataRef itemData
)
1483 item
->Notification( this, message
, itemData
);
1486 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1487 bool recurse
, DataBrowserItemState state
) const
1489 ItemCount numItems
= 0;
1490 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1491 recurse
, state
, &numItems
) );
1495 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1496 bool recurse
) const
1498 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1502 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1503 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1505 Handle handle
= NewHandle(0);
1506 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1507 recurse
, state
, handle
) );
1509 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1511 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1512 for ( int i
= 0; i
< itemCount
; ++i
)
1514 items
.Add(itemsArray
[i
]);
1517 DisposeHandle( handle
);
1520 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1522 DataBrowserTableViewRowIndex row
;
1523 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1524 wxASSERT( err
== noErr
);
1528 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1530 DataBrowserItemID id
;
1531 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1532 wxASSERT( err
== noErr
);
1533 return (wxMacDataItem
*) id
;
1536 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1537 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1539 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1540 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1543 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1544 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1546 unsigned int noItems
= itemArray
.GetCount();
1547 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1548 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1549 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1551 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1552 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1556 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1557 const wxString
& title
, SInt16 just
, int defaultWidth
)
1559 DataBrowserListViewColumnDesc columnDesc
;
1560 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1561 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1563 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1564 kControlUseFontMask
| kControlUseJustMask
;
1566 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1567 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1568 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1569 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1571 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1572 // defined for other modes?
1575 enc
= m_font
.GetEncoding();
1577 enc
= wxLocale::GetSystemEncoding();
1578 wxMacCFStringHolder cfTitle
;
1579 cfTitle
.Assign( title
, enc
);
1580 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1582 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1583 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1585 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1586 columnDesc
.propertyDesc
.propertyType
= colType
;
1587 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1588 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1589 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1591 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1593 if (defaultWidth
> 0){
1594 SetColumnWidth(colId
, defaultWidth
);
1599 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1601 DataBrowserPropertyID id
;
1602 GetColumnIDFromIndex(colId
, &id
);
1603 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1606 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1608 DataBrowserPropertyID id
;
1609 GetColumnIDFromIndex(colId
, &id
);
1611 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1615 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1617 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1618 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1621 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1623 unsigned int noItems
= itemArray
.GetCount();
1624 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1625 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1626 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1628 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1629 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1633 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1635 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1636 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1637 verify_noerr( err
);
1640 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1642 unsigned int noItems
= itemArray
.GetCount();
1643 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1644 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1645 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1647 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1648 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1649 verify_noerr( err
);
1653 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1655 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1656 verify_noerr( err
);
1659 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1661 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1664 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1666 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1669 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1671 unsigned int noItems
= itemArray
.GetCount();
1672 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1673 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1674 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1676 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1680 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1682 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1685 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1687 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1690 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1692 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1695 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1697 return m_clientDataItemsType
;
1699 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1701 m_clientDataItemsType
= clientDataItemsType
;
1704 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1706 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
1709 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1711 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1712 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1715 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
,
1716 const wxArrayStringsAdapter
& items
,
1719 size_t itemsCount
= items
.GetCount();
1720 if ( itemsCount
== 0 )
1723 SInt32 frontLineOrder
= 0;
1725 if ( m_sortOrder
== SortOrder_None
)
1727 // increase the order of the lines to be shifted
1728 unsigned int lines
= MacGetCount();
1729 for ( unsigned int i
= n
; i
< lines
; ++i
)
1731 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1732 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
1736 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1737 frontLineOrder
= iter
->GetOrder();
1741 wxArrayMacDataItemPtr ids
;
1742 ids
.SetCount( itemsCount
);
1744 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
1746 wxMacDataItem
* item
= CreateItem();
1747 item
->SetLabel( items
[i
]);
1749 item
->SetColumn( kMinColumnId
+ column
);
1751 if ( m_sortOrder
== SortOrder_None
)
1752 item
->SetOrder( frontLineOrder
+ 1 + i
);
1757 AddItems( wxMacDataBrowserRootContainer
, ids
);
1760 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
1762 wxMacDataItem
* item
= CreateItem();
1763 item
->SetLabel( text
);
1764 if ( m_sortOrder
== SortOrder_None
)
1766 unsigned int lines
= MacGetCount();
1768 item
->SetOrder( 1 );
1771 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
1772 item
->SetOrder( frontItem
->GetOrder() + 1 );
1775 AddItem( wxMacDataBrowserRootContainer
, item
);
1777 return GetLineFromItem(item
);
1780 void wxMacDataItemBrowserControl::MacClear()
1782 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1783 RemoveAllItems(wxMacDataBrowserRootContainer
);
1786 void wxMacDataItemBrowserControl::MacDeselectAll()
1788 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1789 SetSelectedAllItems( kDataBrowserItemsRemove
);
1792 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
1794 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1795 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1797 if ( IsItemSelected( item
) != select
)
1800 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
1802 SetSelectedItem( item
, kDataBrowserItemsRemove
);
1808 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
1810 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1811 return IsItemSelected( item
);
1814 int wxMacDataItemBrowserControl::MacGetSelection() const
1816 wxMacDataItemPtr first
, last
;
1817 GetSelectionAnchor( &first
, &last
);
1819 if ( first
!= NULL
)
1821 return GetLineFromItem( first
);
1827 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
1829 aSelections
.Empty();
1830 wxArrayMacDataItemPtr selectedItems
;
1831 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
1833 int count
= selectedItems
.GetCount();
1835 for ( int i
= 0; i
< count
; ++i
)
1837 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
1843 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
1845 // as we don't store the strings we only have to issue a redraw
1846 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1847 item
->SetLabel( text
);
1848 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
1851 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
1853 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1854 return item
->GetLabel();
1857 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
1859 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1860 item
->SetData( data
);
1861 // not displayed, therefore no Update infos to DataBrowser
1864 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
1866 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1867 return item
->GetData();
1870 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
1873 GetScrollPosition( &top
, &left
) ;
1874 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1877 GetRowHeight( (DataBrowserItemID
) item
, &height
) ;
1878 SetScrollPosition( n
* ((UInt32
)height
) , left
) ;
1880 RevealItem( item
, kDataBrowserRevealWithoutSelecting
);
1889 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1891 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
1898 // snippets from Sketch Sample from Apple :
1900 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
1903 This function locates, opens, and returns the profile reference for the calibrated
1904 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
1905 with the profile reference this function returns.
1907 CMProfileRef
wxMacOpenGenericProfile()
1909 static CMProfileRef cachedRGBProfileRef
= NULL
;
1911 // we only create the profile reference once
1912 if (cachedRGBProfileRef
== NULL
)
1914 CMProfileLocation loc
;
1916 loc
.locType
= cmPathBasedProfile
;
1917 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
1919 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
1922 // clone the profile reference so that the caller has their own reference, not our cached one
1923 if (cachedRGBProfileRef
)
1924 CMCloneProfileRef(cachedRGBProfileRef
);
1926 return cachedRGBProfileRef
;
1930 Return the generic RGB color space. This is a 'get' function and the caller should
1931 not release the returned value unless the caller retains it first. Usually callers
1932 of this routine will immediately use the returned colorspace with CoreGraphics
1933 so they typically do not need to retain it themselves.
1935 This function creates the generic RGB color space once and hangs onto it so it can
1936 return it whenever this function is called.
1939 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
1941 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
1943 if (genericRGBColorSpace
== NULL
)
1945 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
1948 return genericRGBColorSpace
;
1953 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
1955 ::GetPort( &m_port
);
1959 wxMacPortSaver::~wxMacPortSaver()
1961 ::SetPort( m_port
);
1965 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
1967 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1968 HIViewRef contentView
;
1969 // TODO check toolbar offset
1970 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1971 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1976 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
1978 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1979 HIViewRef contentView
;
1980 // TODO check toolbar offset
1981 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1982 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);