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()
320 return wxString::Format(_T("Mac OS X (%s %s %s)"),
321 wxString::FromAscii(name
.sysname
).c_str(),
322 wxString::FromAscii(name
.release
).c_str(),
323 wxString::FromAscii(name
.machine
).c_str());
327 wxString
wxGetUserHome (const wxString
& user
)
333 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
342 int pos
= p
.Find(':');
343 if ( pos
!= wxNOT_FOUND
)
351 err
= wxMacPathToFSRef( p
, &fsRef
);
354 FSVolumeRefNum vRefNum
;
355 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
358 UInt64 freeBytes
, totalBytes
;
359 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
363 *pTotal
= wxDiskspaceSize_t( totalBytes
);
365 *pFree
= wxDiskspaceSize_t( freeBytes
);
372 #endif // !__DARWIN__
374 //---------------------------------------------------------------------------
375 // wxMac Specific utility functions
376 //---------------------------------------------------------------------------
378 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
380 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
381 int len
= strlen(buf
);
386 memcpy( (char*) &to
[1] , buf
, len
);
389 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
391 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
394 // ----------------------------------------------------------------------------
395 // Common Event Support
396 // ----------------------------------------------------------------------------
400 OSStatus err
= noErr
;
403 // lead sometimes to race conditions, although all calls used should be thread safe ...
404 static wxMacCarbonEvent s_wakeupEvent
;
405 if ( !s_wakeupEvent
.IsValid() )
407 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
408 kEventAttributeNone
);
413 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
415 s_wakeupEvent
.SetCurrentTime();
416 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
417 kEventPriorityHigh
);
420 wxMacCarbonEvent wakeupEvent
;
421 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
422 kEventAttributeNone
);
423 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
424 kEventPriorityHigh
);
432 // ----------------------------------------------------------------------------
433 // Native Struct Conversions
434 // ----------------------------------------------------------------------------
436 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
440 n
->right
= wx
->x
+ wx
->width
;
441 n
->bottom
= wx
->y
+ wx
->height
;
444 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
448 wx
->width
= n
->right
- n
->left
;
449 wx
->height
= n
->bottom
- n
->top
;
452 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
458 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
464 // ----------------------------------------------------------------------------
465 // Carbon Event Support
466 // ----------------------------------------------------------------------------
468 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
470 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
473 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
475 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
478 // ----------------------------------------------------------------------------
479 // Control Access Support
480 // ----------------------------------------------------------------------------
482 #if wxMAC_USE_QUICKDRAW
484 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
486 wxMacControl::wxMacControl()
491 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
495 m_isRootControl
= isRootControl
;
498 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
502 m_controlRef
= control
;
505 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
509 m_controlRef
= (ControlRef
) control
;
512 wxMacControl::~wxMacControl()
516 void wxMacControl::Init()
520 m_needsFocusRect
= false;
521 m_isRootControl
= false;
524 void wxMacControl::Dispose()
526 wxASSERT_MSG( m_controlRef
!= NULL
, wxT("Control Handle already NULL, Dispose called twice ?") );
527 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
529 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
530 // we can have situations when being embedded, where the control gets deleted behind our back, so only
531 // CFRelease if we are safe
532 if ( IsValidControlHandle(m_controlRef
) )
533 CFRelease(m_controlRef
);
537 void wxMacControl::SetReference( URefCon data
)
539 SetControlReference( m_controlRef
, data
);
542 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
544 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
547 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
549 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
552 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
554 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
557 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
559 return SendEventToEventTargetWithOptions( event
,
560 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
563 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
565 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
567 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
569 return SendEvent( event
, inOptions
);
572 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
576 memset( &command
, 0 , sizeof(command
) );
577 command
.commandID
= commandID
;
578 return SendHICommand( command
, inOptions
);
581 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
583 unsigned long finalTicks
;
585 HiliteControl( m_controlRef
, part
);
586 Delay( ticks
, &finalTicks
);
587 HiliteControl( m_controlRef
, kControlNoPart
);
590 SInt32
wxMacControl::GetValue() const
592 return ::GetControl32BitValue( m_controlRef
);
595 SInt32
wxMacControl::GetMaximum() const
597 return ::GetControl32BitMaximum( m_controlRef
);
600 SInt32
wxMacControl::GetMinimum() const
602 return ::GetControl32BitMinimum( m_controlRef
);
605 void wxMacControl::SetValue( SInt32 v
)
607 ::SetControl32BitValue( m_controlRef
, v
);
610 void wxMacControl::SetMinimum( SInt32 v
)
612 ::SetControl32BitMinimum( m_controlRef
, v
);
615 void wxMacControl::SetMaximum( SInt32 v
)
617 ::SetControl32BitMaximum( m_controlRef
, v
);
620 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
622 ::SetControl32BitMinimum( m_controlRef
, minimum
);
623 ::SetControl32BitMaximum( m_controlRef
, maximum
);
624 ::SetControl32BitValue( m_controlRef
, value
);
627 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
629 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
632 bool wxMacControl::HasFocus() const
635 GetKeyboardFocus( GetUserFocusWindow() , &control
);
636 return control
== m_controlRef
;
639 void wxMacControl::SetNeedsFocusRect( bool needs
)
641 m_needsFocusRect
= needs
;
644 bool wxMacControl::NeedsFocusRect() const
646 return m_needsFocusRect
;
649 void wxMacControl::VisibilityChanged(bool WXUNUSED(shown
))
653 void wxMacControl::SuperChangedPosition()
657 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
660 #if wxMAC_USE_CORE_TEXT
661 if ( UMAGetSystemVersion() >= 0x1050 )
663 HIViewPartCode part
= 0;
664 HIThemeTextHorizontalFlush flush
= kHIThemeTextHorizontalFlushDefault
;
665 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
666 flush
= kHIThemeTextHorizontalFlushCenter
;
667 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
668 flush
= kHIThemeTextHorizontalFlushRight
;
669 HIViewSetTextFont( m_controlRef
, part
, (CTFontRef
) font
.MacGetCTFont() );
670 HIViewSetTextHorizontalFlush( m_controlRef
, part
, flush
);
672 if ( foreground
!= *wxBLACK
)
674 ControlFontStyleRec fontStyle
;
675 foreground
.GetRGBColor( &fontStyle
.foreColor
);
676 fontStyle
.flags
= kControlUseForeColorMask
;
677 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
682 #if wxMAC_USE_ATSU_TEXT
683 ControlFontStyleRec fontStyle
;
684 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
686 switch ( font
.MacGetThemeFontID() )
688 case kThemeSmallSystemFont
:
689 fontStyle
.font
= kControlFontSmallSystemFont
;
692 case 109 : // mini font
696 case kThemeSystemFont
:
697 fontStyle
.font
= kControlFontBigSystemFont
;
701 fontStyle
.font
= kControlFontBigSystemFont
;
705 fontStyle
.flags
= kControlUseFontMask
;
709 fontStyle
.font
= font
.MacGetFontNum();
710 fontStyle
.style
= font
.MacGetFontStyle();
711 fontStyle
.size
= font
.MacGetFontSize();
712 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
715 fontStyle
.just
= teJustLeft
;
716 fontStyle
.flags
|= kControlUseJustMask
;
717 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
718 fontStyle
.just
= teJustCenter
;
719 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
720 fontStyle
.just
= teJustRight
;
723 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
724 // won't get grayed out by the system anymore
726 if ( foreground
!= *wxBLACK
)
728 foreground
.GetRGBColor( &fontStyle
.foreColor
);
729 fontStyle
.flags
|= kControlUseForeColorMask
;
732 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
736 void wxMacControl::SetBackgroundColour( const wxColour
&WXUNUSED(col
) )
738 // HITextViewSetBackgroundColor( m_textView , color );
741 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
743 ::SetControl32BitMinimum( m_controlRef
, minimum
);
744 ::SetControl32BitMaximum( m_controlRef
, maximum
);
747 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
750 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
756 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
758 SetControlAction( m_controlRef
, actionProc
);
761 void wxMacControl::SetViewSize( SInt32 viewSize
)
763 SetControlViewSize(m_controlRef
, viewSize
);
766 SInt32
wxMacControl::GetViewSize() const
768 return GetControlViewSize( m_controlRef
);
771 bool wxMacControl::IsVisible() const
773 return IsControlVisible( m_controlRef
);
776 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
778 SetControlVisibility( m_controlRef
, visible
, redraw
);
781 bool wxMacControl::IsEnabled() const
783 return IsControlEnabled( m_controlRef
);
786 bool wxMacControl::IsActive() const
788 return IsControlActive( m_controlRef
);
791 void wxMacControl::Enable( bool enable
)
794 EnableControl( m_controlRef
);
796 DisableControl( m_controlRef
);
799 void wxMacControl::SetDrawingEnabled( bool enable
)
801 HIViewSetDrawingEnabled( m_controlRef
, enable
);
804 bool wxMacControl::GetNeedsDisplay() const
806 return HIViewGetNeedsDisplay( m_controlRef
);
809 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
814 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
817 void wxMacControl::SetNeedsDisplay( Rect
* where
)
824 RgnHandle update
= NewRgn();
825 RectRgn( update
, where
);
826 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
827 DisposeRgn( update
);
830 HIViewSetNeedsDisplay( m_controlRef
, true );
833 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
839 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
840 pt
->x
= (int)hiPoint
.x
;
841 pt
->y
= (int)hiPoint
.y
;
844 void wxMacControl::SetRect( Rect
*r
)
846 //A HIRect is actually a CGRect on OSX - which consists of two structures -
847 //CGPoint and CGSize, which have two floats each
848 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
849 HIViewSetFrame ( m_controlRef
, &hir
);
850 // eventuall we might have to do a SetVisibility( false , true );
851 // before and a SetVisibility( true , true ); after
854 void wxMacControl::GetRect( Rect
*r
)
856 GetControlBounds( m_controlRef
, r
);
859 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
861 GetControlBounds( m_controlRef
, r
) ;
863 WindowRef tlwref
= GetControlOwner( m_controlRef
) ;
865 wxTopLevelWindowMac
* tlwwx
= wxFindWinFromMacWindow( tlwref
) ;
868 ControlRef rootControl
= tlwwx
->GetPeer()->GetControlRef() ;
869 HIPoint hiPoint
= CGPointMake( 0 , 0 ) ;
870 HIViewConvertPoint( &hiPoint
, HIViewGetSuperview(m_controlRef
) , rootControl
) ;
871 OffsetRect( r
, (short) hiPoint
.x
, (short) hiPoint
.y
) ;
875 void wxMacControl::GetBestRect( Rect
*r
)
877 short baselineoffset
;
879 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
882 void wxMacControl::SetLabel( const wxString
&title
)
884 wxFontEncoding encoding
;
887 encoding
= m_font
.GetEncoding();
889 encoding
= wxFont::GetDefaultEncoding();
891 SetControlTitleWithCFString( m_controlRef
, wxCFStringRef( title
, encoding
) );
894 void wxMacControl::GetFeatures( UInt32
* features
)
896 GetControlFeatures( m_controlRef
, features
);
899 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
901 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
905 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
907 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
908 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
911 // SetNeedsDisplay would not invalidate the children
912 static void InvalidateControlAndChildren( HIViewRef control
)
914 HIViewSetNeedsDisplay( control
, true );
915 UInt16 childrenCount
= 0;
916 OSStatus err
= CountSubControls( control
, &childrenCount
);
917 if ( err
== errControlIsNotEmbedder
)
920 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
922 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
926 err
= GetIndexedSubControl( control
, i
, & child
);
927 if ( err
== errControlIsNotEmbedder
)
930 InvalidateControlAndChildren( child
);
934 void wxMacControl::InvalidateWithChildren()
936 InvalidateControlAndChildren( m_controlRef
);
939 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
941 wxASSERT( r
!= NULL
);
943 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
944 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
947 OSType wxMacCreator
= 'WXMC';
948 OSType wxMacControlProperty
= 'MCCT';
950 void wxMacControl::SetReferenceInNativeControl()
953 verify_noerr( SetControlProperty ( m_controlRef
,
954 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
957 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
959 wxMacControl
* ctl
= NULL
;
960 ByteCount actualSize
;
961 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
962 &actualSize
, &ctl
) == noErr
)
969 // ============================================================================
970 // DataBrowser Wrapper
971 // ============================================================================
973 // basing on DataBrowserItemIDs
976 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
978 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
980 DataBrowserItemID itemID
,
981 DataBrowserItemNotification message
,
982 DataBrowserItemDataRef itemData
)
984 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
987 ctl
->ItemNotification(itemID
, message
, itemData
);
991 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
993 DataBrowserItemID itemID
,
994 DataBrowserPropertyID property
,
995 DataBrowserItemDataRef itemData
,
996 Boolean changeValue
)
998 OSStatus err
= errDataBrowserPropertyNotSupported
;
999 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1002 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1007 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1009 DataBrowserItemID itemOneID
,
1010 DataBrowserItemID itemTwoID
,
1011 DataBrowserPropertyID sortProperty
)
1013 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1016 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1021 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1022 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1023 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1025 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
1028 long WXUNUSED(style
))
1029 : wxMacControl( peer
)
1031 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1032 OSStatus err
= ::CreateDataBrowserControl(
1033 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1034 &bounds
, kDataBrowserListView
, &m_controlRef
);
1035 SetReferenceInNativeControl();
1036 verify_noerr( err
);
1037 if ( gDataBrowserItemCompareUPP
== NULL
)
1038 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1039 if ( gDataBrowserItemDataUPP
== NULL
)
1040 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1041 if ( gDataBrowserItemNotificationUPP
== NULL
)
1043 gDataBrowserItemNotificationUPP
=
1044 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1047 DataBrowserCallbacks callbacks
;
1048 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1050 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1051 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1052 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1053 SetCallbacks( &callbacks
);
1057 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1059 DataBrowserItemState state
,
1060 ItemCount
*numItems
) const
1062 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1065 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1067 DataBrowserItemState state
,
1070 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1073 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1075 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1078 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1079 DataBrowserTableViewColumnIndex position
)
1081 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1084 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1085 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1088 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1090 DataBrowserTableViewColumnID id
;
1091 GetColumnIDFromIndex( position
, &id
);
1092 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1095 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1097 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1100 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1102 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1105 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1107 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1110 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1112 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1115 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1117 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1120 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1122 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1125 OSStatus
wxMacDataBrowserControl::UpdateItems(
1126 DataBrowserItemID container
,
1128 const DataBrowserItemID
*items
,
1129 DataBrowserPropertyID preSortProperty
,
1130 DataBrowserPropertyID propertyID
) const
1132 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1135 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1137 return IsDataBrowserItemSelected( m_controlRef
, item
);
1140 OSStatus
wxMacDataBrowserControl::AddItems(
1141 DataBrowserItemID container
,
1143 const DataBrowserItemID
*items
,
1144 DataBrowserPropertyID preSortProperty
)
1146 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1149 OSStatus
wxMacDataBrowserControl::RemoveItems(
1150 DataBrowserItemID container
,
1152 const DataBrowserItemID
*items
,
1153 DataBrowserPropertyID preSortProperty
)
1155 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1158 OSStatus
wxMacDataBrowserControl::RevealItem(
1159 DataBrowserItemID item
,
1160 DataBrowserPropertyID propertyID
,
1161 DataBrowserRevealOptions options
) const
1163 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1166 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1168 const DataBrowserItemID
*items
,
1169 DataBrowserSetOption operation
)
1171 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1174 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1176 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1179 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1181 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1184 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1186 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1189 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1191 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1194 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1196 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1199 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1201 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1204 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1206 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1209 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1211 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1214 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1216 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1219 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1221 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1224 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1226 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1229 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1231 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1234 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1235 DataBrowserTableViewColumnIndex
*position
) const
1237 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1240 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1242 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1245 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1247 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1250 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1252 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1255 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1257 return GetDataBrowserSortProperty( m_controlRef
, column
);
1260 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1262 return SetDataBrowserSortProperty( m_controlRef
, column
);
1265 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1267 return GetDataBrowserSortOrder( m_controlRef
, order
);
1270 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1272 return SetDataBrowserSortOrder( m_controlRef
, order
);
1275 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1276 DataBrowserPropertyFlags
*flags
) const
1278 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1281 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1282 DataBrowserPropertyFlags flags
)
1284 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1287 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1288 DataBrowserListViewHeaderDesc
*desc
) const
1290 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1293 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1294 DataBrowserListViewHeaderDesc
*desc
)
1296 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1299 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1300 Boolean expandableRows
)
1302 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1305 // ============================================================================
1306 // Higher-level Databrowser
1307 // ============================================================================
1309 // basing on data item objects
1312 wxMacDataItem::wxMacDataItem()
1317 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1320 wxMacDataItem::~wxMacDataItem()
1324 void wxMacDataItem::SetOrder( SInt32 order
)
1329 SInt32
wxMacDataItem::GetOrder() const
1334 void wxMacDataItem::SetData( void* data
)
1339 void* wxMacDataItem::GetData() const
1344 short wxMacDataItem::GetColumn()
1349 void wxMacDataItem::SetColumn( short col
)
1354 void wxMacDataItem::SetLabel( const wxString
& str
)
1357 m_cfLabel
= wxCFStringRef( str
, wxLocale::GetSystemEncoding());
1360 const wxString
& wxMacDataItem::GetLabel() const
1365 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1366 const wxMacDataItem
* rhs
,
1367 DataBrowserPropertyID sortProperty
) const
1369 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1370 bool retval
= false;
1372 if ( sortProperty
== m_colId
){
1373 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1376 else if ( sortProperty
== kNumericOrderColumnId
)
1377 retval
= m_order
< otherItem
->m_order
;
1382 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1383 DataBrowserPropertyID property
,
1384 DataBrowserItemDataRef itemData
,
1387 OSStatus err
= errDataBrowserPropertyNotSupported
;
1390 if ( property
== m_colId
){
1391 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1394 else if ( property
== kNumericOrderColumnId
){
1395 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1405 // no editable props here
1414 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1415 DataBrowserItemNotification
WXUNUSED(message
),
1416 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
1420 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1422 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1423 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1425 m_suppressSelection
= false;
1426 m_sortOrder
= SortOrder_None
;
1427 m_clientDataItemsType
= wxClientData_None
;
1430 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1432 return new wxMacDataItem();
1435 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1437 m_former
= browser
->SuppressSelection(true);
1438 m_browser
= browser
;
1441 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1443 m_browser
->SuppressSelection(m_former
);
1446 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1448 bool former
= m_suppressSelection
;
1449 m_suppressSelection
= suppress
;
1454 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1455 DataBrowserItemID itemTwoID
,
1456 DataBrowserPropertyID sortProperty
)
1458 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1459 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1460 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1463 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1464 const wxMacDataItem
* itemTwo
,
1465 DataBrowserPropertyID sortProperty
)
1467 Boolean retval
= false;
1468 if ( itemOne
!= NULL
)
1469 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1473 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1474 DataBrowserItemID itemID
,
1475 DataBrowserPropertyID property
,
1476 DataBrowserItemDataRef itemData
,
1477 Boolean changeValue
)
1479 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1480 return GetSetItemData(item
, property
, itemData
, changeValue
);
1483 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1484 wxMacDataItem
* item
,
1485 DataBrowserPropertyID property
,
1486 DataBrowserItemDataRef itemData
,
1487 Boolean changeValue
)
1489 OSStatus err
= errDataBrowserPropertyNotSupported
;
1492 case kDataBrowserContainerIsClosableProperty
:
1493 case kDataBrowserContainerIsSortableProperty
:
1494 case kDataBrowserContainerIsOpenableProperty
:
1495 // right now default behaviour on these
1499 if ( item
!= NULL
){
1500 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1508 void wxMacDataItemBrowserControl::ItemNotification(
1509 DataBrowserItemID itemID
,
1510 DataBrowserItemNotification message
,
1511 DataBrowserItemDataRef itemData
)
1513 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1514 ItemNotification( item
, message
, itemData
);
1517 void wxMacDataItemBrowserControl::ItemNotification(
1518 const wxMacDataItem
* item
,
1519 DataBrowserItemNotification message
,
1520 DataBrowserItemDataRef itemData
)
1523 item
->Notification( this, message
, itemData
);
1526 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1527 bool recurse
, DataBrowserItemState state
) const
1529 ItemCount numItems
= 0;
1530 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1531 recurse
, state
, &numItems
) );
1535 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1536 bool recurse
) const
1538 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1542 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1543 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1545 Handle handle
= NewHandle(0);
1546 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1547 recurse
, state
, handle
) );
1549 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1551 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1552 for ( int i
= 0; i
< itemCount
; ++i
)
1554 items
.Add(itemsArray
[i
]);
1557 DisposeHandle( handle
);
1560 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1562 DataBrowserTableViewRowIndex row
;
1563 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1564 wxASSERT( err
== noErr
);
1568 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1570 DataBrowserItemID id
;
1571 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1572 wxASSERT( err
== noErr
);
1573 return (wxMacDataItem
*) id
;
1576 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1577 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1579 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1580 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1583 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1584 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1586 unsigned int noItems
= itemArray
.GetCount();
1587 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1588 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1589 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1591 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1592 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1596 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1597 const wxString
& title
, SInt16 just
, int defaultWidth
)
1599 DataBrowserListViewColumnDesc columnDesc
;
1600 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1601 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1603 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1604 kControlUseFontMask
| kControlUseJustMask
;
1606 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1607 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1608 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1609 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1611 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1612 // defined for other modes?
1615 enc
= m_font
.GetEncoding();
1617 enc
= wxLocale::GetSystemEncoding();
1618 wxCFStringRef
cfTitle( title
, enc
);
1619 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1621 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1622 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1624 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1625 columnDesc
.propertyDesc
.propertyType
= colType
;
1626 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1627 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1628 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1630 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1632 if (defaultWidth
> 0){
1633 SetColumnWidth(colId
, defaultWidth
);
1638 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1640 DataBrowserPropertyID id
;
1641 GetColumnIDFromIndex(colId
, &id
);
1642 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1645 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1647 DataBrowserPropertyID id
;
1648 GetColumnIDFromIndex(colId
, &id
);
1650 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1654 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1656 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1657 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1660 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1662 unsigned int noItems
= itemArray
.GetCount();
1663 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1664 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1665 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1667 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1668 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1672 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1674 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1675 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1676 verify_noerr( err
);
1679 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1681 unsigned int noItems
= itemArray
.GetCount();
1682 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1683 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1684 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1686 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1687 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1688 verify_noerr( err
);
1692 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1694 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1695 verify_noerr( err
);
1698 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1700 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1703 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1705 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1708 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1710 unsigned int noItems
= itemArray
.GetCount();
1711 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1712 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1713 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1715 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1719 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1721 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1724 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1726 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1729 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1731 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1734 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1736 return m_clientDataItemsType
;
1738 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1740 m_clientDataItemsType
= clientDataItemsType
;
1743 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1745 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
1748 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1750 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1751 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1754 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
,
1755 const wxArrayStringsAdapter
& items
,
1758 size_t itemsCount
= items
.GetCount();
1759 if ( itemsCount
== 0 )
1762 SInt32 frontLineOrder
= 0;
1764 if ( m_sortOrder
== SortOrder_None
)
1766 // increase the order of the lines to be shifted
1767 unsigned int lines
= MacGetCount();
1768 for ( unsigned int i
= n
; i
< lines
; ++i
)
1770 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1771 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
1775 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1776 frontLineOrder
= iter
->GetOrder();
1780 wxArrayMacDataItemPtr ids
;
1781 ids
.SetCount( itemsCount
);
1783 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
1785 wxMacDataItem
* item
= CreateItem();
1786 item
->SetLabel( items
[i
]);
1788 item
->SetColumn( kMinColumnId
+ column
);
1790 if ( m_sortOrder
== SortOrder_None
)
1791 item
->SetOrder( frontLineOrder
+ 1 + i
);
1796 AddItems( wxMacDataBrowserRootContainer
, ids
);
1799 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
1801 wxMacDataItem
* item
= CreateItem();
1802 item
->SetLabel( text
);
1803 if ( m_sortOrder
== SortOrder_None
)
1805 unsigned int lines
= MacGetCount();
1807 item
->SetOrder( 1 );
1810 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
1811 item
->SetOrder( frontItem
->GetOrder() + 1 );
1814 AddItem( wxMacDataBrowserRootContainer
, item
);
1816 return GetLineFromItem(item
);
1819 void wxMacDataItemBrowserControl::MacClear()
1821 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1822 RemoveAllItems(wxMacDataBrowserRootContainer
);
1825 void wxMacDataItemBrowserControl::MacDeselectAll()
1827 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1828 SetSelectedAllItems( kDataBrowserItemsRemove
);
1831 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
1833 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1834 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1836 if ( IsItemSelected( item
) != select
)
1839 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
1841 SetSelectedItem( item
, kDataBrowserItemsRemove
);
1847 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
1849 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1850 return IsItemSelected( item
);
1853 int wxMacDataItemBrowserControl::MacGetSelection() const
1855 wxMacDataItemPtr first
, last
;
1856 GetSelectionAnchor( &first
, &last
);
1858 if ( first
!= NULL
)
1860 return GetLineFromItem( first
);
1866 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
1868 aSelections
.Empty();
1869 wxArrayMacDataItemPtr selectedItems
;
1870 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
1872 int count
= selectedItems
.GetCount();
1874 for ( int i
= 0; i
< count
; ++i
)
1876 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
1882 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
1884 // as we don't store the strings we only have to issue a redraw
1885 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1886 item
->SetLabel( text
);
1887 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
1890 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
1892 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1893 return item
->GetLabel();
1896 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
1898 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1899 item
->SetData( data
);
1900 // not displayed, therefore no Update infos to DataBrowser
1903 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
1905 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1906 return item
->GetData();
1909 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
1912 GetScrollPosition( &top
, &left
) ;
1913 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1915 // there is a bug in RevealItem that leads to situations
1916 // in large lists, where the item does not get scrolled
1917 // into sight, so we do a pre-scroll if necessary
1919 GetRowHeight( (DataBrowserItemID
) item
, &height
) ;
1920 UInt32 linetop
= n
* ((UInt32
) height
);
1921 UInt32 linebottom
= linetop
+ height
;
1925 if ( linetop
< top
|| linebottom
> (top
+ rect
.bottom
- rect
.top
) )
1926 SetScrollPosition( wxMax( n
-2, 0 ) * ((UInt32
)height
) , left
) ;
1928 RevealItem( item
, kDataBrowserRevealWithoutSelecting
);
1937 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1939 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
1949 Return the generic RGB color space. This is a 'get' function and the caller should
1950 not release the returned value unless the caller retains it first. Usually callers
1951 of this routine will immediately use the returned colorspace with CoreGraphics
1952 so they typically do not need to retain it themselves.
1954 This function creates the generic RGB color space once and hangs onto it so it can
1955 return it whenever this function is called.
1958 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
1960 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
1962 if (genericRGBColorSpace
== NULL
)
1964 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
1967 return genericRGBColorSpace
;
1970 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
1973 HIThemeBrushCreateCGColor( brush
, &color
);
1977 #if wxMAC_USE_QUICKDRAW
1979 static inline void PointFromHIPoint(const HIPoint
& p
, Point
*pt
)
1981 pt
->h
= wx_static_cast(short, p
.x
);
1982 pt
->v
= wx_static_cast(short, p
.y
);
1985 void wxMacGlobalToLocal( 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
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1992 PointFromHIPoint(p
, pt
);
1995 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
1997 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1998 HIViewRef contentView
;
1999 // TODO check toolbar offset
2000 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2001 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2002 PointFromHIPoint(p
, pt
);
2005 #endif // wxMAC_USE_QUICKDRAW