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 wxSetCursor(*cursor
);
132 //else: nothing to do, already set
135 // Restore cursor to normal
136 void wxEndBusyCursor()
138 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
139 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
141 if (--gs_wxBusyCursorCount
== 0)
143 gMacStoredActiveCursor
.MacInstall();
144 gMacStoredActiveCursor
= wxNullCursor
;
146 wxSetCursor(wxNullCursor
);
150 // true if we're between the above two calls
153 return (gs_wxBusyCursorCount
> 0);
160 wxString
wxMacFindFolderNoSeparator( short vol
,
162 Boolean createFolder
)
167 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
169 strDir
= wxMacFSRefToPath( &fsRef
);
175 wxString
wxMacFindFolder( short vol
,
177 Boolean createFolder
)
179 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
186 // Check whether this window wants to process messages, e.g. Stop button
187 // in long calculations.
188 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
194 void wxGetMousePosition( int* x
, int* y
)
196 #if wxMAC_USE_QUICKDRAW
206 // Return true if we have a colour display
207 bool wxColourDisplay()
212 // Returns depth of screen
215 #if wxMAC_USE_QUICKDRAW
216 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
218 SetRect(&globRect
, -32760, -32760, 32760, 32760);
219 GDHandle theMaxDevice
;
221 theMaxDevice
= GetMaxDevice(&globRect
);
222 if (theMaxDevice
!= NULL
)
223 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
231 // Get size of display
232 void wxDisplaySize(int *width
, int *height
)
234 // TODO adapt for multi-displays
235 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
237 *width
= (int)bounds
.size
.width
;
239 *height
= (int)bounds
.size
.height
;
242 void wxDisplaySizeMM(int *width
, int *height
)
244 wxDisplaySize(width
, height
);
245 // on mac 72 is fixed (at least now;-)
246 float cvPt2Mm
= 25.4 / 72;
249 *width
= int( *width
* cvPt2Mm
);
252 *height
= int( *height
* cvPt2Mm
);
255 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
257 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
258 #if wxMAC_USE_QUICKDRAW
261 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
264 *x
= bounds
.origin
.x
;
266 *y
= bounds
.origin
.y
;
268 *width
= bounds
.size
.width
;
270 *height
= bounds
.size
.height
;
273 wxDisplaySize(&w
,&h
);
285 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
291 *width
= r
.right
- r
.left
;
293 *height
= r
.bottom
- r
.top
;
297 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
299 return wxGenericFindWindowAtPoint(pt
);
306 wxString
wxGetOsDescription()
308 #ifdef WXWIN_OS_DESCRIPTION
309 // use configure generated description if available
310 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
312 return wxT("MacOS"); //TODO:define further
317 wxString
wxGetUserHome (const wxString
& user
)
323 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
332 int pos
= p
.Find(':');
333 if ( pos
!= wxNOT_FOUND
)
341 err
= wxMacPathToFSRef( p
, &fsRef
);
344 FSVolumeRefNum vRefNum
;
345 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
348 UInt64 freeBytes
, totalBytes
;
349 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
353 *pTotal
= wxDiskspaceSize_t( totalBytes
);
355 *pFree
= wxDiskspaceSize_t( freeBytes
);
362 #endif // !__DARWIN__
364 //---------------------------------------------------------------------------
365 // wxMac Specific utility functions
366 //---------------------------------------------------------------------------
368 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
370 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
371 int len
= strlen(buf
);
376 memcpy( (char*) &to
[1] , buf
, len
);
379 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
381 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
384 // ----------------------------------------------------------------------------
385 // Common Event Support
386 // ----------------------------------------------------------------------------
390 OSStatus err
= noErr
;
393 // lead sometimes to race conditions, although all calls used should be thread safe ...
394 static wxMacCarbonEvent s_wakeupEvent
;
395 if ( !s_wakeupEvent
.IsValid() )
397 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
398 kEventAttributeNone
);
403 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
405 s_wakeupEvent
.SetCurrentTime();
406 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
407 kEventPriorityHigh
);
410 wxMacCarbonEvent wakeupEvent
;
411 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
412 kEventAttributeNone
);
413 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
414 kEventPriorityHigh
);
422 // ----------------------------------------------------------------------------
423 // Native Struct Conversions
424 // ----------------------------------------------------------------------------
426 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
430 n
->right
= wx
->x
+ wx
->width
;
431 n
->bottom
= wx
->y
+ wx
->height
;
434 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
438 wx
->width
= n
->right
- n
->left
;
439 wx
->height
= n
->bottom
- n
->top
;
442 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
448 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
454 // ----------------------------------------------------------------------------
455 // Carbon Event Support
456 // ----------------------------------------------------------------------------
458 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
460 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
463 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
465 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
468 // ----------------------------------------------------------------------------
469 // Control Access Support
470 // ----------------------------------------------------------------------------
472 #if wxMAC_USE_QUICKDRAW
474 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
476 wxMacControl::wxMacControl()
481 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
485 m_isRootControl
= isRootControl
;
488 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
492 m_controlRef
= control
;
495 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
499 m_controlRef
= (ControlRef
) control
;
502 wxMacControl::~wxMacControl()
506 void wxMacControl::Init()
510 m_needsFocusRect
= false;
511 m_isRootControl
= false;
514 void wxMacControl::Dispose()
516 wxASSERT_MSG( m_controlRef
!= NULL
, wxT("Control Handle already NULL, Dispose called twice ?") );
517 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
519 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
520 // we can have situations when being embedded, where the control gets deleted behind our back, so only
521 // CFRelease if we are safe
522 if ( IsValidControlHandle(m_controlRef
) )
523 CFRelease(m_controlRef
);
527 void wxMacControl::SetReference( URefCon data
)
529 SetControlReference( m_controlRef
, data
);
532 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
534 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
537 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
539 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
542 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
544 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
547 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
549 return SendEventToEventTargetWithOptions( event
,
550 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
553 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
555 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
557 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
559 return SendEvent( event
, inOptions
);
562 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
566 memset( &command
, 0 , sizeof(command
) );
567 command
.commandID
= commandID
;
568 return SendHICommand( command
, inOptions
);
571 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
573 unsigned long finalTicks
;
575 HiliteControl( m_controlRef
, part
);
576 Delay( ticks
, &finalTicks
);
577 HiliteControl( m_controlRef
, kControlNoPart
);
580 SInt32
wxMacControl::GetValue() const
582 return ::GetControl32BitValue( m_controlRef
);
585 SInt32
wxMacControl::GetMaximum() const
587 return ::GetControl32BitMaximum( m_controlRef
);
590 SInt32
wxMacControl::GetMinimum() const
592 return ::GetControl32BitMinimum( m_controlRef
);
595 void wxMacControl::SetValue( SInt32 v
)
597 ::SetControl32BitValue( m_controlRef
, v
);
600 void wxMacControl::SetMinimum( SInt32 v
)
602 ::SetControl32BitMinimum( m_controlRef
, v
);
605 void wxMacControl::SetMaximum( SInt32 v
)
607 ::SetControl32BitMaximum( m_controlRef
, v
);
610 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
612 ::SetControl32BitMinimum( m_controlRef
, minimum
);
613 ::SetControl32BitMaximum( m_controlRef
, maximum
);
614 ::SetControl32BitValue( m_controlRef
, value
);
617 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
619 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
622 bool wxMacControl::HasFocus() const
625 GetKeyboardFocus( GetUserFocusWindow() , &control
);
626 return control
== m_controlRef
;
629 void wxMacControl::SetNeedsFocusRect( bool needs
)
631 m_needsFocusRect
= needs
;
634 bool wxMacControl::NeedsFocusRect() const
636 return m_needsFocusRect
;
639 void wxMacControl::VisibilityChanged(bool WXUNUSED(shown
))
643 void wxMacControl::SuperChangedPosition()
647 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
650 #if wxMAC_USE_CORE_TEXT
651 if ( UMAGetSystemVersion() >= 0x1050 )
653 HIViewPartCode part
= 0;
654 HIThemeTextHorizontalFlush flush
= kHIThemeTextHorizontalFlushDefault
;
655 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
656 flush
= kHIThemeTextHorizontalFlushCenter
;
657 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
658 flush
= kHIThemeTextHorizontalFlushRight
;
659 HIViewSetTextFont( m_controlRef
, part
, (CTFontRef
) font
.MacGetCTFont() );
660 HIViewSetTextHorizontalFlush( m_controlRef
, part
, flush
);
662 if ( foreground
!= *wxBLACK
)
664 ControlFontStyleRec fontStyle
;
665 foreground
.GetRGBColor( &fontStyle
.foreColor
);
666 fontStyle
.flags
= kControlUseForeColorMask
;
667 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
672 #if wxMAC_USE_ATSU_TEXT
673 ControlFontStyleRec fontStyle
;
674 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
676 switch ( font
.MacGetThemeFontID() )
678 case kThemeSmallSystemFont
:
679 fontStyle
.font
= kControlFontSmallSystemFont
;
682 case 109 : // mini font
686 case kThemeSystemFont
:
687 fontStyle
.font
= kControlFontBigSystemFont
;
691 fontStyle
.font
= kControlFontBigSystemFont
;
695 fontStyle
.flags
= kControlUseFontMask
;
699 fontStyle
.font
= font
.MacGetFontNum();
700 fontStyle
.style
= font
.MacGetFontStyle();
701 fontStyle
.size
= font
.MacGetFontSize();
702 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
705 fontStyle
.just
= teJustLeft
;
706 fontStyle
.flags
|= kControlUseJustMask
;
707 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
708 fontStyle
.just
= teJustCenter
;
709 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
710 fontStyle
.just
= teJustRight
;
713 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
714 // won't get grayed out by the system anymore
716 if ( foreground
!= *wxBLACK
)
718 foreground
.GetRGBColor( &fontStyle
.foreColor
);
719 fontStyle
.flags
|= kControlUseForeColorMask
;
722 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
726 void wxMacControl::SetBackgroundColour( const wxColour
&WXUNUSED(col
) )
728 // HITextViewSetBackgroundColor( m_textView , color );
731 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
733 ::SetControl32BitMinimum( m_controlRef
, minimum
);
734 ::SetControl32BitMaximum( m_controlRef
, maximum
);
737 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
740 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
746 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
748 SetControlAction( m_controlRef
, actionProc
);
751 void wxMacControl::SetViewSize( SInt32 viewSize
)
753 SetControlViewSize(m_controlRef
, viewSize
);
756 SInt32
wxMacControl::GetViewSize() const
758 return GetControlViewSize( m_controlRef
);
761 bool wxMacControl::IsVisible() const
763 return IsControlVisible( m_controlRef
);
766 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
768 SetControlVisibility( m_controlRef
, visible
, redraw
);
771 bool wxMacControl::IsEnabled() const
773 return IsControlEnabled( m_controlRef
);
776 bool wxMacControl::IsActive() const
778 return IsControlActive( m_controlRef
);
781 void wxMacControl::Enable( bool enable
)
784 EnableControl( m_controlRef
);
786 DisableControl( m_controlRef
);
789 void wxMacControl::SetDrawingEnabled( bool enable
)
791 HIViewSetDrawingEnabled( m_controlRef
, enable
);
794 bool wxMacControl::GetNeedsDisplay() const
796 return HIViewGetNeedsDisplay( m_controlRef
);
799 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
804 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
807 void wxMacControl::SetNeedsDisplay( Rect
* where
)
814 RgnHandle update
= NewRgn();
815 RectRgn( update
, where
);
816 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
817 DisposeRgn( update
);
820 HIViewSetNeedsDisplay( m_controlRef
, true );
823 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
829 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
830 pt
->x
= (int)hiPoint
.x
;
831 pt
->y
= (int)hiPoint
.y
;
834 void wxMacControl::SetRect( Rect
*r
)
836 //A HIRect is actually a CGRect on OSX - which consists of two structures -
837 //CGPoint and CGSize, which have two floats each
838 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
839 HIViewSetFrame ( m_controlRef
, &hir
);
840 // eventuall we might have to do a SetVisibility( false , true );
841 // before and a SetVisibility( true , true ); after
844 void wxMacControl::GetRect( Rect
*r
)
846 GetControlBounds( m_controlRef
, r
);
849 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
851 GetControlBounds( m_controlRef
, r
) ;
853 WindowRef tlwref
= GetControlOwner( m_controlRef
) ;
855 wxTopLevelWindowMac
* tlwwx
= wxFindWinFromMacWindow( tlwref
) ;
858 ControlRef rootControl
= tlwwx
->GetPeer()->GetControlRef() ;
859 HIPoint hiPoint
= CGPointMake( 0 , 0 ) ;
860 HIViewConvertPoint( &hiPoint
, HIViewGetSuperview(m_controlRef
) , rootControl
) ;
861 OffsetRect( r
, (short) hiPoint
.x
, (short) hiPoint
.y
) ;
865 void wxMacControl::GetBestRect( Rect
*r
)
867 short baselineoffset
;
869 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
872 void wxMacControl::SetLabel( const wxString
&title
)
874 wxFontEncoding encoding
;
877 encoding
= m_font
.GetEncoding();
879 encoding
= wxFont::GetDefaultEncoding();
881 SetControlTitleWithCFString( m_controlRef
, wxCFStringRef( title
, encoding
) );
884 void wxMacControl::GetFeatures( UInt32
* features
)
886 GetControlFeatures( m_controlRef
, features
);
889 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
891 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
895 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
897 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
898 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
901 // SetNeedsDisplay would not invalidate the children
902 static void InvalidateControlAndChildren( HIViewRef control
)
904 HIViewSetNeedsDisplay( control
, true );
905 UInt16 childrenCount
= 0;
906 OSStatus err
= CountSubControls( control
, &childrenCount
);
907 if ( err
== errControlIsNotEmbedder
)
910 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
912 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
916 err
= GetIndexedSubControl( control
, i
, & child
);
917 if ( err
== errControlIsNotEmbedder
)
920 InvalidateControlAndChildren( child
);
924 void wxMacControl::InvalidateWithChildren()
926 InvalidateControlAndChildren( m_controlRef
);
929 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
931 wxASSERT( r
!= NULL
);
933 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
934 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
937 OSType wxMacCreator
= 'WXMC';
938 OSType wxMacControlProperty
= 'MCCT';
940 void wxMacControl::SetReferenceInNativeControl()
943 verify_noerr( SetControlProperty ( m_controlRef
,
944 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
947 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
949 wxMacControl
* ctl
= NULL
;
950 ByteCount actualSize
;
951 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
952 &actualSize
, &ctl
) == noErr
)
959 // ============================================================================
960 // DataBrowser Wrapper
961 // ============================================================================
963 // basing on DataBrowserItemIDs
966 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
968 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
970 DataBrowserItemID itemID
,
971 DataBrowserItemNotification message
,
972 DataBrowserItemDataRef itemData
)
974 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
977 ctl
->ItemNotification(itemID
, message
, itemData
);
981 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
983 DataBrowserItemID itemID
,
984 DataBrowserPropertyID property
,
985 DataBrowserItemDataRef itemData
,
986 Boolean changeValue
)
988 OSStatus err
= errDataBrowserPropertyNotSupported
;
989 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
992 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
997 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
999 DataBrowserItemID itemOneID
,
1000 DataBrowserItemID itemTwoID
,
1001 DataBrowserPropertyID sortProperty
)
1003 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1006 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1011 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1012 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1013 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1015 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
1018 long WXUNUSED(style
))
1019 : wxMacControl( peer
)
1021 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1022 OSStatus err
= ::CreateDataBrowserControl(
1023 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1024 &bounds
, kDataBrowserListView
, &m_controlRef
);
1025 SetReferenceInNativeControl();
1026 verify_noerr( err
);
1027 if ( gDataBrowserItemCompareUPP
== NULL
)
1028 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1029 if ( gDataBrowserItemDataUPP
== NULL
)
1030 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1031 if ( gDataBrowserItemNotificationUPP
== NULL
)
1033 gDataBrowserItemNotificationUPP
=
1034 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1037 DataBrowserCallbacks callbacks
;
1038 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1040 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1041 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1042 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1043 SetCallbacks( &callbacks
);
1047 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1049 DataBrowserItemState state
,
1050 ItemCount
*numItems
) const
1052 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1055 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1057 DataBrowserItemState state
,
1060 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1063 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1065 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1068 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1069 DataBrowserTableViewColumnIndex position
)
1071 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1074 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1075 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1078 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1080 DataBrowserTableViewColumnID id
;
1081 GetColumnIDFromIndex( position
, &id
);
1082 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1085 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1087 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1090 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1092 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1095 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1097 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1100 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1102 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1105 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1107 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1110 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1112 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1115 OSStatus
wxMacDataBrowserControl::UpdateItems(
1116 DataBrowserItemID container
,
1118 const DataBrowserItemID
*items
,
1119 DataBrowserPropertyID preSortProperty
,
1120 DataBrowserPropertyID propertyID
) const
1122 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1125 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1127 return IsDataBrowserItemSelected( m_controlRef
, item
);
1130 OSStatus
wxMacDataBrowserControl::AddItems(
1131 DataBrowserItemID container
,
1133 const DataBrowserItemID
*items
,
1134 DataBrowserPropertyID preSortProperty
)
1136 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1139 OSStatus
wxMacDataBrowserControl::RemoveItems(
1140 DataBrowserItemID container
,
1142 const DataBrowserItemID
*items
,
1143 DataBrowserPropertyID preSortProperty
)
1145 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1148 OSStatus
wxMacDataBrowserControl::RevealItem(
1149 DataBrowserItemID item
,
1150 DataBrowserPropertyID propertyID
,
1151 DataBrowserRevealOptions options
) const
1153 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1156 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1158 const DataBrowserItemID
*items
,
1159 DataBrowserSetOption operation
)
1161 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1164 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1166 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1169 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1171 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1174 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1176 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1179 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1181 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1184 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1186 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1189 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1191 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1194 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1196 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1199 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1201 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1204 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1206 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1209 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1211 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1214 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1216 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1219 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1221 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1224 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1225 DataBrowserTableViewColumnIndex
*position
) const
1227 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1230 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1232 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1235 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1237 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1240 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1242 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1245 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1247 return GetDataBrowserSortProperty( m_controlRef
, column
);
1250 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1252 return SetDataBrowserSortProperty( m_controlRef
, column
);
1255 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1257 return GetDataBrowserSortOrder( m_controlRef
, order
);
1260 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1262 return SetDataBrowserSortOrder( m_controlRef
, order
);
1265 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1266 DataBrowserPropertyFlags
*flags
) const
1268 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1271 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1272 DataBrowserPropertyFlags flags
)
1274 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1277 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1278 DataBrowserListViewHeaderDesc
*desc
) const
1280 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1283 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1284 DataBrowserListViewHeaderDesc
*desc
)
1286 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1289 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1290 Boolean expandableRows
)
1292 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1295 // ============================================================================
1296 // Higher-level Databrowser
1297 // ============================================================================
1299 // basing on data item objects
1302 wxMacDataItem::wxMacDataItem()
1307 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1310 wxMacDataItem::~wxMacDataItem()
1314 void wxMacDataItem::SetOrder( SInt32 order
)
1319 SInt32
wxMacDataItem::GetOrder() const
1324 void wxMacDataItem::SetData( void* data
)
1329 void* wxMacDataItem::GetData() const
1334 short wxMacDataItem::GetColumn()
1339 void wxMacDataItem::SetColumn( short col
)
1344 void wxMacDataItem::SetLabel( const wxString
& str
)
1347 m_cfLabel
= wxCFStringRef( str
, wxLocale::GetSystemEncoding());
1350 const wxString
& wxMacDataItem::GetLabel() const
1355 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1356 const wxMacDataItem
* rhs
,
1357 DataBrowserPropertyID sortProperty
) const
1359 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1360 bool retval
= false;
1362 if ( sortProperty
== m_colId
){
1363 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1366 else if ( sortProperty
== kNumericOrderColumnId
)
1367 retval
= m_order
< otherItem
->m_order
;
1372 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1373 DataBrowserPropertyID property
,
1374 DataBrowserItemDataRef itemData
,
1377 OSStatus err
= errDataBrowserPropertyNotSupported
;
1380 if ( property
== m_colId
){
1381 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1384 else if ( property
== kNumericOrderColumnId
){
1385 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1395 // no editable props here
1404 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1405 DataBrowserItemNotification
WXUNUSED(message
),
1406 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
1410 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1412 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1413 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1415 m_suppressSelection
= false;
1416 m_sortOrder
= SortOrder_None
;
1417 m_clientDataItemsType
= wxClientData_None
;
1420 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1422 return new wxMacDataItem();
1425 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1427 m_former
= browser
->SuppressSelection(true);
1428 m_browser
= browser
;
1431 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1433 m_browser
->SuppressSelection(m_former
);
1436 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1438 bool former
= m_suppressSelection
;
1439 m_suppressSelection
= suppress
;
1444 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1445 DataBrowserItemID itemTwoID
,
1446 DataBrowserPropertyID sortProperty
)
1448 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1449 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1450 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1453 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1454 const wxMacDataItem
* itemTwo
,
1455 DataBrowserPropertyID sortProperty
)
1457 Boolean retval
= false;
1458 if ( itemOne
!= NULL
)
1459 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1463 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1464 DataBrowserItemID itemID
,
1465 DataBrowserPropertyID property
,
1466 DataBrowserItemDataRef itemData
,
1467 Boolean changeValue
)
1469 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1470 return GetSetItemData(item
, property
, itemData
, changeValue
);
1473 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1474 wxMacDataItem
* item
,
1475 DataBrowserPropertyID property
,
1476 DataBrowserItemDataRef itemData
,
1477 Boolean changeValue
)
1479 OSStatus err
= errDataBrowserPropertyNotSupported
;
1482 case kDataBrowserContainerIsClosableProperty
:
1483 case kDataBrowserContainerIsSortableProperty
:
1484 case kDataBrowserContainerIsOpenableProperty
:
1485 // right now default behaviour on these
1489 if ( item
!= NULL
){
1490 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1498 void wxMacDataItemBrowserControl::ItemNotification(
1499 DataBrowserItemID itemID
,
1500 DataBrowserItemNotification message
,
1501 DataBrowserItemDataRef itemData
)
1503 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1504 ItemNotification( item
, message
, itemData
);
1507 void wxMacDataItemBrowserControl::ItemNotification(
1508 const wxMacDataItem
* item
,
1509 DataBrowserItemNotification message
,
1510 DataBrowserItemDataRef itemData
)
1513 item
->Notification( this, message
, itemData
);
1516 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1517 bool recurse
, DataBrowserItemState state
) const
1519 ItemCount numItems
= 0;
1520 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1521 recurse
, state
, &numItems
) );
1525 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1526 bool recurse
) const
1528 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1532 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1533 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1535 Handle handle
= NewHandle(0);
1536 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1537 recurse
, state
, handle
) );
1539 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1541 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1542 for ( int i
= 0; i
< itemCount
; ++i
)
1544 items
.Add(itemsArray
[i
]);
1547 DisposeHandle( handle
);
1550 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1552 DataBrowserTableViewRowIndex row
;
1553 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1554 wxASSERT( err
== noErr
);
1558 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1560 DataBrowserItemID id
;
1561 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1562 wxASSERT( err
== noErr
);
1563 return (wxMacDataItem
*) id
;
1566 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1567 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1569 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1570 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1573 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1574 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1576 unsigned int noItems
= itemArray
.GetCount();
1577 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1578 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1579 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1581 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1582 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1586 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1587 const wxString
& title
, SInt16 just
, int defaultWidth
)
1589 DataBrowserListViewColumnDesc columnDesc
;
1590 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1591 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1593 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1594 kControlUseFontMask
| kControlUseJustMask
;
1596 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1597 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1598 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1599 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1601 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1602 // defined for other modes?
1605 enc
= m_font
.GetEncoding();
1607 enc
= wxLocale::GetSystemEncoding();
1608 wxCFStringRef
cfTitle( title
, enc
);
1609 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1611 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1612 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1614 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1615 columnDesc
.propertyDesc
.propertyType
= colType
;
1616 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1617 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1618 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1620 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1622 if (defaultWidth
> 0){
1623 SetColumnWidth(colId
, defaultWidth
);
1628 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1630 DataBrowserPropertyID id
;
1631 GetColumnIDFromIndex(colId
, &id
);
1632 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1635 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1637 DataBrowserPropertyID id
;
1638 GetColumnIDFromIndex(colId
, &id
);
1640 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1644 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1646 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1647 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1650 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1652 unsigned int noItems
= itemArray
.GetCount();
1653 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1654 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1655 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1657 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1658 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1662 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1664 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1665 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1666 verify_noerr( err
);
1669 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
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 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1677 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1678 verify_noerr( err
);
1682 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1684 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1685 verify_noerr( err
);
1688 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1690 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1693 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1695 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1698 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1700 unsigned int noItems
= itemArray
.GetCount();
1701 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1702 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1703 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1705 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1709 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1711 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1714 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1716 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1719 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1721 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1724 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1726 return m_clientDataItemsType
;
1728 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1730 m_clientDataItemsType
= clientDataItemsType
;
1733 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1735 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
1738 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1740 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1741 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1744 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
,
1745 const wxArrayStringsAdapter
& items
,
1748 size_t itemsCount
= items
.GetCount();
1749 if ( itemsCount
== 0 )
1752 SInt32 frontLineOrder
= 0;
1754 if ( m_sortOrder
== SortOrder_None
)
1756 // increase the order of the lines to be shifted
1757 unsigned int lines
= MacGetCount();
1758 for ( unsigned int i
= n
; i
< lines
; ++i
)
1760 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1761 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
1765 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1766 frontLineOrder
= iter
->GetOrder();
1770 wxArrayMacDataItemPtr ids
;
1771 ids
.SetCount( itemsCount
);
1773 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
1775 wxMacDataItem
* item
= CreateItem();
1776 item
->SetLabel( items
[i
]);
1778 item
->SetColumn( kMinColumnId
+ column
);
1780 if ( m_sortOrder
== SortOrder_None
)
1781 item
->SetOrder( frontLineOrder
+ 1 + i
);
1786 AddItems( wxMacDataBrowserRootContainer
, ids
);
1789 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
1791 wxMacDataItem
* item
= CreateItem();
1792 item
->SetLabel( text
);
1793 if ( m_sortOrder
== SortOrder_None
)
1795 unsigned int lines
= MacGetCount();
1797 item
->SetOrder( 1 );
1800 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
1801 item
->SetOrder( frontItem
->GetOrder() + 1 );
1804 AddItem( wxMacDataBrowserRootContainer
, item
);
1806 return GetLineFromItem(item
);
1809 void wxMacDataItemBrowserControl::MacClear()
1811 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1812 RemoveAllItems(wxMacDataBrowserRootContainer
);
1815 void wxMacDataItemBrowserControl::MacDeselectAll()
1817 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1818 SetSelectedAllItems( kDataBrowserItemsRemove
);
1821 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
1823 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1824 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1826 if ( IsItemSelected( item
) != select
)
1829 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
1831 SetSelectedItem( item
, kDataBrowserItemsRemove
);
1837 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
1839 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1840 return IsItemSelected( item
);
1843 int wxMacDataItemBrowserControl::MacGetSelection() const
1845 wxMacDataItemPtr first
, last
;
1846 GetSelectionAnchor( &first
, &last
);
1848 if ( first
!= NULL
)
1850 return GetLineFromItem( first
);
1856 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
1858 aSelections
.Empty();
1859 wxArrayMacDataItemPtr selectedItems
;
1860 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
1862 int count
= selectedItems
.GetCount();
1864 for ( int i
= 0; i
< count
; ++i
)
1866 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
1872 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
1874 // as we don't store the strings we only have to issue a redraw
1875 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1876 item
->SetLabel( text
);
1877 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
1880 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
1882 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1883 return item
->GetLabel();
1886 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
1888 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1889 item
->SetData( data
);
1890 // not displayed, therefore no Update infos to DataBrowser
1893 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
1895 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1896 return item
->GetData();
1899 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
1902 GetScrollPosition( &top
, &left
) ;
1903 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1905 // there is a bug in RevealItem that leads to situations
1906 // in large lists, where the item does not get scrolled
1907 // into sight, so we do a pre-scroll if necessary
1909 GetRowHeight( (DataBrowserItemID
) item
, &height
) ;
1910 UInt32 linetop
= n
* ((UInt32
) height
);
1911 UInt32 linebottom
= linetop
+ height
;
1915 if ( linetop
< top
|| linebottom
> (top
+ rect
.bottom
- rect
.top
) )
1916 SetScrollPosition( wxMax( n
-2, 0 ) * ((UInt32
)height
) , left
) ;
1918 RevealItem( item
, kDataBrowserRevealWithoutSelecting
);
1927 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1929 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
1939 Return the generic RGB color space. This is a 'get' function and the caller should
1940 not release the returned value unless the caller retains it first. Usually callers
1941 of this routine will immediately use the returned colorspace with CoreGraphics
1942 so they typically do not need to retain it themselves.
1944 This function creates the generic RGB color space once and hangs onto it so it can
1945 return it whenever this function is called.
1948 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
1950 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
1952 if (genericRGBColorSpace
== NULL
)
1954 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
1957 return genericRGBColorSpace
;
1960 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
1963 HIThemeBrushCreateCGColor( brush
, &color
);
1967 #if wxMAC_USE_QUICKDRAW
1969 static inline void PointFromHIPoint(const HIPoint
& p
, Point
*pt
)
1971 pt
->h
= wx_static_cast(short, p
.x
);
1972 pt
->v
= wx_static_cast(short, p
.y
);
1975 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
1977 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1978 HIViewRef contentView
;
1979 // TODO check toolbar offset
1980 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1981 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1982 PointFromHIPoint(p
, pt
);
1985 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
1987 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1988 HIViewRef contentView
;
1989 // TODO check toolbar offset
1990 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1991 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1992 PointFromHIPoint(p
, pt
);
1995 #endif // wxMAC_USE_QUICKDRAW