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"
40 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
41 #include <AudioToolbox/AudioServices.h>
45 #include <CoreServices/CoreServices.h>
46 #include <Carbon/Carbon.h>
47 #include "wx/mac/private/timer.h"
50 #include "wx/evtloop.h"
51 #include "wx/mac/private.h"
53 #if defined(__MWERKS__) && wxUSE_UNICODE
54 #if __MWERKS__ < 0x4100
61 // our OS version is the same in non GUI and GUI cases
62 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
65 Gestalt(gestaltSystemVersion
, &theSystem
);
67 if ( majorVsn
!= NULL
)
68 *majorVsn
= (theSystem
>> 8);
70 if ( minorVsn
!= NULL
)
71 *minorVsn
= (theSystem
& 0xFF);
73 #if defined( __DARWIN__ )
74 return wxOS_MAC_OSX_DARWIN
;
80 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
82 // TODO : try to find out ...
89 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
90 if ( AudioServicesPlayAlertSound
)
91 AudioServicesPlayAlertSound(kUserPreferredAlert
);
94 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
107 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
109 // We suppose that toolkit version is the same as OS version under Mac
110 wxGetOsVersion(verMaj
, verMin
);
115 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
117 return new wxEventLoop
;
120 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
122 return new wxCarbonTimerImpl(timer
);
125 int gs_wxBusyCursorCount
= 0;
126 extern wxCursor gMacCurrentCursor
;
127 wxCursor gMacStoredActiveCursor
;
129 // Set the cursor to the busy cursor for all windows
130 void wxBeginBusyCursor(const wxCursor
*cursor
)
132 if (gs_wxBusyCursorCount
++ == 0)
134 gMacStoredActiveCursor
= gMacCurrentCursor
;
135 cursor
->MacInstall();
137 wxSetCursor(*cursor
);
139 //else: nothing to do, already set
142 // Restore cursor to normal
143 void wxEndBusyCursor()
145 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
146 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
148 if (--gs_wxBusyCursorCount
== 0)
150 gMacStoredActiveCursor
.MacInstall();
151 gMacStoredActiveCursor
= wxNullCursor
;
153 wxSetCursor(wxNullCursor
);
157 // true if we're between the above two calls
160 return (gs_wxBusyCursorCount
> 0);
167 wxString
wxMacFindFolderNoSeparator( short vol
,
169 Boolean createFolder
)
174 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
176 strDir
= wxMacFSRefToPath( &fsRef
);
182 wxString
wxMacFindFolder( short vol
,
184 Boolean createFolder
)
186 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
193 // Check whether this window wants to process messages, e.g. Stop button
194 // in long calculations.
195 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
201 void wxGetMousePosition( int* x
, int* y
)
203 #if wxMAC_USE_QUICKDRAW
213 // Return true if we have a colour display
214 bool wxColourDisplay()
219 // Returns depth of screen
222 #if wxMAC_USE_QUICKDRAW
223 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
225 SetRect(&globRect
, -32760, -32760, 32760, 32760);
226 GDHandle theMaxDevice
;
228 theMaxDevice
= GetMaxDevice(&globRect
);
229 if (theMaxDevice
!= NULL
)
230 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
238 // Get size of display
239 void wxDisplaySize(int *width
, int *height
)
241 // TODO adapt for multi-displays
242 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
244 *width
= (int)bounds
.size
.width
;
246 *height
= (int)bounds
.size
.height
;
249 void wxDisplaySizeMM(int *width
, int *height
)
251 wxDisplaySize(width
, height
);
252 // on mac 72 is fixed (at least now;-)
253 float cvPt2Mm
= 25.4 / 72;
256 *width
= int( *width
* cvPt2Mm
);
259 *height
= int( *height
* cvPt2Mm
);
262 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
264 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
265 #if wxMAC_USE_QUICKDRAW
268 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
271 *x
= bounds
.origin
.x
;
273 *y
= bounds
.origin
.y
;
275 *width
= bounds
.size
.width
;
277 *height
= bounds
.size
.height
;
280 wxDisplaySize(&w
,&h
);
292 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
298 *width
= r
.right
- r
.left
;
300 *height
= r
.bottom
- r
.top
;
304 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
306 return wxGenericFindWindowAtPoint(pt
);
313 #include <sys/utsname.h>
315 wxString
wxGetOsDescription()
319 return wxString::Format(_T("Mac OS X (%s %s %s)"),
320 wxString::FromAscii(name
.sysname
).c_str(),
321 wxString::FromAscii(name
.release
).c_str(),
322 wxString::FromAscii(name
.machine
).c_str());
326 wxString
wxGetUserHome (const wxString
& user
)
332 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
341 int pos
= p
.Find(':');
342 if ( pos
!= wxNOT_FOUND
)
350 err
= wxMacPathToFSRef( p
, &fsRef
);
353 FSVolumeRefNum vRefNum
;
354 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
357 UInt64 freeBytes
, totalBytes
;
358 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
362 *pTotal
= wxDiskspaceSize_t( totalBytes
);
364 *pFree
= wxDiskspaceSize_t( freeBytes
);
371 #endif // !__DARWIN__
373 //---------------------------------------------------------------------------
374 // wxMac Specific utility functions
375 //---------------------------------------------------------------------------
377 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
379 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
380 int len
= strlen(buf
);
385 memcpy( (char*) &to
[1] , buf
, len
);
388 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
390 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
393 // ----------------------------------------------------------------------------
394 // Common Event Support
395 // ----------------------------------------------------------------------------
399 OSStatus err
= noErr
;
402 // lead sometimes to race conditions, although all calls used should be thread safe ...
403 static wxMacCarbonEvent s_wakeupEvent
;
404 if ( !s_wakeupEvent
.IsValid() )
406 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
407 kEventAttributeNone
);
412 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
414 s_wakeupEvent
.SetCurrentTime();
415 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
416 kEventPriorityHigh
);
419 wxMacCarbonEvent wakeupEvent
;
420 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
421 kEventAttributeNone
);
422 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
423 kEventPriorityHigh
);
431 // ----------------------------------------------------------------------------
432 // Native Struct Conversions
433 // ----------------------------------------------------------------------------
435 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
439 n
->right
= wx
->x
+ wx
->width
;
440 n
->bottom
= wx
->y
+ wx
->height
;
443 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
447 wx
->width
= n
->right
- n
->left
;
448 wx
->height
= n
->bottom
- n
->top
;
451 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
457 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
463 // ----------------------------------------------------------------------------
464 // Carbon Event Support
465 // ----------------------------------------------------------------------------
467 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
469 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
472 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
474 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
477 // ----------------------------------------------------------------------------
478 // Control Access Support
479 // ----------------------------------------------------------------------------
481 #if wxMAC_USE_QUICKDRAW
483 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
485 wxMacControl::wxMacControl()
490 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
494 m_isRootControl
= isRootControl
;
497 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
501 m_controlRef
= control
;
504 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
508 m_controlRef
= (ControlRef
) control
;
511 wxMacControl::~wxMacControl()
515 void wxMacControl::Init()
519 m_needsFocusRect
= false;
520 m_isRootControl
= false;
523 void wxMacControl::Dispose()
525 wxASSERT_MSG( m_controlRef
!= NULL
, wxT("Control Handle already NULL, Dispose called twice ?") );
526 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
528 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
529 // we can have situations when being embedded, where the control gets deleted behind our back, so only
530 // CFRelease if we are safe
531 if ( IsValidControlHandle(m_controlRef
) )
532 CFRelease(m_controlRef
);
536 void wxMacControl::SetReference( URefCon data
)
538 SetControlReference( m_controlRef
, data
);
541 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
543 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
546 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
548 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
551 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
553 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
556 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
558 return SendEventToEventTargetWithOptions( event
,
559 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
562 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
564 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
566 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
568 return SendEvent( event
, inOptions
);
571 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
575 memset( &command
, 0 , sizeof(command
) );
576 command
.commandID
= commandID
;
577 return SendHICommand( command
, inOptions
);
580 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
582 unsigned long finalTicks
;
584 HiliteControl( m_controlRef
, part
);
585 Delay( ticks
, &finalTicks
);
586 HiliteControl( m_controlRef
, kControlNoPart
);
589 SInt32
wxMacControl::GetValue() const
591 return ::GetControl32BitValue( m_controlRef
);
594 SInt32
wxMacControl::GetMaximum() const
596 return ::GetControl32BitMaximum( m_controlRef
);
599 SInt32
wxMacControl::GetMinimum() const
601 return ::GetControl32BitMinimum( m_controlRef
);
604 void wxMacControl::SetValue( SInt32 v
)
606 ::SetControl32BitValue( m_controlRef
, v
);
609 void wxMacControl::SetMinimum( SInt32 v
)
611 ::SetControl32BitMinimum( m_controlRef
, v
);
614 void wxMacControl::SetMaximum( SInt32 v
)
616 ::SetControl32BitMaximum( m_controlRef
, v
);
619 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
621 ::SetControl32BitMinimum( m_controlRef
, minimum
);
622 ::SetControl32BitMaximum( m_controlRef
, maximum
);
623 ::SetControl32BitValue( m_controlRef
, value
);
626 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
628 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
631 bool wxMacControl::HasFocus() const
634 GetKeyboardFocus( GetUserFocusWindow() , &control
);
635 return control
== m_controlRef
;
638 void wxMacControl::SetNeedsFocusRect( bool needs
)
640 m_needsFocusRect
= needs
;
643 bool wxMacControl::NeedsFocusRect() const
645 return m_needsFocusRect
;
648 void wxMacControl::VisibilityChanged(bool WXUNUSED(shown
))
652 void wxMacControl::SuperChangedPosition()
656 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
659 #if wxMAC_USE_CORE_TEXT
660 if ( UMAGetSystemVersion() >= 0x1050 )
662 HIViewPartCode part
= 0;
663 HIThemeTextHorizontalFlush flush
= kHIThemeTextHorizontalFlushDefault
;
664 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
665 flush
= kHIThemeTextHorizontalFlushCenter
;
666 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
667 flush
= kHIThemeTextHorizontalFlushRight
;
668 HIViewSetTextFont( m_controlRef
, part
, (CTFontRef
) font
.MacGetCTFont() );
669 HIViewSetTextHorizontalFlush( m_controlRef
, part
, flush
);
671 if ( foreground
!= *wxBLACK
)
673 ControlFontStyleRec fontStyle
;
674 foreground
.GetRGBColor( &fontStyle
.foreColor
);
675 fontStyle
.flags
= kControlUseForeColorMask
;
676 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
681 #if wxMAC_USE_ATSU_TEXT
682 ControlFontStyleRec fontStyle
;
683 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
685 switch ( font
.MacGetThemeFontID() )
687 case kThemeSmallSystemFont
:
688 fontStyle
.font
= kControlFontSmallSystemFont
;
691 case 109 : // mini font
695 case kThemeSystemFont
:
696 fontStyle
.font
= kControlFontBigSystemFont
;
700 fontStyle
.font
= kControlFontBigSystemFont
;
704 fontStyle
.flags
= kControlUseFontMask
;
708 fontStyle
.font
= font
.MacGetFontNum();
709 fontStyle
.style
= font
.MacGetFontStyle();
710 fontStyle
.size
= font
.MacGetFontSize();
711 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
714 fontStyle
.just
= teJustLeft
;
715 fontStyle
.flags
|= kControlUseJustMask
;
716 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
717 fontStyle
.just
= teJustCenter
;
718 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
719 fontStyle
.just
= teJustRight
;
722 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
723 // won't get grayed out by the system anymore
725 if ( foreground
!= *wxBLACK
)
727 foreground
.GetRGBColor( &fontStyle
.foreColor
);
728 fontStyle
.flags
|= kControlUseForeColorMask
;
731 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
735 void wxMacControl::SetBackgroundColour( const wxColour
&WXUNUSED(col
) )
737 // HITextViewSetBackgroundColor( m_textView , color );
740 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
742 ::SetControl32BitMinimum( m_controlRef
, minimum
);
743 ::SetControl32BitMaximum( m_controlRef
, maximum
);
746 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
749 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
755 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
757 SetControlAction( m_controlRef
, actionProc
);
760 void wxMacControl::SetViewSize( SInt32 viewSize
)
762 SetControlViewSize(m_controlRef
, viewSize
);
765 SInt32
wxMacControl::GetViewSize() const
767 return GetControlViewSize( m_controlRef
);
770 bool wxMacControl::IsVisible() const
772 return IsControlVisible( m_controlRef
);
775 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
777 SetControlVisibility( m_controlRef
, visible
, redraw
);
780 bool wxMacControl::IsEnabled() const
782 return IsControlEnabled( m_controlRef
);
785 bool wxMacControl::IsActive() const
787 return IsControlActive( m_controlRef
);
790 void wxMacControl::Enable( bool enable
)
793 EnableControl( m_controlRef
);
795 DisableControl( m_controlRef
);
798 void wxMacControl::SetDrawingEnabled( bool enable
)
800 HIViewSetDrawingEnabled( m_controlRef
, enable
);
803 bool wxMacControl::GetNeedsDisplay() const
805 return HIViewGetNeedsDisplay( m_controlRef
);
808 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
813 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
816 void wxMacControl::SetNeedsDisplay( Rect
* where
)
823 RgnHandle update
= NewRgn();
824 RectRgn( update
, where
);
825 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
826 DisposeRgn( update
);
829 HIViewSetNeedsDisplay( m_controlRef
, true );
832 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
838 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
839 pt
->x
= (int)hiPoint
.x
;
840 pt
->y
= (int)hiPoint
.y
;
843 void wxMacControl::SetRect( Rect
*r
)
845 //A HIRect is actually a CGRect on OSX - which consists of two structures -
846 //CGPoint and CGSize, which have two floats each
847 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
848 HIViewSetFrame ( m_controlRef
, &hir
);
849 // eventuall we might have to do a SetVisibility( false , true );
850 // before and a SetVisibility( true , true ); after
853 void wxMacControl::GetRect( Rect
*r
)
855 GetControlBounds( m_controlRef
, r
);
858 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
860 GetControlBounds( m_controlRef
, r
) ;
862 WindowRef tlwref
= GetControlOwner( m_controlRef
) ;
864 wxNonOwnedWindow
* tlwwx
= wxFindWinFromMacWindow( tlwref
) ;
867 ControlRef rootControl
= tlwwx
->GetPeer()->GetControlRef() ;
868 HIPoint hiPoint
= CGPointMake( 0 , 0 ) ;
869 HIViewConvertPoint( &hiPoint
, HIViewGetSuperview(m_controlRef
) , rootControl
) ;
870 OffsetRect( r
, (short) hiPoint
.x
, (short) hiPoint
.y
) ;
874 void wxMacControl::GetBestRect( Rect
*r
)
876 short baselineoffset
;
878 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
881 void wxMacControl::SetLabel( const wxString
&title
)
883 wxFontEncoding encoding
;
886 encoding
= m_font
.GetEncoding();
888 encoding
= wxFont::GetDefaultEncoding();
890 SetControlTitleWithCFString( m_controlRef
, wxCFStringRef( title
, encoding
) );
893 void wxMacControl::GetFeatures( UInt32
* features
)
895 GetControlFeatures( m_controlRef
, features
);
898 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
900 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
904 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
906 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
907 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
910 // SetNeedsDisplay would not invalidate the children
911 static void InvalidateControlAndChildren( HIViewRef control
)
913 HIViewSetNeedsDisplay( control
, true );
914 UInt16 childrenCount
= 0;
915 OSStatus err
= CountSubControls( control
, &childrenCount
);
916 if ( err
== errControlIsNotEmbedder
)
919 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
921 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
925 err
= GetIndexedSubControl( control
, i
, & child
);
926 if ( err
== errControlIsNotEmbedder
)
929 InvalidateControlAndChildren( child
);
933 void wxMacControl::InvalidateWithChildren()
935 InvalidateControlAndChildren( m_controlRef
);
938 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
940 wxASSERT( r
!= NULL
);
942 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
943 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
946 OSType wxMacCreator
= 'WXMC';
947 OSType wxMacControlProperty
= 'MCCT';
949 void wxMacControl::SetReferenceInNativeControl()
952 verify_noerr( SetControlProperty ( m_controlRef
,
953 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
956 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
958 wxMacControl
* ctl
= NULL
;
959 ByteCount actualSize
;
960 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
961 &actualSize
, &ctl
) == noErr
)
968 // ============================================================================
969 // DataBrowser Wrapper
970 // ============================================================================
972 // basing on DataBrowserItemIDs
975 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
977 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
979 DataBrowserItemID itemID
,
980 DataBrowserItemNotification message
,
981 DataBrowserItemDataRef itemData
)
983 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
986 ctl
->ItemNotification(itemID
, message
, itemData
);
990 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
992 DataBrowserItemID itemID
,
993 DataBrowserPropertyID property
,
994 DataBrowserItemDataRef itemData
,
995 Boolean changeValue
)
997 OSStatus err
= errDataBrowserPropertyNotSupported
;
998 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1001 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1006 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1008 DataBrowserItemID itemOneID
,
1009 DataBrowserItemID itemTwoID
,
1010 DataBrowserPropertyID sortProperty
)
1012 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1015 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1020 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1021 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1022 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1024 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
1027 long WXUNUSED(style
))
1028 : wxMacControl( peer
)
1030 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1031 OSStatus err
= ::CreateDataBrowserControl(
1032 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1033 &bounds
, kDataBrowserListView
, &m_controlRef
);
1034 SetReferenceInNativeControl();
1035 verify_noerr( err
);
1036 if ( gDataBrowserItemCompareUPP
== NULL
)
1037 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1038 if ( gDataBrowserItemDataUPP
== NULL
)
1039 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1040 if ( gDataBrowserItemNotificationUPP
== NULL
)
1042 gDataBrowserItemNotificationUPP
=
1043 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1046 DataBrowserCallbacks callbacks
;
1047 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1049 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1050 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1051 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1052 SetCallbacks( &callbacks
);
1056 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1058 DataBrowserItemState state
,
1059 ItemCount
*numItems
) const
1061 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1064 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1066 DataBrowserItemState state
,
1069 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1072 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1074 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1077 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1078 DataBrowserTableViewColumnIndex position
)
1080 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1083 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1084 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1087 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1089 DataBrowserTableViewColumnID id
;
1090 GetColumnIDFromIndex( position
, &id
);
1091 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1094 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1096 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1099 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1101 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1104 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1106 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1109 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1111 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1114 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1116 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1119 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1121 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1124 OSStatus
wxMacDataBrowserControl::UpdateItems(
1125 DataBrowserItemID container
,
1127 const DataBrowserItemID
*items
,
1128 DataBrowserPropertyID preSortProperty
,
1129 DataBrowserPropertyID propertyID
) const
1131 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1134 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1136 return IsDataBrowserItemSelected( m_controlRef
, item
);
1139 OSStatus
wxMacDataBrowserControl::AddItems(
1140 DataBrowserItemID container
,
1142 const DataBrowserItemID
*items
,
1143 DataBrowserPropertyID preSortProperty
)
1145 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1148 OSStatus
wxMacDataBrowserControl::RemoveItems(
1149 DataBrowserItemID container
,
1151 const DataBrowserItemID
*items
,
1152 DataBrowserPropertyID preSortProperty
)
1154 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1157 OSStatus
wxMacDataBrowserControl::RevealItem(
1158 DataBrowserItemID item
,
1159 DataBrowserPropertyID propertyID
,
1160 DataBrowserRevealOptions options
) const
1162 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1165 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1167 const DataBrowserItemID
*items
,
1168 DataBrowserSetOption operation
)
1170 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1173 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1175 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1178 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1180 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1183 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1185 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1188 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1190 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1193 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1195 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1198 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1200 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1203 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1205 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1208 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1210 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1213 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1215 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1218 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1220 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1223 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1225 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1228 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1230 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1233 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1234 DataBrowserTableViewColumnIndex
*position
) const
1236 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1239 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1241 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1244 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1246 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1249 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1251 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1254 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1256 return GetDataBrowserSortProperty( m_controlRef
, column
);
1259 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1261 return SetDataBrowserSortProperty( m_controlRef
, column
);
1264 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1266 return GetDataBrowserSortOrder( m_controlRef
, order
);
1269 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1271 return SetDataBrowserSortOrder( m_controlRef
, order
);
1274 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1275 DataBrowserPropertyFlags
*flags
) const
1277 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1280 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1281 DataBrowserPropertyFlags flags
)
1283 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1286 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1287 DataBrowserListViewHeaderDesc
*desc
) const
1289 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1292 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1293 DataBrowserListViewHeaderDesc
*desc
)
1295 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1298 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1299 Boolean expandableRows
)
1301 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1304 // ============================================================================
1305 // Higher-level Databrowser
1306 // ============================================================================
1308 // basing on data item objects
1311 wxMacDataItem::wxMacDataItem()
1316 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1319 wxMacDataItem::~wxMacDataItem()
1323 void wxMacDataItem::SetOrder( SInt32 order
)
1328 SInt32
wxMacDataItem::GetOrder() const
1333 void wxMacDataItem::SetData( void* data
)
1338 void* wxMacDataItem::GetData() const
1343 short wxMacDataItem::GetColumn()
1348 void wxMacDataItem::SetColumn( short col
)
1353 void wxMacDataItem::SetLabel( const wxString
& str
)
1356 m_cfLabel
= wxCFStringRef( str
, wxLocale::GetSystemEncoding());
1359 const wxString
& wxMacDataItem::GetLabel() const
1364 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1365 const wxMacDataItem
* rhs
,
1366 DataBrowserPropertyID sortProperty
) const
1368 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1369 bool retval
= false;
1371 if ( sortProperty
== m_colId
){
1372 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1375 else if ( sortProperty
== kNumericOrderColumnId
)
1376 retval
= m_order
< otherItem
->m_order
;
1381 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1382 DataBrowserPropertyID property
,
1383 DataBrowserItemDataRef itemData
,
1386 OSStatus err
= errDataBrowserPropertyNotSupported
;
1389 if ( property
== m_colId
){
1390 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1393 else if ( property
== kNumericOrderColumnId
){
1394 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1404 // no editable props here
1413 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1414 DataBrowserItemNotification
WXUNUSED(message
),
1415 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
1419 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1421 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1422 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1424 m_suppressSelection
= false;
1425 m_sortOrder
= SortOrder_None
;
1426 m_clientDataItemsType
= wxClientData_None
;
1429 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1431 return new wxMacDataItem();
1434 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1436 m_former
= browser
->SuppressSelection(true);
1437 m_browser
= browser
;
1440 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1442 m_browser
->SuppressSelection(m_former
);
1445 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1447 bool former
= m_suppressSelection
;
1448 m_suppressSelection
= suppress
;
1453 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1454 DataBrowserItemID itemTwoID
,
1455 DataBrowserPropertyID sortProperty
)
1457 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1458 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1459 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1462 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1463 const wxMacDataItem
* itemTwo
,
1464 DataBrowserPropertyID sortProperty
)
1466 Boolean retval
= false;
1467 if ( itemOne
!= NULL
)
1468 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1472 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1473 DataBrowserItemID itemID
,
1474 DataBrowserPropertyID property
,
1475 DataBrowserItemDataRef itemData
,
1476 Boolean changeValue
)
1478 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1479 return GetSetItemData(item
, property
, itemData
, changeValue
);
1482 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1483 wxMacDataItem
* item
,
1484 DataBrowserPropertyID property
,
1485 DataBrowserItemDataRef itemData
,
1486 Boolean changeValue
)
1488 OSStatus err
= errDataBrowserPropertyNotSupported
;
1491 case kDataBrowserContainerIsClosableProperty
:
1492 case kDataBrowserContainerIsSortableProperty
:
1493 case kDataBrowserContainerIsOpenableProperty
:
1494 // right now default behaviour on these
1498 if ( item
!= NULL
){
1499 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1507 void wxMacDataItemBrowserControl::ItemNotification(
1508 DataBrowserItemID itemID
,
1509 DataBrowserItemNotification message
,
1510 DataBrowserItemDataRef itemData
)
1512 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1513 ItemNotification( item
, message
, itemData
);
1516 void wxMacDataItemBrowserControl::ItemNotification(
1517 const wxMacDataItem
* item
,
1518 DataBrowserItemNotification message
,
1519 DataBrowserItemDataRef itemData
)
1522 item
->Notification( this, message
, itemData
);
1525 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1526 bool recurse
, DataBrowserItemState state
) const
1528 ItemCount numItems
= 0;
1529 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1530 recurse
, state
, &numItems
) );
1534 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1535 bool recurse
) const
1537 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1541 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1542 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1544 Handle handle
= NewHandle(0);
1545 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1546 recurse
, state
, handle
) );
1548 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1550 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1551 for ( int i
= 0; i
< itemCount
; ++i
)
1553 items
.Add(itemsArray
[i
]);
1556 DisposeHandle( handle
);
1559 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1561 DataBrowserTableViewRowIndex row
;
1562 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1563 wxCHECK( err
== noErr
, (unsigned)-1 );
1567 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1569 DataBrowserItemID id
;
1570 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1571 wxCHECK( err
== noErr
, NULL
);
1572 return (wxMacDataItem
*) id
;
1575 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1576 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1578 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1579 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1582 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1583 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1585 unsigned int noItems
= itemArray
.GetCount();
1586 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1587 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1588 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1590 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1591 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1595 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1596 const wxString
& title
, SInt16 just
, int defaultWidth
)
1598 DataBrowserListViewColumnDesc columnDesc
;
1599 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1600 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1602 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1603 kControlUseFontMask
| kControlUseJustMask
;
1605 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1606 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1607 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1608 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1610 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1611 // defined for other modes?
1614 enc
= m_font
.GetEncoding();
1616 enc
= wxLocale::GetSystemEncoding();
1617 wxCFStringRef
cfTitle( title
, enc
);
1618 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1620 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1621 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1623 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1624 columnDesc
.propertyDesc
.propertyType
= colType
;
1625 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1626 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1627 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1629 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1631 if (defaultWidth
> 0){
1632 SetColumnWidth(colId
, defaultWidth
);
1637 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1639 DataBrowserPropertyID id
;
1640 GetColumnIDFromIndex(colId
, &id
);
1641 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1644 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1646 DataBrowserPropertyID id
;
1647 GetColumnIDFromIndex(colId
, &id
);
1649 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1653 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1655 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1656 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1659 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1661 unsigned int noItems
= itemArray
.GetCount();
1662 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1663 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1664 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1666 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1667 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1671 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1673 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1674 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1675 verify_noerr( err
);
1678 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1680 unsigned int noItems
= itemArray
.GetCount();
1681 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1682 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1683 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1685 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1686 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1687 verify_noerr( err
);
1691 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1693 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1694 verify_noerr( err
);
1697 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1699 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1702 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1704 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1707 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1709 unsigned int noItems
= itemArray
.GetCount();
1710 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1711 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1712 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1714 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1718 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1720 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1723 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1725 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1728 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1730 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1733 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1735 return m_clientDataItemsType
;
1737 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1739 m_clientDataItemsType
= clientDataItemsType
;
1742 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1744 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
1747 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1749 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1750 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1753 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
,
1754 const wxArrayStringsAdapter
& items
,
1757 size_t itemsCount
= items
.GetCount();
1758 if ( itemsCount
== 0 )
1761 SInt32 frontLineOrder
= 0;
1763 if ( m_sortOrder
== SortOrder_None
)
1765 // increase the order of the lines to be shifted
1766 unsigned int lines
= MacGetCount();
1767 for ( unsigned int i
= n
; i
< lines
; ++i
)
1769 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1770 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
1774 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1775 frontLineOrder
= iter
->GetOrder();
1779 wxArrayMacDataItemPtr ids
;
1780 ids
.SetCount( itemsCount
);
1782 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
1784 wxMacDataItem
* item
= CreateItem();
1785 item
->SetLabel( items
[i
]);
1787 item
->SetColumn( kMinColumnId
+ column
);
1789 if ( m_sortOrder
== SortOrder_None
)
1790 item
->SetOrder( frontLineOrder
+ 1 + i
);
1795 AddItems( wxMacDataBrowserRootContainer
, ids
);
1798 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
1800 wxMacDataItem
* item
= CreateItem();
1801 item
->SetLabel( text
);
1802 if ( m_sortOrder
== SortOrder_None
)
1804 unsigned int lines
= MacGetCount();
1806 item
->SetOrder( 1 );
1809 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
1810 item
->SetOrder( frontItem
->GetOrder() + 1 );
1813 AddItem( wxMacDataBrowserRootContainer
, item
);
1815 return GetLineFromItem(item
);
1818 void wxMacDataItemBrowserControl::MacClear()
1820 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1821 RemoveAllItems(wxMacDataBrowserRootContainer
);
1824 void wxMacDataItemBrowserControl::MacDeselectAll()
1826 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1827 SetSelectedAllItems( kDataBrowserItemsRemove
);
1830 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
1832 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1833 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1835 if ( IsItemSelected( item
) != select
)
1838 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
1840 SetSelectedItem( item
, kDataBrowserItemsRemove
);
1846 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
1848 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1849 return IsItemSelected( item
);
1852 int wxMacDataItemBrowserControl::MacGetSelection() const
1854 wxMacDataItemPtr first
, last
;
1855 GetSelectionAnchor( &first
, &last
);
1857 if ( first
!= NULL
)
1859 return GetLineFromItem( first
);
1865 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
1867 aSelections
.Empty();
1868 wxArrayMacDataItemPtr selectedItems
;
1869 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
1871 int count
= selectedItems
.GetCount();
1873 for ( int i
= 0; i
< count
; ++i
)
1875 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
1881 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
1883 // as we don't store the strings we only have to issue a redraw
1884 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1885 item
->SetLabel( text
);
1886 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
1889 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
1891 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1892 return item
->GetLabel();
1895 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
1897 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1898 item
->SetData( data
);
1899 // not displayed, therefore no Update infos to DataBrowser
1902 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
1904 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1905 return item
->GetData();
1908 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
1911 GetScrollPosition( &top
, &left
) ;
1912 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1914 // there is a bug in RevealItem that leads to situations
1915 // in large lists, where the item does not get scrolled
1916 // into sight, so we do a pre-scroll if necessary
1918 GetRowHeight( (DataBrowserItemID
) item
, &height
) ;
1919 UInt32 linetop
= n
* ((UInt32
) height
);
1920 UInt32 linebottom
= linetop
+ height
;
1924 if ( linetop
< top
|| linebottom
> (top
+ rect
.bottom
- rect
.top
) )
1925 SetScrollPosition( wxMax( n
-2, 0 ) * ((UInt32
)height
) , left
) ;
1927 RevealItem( item
, kDataBrowserRevealWithoutSelecting
);
1936 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1938 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
1948 Return the generic RGB color space. This is a 'get' function and the caller should
1949 not release the returned value unless the caller retains it first. Usually callers
1950 of this routine will immediately use the returned colorspace with CoreGraphics
1951 so they typically do not need to retain it themselves.
1953 This function creates the generic RGB color space once and hangs onto it so it can
1954 return it whenever this function is called.
1957 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
1959 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
1961 if (genericRGBColorSpace
== NULL
)
1963 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
1966 return genericRGBColorSpace
;
1969 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
1972 HIThemeBrushCreateCGColor( brush
, &color
);
1976 #if wxMAC_USE_QUICKDRAW
1978 static inline void PointFromHIPoint(const HIPoint
& p
, Point
*pt
)
1980 pt
->h
= wx_static_cast(short, p
.x
);
1981 pt
->v
= wx_static_cast(short, p
.y
);
1984 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
1986 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1987 HIViewRef contentView
;
1988 // TODO check toolbar offset
1989 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1990 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1991 PointFromHIPoint(p
, pt
);
1994 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
1996 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1997 HIViewRef contentView
;
1998 // TODO check toolbar offset
1999 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2000 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2001 PointFromHIPoint(p
, pt
);
2004 #endif // wxMAC_USE_QUICKDRAW