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 sprintf(data
, "Mac OS X (%s %s %s)", name
.sysname
, name
.release
, name
.machine
);
321 return wxString(data
, wxConvUTF8
);
325 wxString
wxGetUserHome (const wxString
& user
)
331 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
340 int pos
= p
.Find(':');
341 if ( pos
!= wxNOT_FOUND
)
349 err
= wxMacPathToFSRef( p
, &fsRef
);
352 FSVolumeRefNum vRefNum
;
353 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
356 UInt64 freeBytes
, totalBytes
;
357 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
361 *pTotal
= wxDiskspaceSize_t( totalBytes
);
363 *pFree
= wxDiskspaceSize_t( freeBytes
);
370 #endif // !__DARWIN__
372 //---------------------------------------------------------------------------
373 // wxMac Specific utility functions
374 //---------------------------------------------------------------------------
376 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
378 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
379 int len
= strlen(buf
);
384 memcpy( (char*) &to
[1] , buf
, len
);
387 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
389 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
392 // ----------------------------------------------------------------------------
393 // Common Event Support
394 // ----------------------------------------------------------------------------
398 OSStatus err
= noErr
;
401 // lead sometimes to race conditions, although all calls used should be thread safe ...
402 static wxMacCarbonEvent s_wakeupEvent
;
403 if ( !s_wakeupEvent
.IsValid() )
405 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
406 kEventAttributeNone
);
411 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
413 s_wakeupEvent
.SetCurrentTime();
414 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
415 kEventPriorityHigh
);
418 wxMacCarbonEvent wakeupEvent
;
419 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
420 kEventAttributeNone
);
421 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
422 kEventPriorityHigh
);
430 // ----------------------------------------------------------------------------
431 // Native Struct Conversions
432 // ----------------------------------------------------------------------------
434 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
438 n
->right
= wx
->x
+ wx
->width
;
439 n
->bottom
= wx
->y
+ wx
->height
;
442 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
446 wx
->width
= n
->right
- n
->left
;
447 wx
->height
= n
->bottom
- n
->top
;
450 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
456 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
462 // ----------------------------------------------------------------------------
463 // Carbon Event Support
464 // ----------------------------------------------------------------------------
466 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
468 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
471 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
473 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
476 // ----------------------------------------------------------------------------
477 // Control Access Support
478 // ----------------------------------------------------------------------------
480 #if wxMAC_USE_QUICKDRAW
482 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
484 wxMacControl::wxMacControl()
489 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
493 m_isRootControl
= isRootControl
;
496 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
500 m_controlRef
= control
;
503 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
507 m_controlRef
= (ControlRef
) control
;
510 wxMacControl::~wxMacControl()
514 void wxMacControl::Init()
518 m_needsFocusRect
= false;
519 m_isRootControl
= false;
522 void wxMacControl::Dispose()
524 wxASSERT_MSG( m_controlRef
!= NULL
, wxT("Control Handle already NULL, Dispose called twice ?") );
525 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
527 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
528 // we can have situations when being embedded, where the control gets deleted behind our back, so only
529 // CFRelease if we are safe
530 if ( IsValidControlHandle(m_controlRef
) )
531 CFRelease(m_controlRef
);
535 void wxMacControl::SetReference( URefCon data
)
537 SetControlReference( m_controlRef
, data
);
540 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
542 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
545 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
547 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
550 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
552 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
555 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
557 return SendEventToEventTargetWithOptions( event
,
558 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
561 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
563 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
565 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
567 return SendEvent( event
, inOptions
);
570 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
574 memset( &command
, 0 , sizeof(command
) );
575 command
.commandID
= commandID
;
576 return SendHICommand( command
, inOptions
);
579 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
581 unsigned long finalTicks
;
583 HiliteControl( m_controlRef
, part
);
584 Delay( ticks
, &finalTicks
);
585 HiliteControl( m_controlRef
, kControlNoPart
);
588 SInt32
wxMacControl::GetValue() const
590 return ::GetControl32BitValue( m_controlRef
);
593 SInt32
wxMacControl::GetMaximum() const
595 return ::GetControl32BitMaximum( m_controlRef
);
598 SInt32
wxMacControl::GetMinimum() const
600 return ::GetControl32BitMinimum( m_controlRef
);
603 void wxMacControl::SetValue( SInt32 v
)
605 ::SetControl32BitValue( m_controlRef
, v
);
608 void wxMacControl::SetMinimum( SInt32 v
)
610 ::SetControl32BitMinimum( m_controlRef
, v
);
613 void wxMacControl::SetMaximum( SInt32 v
)
615 ::SetControl32BitMaximum( m_controlRef
, v
);
618 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
620 ::SetControl32BitMinimum( m_controlRef
, minimum
);
621 ::SetControl32BitMaximum( m_controlRef
, maximum
);
622 ::SetControl32BitValue( m_controlRef
, value
);
625 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
627 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
630 bool wxMacControl::HasFocus() const
633 GetKeyboardFocus( GetUserFocusWindow() , &control
);
634 return control
== m_controlRef
;
637 void wxMacControl::SetNeedsFocusRect( bool needs
)
639 m_needsFocusRect
= needs
;
642 bool wxMacControl::NeedsFocusRect() const
644 return m_needsFocusRect
;
647 void wxMacControl::VisibilityChanged(bool WXUNUSED(shown
))
651 void wxMacControl::SuperChangedPosition()
655 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
658 #if wxMAC_USE_CORE_TEXT
659 if ( UMAGetSystemVersion() >= 0x1050 )
661 HIViewPartCode part
= 0;
662 HIThemeTextHorizontalFlush flush
= kHIThemeTextHorizontalFlushDefault
;
663 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
664 flush
= kHIThemeTextHorizontalFlushCenter
;
665 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
666 flush
= kHIThemeTextHorizontalFlushRight
;
667 HIViewSetTextFont( m_controlRef
, part
, (CTFontRef
) font
.MacGetCTFont() );
668 HIViewSetTextHorizontalFlush( m_controlRef
, part
, flush
);
670 if ( foreground
!= *wxBLACK
)
672 ControlFontStyleRec fontStyle
;
673 foreground
.GetRGBColor( &fontStyle
.foreColor
);
674 fontStyle
.flags
= kControlUseForeColorMask
;
675 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
680 #if wxMAC_USE_ATSU_TEXT
681 ControlFontStyleRec fontStyle
;
682 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
684 switch ( font
.MacGetThemeFontID() )
686 case kThemeSmallSystemFont
:
687 fontStyle
.font
= kControlFontSmallSystemFont
;
690 case 109 : // mini font
694 case kThemeSystemFont
:
695 fontStyle
.font
= kControlFontBigSystemFont
;
699 fontStyle
.font
= kControlFontBigSystemFont
;
703 fontStyle
.flags
= kControlUseFontMask
;
707 fontStyle
.font
= font
.MacGetFontNum();
708 fontStyle
.style
= font
.MacGetFontStyle();
709 fontStyle
.size
= font
.MacGetFontSize();
710 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
713 fontStyle
.just
= teJustLeft
;
714 fontStyle
.flags
|= kControlUseJustMask
;
715 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
716 fontStyle
.just
= teJustCenter
;
717 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
718 fontStyle
.just
= teJustRight
;
721 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
722 // won't get grayed out by the system anymore
724 if ( foreground
!= *wxBLACK
)
726 foreground
.GetRGBColor( &fontStyle
.foreColor
);
727 fontStyle
.flags
|= kControlUseForeColorMask
;
730 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
734 void wxMacControl::SetBackgroundColour( const wxColour
&WXUNUSED(col
) )
736 // HITextViewSetBackgroundColor( m_textView , color );
739 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
741 ::SetControl32BitMinimum( m_controlRef
, minimum
);
742 ::SetControl32BitMaximum( m_controlRef
, maximum
);
745 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
748 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
754 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
756 SetControlAction( m_controlRef
, actionProc
);
759 void wxMacControl::SetViewSize( SInt32 viewSize
)
761 SetControlViewSize(m_controlRef
, viewSize
);
764 SInt32
wxMacControl::GetViewSize() const
766 return GetControlViewSize( m_controlRef
);
769 bool wxMacControl::IsVisible() const
771 return IsControlVisible( m_controlRef
);
774 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
776 SetControlVisibility( m_controlRef
, visible
, redraw
);
779 bool wxMacControl::IsEnabled() const
781 return IsControlEnabled( m_controlRef
);
784 bool wxMacControl::IsActive() const
786 return IsControlActive( m_controlRef
);
789 void wxMacControl::Enable( bool enable
)
792 EnableControl( m_controlRef
);
794 DisableControl( m_controlRef
);
797 void wxMacControl::SetDrawingEnabled( bool enable
)
799 HIViewSetDrawingEnabled( m_controlRef
, enable
);
802 bool wxMacControl::GetNeedsDisplay() const
804 return HIViewGetNeedsDisplay( m_controlRef
);
807 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
812 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
815 void wxMacControl::SetNeedsDisplay( Rect
* where
)
822 RgnHandle update
= NewRgn();
823 RectRgn( update
, where
);
824 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
825 DisposeRgn( update
);
828 HIViewSetNeedsDisplay( m_controlRef
, true );
831 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
837 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
838 pt
->x
= (int)hiPoint
.x
;
839 pt
->y
= (int)hiPoint
.y
;
842 void wxMacControl::SetRect( Rect
*r
)
844 //A HIRect is actually a CGRect on OSX - which consists of two structures -
845 //CGPoint and CGSize, which have two floats each
846 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
847 HIViewSetFrame ( m_controlRef
, &hir
);
848 // eventuall we might have to do a SetVisibility( false , true );
849 // before and a SetVisibility( true , true ); after
852 void wxMacControl::GetRect( Rect
*r
)
854 GetControlBounds( m_controlRef
, r
);
857 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
859 GetControlBounds( m_controlRef
, r
) ;
861 WindowRef tlwref
= GetControlOwner( m_controlRef
) ;
863 wxTopLevelWindowMac
* tlwwx
= wxFindWinFromMacWindow( tlwref
) ;
866 ControlRef rootControl
= tlwwx
->GetPeer()->GetControlRef() ;
867 HIPoint hiPoint
= CGPointMake( 0 , 0 ) ;
868 HIViewConvertPoint( &hiPoint
, HIViewGetSuperview(m_controlRef
) , rootControl
) ;
869 OffsetRect( r
, (short) hiPoint
.x
, (short) hiPoint
.y
) ;
873 void wxMacControl::GetBestRect( Rect
*r
)
875 short baselineoffset
;
877 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
880 void wxMacControl::SetLabel( const wxString
&title
)
882 wxFontEncoding encoding
;
885 encoding
= m_font
.GetEncoding();
887 encoding
= wxFont::GetDefaultEncoding();
889 SetControlTitleWithCFString( m_controlRef
, wxCFStringRef( title
, encoding
) );
892 void wxMacControl::GetFeatures( UInt32
* features
)
894 GetControlFeatures( m_controlRef
, features
);
897 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
899 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
903 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
905 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
906 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
909 // SetNeedsDisplay would not invalidate the children
910 static void InvalidateControlAndChildren( HIViewRef control
)
912 HIViewSetNeedsDisplay( control
, true );
913 UInt16 childrenCount
= 0;
914 OSStatus err
= CountSubControls( control
, &childrenCount
);
915 if ( err
== errControlIsNotEmbedder
)
918 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
920 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
924 err
= GetIndexedSubControl( control
, i
, & child
);
925 if ( err
== errControlIsNotEmbedder
)
928 InvalidateControlAndChildren( child
);
932 void wxMacControl::InvalidateWithChildren()
934 InvalidateControlAndChildren( m_controlRef
);
937 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
939 wxASSERT( r
!= NULL
);
941 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
942 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
945 OSType wxMacCreator
= 'WXMC';
946 OSType wxMacControlProperty
= 'MCCT';
948 void wxMacControl::SetReferenceInNativeControl()
951 verify_noerr( SetControlProperty ( m_controlRef
,
952 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
955 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
957 wxMacControl
* ctl
= NULL
;
958 ByteCount actualSize
;
959 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
960 &actualSize
, &ctl
) == noErr
)
967 // ============================================================================
968 // DataBrowser Wrapper
969 // ============================================================================
971 // basing on DataBrowserItemIDs
974 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
976 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
978 DataBrowserItemID itemID
,
979 DataBrowserItemNotification message
,
980 DataBrowserItemDataRef itemData
)
982 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
985 ctl
->ItemNotification(itemID
, message
, itemData
);
989 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
991 DataBrowserItemID itemID
,
992 DataBrowserPropertyID property
,
993 DataBrowserItemDataRef itemData
,
994 Boolean changeValue
)
996 OSStatus err
= errDataBrowserPropertyNotSupported
;
997 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1000 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1005 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1007 DataBrowserItemID itemOneID
,
1008 DataBrowserItemID itemTwoID
,
1009 DataBrowserPropertyID sortProperty
)
1011 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1014 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1019 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1020 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1021 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1023 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
1026 long WXUNUSED(style
))
1027 : wxMacControl( peer
)
1029 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1030 OSStatus err
= ::CreateDataBrowserControl(
1031 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1032 &bounds
, kDataBrowserListView
, &m_controlRef
);
1033 SetReferenceInNativeControl();
1034 verify_noerr( err
);
1035 if ( gDataBrowserItemCompareUPP
== NULL
)
1036 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1037 if ( gDataBrowserItemDataUPP
== NULL
)
1038 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1039 if ( gDataBrowserItemNotificationUPP
== NULL
)
1041 gDataBrowserItemNotificationUPP
=
1042 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1045 DataBrowserCallbacks callbacks
;
1046 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1048 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1049 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1050 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1051 SetCallbacks( &callbacks
);
1055 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1057 DataBrowserItemState state
,
1058 ItemCount
*numItems
) const
1060 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1063 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1065 DataBrowserItemState state
,
1068 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1071 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1073 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1076 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1077 DataBrowserTableViewColumnIndex position
)
1079 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1082 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1083 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1086 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1088 DataBrowserTableViewColumnID id
;
1089 GetColumnIDFromIndex( position
, &id
);
1090 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1093 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1095 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1098 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1100 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1103 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1105 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1108 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1110 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1113 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1115 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1118 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1120 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1123 OSStatus
wxMacDataBrowserControl::UpdateItems(
1124 DataBrowserItemID container
,
1126 const DataBrowserItemID
*items
,
1127 DataBrowserPropertyID preSortProperty
,
1128 DataBrowserPropertyID propertyID
) const
1130 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1133 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1135 return IsDataBrowserItemSelected( m_controlRef
, item
);
1138 OSStatus
wxMacDataBrowserControl::AddItems(
1139 DataBrowserItemID container
,
1141 const DataBrowserItemID
*items
,
1142 DataBrowserPropertyID preSortProperty
)
1144 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1147 OSStatus
wxMacDataBrowserControl::RemoveItems(
1148 DataBrowserItemID container
,
1150 const DataBrowserItemID
*items
,
1151 DataBrowserPropertyID preSortProperty
)
1153 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1156 OSStatus
wxMacDataBrowserControl::RevealItem(
1157 DataBrowserItemID item
,
1158 DataBrowserPropertyID propertyID
,
1159 DataBrowserRevealOptions options
) const
1161 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1164 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1166 const DataBrowserItemID
*items
,
1167 DataBrowserSetOption operation
)
1169 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1172 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1174 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1177 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1179 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1182 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1184 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1187 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1189 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1192 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1194 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1197 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1199 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1202 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1204 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1207 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1209 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1212 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1214 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1217 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1219 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1222 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1224 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1227 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1229 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1232 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1233 DataBrowserTableViewColumnIndex
*position
) const
1235 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1238 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1240 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1243 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1245 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1248 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1250 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1253 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1255 return GetDataBrowserSortProperty( m_controlRef
, column
);
1258 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1260 return SetDataBrowserSortProperty( m_controlRef
, column
);
1263 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1265 return GetDataBrowserSortOrder( m_controlRef
, order
);
1268 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1270 return SetDataBrowserSortOrder( m_controlRef
, order
);
1273 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1274 DataBrowserPropertyFlags
*flags
) const
1276 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1279 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1280 DataBrowserPropertyFlags flags
)
1282 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1285 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1286 DataBrowserListViewHeaderDesc
*desc
) const
1288 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1291 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1292 DataBrowserListViewHeaderDesc
*desc
)
1294 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1297 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1298 Boolean expandableRows
)
1300 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1303 // ============================================================================
1304 // Higher-level Databrowser
1305 // ============================================================================
1307 // basing on data item objects
1310 wxMacDataItem::wxMacDataItem()
1315 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1318 wxMacDataItem::~wxMacDataItem()
1322 void wxMacDataItem::SetOrder( SInt32 order
)
1327 SInt32
wxMacDataItem::GetOrder() const
1332 void wxMacDataItem::SetData( void* data
)
1337 void* wxMacDataItem::GetData() const
1342 short wxMacDataItem::GetColumn()
1347 void wxMacDataItem::SetColumn( short col
)
1352 void wxMacDataItem::SetLabel( const wxString
& str
)
1355 m_cfLabel
= wxCFStringRef( str
, wxLocale::GetSystemEncoding());
1358 const wxString
& wxMacDataItem::GetLabel() const
1363 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1364 const wxMacDataItem
* rhs
,
1365 DataBrowserPropertyID sortProperty
) const
1367 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1368 bool retval
= false;
1370 if ( sortProperty
== m_colId
){
1371 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1374 else if ( sortProperty
== kNumericOrderColumnId
)
1375 retval
= m_order
< otherItem
->m_order
;
1380 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1381 DataBrowserPropertyID property
,
1382 DataBrowserItemDataRef itemData
,
1385 OSStatus err
= errDataBrowserPropertyNotSupported
;
1388 if ( property
== m_colId
){
1389 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1392 else if ( property
== kNumericOrderColumnId
){
1393 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1403 // no editable props here
1412 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1413 DataBrowserItemNotification
WXUNUSED(message
),
1414 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
1418 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1420 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1421 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1423 m_suppressSelection
= false;
1424 m_sortOrder
= SortOrder_None
;
1425 m_clientDataItemsType
= wxClientData_None
;
1428 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1430 return new wxMacDataItem();
1433 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1435 m_former
= browser
->SuppressSelection(true);
1436 m_browser
= browser
;
1439 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1441 m_browser
->SuppressSelection(m_former
);
1444 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1446 bool former
= m_suppressSelection
;
1447 m_suppressSelection
= suppress
;
1452 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1453 DataBrowserItemID itemTwoID
,
1454 DataBrowserPropertyID sortProperty
)
1456 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1457 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1458 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1461 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1462 const wxMacDataItem
* itemTwo
,
1463 DataBrowserPropertyID sortProperty
)
1465 Boolean retval
= false;
1466 if ( itemOne
!= NULL
)
1467 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1471 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1472 DataBrowserItemID itemID
,
1473 DataBrowserPropertyID property
,
1474 DataBrowserItemDataRef itemData
,
1475 Boolean changeValue
)
1477 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1478 return GetSetItemData(item
, property
, itemData
, changeValue
);
1481 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1482 wxMacDataItem
* item
,
1483 DataBrowserPropertyID property
,
1484 DataBrowserItemDataRef itemData
,
1485 Boolean changeValue
)
1487 OSStatus err
= errDataBrowserPropertyNotSupported
;
1490 case kDataBrowserContainerIsClosableProperty
:
1491 case kDataBrowserContainerIsSortableProperty
:
1492 case kDataBrowserContainerIsOpenableProperty
:
1493 // right now default behaviour on these
1497 if ( item
!= NULL
){
1498 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1506 void wxMacDataItemBrowserControl::ItemNotification(
1507 DataBrowserItemID itemID
,
1508 DataBrowserItemNotification message
,
1509 DataBrowserItemDataRef itemData
)
1511 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1512 ItemNotification( item
, message
, itemData
);
1515 void wxMacDataItemBrowserControl::ItemNotification(
1516 const wxMacDataItem
* item
,
1517 DataBrowserItemNotification message
,
1518 DataBrowserItemDataRef itemData
)
1521 item
->Notification( this, message
, itemData
);
1524 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1525 bool recurse
, DataBrowserItemState state
) const
1527 ItemCount numItems
= 0;
1528 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1529 recurse
, state
, &numItems
) );
1533 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1534 bool recurse
) const
1536 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1540 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1541 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1543 Handle handle
= NewHandle(0);
1544 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1545 recurse
, state
, handle
) );
1547 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1549 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1550 for ( int i
= 0; i
< itemCount
; ++i
)
1552 items
.Add(itemsArray
[i
]);
1555 DisposeHandle( handle
);
1558 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1560 DataBrowserTableViewRowIndex row
;
1561 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1562 wxASSERT( err
== noErr
);
1566 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1568 DataBrowserItemID id
;
1569 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1570 wxASSERT( err
== noErr
);
1571 return (wxMacDataItem
*) id
;
1574 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1575 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1577 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1578 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1581 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1582 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1584 unsigned int noItems
= itemArray
.GetCount();
1585 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1586 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1587 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1589 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1590 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1594 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1595 const wxString
& title
, SInt16 just
, int defaultWidth
)
1597 DataBrowserListViewColumnDesc columnDesc
;
1598 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1599 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1601 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1602 kControlUseFontMask
| kControlUseJustMask
;
1604 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1605 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1606 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1607 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1609 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1610 // defined for other modes?
1613 enc
= m_font
.GetEncoding();
1615 enc
= wxLocale::GetSystemEncoding();
1616 wxCFStringRef
cfTitle( title
, enc
);
1617 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1619 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1620 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1622 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1623 columnDesc
.propertyDesc
.propertyType
= colType
;
1624 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1625 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1626 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1628 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1630 if (defaultWidth
> 0){
1631 SetColumnWidth(colId
, defaultWidth
);
1636 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1638 DataBrowserPropertyID id
;
1639 GetColumnIDFromIndex(colId
, &id
);
1640 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1643 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1645 DataBrowserPropertyID id
;
1646 GetColumnIDFromIndex(colId
, &id
);
1648 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1652 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1654 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1655 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1658 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1660 unsigned int noItems
= itemArray
.GetCount();
1661 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1662 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1663 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1665 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1666 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1670 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1672 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1673 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1674 verify_noerr( err
);
1677 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1679 unsigned int noItems
= itemArray
.GetCount();
1680 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1681 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1682 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1684 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1685 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1686 verify_noerr( err
);
1690 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1692 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1693 verify_noerr( err
);
1696 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1698 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1701 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1703 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1706 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1708 unsigned int noItems
= itemArray
.GetCount();
1709 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1710 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1711 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1713 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1717 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1719 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1722 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1724 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1727 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1729 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1732 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1734 return m_clientDataItemsType
;
1736 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1738 m_clientDataItemsType
= clientDataItemsType
;
1741 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1743 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
1746 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1748 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1749 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1752 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
,
1753 const wxArrayStringsAdapter
& items
,
1756 size_t itemsCount
= items
.GetCount();
1757 if ( itemsCount
== 0 )
1760 SInt32 frontLineOrder
= 0;
1762 if ( m_sortOrder
== SortOrder_None
)
1764 // increase the order of the lines to be shifted
1765 unsigned int lines
= MacGetCount();
1766 for ( unsigned int i
= n
; i
< lines
; ++i
)
1768 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1769 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
1773 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1774 frontLineOrder
= iter
->GetOrder();
1778 wxArrayMacDataItemPtr ids
;
1779 ids
.SetCount( itemsCount
);
1781 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
1783 wxMacDataItem
* item
= CreateItem();
1784 item
->SetLabel( items
[i
]);
1786 item
->SetColumn( kMinColumnId
+ column
);
1788 if ( m_sortOrder
== SortOrder_None
)
1789 item
->SetOrder( frontLineOrder
+ 1 + i
);
1794 AddItems( wxMacDataBrowserRootContainer
, ids
);
1797 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
1799 wxMacDataItem
* item
= CreateItem();
1800 item
->SetLabel( text
);
1801 if ( m_sortOrder
== SortOrder_None
)
1803 unsigned int lines
= MacGetCount();
1805 item
->SetOrder( 1 );
1808 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
1809 item
->SetOrder( frontItem
->GetOrder() + 1 );
1812 AddItem( wxMacDataBrowserRootContainer
, item
);
1814 return GetLineFromItem(item
);
1817 void wxMacDataItemBrowserControl::MacClear()
1819 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1820 RemoveAllItems(wxMacDataBrowserRootContainer
);
1823 void wxMacDataItemBrowserControl::MacDeselectAll()
1825 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1826 SetSelectedAllItems( kDataBrowserItemsRemove
);
1829 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
1831 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1832 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1834 if ( IsItemSelected( item
) != select
)
1837 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
1839 SetSelectedItem( item
, kDataBrowserItemsRemove
);
1845 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
1847 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1848 return IsItemSelected( item
);
1851 int wxMacDataItemBrowserControl::MacGetSelection() const
1853 wxMacDataItemPtr first
, last
;
1854 GetSelectionAnchor( &first
, &last
);
1856 if ( first
!= NULL
)
1858 return GetLineFromItem( first
);
1864 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
1866 aSelections
.Empty();
1867 wxArrayMacDataItemPtr selectedItems
;
1868 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
1870 int count
= selectedItems
.GetCount();
1872 for ( int i
= 0; i
< count
; ++i
)
1874 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
1880 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
1882 // as we don't store the strings we only have to issue a redraw
1883 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1884 item
->SetLabel( text
);
1885 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
1888 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
1890 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1891 return item
->GetLabel();
1894 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
1896 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1897 item
->SetData( data
);
1898 // not displayed, therefore no Update infos to DataBrowser
1901 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
1903 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1904 return item
->GetData();
1907 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
1910 GetScrollPosition( &top
, &left
) ;
1911 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1913 // there is a bug in RevealItem that leads to situations
1914 // in large lists, where the item does not get scrolled
1915 // into sight, so we do a pre-scroll if necessary
1917 GetRowHeight( (DataBrowserItemID
) item
, &height
) ;
1918 UInt32 linetop
= n
* ((UInt32
) height
);
1919 UInt32 linebottom
= linetop
+ height
;
1923 if ( linetop
< top
|| linebottom
> (top
+ rect
.bottom
- rect
.top
) )
1924 SetScrollPosition( wxMax( n
-2, 0 ) * ((UInt32
)height
) , left
) ;
1926 RevealItem( item
, kDataBrowserRevealWithoutSelecting
);
1935 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1937 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
1947 Return the generic RGB color space. This is a 'get' function and the caller should
1948 not release the returned value unless the caller retains it first. Usually callers
1949 of this routine will immediately use the returned colorspace with CoreGraphics
1950 so they typically do not need to retain it themselves.
1952 This function creates the generic RGB color space once and hangs onto it so it can
1953 return it whenever this function is called.
1956 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
1958 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
1960 if (genericRGBColorSpace
== NULL
)
1962 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
1965 return genericRGBColorSpace
;
1968 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
1971 HIThemeBrushCreateCGColor( brush
, &color
);
1975 #if wxMAC_USE_QUICKDRAW
1977 static inline void PointFromHIPoint(const HIPoint
& p
, Point
*pt
)
1979 pt
->h
= wx_static_cast(short, p
.x
);
1980 pt
->v
= wx_static_cast(short, p
.y
);
1983 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
1985 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1986 HIViewRef contentView
;
1987 // TODO check toolbar offset
1988 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1989 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1990 PointFromHIPoint(p
, pt
);
1993 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
1995 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1996 HIViewRef contentView
;
1997 // TODO check toolbar offset
1998 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1999 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2000 PointFromHIPoint(p
, pt
);
2003 #endif // wxMAC_USE_QUICKDRAW