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
)
192 #if wxMAC_USE_QUICKDRAW
202 // Return true if we have a colour display
203 bool wxColourDisplay()
208 // Returns depth of screen
211 #if wxMAC_USE_QUICKDRAW
212 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
214 SetRect(&globRect
, -32760, -32760, 32760, 32760);
215 GDHandle theMaxDevice
;
217 theMaxDevice
= GetMaxDevice(&globRect
);
218 if (theMaxDevice
!= NULL
)
219 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
227 // Get size of display
228 void wxDisplaySize(int *width
, int *height
)
230 // TODO adapt for multi-displays
231 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
233 *width
= (int)bounds
.size
.width
;
235 *height
= (int)bounds
.size
.height
;
238 void wxDisplaySizeMM(int *width
, int *height
)
240 wxDisplaySize(width
, height
);
241 // on mac 72 is fixed (at least now;-)
242 float cvPt2Mm
= 25.4 / 72;
245 *width
= int( *width
* cvPt2Mm
);
248 *height
= int( *height
* cvPt2Mm
);
251 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
253 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
254 #if wxMAC_USE_QUICKDRAW
257 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
260 *x
= bounds
.origin
.x
;
262 *y
= bounds
.origin
.y
;
264 *width
= bounds
.size
.width
;
266 *height
= bounds
.size
.height
;
269 wxDisplaySize(&w
,&h
);
281 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
287 *width
= r
.right
- r
.left
;
289 *height
= r
.bottom
- r
.top
;
293 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
295 return wxGenericFindWindowAtPoint(pt
);
302 wxString
wxGetOsDescription()
304 #ifdef WXWIN_OS_DESCRIPTION
305 // use configure generated description if available
306 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
308 return wxT("MacOS"); //TODO:define further
313 wxString
wxGetUserHome (const wxString
& user
)
319 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
328 int pos
= p
.Find(':');
329 if ( pos
!= wxNOT_FOUND
)
337 err
= wxMacPathToFSRef( p
, &fsRef
);
340 FSVolumeRefNum vRefNum
;
341 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
344 UInt64 freeBytes
, totalBytes
;
345 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
349 *pTotal
= wxDiskspaceSize_t( totalBytes
);
351 *pFree
= wxDiskspaceSize_t( freeBytes
);
358 #endif // !__DARWIN__
360 //---------------------------------------------------------------------------
361 // wxMac Specific utility functions
362 //---------------------------------------------------------------------------
364 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
366 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
367 int len
= strlen(buf
);
372 memcpy( (char*) &to
[1] , buf
, len
);
375 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
377 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
380 // ----------------------------------------------------------------------------
381 // Common Event Support
382 // ----------------------------------------------------------------------------
386 OSStatus err
= noErr
;
389 // lead sometimes to race conditions, although all calls used should be thread safe ...
390 static wxMacCarbonEvent s_wakeupEvent
;
391 if ( !s_wakeupEvent
.IsValid() )
393 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
394 kEventAttributeNone
);
399 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
401 s_wakeupEvent
.SetCurrentTime();
402 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
403 kEventPriorityHigh
);
406 wxMacCarbonEvent wakeupEvent
;
407 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
408 kEventAttributeNone
);
409 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
410 kEventPriorityHigh
);
418 // ----------------------------------------------------------------------------
419 // Native Struct Conversions
420 // ----------------------------------------------------------------------------
422 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
426 n
->right
= wx
->x
+ wx
->width
;
427 n
->bottom
= wx
->y
+ wx
->height
;
430 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
434 wx
->width
= n
->right
- n
->left
;
435 wx
->height
= n
->bottom
- n
->top
;
438 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
444 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
450 // ----------------------------------------------------------------------------
451 // Carbon Event Support
452 // ----------------------------------------------------------------------------
454 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
456 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
459 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
461 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
464 // ----------------------------------------------------------------------------
465 // Control Access Support
466 // ----------------------------------------------------------------------------
468 #if wxMAC_USE_QUICKDRAW
470 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
472 wxMacControl::wxMacControl()
477 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
481 m_isRootControl
= isRootControl
;
484 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
488 m_controlRef
= control
;
491 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
495 m_controlRef
= (ControlRef
) control
;
498 wxMacControl::~wxMacControl()
502 void wxMacControl::Init()
506 m_needsFocusRect
= false;
507 m_isRootControl
= false;
510 void wxMacControl::Dispose()
512 wxASSERT_MSG( m_controlRef
!= NULL
, wxT("Control Handle already NULL, Dispose called twice ?") );
513 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
515 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
516 // we can have situations when being embedded, where the control gets deleted behind our back, so only
517 // CFRelease if we are safe
518 if ( IsValidControlHandle(m_controlRef
) )
519 CFRelease(m_controlRef
);
523 void wxMacControl::SetReference( URefCon data
)
525 SetControlReference( m_controlRef
, data
);
528 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
530 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
533 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
535 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
538 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
540 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
543 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
545 return SendEventToEventTargetWithOptions( event
,
546 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
549 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
551 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
553 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
555 return SendEvent( event
, inOptions
);
558 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
562 memset( &command
, 0 , sizeof(command
) );
563 command
.commandID
= commandID
;
564 return SendHICommand( command
, inOptions
);
567 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
569 unsigned long finalTicks
;
571 HiliteControl( m_controlRef
, part
);
572 Delay( ticks
, &finalTicks
);
573 HiliteControl( m_controlRef
, kControlNoPart
);
576 SInt32
wxMacControl::GetValue() const
578 return ::GetControl32BitValue( m_controlRef
);
581 SInt32
wxMacControl::GetMaximum() const
583 return ::GetControl32BitMaximum( m_controlRef
);
586 SInt32
wxMacControl::GetMinimum() const
588 return ::GetControl32BitMinimum( m_controlRef
);
591 void wxMacControl::SetValue( SInt32 v
)
593 ::SetControl32BitValue( m_controlRef
, v
);
596 void wxMacControl::SetMinimum( SInt32 v
)
598 ::SetControl32BitMinimum( m_controlRef
, v
);
601 void wxMacControl::SetMaximum( SInt32 v
)
603 ::SetControl32BitMaximum( m_controlRef
, v
);
606 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
608 ::SetControl32BitMinimum( m_controlRef
, minimum
);
609 ::SetControl32BitMaximum( m_controlRef
, maximum
);
610 ::SetControl32BitValue( m_controlRef
, value
);
613 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
615 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
618 bool wxMacControl::HasFocus() const
621 GetKeyboardFocus( GetUserFocusWindow() , &control
);
622 return control
== m_controlRef
;
625 void wxMacControl::SetNeedsFocusRect( bool needs
)
627 m_needsFocusRect
= needs
;
630 bool wxMacControl::NeedsFocusRect() const
632 return m_needsFocusRect
;
635 void wxMacControl::VisibilityChanged(bool WXUNUSED(shown
))
639 void wxMacControl::SuperChangedPosition()
643 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
647 ControlFontStyleRec fontStyle
;
648 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
650 switch ( font
.MacGetThemeFontID() )
652 case kThemeSmallSystemFont
:
653 fontStyle
.font
= kControlFontSmallSystemFont
;
656 case 109 : // mini font
660 case kThemeSystemFont
:
661 fontStyle
.font
= kControlFontBigSystemFont
;
665 fontStyle
.font
= kControlFontBigSystemFont
;
669 fontStyle
.flags
= kControlUseFontMask
;
673 fontStyle
.font
= font
.MacGetFontNum();
674 fontStyle
.style
= font
.MacGetFontStyle();
675 fontStyle
.size
= font
.MacGetFontSize();
676 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
679 fontStyle
.just
= teJustLeft
;
680 fontStyle
.flags
|= kControlUseJustMask
;
681 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
682 fontStyle
.just
= teJustCenter
;
683 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
684 fontStyle
.just
= teJustRight
;
687 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
688 // won't get grayed out by the system anymore
690 if ( foreground
!= *wxBLACK
)
692 foreground
.GetRGBColor( &fontStyle
.foreColor
);
693 fontStyle
.flags
|= kControlUseForeColorMask
;
696 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
700 void wxMacControl::SetBackgroundColour( const wxColour
&WXUNUSED(col
) )
703 // setting up a color proc is not recommended anymore
706 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
708 ::SetControl32BitMinimum( m_controlRef
, minimum
);
709 ::SetControl32BitMaximum( m_controlRef
, maximum
);
712 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
715 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
721 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
723 SetControlAction( m_controlRef
, actionProc
);
726 void wxMacControl::SetViewSize( SInt32 viewSize
)
728 SetControlViewSize(m_controlRef
, viewSize
);
731 SInt32
wxMacControl::GetViewSize() const
733 return GetControlViewSize( m_controlRef
);
736 bool wxMacControl::IsVisible() const
738 return IsControlVisible( m_controlRef
);
741 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
743 SetControlVisibility( m_controlRef
, visible
, redraw
);
746 bool wxMacControl::IsEnabled() const
748 return IsControlEnabled( m_controlRef
);
751 bool wxMacControl::IsActive() const
753 return IsControlActive( m_controlRef
);
756 void wxMacControl::Enable( bool enable
)
759 EnableControl( m_controlRef
);
761 DisableControl( m_controlRef
);
764 void wxMacControl::SetDrawingEnabled( bool enable
)
766 HIViewSetDrawingEnabled( m_controlRef
, enable
);
769 bool wxMacControl::GetNeedsDisplay() const
771 return HIViewGetNeedsDisplay( m_controlRef
);
774 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
779 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
782 void wxMacControl::SetNeedsDisplay( Rect
* where
)
789 RgnHandle update
= NewRgn();
790 RectRgn( update
, where
);
791 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
792 DisposeRgn( update
);
795 HIViewSetNeedsDisplay( m_controlRef
, true );
798 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
804 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
805 pt
->x
= (int)hiPoint
.x
;
806 pt
->y
= (int)hiPoint
.y
;
809 void wxMacControl::SetRect( Rect
*r
)
811 //A HIRect is actually a CGRect on OSX - which consists of two structures -
812 //CGPoint and CGSize, which have two floats each
813 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
814 HIViewSetFrame ( m_controlRef
, &hir
);
815 // eventuall we might have to do a SetVisibility( false , true );
816 // before and a SetVisibility( true , true ); after
819 void wxMacControl::GetRect( Rect
*r
)
821 GetControlBounds( m_controlRef
, r
);
824 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
826 GetControlBounds( m_controlRef
, r
) ;
828 WindowRef tlwref
= GetControlOwner( m_controlRef
) ;
830 wxTopLevelWindowMac
* tlwwx
= wxFindWinFromMacWindow( tlwref
) ;
833 ControlRef rootControl
= tlwwx
->GetPeer()->GetControlRef() ;
834 HIPoint hiPoint
= CGPointMake( 0 , 0 ) ;
835 HIViewConvertPoint( &hiPoint
, HIViewGetSuperview(m_controlRef
) , rootControl
) ;
836 OffsetRect( r
, (short) hiPoint
.x
, (short) hiPoint
.y
) ;
840 void wxMacControl::GetBestRect( Rect
*r
)
842 short baselineoffset
;
844 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
847 void wxMacControl::SetLabel( const wxString
&title
)
849 wxFontEncoding encoding
;
852 encoding
= m_font
.GetEncoding();
854 encoding
= wxFont::GetDefaultEncoding();
856 SetControlTitleWithCFString( m_controlRef
, wxMacCFStringHolder( title
, encoding
) );
859 void wxMacControl::GetFeatures( UInt32
* features
)
861 GetControlFeatures( m_controlRef
, features
);
864 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
866 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
870 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
872 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
873 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
876 // SetNeedsDisplay would not invalidate the children
877 static void InvalidateControlAndChildren( HIViewRef control
)
879 HIViewSetNeedsDisplay( control
, true );
880 UInt16 childrenCount
= 0;
881 OSStatus err
= CountSubControls( control
, &childrenCount
);
882 if ( err
== errControlIsNotEmbedder
)
885 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
887 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
891 err
= GetIndexedSubControl( control
, i
, & child
);
892 if ( err
== errControlIsNotEmbedder
)
895 InvalidateControlAndChildren( child
);
899 void wxMacControl::InvalidateWithChildren()
901 InvalidateControlAndChildren( m_controlRef
);
904 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
906 wxASSERT( r
!= NULL
);
908 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
909 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
912 OSType wxMacCreator
= 'WXMC';
913 OSType wxMacControlProperty
= 'MCCT';
915 void wxMacControl::SetReferenceInNativeControl()
918 verify_noerr( SetControlProperty ( m_controlRef
,
919 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
922 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
924 wxMacControl
* ctl
= NULL
;
925 ByteCount actualSize
;
926 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
927 &actualSize
, &ctl
) == noErr
)
934 // ============================================================================
935 // DataBrowser Wrapper
936 // ============================================================================
938 // basing on DataBrowserItemIDs
941 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
943 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
945 DataBrowserItemID itemID
,
946 DataBrowserItemNotification message
,
947 DataBrowserItemDataRef itemData
)
949 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
952 ctl
->ItemNotification(itemID
, message
, itemData
);
956 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
958 DataBrowserItemID itemID
,
959 DataBrowserPropertyID property
,
960 DataBrowserItemDataRef itemData
,
961 Boolean changeValue
)
963 OSStatus err
= errDataBrowserPropertyNotSupported
;
964 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
967 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
972 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
974 DataBrowserItemID itemOneID
,
975 DataBrowserItemID itemTwoID
,
976 DataBrowserPropertyID sortProperty
)
978 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
981 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
986 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
987 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
988 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
990 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
993 long WXUNUSED(style
))
994 : wxMacControl( peer
)
996 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
997 OSStatus err
= ::CreateDataBrowserControl(
998 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
999 &bounds
, kDataBrowserListView
, &m_controlRef
);
1000 SetReferenceInNativeControl();
1001 verify_noerr( err
);
1002 if ( gDataBrowserItemCompareUPP
== NULL
)
1003 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1004 if ( gDataBrowserItemDataUPP
== NULL
)
1005 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1006 if ( gDataBrowserItemNotificationUPP
== NULL
)
1008 gDataBrowserItemNotificationUPP
=
1009 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1012 DataBrowserCallbacks callbacks
;
1013 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1015 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1016 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1017 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1018 SetCallbacks( &callbacks
);
1022 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1024 DataBrowserItemState state
,
1025 ItemCount
*numItems
) const
1027 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1030 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1032 DataBrowserItemState state
,
1035 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1038 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1040 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1043 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1044 DataBrowserTableViewColumnIndex position
)
1046 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1049 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1050 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1053 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1055 DataBrowserTableViewColumnID id
;
1056 GetColumnIDFromIndex( position
, &id
);
1057 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1060 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1062 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1065 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1067 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1070 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1072 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1075 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1077 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1080 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1082 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1085 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1087 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1090 OSStatus
wxMacDataBrowserControl::UpdateItems(
1091 DataBrowserItemID container
,
1093 const DataBrowserItemID
*items
,
1094 DataBrowserPropertyID preSortProperty
,
1095 DataBrowserPropertyID propertyID
) const
1097 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1100 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1102 return IsDataBrowserItemSelected( m_controlRef
, item
);
1105 OSStatus
wxMacDataBrowserControl::AddItems(
1106 DataBrowserItemID container
,
1108 const DataBrowserItemID
*items
,
1109 DataBrowserPropertyID preSortProperty
)
1111 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1114 OSStatus
wxMacDataBrowserControl::RemoveItems(
1115 DataBrowserItemID container
,
1117 const DataBrowserItemID
*items
,
1118 DataBrowserPropertyID preSortProperty
)
1120 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1123 OSStatus
wxMacDataBrowserControl::RevealItem(
1124 DataBrowserItemID item
,
1125 DataBrowserPropertyID propertyID
,
1126 DataBrowserRevealOptions options
) const
1128 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1131 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1133 const DataBrowserItemID
*items
,
1134 DataBrowserSetOption operation
)
1136 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1139 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1141 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1144 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1146 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1149 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1151 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1154 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1156 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1159 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1161 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1164 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1166 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1169 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1171 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1174 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1176 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1179 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1181 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1184 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1186 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1189 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1191 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1194 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1196 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1199 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1200 DataBrowserTableViewColumnIndex
*position
) const
1202 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1205 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1207 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1210 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1212 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1215 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1217 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1220 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1222 return GetDataBrowserSortProperty( m_controlRef
, column
);
1225 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1227 return SetDataBrowserSortProperty( m_controlRef
, column
);
1230 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1232 return GetDataBrowserSortOrder( m_controlRef
, order
);
1235 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1237 return SetDataBrowserSortOrder( m_controlRef
, order
);
1240 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1241 DataBrowserPropertyFlags
*flags
) const
1243 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1246 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1247 DataBrowserPropertyFlags flags
)
1249 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1252 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1253 DataBrowserListViewHeaderDesc
*desc
) const
1255 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1258 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1259 DataBrowserListViewHeaderDesc
*desc
)
1261 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1264 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1265 Boolean expandableRows
)
1267 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1270 // ============================================================================
1271 // Higher-level Databrowser
1272 // ============================================================================
1274 // basing on data item objects
1277 wxMacDataItem::wxMacDataItem()
1282 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1285 wxMacDataItem::~wxMacDataItem()
1289 void wxMacDataItem::SetOrder( SInt32 order
)
1294 SInt32
wxMacDataItem::GetOrder() const
1299 void wxMacDataItem::SetData( void* data
)
1304 void* wxMacDataItem::GetData() const
1309 short wxMacDataItem::GetColumn()
1314 void wxMacDataItem::SetColumn( short col
)
1319 void wxMacDataItem::SetLabel( const wxString
& str
)
1322 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1325 const wxString
& wxMacDataItem::GetLabel() const
1330 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1331 const wxMacDataItem
* rhs
,
1332 DataBrowserPropertyID sortProperty
) const
1334 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1335 bool retval
= false;
1337 if ( sortProperty
== m_colId
){
1338 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1341 else if ( sortProperty
== kNumericOrderColumnId
)
1342 retval
= m_order
< otherItem
->m_order
;
1347 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1348 DataBrowserPropertyID property
,
1349 DataBrowserItemDataRef itemData
,
1352 OSStatus err
= errDataBrowserPropertyNotSupported
;
1355 if ( property
== m_colId
){
1356 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1359 else if ( property
== kNumericOrderColumnId
){
1360 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1370 // no editable props here
1379 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1380 DataBrowserItemNotification
WXUNUSED(message
),
1381 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
1385 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1387 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1388 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1390 m_suppressSelection
= false;
1391 m_sortOrder
= SortOrder_None
;
1392 m_clientDataItemsType
= wxClientData_None
;
1395 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1397 return new wxMacDataItem();
1400 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1402 m_former
= browser
->SuppressSelection(true);
1403 m_browser
= browser
;
1406 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1408 m_browser
->SuppressSelection(m_former
);
1411 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1413 bool former
= m_suppressSelection
;
1414 m_suppressSelection
= suppress
;
1419 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1420 DataBrowserItemID itemTwoID
,
1421 DataBrowserPropertyID sortProperty
)
1423 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1424 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1425 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1428 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1429 const wxMacDataItem
* itemTwo
,
1430 DataBrowserPropertyID sortProperty
)
1432 Boolean retval
= false;
1433 if ( itemOne
!= NULL
)
1434 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1438 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1439 DataBrowserItemID itemID
,
1440 DataBrowserPropertyID property
,
1441 DataBrowserItemDataRef itemData
,
1442 Boolean changeValue
)
1444 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1445 return GetSetItemData(item
, property
, itemData
, changeValue
);
1448 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1449 wxMacDataItem
* item
,
1450 DataBrowserPropertyID property
,
1451 DataBrowserItemDataRef itemData
,
1452 Boolean changeValue
)
1454 OSStatus err
= errDataBrowserPropertyNotSupported
;
1457 case kDataBrowserContainerIsClosableProperty
:
1458 case kDataBrowserContainerIsSortableProperty
:
1459 case kDataBrowserContainerIsOpenableProperty
:
1460 // right now default behaviour on these
1464 if ( item
!= NULL
){
1465 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1473 void wxMacDataItemBrowserControl::ItemNotification(
1474 DataBrowserItemID itemID
,
1475 DataBrowserItemNotification message
,
1476 DataBrowserItemDataRef itemData
)
1478 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1479 ItemNotification( item
, message
, itemData
);
1482 void wxMacDataItemBrowserControl::ItemNotification(
1483 const wxMacDataItem
* item
,
1484 DataBrowserItemNotification message
,
1485 DataBrowserItemDataRef itemData
)
1488 item
->Notification( this, message
, itemData
);
1491 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1492 bool recurse
, DataBrowserItemState state
) const
1494 ItemCount numItems
= 0;
1495 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1496 recurse
, state
, &numItems
) );
1500 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1501 bool recurse
) const
1503 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1507 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1508 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1510 Handle handle
= NewHandle(0);
1511 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1512 recurse
, state
, handle
) );
1514 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1516 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1517 for ( int i
= 0; i
< itemCount
; ++i
)
1519 items
.Add(itemsArray
[i
]);
1522 DisposeHandle( handle
);
1525 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1527 DataBrowserTableViewRowIndex row
;
1528 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1529 wxASSERT( err
== noErr
);
1533 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1535 DataBrowserItemID id
;
1536 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1537 wxASSERT( err
== noErr
);
1538 return (wxMacDataItem
*) id
;
1541 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1542 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1544 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1545 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1548 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1549 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1551 unsigned int noItems
= itemArray
.GetCount();
1552 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1553 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1554 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1556 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1557 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1561 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1562 const wxString
& title
, SInt16 just
, int defaultWidth
)
1564 DataBrowserListViewColumnDesc columnDesc
;
1565 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1566 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1568 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1569 kControlUseFontMask
| kControlUseJustMask
;
1571 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1572 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1573 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1574 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1576 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1577 // defined for other modes?
1580 enc
= m_font
.GetEncoding();
1582 enc
= wxLocale::GetSystemEncoding();
1583 wxMacCFStringHolder cfTitle
;
1584 cfTitle
.Assign( title
, enc
);
1585 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1587 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1588 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1590 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1591 columnDesc
.propertyDesc
.propertyType
= colType
;
1592 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1593 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1594 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1596 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1598 if (defaultWidth
> 0){
1599 SetColumnWidth(colId
, defaultWidth
);
1604 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1606 DataBrowserPropertyID id
;
1607 GetColumnIDFromIndex(colId
, &id
);
1608 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1611 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1613 DataBrowserPropertyID id
;
1614 GetColumnIDFromIndex(colId
, &id
);
1616 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1620 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1622 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1623 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1626 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1628 unsigned int noItems
= itemArray
.GetCount();
1629 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1630 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1631 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1633 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1634 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1638 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1640 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1641 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1642 verify_noerr( err
);
1645 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1647 unsigned int noItems
= itemArray
.GetCount();
1648 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1649 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1650 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1652 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1653 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1654 verify_noerr( err
);
1658 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1660 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1661 verify_noerr( err
);
1664 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1666 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1669 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1671 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1674 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1676 unsigned int noItems
= itemArray
.GetCount();
1677 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1678 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1679 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1681 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1685 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1687 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1690 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1692 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1695 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1697 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1700 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1702 return m_clientDataItemsType
;
1704 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1706 m_clientDataItemsType
= clientDataItemsType
;
1709 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1711 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
1714 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1716 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1717 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1720 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
,
1721 const wxArrayStringsAdapter
& items
,
1724 size_t itemsCount
= items
.GetCount();
1725 if ( itemsCount
== 0 )
1728 SInt32 frontLineOrder
= 0;
1730 if ( m_sortOrder
== SortOrder_None
)
1732 // increase the order of the lines to be shifted
1733 unsigned int lines
= MacGetCount();
1734 for ( unsigned int i
= n
; i
< lines
; ++i
)
1736 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1737 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
1741 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1742 frontLineOrder
= iter
->GetOrder();
1746 wxArrayMacDataItemPtr ids
;
1747 ids
.SetCount( itemsCount
);
1749 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
1751 wxMacDataItem
* item
= CreateItem();
1752 item
->SetLabel( items
[i
]);
1754 item
->SetColumn( kMinColumnId
+ column
);
1756 if ( m_sortOrder
== SortOrder_None
)
1757 item
->SetOrder( frontLineOrder
+ 1 + i
);
1762 AddItems( wxMacDataBrowserRootContainer
, ids
);
1765 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
1767 wxMacDataItem
* item
= CreateItem();
1768 item
->SetLabel( text
);
1769 if ( m_sortOrder
== SortOrder_None
)
1771 unsigned int lines
= MacGetCount();
1773 item
->SetOrder( 1 );
1776 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
1777 item
->SetOrder( frontItem
->GetOrder() + 1 );
1780 AddItem( wxMacDataBrowserRootContainer
, item
);
1782 return GetLineFromItem(item
);
1785 void wxMacDataItemBrowserControl::MacClear()
1787 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1788 RemoveAllItems(wxMacDataBrowserRootContainer
);
1791 void wxMacDataItemBrowserControl::MacDeselectAll()
1793 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1794 SetSelectedAllItems( kDataBrowserItemsRemove
);
1797 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
1799 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1800 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1802 if ( IsItemSelected( item
) != select
)
1805 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
1807 SetSelectedItem( item
, kDataBrowserItemsRemove
);
1813 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
1815 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1816 return IsItemSelected( item
);
1819 int wxMacDataItemBrowserControl::MacGetSelection() const
1821 wxMacDataItemPtr first
, last
;
1822 GetSelectionAnchor( &first
, &last
);
1824 if ( first
!= NULL
)
1826 return GetLineFromItem( first
);
1832 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
1834 aSelections
.Empty();
1835 wxArrayMacDataItemPtr selectedItems
;
1836 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
1838 int count
= selectedItems
.GetCount();
1840 for ( int i
= 0; i
< count
; ++i
)
1842 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
1848 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
1850 // as we don't store the strings we only have to issue a redraw
1851 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1852 item
->SetLabel( text
);
1853 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
1856 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
1858 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1859 return item
->GetLabel();
1862 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
1864 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1865 item
->SetData( data
);
1866 // not displayed, therefore no Update infos to DataBrowser
1869 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
1871 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1872 return item
->GetData();
1875 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
1878 GetScrollPosition( &top
, &left
) ;
1879 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1882 GetRowHeight( (DataBrowserItemID
) item
, &height
) ;
1883 SetScrollPosition( n
* ((UInt32
)height
) , left
) ;
1885 RevealItem( item
, kDataBrowserRevealWithoutSelecting
);
1894 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1896 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
1906 Return the generic RGB color space. This is a 'get' function and the caller should
1907 not release the returned value unless the caller retains it first. Usually callers
1908 of this routine will immediately use the returned colorspace with CoreGraphics
1909 so they typically do not need to retain it themselves.
1911 This function creates the generic RGB color space once and hangs onto it so it can
1912 return it whenever this function is called.
1915 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
1917 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
1919 if (genericRGBColorSpace
== NULL
)
1921 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
1924 return genericRGBColorSpace
;
1927 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
1930 HIThemeBrushCreateCGColor( brush
, &color
);
1936 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
1938 ::GetPort( &m_port
);
1942 wxMacPortSaver::~wxMacPortSaver()
1944 ::SetPort( m_port
);
1948 #if wxMAC_USE_QUICKDRAW
1950 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
1952 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1953 HIViewRef contentView
;
1954 // TODO check toolbar offset
1955 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1956 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1961 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
1963 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1964 HIViewRef contentView
;
1965 // TODO check toolbar offset
1966 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1967 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);