1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/utils.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/toplevel.h"
25 #include "wx/apptrait.h"
28 #include "wx/mac/uma.h"
38 // #include "MoreFilesX.h"
46 #include <CoreServices/CoreServices.h>
47 #include <Carbon/Carbon.h>
48 #include "wx/mac/private/timer.h"
51 #include "wx/evtloop.h"
52 #include "wx/mac/private.h"
54 #if defined(__MWERKS__) && wxUSE_UNICODE
55 #if __MWERKS__ < 0x4100
62 // our OS version is the same in non GUI and GUI cases
63 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
66 Gestalt(gestaltSystemVersion
, &theSystem
);
68 if ( majorVsn
!= NULL
)
69 *majorVsn
= (theSystem
>> 8);
71 if ( minorVsn
!= NULL
)
72 *minorVsn
= (theSystem
& 0xFF);
74 #if defined( __DARWIN__ )
75 return wxOS_MAC_OSX_DARWIN
;
81 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
83 // TODO : try to find out ...
100 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
102 // We suppose that toolkit version is the same as OS version under Mac
103 wxGetOsVersion(verMaj
, verMin
);
108 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
110 return new wxEventLoop
;
113 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
115 return new wxCarbonTimerImpl(timer
);
118 int gs_wxBusyCursorCount
= 0;
119 extern wxCursor gMacCurrentCursor
;
120 wxCursor gMacStoredActiveCursor
;
122 // Set the cursor to the busy cursor for all windows
123 void wxBeginBusyCursor(const wxCursor
*cursor
)
125 if (gs_wxBusyCursorCount
++ == 0)
127 gMacStoredActiveCursor
= gMacCurrentCursor
;
128 cursor
->MacInstall();
130 //else: nothing to do, already set
133 // Restore cursor to normal
134 void wxEndBusyCursor()
136 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
137 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
139 if (--gs_wxBusyCursorCount
== 0)
141 gMacStoredActiveCursor
.MacInstall();
142 gMacStoredActiveCursor
= wxNullCursor
;
146 // true if we're between the above two calls
149 return (gs_wxBusyCursorCount
> 0);
156 wxString
wxMacFindFolderNoSeparator( short vol
,
158 Boolean createFolder
)
163 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
165 strDir
= wxMacFSRefToPath( &fsRef
);
171 wxString
wxMacFindFolder( short vol
,
173 Boolean createFolder
)
175 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
182 // Check whether this window wants to process messages, e.g. Stop button
183 // in long calculations.
184 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
190 void wxGetMousePosition( int* x
, int* y
)
192 #if wxMAC_USE_QUICKDRAW
202 // Return true if we have a colour display
203 bool wxColourDisplay()
208 // Returns depth of screen
211 #if wxMAC_USE_QUICKDRAW
212 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
214 SetRect(&globRect
, -32760, -32760, 32760, 32760);
215 GDHandle theMaxDevice
;
217 theMaxDevice
= GetMaxDevice(&globRect
);
218 if (theMaxDevice
!= NULL
)
219 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
227 // Get size of display
228 void wxDisplaySize(int *width
, int *height
)
230 // TODO adapt for multi-displays
231 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
233 *width
= (int)bounds
.size
.width
;
235 *height
= (int)bounds
.size
.height
;
238 void wxDisplaySizeMM(int *width
, int *height
)
240 wxDisplaySize(width
, height
);
241 // on mac 72 is fixed (at least now;-)
242 float cvPt2Mm
= 25.4 / 72;
245 *width
= int( *width
* cvPt2Mm
);
248 *height
= int( *height
* cvPt2Mm
);
251 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
253 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
254 #if wxMAC_USE_QUICKDRAW
257 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
260 *x
= bounds
.origin
.x
;
262 *y
= bounds
.origin
.y
;
264 *width
= bounds
.size
.width
;
266 *height
= bounds
.size
.height
;
269 wxDisplaySize(&w
,&h
);
281 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
287 *width
= r
.right
- r
.left
;
289 *height
= r
.bottom
- r
.top
;
293 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
295 return wxGenericFindWindowAtPoint(pt
);
302 wxString
wxGetOsDescription()
304 #ifdef WXWIN_OS_DESCRIPTION
305 // use configure generated description if available
306 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
308 return wxT("MacOS"); //TODO:define further
313 wxString
wxGetUserHome (const wxString
& user
)
319 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
328 int pos
= p
.Find(':');
329 if ( pos
!= wxNOT_FOUND
)
337 err
= wxMacPathToFSRef( p
, &fsRef
);
340 FSVolumeRefNum vRefNum
;
341 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
344 UInt64 freeBytes
, totalBytes
;
345 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
349 *pTotal
= wxDiskspaceSize_t( totalBytes
);
351 *pFree
= wxDiskspaceSize_t( freeBytes
);
358 #endif // !__DARWIN__
360 //---------------------------------------------------------------------------
361 // wxMac Specific utility functions
362 //---------------------------------------------------------------------------
364 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
366 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
367 int len
= strlen(buf
);
372 memcpy( (char*) &to
[1] , buf
, len
);
375 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
377 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
380 // ----------------------------------------------------------------------------
381 // Common Event Support
382 // ----------------------------------------------------------------------------
386 OSStatus err
= noErr
;
389 // lead sometimes to race conditions, although all calls used should be thread safe ...
390 static wxMacCarbonEvent s_wakeupEvent
;
391 if ( !s_wakeupEvent
.IsValid() )
393 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
394 kEventAttributeNone
);
399 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
401 s_wakeupEvent
.SetCurrentTime();
402 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
403 kEventPriorityHigh
);
406 wxMacCarbonEvent wakeupEvent
;
407 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
408 kEventAttributeNone
);
409 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
410 kEventPriorityHigh
);
418 // ----------------------------------------------------------------------------
419 // Native Struct Conversions
420 // ----------------------------------------------------------------------------
422 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
426 n
->right
= wx
->x
+ wx
->width
;
427 n
->bottom
= wx
->y
+ wx
->height
;
430 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
434 wx
->width
= n
->right
- n
->left
;
435 wx
->height
= n
->bottom
- n
->top
;
438 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
444 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
450 // ----------------------------------------------------------------------------
451 // Carbon Event Support
452 // ----------------------------------------------------------------------------
454 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
456 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
459 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
461 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
464 // ----------------------------------------------------------------------------
465 // Control Access Support
466 // ----------------------------------------------------------------------------
468 #if wxMAC_USE_QUICKDRAW
470 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
472 wxMacControl::wxMacControl()
477 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
481 m_isRootControl
= isRootControl
;
484 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
488 m_controlRef
= control
;
491 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
495 m_controlRef
= (ControlRef
) control
;
498 wxMacControl::~wxMacControl()
502 void wxMacControl::Init()
506 m_needsFocusRect
= false;
507 m_isRootControl
= false;
510 void wxMacControl::Dispose()
512 wxASSERT_MSG( m_controlRef
!= NULL
, wxT("Control Handle already NULL, Dispose called twice ?") );
513 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
515 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
516 // we can have situations when being embedded, where the control gets deleted behind our back, so only
517 // CFRelease if we are safe
518 if ( IsValidControlHandle(m_controlRef
) )
519 CFRelease(m_controlRef
);
523 void wxMacControl::SetReference( URefCon data
)
525 SetControlReference( m_controlRef
, data
);
528 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
530 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
533 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
535 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
538 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
540 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
543 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
545 return SendEventToEventTargetWithOptions( event
,
546 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
549 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
551 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
553 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
555 return SendEvent( event
, inOptions
);
558 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
562 memset( &command
, 0 , sizeof(command
) );
563 command
.commandID
= commandID
;
564 return SendHICommand( command
, inOptions
);
567 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
569 unsigned long finalTicks
;
571 HiliteControl( m_controlRef
, part
);
572 Delay( ticks
, &finalTicks
);
573 HiliteControl( m_controlRef
, kControlNoPart
);
576 SInt32
wxMacControl::GetValue() const
578 return ::GetControl32BitValue( m_controlRef
);
581 SInt32
wxMacControl::GetMaximum() const
583 return ::GetControl32BitMaximum( m_controlRef
);
586 SInt32
wxMacControl::GetMinimum() const
588 return ::GetControl32BitMinimum( m_controlRef
);
591 void wxMacControl::SetValue( SInt32 v
)
593 ::SetControl32BitValue( m_controlRef
, v
);
596 void wxMacControl::SetMinimum( SInt32 v
)
598 ::SetControl32BitMinimum( m_controlRef
, v
);
601 void wxMacControl::SetMaximum( SInt32 v
)
603 ::SetControl32BitMaximum( m_controlRef
, v
);
606 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
608 ::SetControl32BitMinimum( m_controlRef
, minimum
);
609 ::SetControl32BitMaximum( m_controlRef
, maximum
);
610 ::SetControl32BitValue( m_controlRef
, value
);
613 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
615 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
618 bool wxMacControl::HasFocus() const
621 GetKeyboardFocus( GetUserFocusWindow() , &control
);
622 return control
== m_controlRef
;
625 void wxMacControl::SetNeedsFocusRect( bool needs
)
627 m_needsFocusRect
= needs
;
630 bool wxMacControl::NeedsFocusRect() const
632 return m_needsFocusRect
;
635 void wxMacControl::VisibilityChanged(bool WXUNUSED(shown
))
639 void wxMacControl::SuperChangedPosition()
643 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
646 #if wxMAC_USE_CORE_TEXT
647 if ( UMAGetSystemVersion() >= 0x1050 )
649 HIViewPartCode part
= 0;
650 HIThemeTextHorizontalFlush flush
= kHIThemeTextHorizontalFlushDefault
;
651 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
652 flush
= kHIThemeTextHorizontalFlushCenter
;
653 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
654 flush
= kHIThemeTextHorizontalFlushRight
;
655 HIViewSetTextFont( m_controlRef
, part
, (CTFontRef
) font
.MacGetCTFont() );
656 HIViewSetTextHorizontalFlush( m_controlRef
, part
, flush
);
658 if ( foreground
!= *wxBLACK
)
660 ControlFontStyleRec fontStyle
;
661 foreground
.GetRGBColor( &fontStyle
.foreColor
);
662 fontStyle
.flags
= kControlUseForeColorMask
;
663 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
668 #if wxMAC_USE_ATSU_TEXT
669 ControlFontStyleRec fontStyle
;
670 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
672 switch ( font
.MacGetThemeFontID() )
674 case kThemeSmallSystemFont
:
675 fontStyle
.font
= kControlFontSmallSystemFont
;
678 case 109 : // mini font
682 case kThemeSystemFont
:
683 fontStyle
.font
= kControlFontBigSystemFont
;
687 fontStyle
.font
= kControlFontBigSystemFont
;
691 fontStyle
.flags
= kControlUseFontMask
;
695 fontStyle
.font
= font
.MacGetFontNum();
696 fontStyle
.style
= font
.MacGetFontStyle();
697 fontStyle
.size
= font
.MacGetFontSize();
698 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
701 fontStyle
.just
= teJustLeft
;
702 fontStyle
.flags
|= kControlUseJustMask
;
703 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
704 fontStyle
.just
= teJustCenter
;
705 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
706 fontStyle
.just
= teJustRight
;
709 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
710 // won't get grayed out by the system anymore
712 if ( foreground
!= *wxBLACK
)
714 foreground
.GetRGBColor( &fontStyle
.foreColor
);
715 fontStyle
.flags
|= kControlUseForeColorMask
;
718 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
722 void wxMacControl::SetBackgroundColour( const wxColour
&WXUNUSED(col
) )
724 // HITextViewSetBackgroundColor( m_textView , color );
727 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
729 ::SetControl32BitMinimum( m_controlRef
, minimum
);
730 ::SetControl32BitMaximum( m_controlRef
, maximum
);
733 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
736 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
742 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
744 SetControlAction( m_controlRef
, actionProc
);
747 void wxMacControl::SetViewSize( SInt32 viewSize
)
749 SetControlViewSize(m_controlRef
, viewSize
);
752 SInt32
wxMacControl::GetViewSize() const
754 return GetControlViewSize( m_controlRef
);
757 bool wxMacControl::IsVisible() const
759 return IsControlVisible( m_controlRef
);
762 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
764 SetControlVisibility( m_controlRef
, visible
, redraw
);
767 bool wxMacControl::IsEnabled() const
769 return IsControlEnabled( m_controlRef
);
772 bool wxMacControl::IsActive() const
774 return IsControlActive( m_controlRef
);
777 void wxMacControl::Enable( bool enable
)
780 EnableControl( m_controlRef
);
782 DisableControl( m_controlRef
);
785 void wxMacControl::SetDrawingEnabled( bool enable
)
787 HIViewSetDrawingEnabled( m_controlRef
, enable
);
790 bool wxMacControl::GetNeedsDisplay() const
792 return HIViewGetNeedsDisplay( m_controlRef
);
795 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
800 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
803 void wxMacControl::SetNeedsDisplay( Rect
* where
)
810 RgnHandle update
= NewRgn();
811 RectRgn( update
, where
);
812 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
813 DisposeRgn( update
);
816 HIViewSetNeedsDisplay( m_controlRef
, true );
819 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
825 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
826 pt
->x
= (int)hiPoint
.x
;
827 pt
->y
= (int)hiPoint
.y
;
830 void wxMacControl::SetRect( Rect
*r
)
832 //A HIRect is actually a CGRect on OSX - which consists of two structures -
833 //CGPoint and CGSize, which have two floats each
834 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
835 HIViewSetFrame ( m_controlRef
, &hir
);
836 // eventuall we might have to do a SetVisibility( false , true );
837 // before and a SetVisibility( true , true ); after
840 void wxMacControl::GetRect( Rect
*r
)
842 GetControlBounds( m_controlRef
, r
);
845 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
847 GetControlBounds( m_controlRef
, r
) ;
849 WindowRef tlwref
= GetControlOwner( m_controlRef
) ;
851 wxTopLevelWindowMac
* tlwwx
= wxFindWinFromMacWindow( tlwref
) ;
854 ControlRef rootControl
= tlwwx
->GetPeer()->GetControlRef() ;
855 HIPoint hiPoint
= CGPointMake( 0 , 0 ) ;
856 HIViewConvertPoint( &hiPoint
, HIViewGetSuperview(m_controlRef
) , rootControl
) ;
857 OffsetRect( r
, (short) hiPoint
.x
, (short) hiPoint
.y
) ;
861 void wxMacControl::GetBestRect( Rect
*r
)
863 short baselineoffset
;
865 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
868 void wxMacControl::SetLabel( const wxString
&title
)
870 wxFontEncoding encoding
;
873 encoding
= m_font
.GetEncoding();
875 encoding
= wxFont::GetDefaultEncoding();
877 SetControlTitleWithCFString( m_controlRef
, wxMacCFStringHolder( title
, encoding
) );
880 void wxMacControl::GetFeatures( UInt32
* features
)
882 GetControlFeatures( m_controlRef
, features
);
885 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
887 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
891 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
893 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
894 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
897 // SetNeedsDisplay would not invalidate the children
898 static void InvalidateControlAndChildren( HIViewRef control
)
900 HIViewSetNeedsDisplay( control
, true );
901 UInt16 childrenCount
= 0;
902 OSStatus err
= CountSubControls( control
, &childrenCount
);
903 if ( err
== errControlIsNotEmbedder
)
906 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
908 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
912 err
= GetIndexedSubControl( control
, i
, & child
);
913 if ( err
== errControlIsNotEmbedder
)
916 InvalidateControlAndChildren( child
);
920 void wxMacControl::InvalidateWithChildren()
922 InvalidateControlAndChildren( m_controlRef
);
925 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
927 wxASSERT( r
!= NULL
);
929 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
930 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
933 OSType wxMacCreator
= 'WXMC';
934 OSType wxMacControlProperty
= 'MCCT';
936 void wxMacControl::SetReferenceInNativeControl()
939 verify_noerr( SetControlProperty ( m_controlRef
,
940 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
943 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
945 wxMacControl
* ctl
= NULL
;
946 ByteCount actualSize
;
947 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
948 &actualSize
, &ctl
) == noErr
)
955 // ============================================================================
956 // DataBrowser Wrapper
957 // ============================================================================
959 // basing on DataBrowserItemIDs
962 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
964 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
966 DataBrowserItemID itemID
,
967 DataBrowserItemNotification message
,
968 DataBrowserItemDataRef itemData
)
970 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
973 ctl
->ItemNotification(itemID
, message
, itemData
);
977 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
979 DataBrowserItemID itemID
,
980 DataBrowserPropertyID property
,
981 DataBrowserItemDataRef itemData
,
982 Boolean changeValue
)
984 OSStatus err
= errDataBrowserPropertyNotSupported
;
985 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
988 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
993 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
995 DataBrowserItemID itemOneID
,
996 DataBrowserItemID itemTwoID
,
997 DataBrowserPropertyID sortProperty
)
999 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1002 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1007 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1008 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1009 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1011 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
1014 long WXUNUSED(style
))
1015 : wxMacControl( peer
)
1017 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1018 OSStatus err
= ::CreateDataBrowserControl(
1019 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1020 &bounds
, kDataBrowserListView
, &m_controlRef
);
1021 SetReferenceInNativeControl();
1022 verify_noerr( err
);
1023 if ( gDataBrowserItemCompareUPP
== NULL
)
1024 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1025 if ( gDataBrowserItemDataUPP
== NULL
)
1026 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1027 if ( gDataBrowserItemNotificationUPP
== NULL
)
1029 gDataBrowserItemNotificationUPP
=
1030 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1033 DataBrowserCallbacks callbacks
;
1034 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1036 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1037 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1038 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1039 SetCallbacks( &callbacks
);
1043 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1045 DataBrowserItemState state
,
1046 ItemCount
*numItems
) const
1048 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1051 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1053 DataBrowserItemState state
,
1056 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1059 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1061 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1064 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1065 DataBrowserTableViewColumnIndex position
)
1067 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1070 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1071 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1074 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1076 DataBrowserTableViewColumnID id
;
1077 GetColumnIDFromIndex( position
, &id
);
1078 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1081 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1083 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1086 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1088 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1091 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1093 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1096 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1098 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1101 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1103 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1106 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1108 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1111 OSStatus
wxMacDataBrowserControl::UpdateItems(
1112 DataBrowserItemID container
,
1114 const DataBrowserItemID
*items
,
1115 DataBrowserPropertyID preSortProperty
,
1116 DataBrowserPropertyID propertyID
) const
1118 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1121 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1123 return IsDataBrowserItemSelected( m_controlRef
, item
);
1126 OSStatus
wxMacDataBrowserControl::AddItems(
1127 DataBrowserItemID container
,
1129 const DataBrowserItemID
*items
,
1130 DataBrowserPropertyID preSortProperty
)
1132 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1135 OSStatus
wxMacDataBrowserControl::RemoveItems(
1136 DataBrowserItemID container
,
1138 const DataBrowserItemID
*items
,
1139 DataBrowserPropertyID preSortProperty
)
1141 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1144 OSStatus
wxMacDataBrowserControl::RevealItem(
1145 DataBrowserItemID item
,
1146 DataBrowserPropertyID propertyID
,
1147 DataBrowserRevealOptions options
) const
1149 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1152 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1154 const DataBrowserItemID
*items
,
1155 DataBrowserSetOption operation
)
1157 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1160 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1162 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1165 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1167 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1170 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1172 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1175 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1177 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1180 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1182 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1185 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1187 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1190 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1192 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1195 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1197 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1200 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1202 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1205 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1207 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1210 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1212 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1215 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1217 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1220 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1221 DataBrowserTableViewColumnIndex
*position
) const
1223 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1226 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1228 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1231 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1233 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1236 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1238 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1241 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1243 return GetDataBrowserSortProperty( m_controlRef
, column
);
1246 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1248 return SetDataBrowserSortProperty( m_controlRef
, column
);
1251 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1253 return GetDataBrowserSortOrder( m_controlRef
, order
);
1256 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1258 return SetDataBrowserSortOrder( m_controlRef
, order
);
1261 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1262 DataBrowserPropertyFlags
*flags
) const
1264 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1267 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1268 DataBrowserPropertyFlags flags
)
1270 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1273 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1274 DataBrowserListViewHeaderDesc
*desc
) const
1276 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1279 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1280 DataBrowserListViewHeaderDesc
*desc
)
1282 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1285 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1286 Boolean expandableRows
)
1288 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1291 // ============================================================================
1292 // Higher-level Databrowser
1293 // ============================================================================
1295 // basing on data item objects
1298 wxMacDataItem::wxMacDataItem()
1303 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1306 wxMacDataItem::~wxMacDataItem()
1310 void wxMacDataItem::SetOrder( SInt32 order
)
1315 SInt32
wxMacDataItem::GetOrder() const
1320 void wxMacDataItem::SetData( void* data
)
1325 void* wxMacDataItem::GetData() const
1330 short wxMacDataItem::GetColumn()
1335 void wxMacDataItem::SetColumn( short col
)
1340 void wxMacDataItem::SetLabel( const wxString
& str
)
1343 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1346 const wxString
& wxMacDataItem::GetLabel() const
1351 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1352 const wxMacDataItem
* rhs
,
1353 DataBrowserPropertyID sortProperty
) const
1355 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1356 bool retval
= false;
1358 if ( sortProperty
== m_colId
){
1359 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1362 else if ( sortProperty
== kNumericOrderColumnId
)
1363 retval
= m_order
< otherItem
->m_order
;
1368 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1369 DataBrowserPropertyID property
,
1370 DataBrowserItemDataRef itemData
,
1373 OSStatus err
= errDataBrowserPropertyNotSupported
;
1376 if ( property
== m_colId
){
1377 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1380 else if ( property
== kNumericOrderColumnId
){
1381 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1391 // no editable props here
1400 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
1401 DataBrowserItemNotification
WXUNUSED(message
),
1402 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
1406 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1408 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1409 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1411 m_suppressSelection
= false;
1412 m_sortOrder
= SortOrder_None
;
1413 m_clientDataItemsType
= wxClientData_None
;
1416 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1418 return new wxMacDataItem();
1421 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1423 m_former
= browser
->SuppressSelection(true);
1424 m_browser
= browser
;
1427 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1429 m_browser
->SuppressSelection(m_former
);
1432 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1434 bool former
= m_suppressSelection
;
1435 m_suppressSelection
= suppress
;
1440 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1441 DataBrowserItemID itemTwoID
,
1442 DataBrowserPropertyID sortProperty
)
1444 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1445 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1446 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1449 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1450 const wxMacDataItem
* itemTwo
,
1451 DataBrowserPropertyID sortProperty
)
1453 Boolean retval
= false;
1454 if ( itemOne
!= NULL
)
1455 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1459 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1460 DataBrowserItemID itemID
,
1461 DataBrowserPropertyID property
,
1462 DataBrowserItemDataRef itemData
,
1463 Boolean changeValue
)
1465 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1466 return GetSetItemData(item
, property
, itemData
, changeValue
);
1469 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1470 wxMacDataItem
* item
,
1471 DataBrowserPropertyID property
,
1472 DataBrowserItemDataRef itemData
,
1473 Boolean changeValue
)
1475 OSStatus err
= errDataBrowserPropertyNotSupported
;
1478 case kDataBrowserContainerIsClosableProperty
:
1479 case kDataBrowserContainerIsSortableProperty
:
1480 case kDataBrowserContainerIsOpenableProperty
:
1481 // right now default behaviour on these
1485 if ( item
!= NULL
){
1486 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1494 void wxMacDataItemBrowserControl::ItemNotification(
1495 DataBrowserItemID itemID
,
1496 DataBrowserItemNotification message
,
1497 DataBrowserItemDataRef itemData
)
1499 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1500 ItemNotification( item
, message
, itemData
);
1503 void wxMacDataItemBrowserControl::ItemNotification(
1504 const wxMacDataItem
* item
,
1505 DataBrowserItemNotification message
,
1506 DataBrowserItemDataRef itemData
)
1509 item
->Notification( this, message
, itemData
);
1512 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1513 bool recurse
, DataBrowserItemState state
) const
1515 ItemCount numItems
= 0;
1516 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1517 recurse
, state
, &numItems
) );
1521 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1522 bool recurse
) const
1524 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1528 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1529 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1531 Handle handle
= NewHandle(0);
1532 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1533 recurse
, state
, handle
) );
1535 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1537 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1538 for ( int i
= 0; i
< itemCount
; ++i
)
1540 items
.Add(itemsArray
[i
]);
1543 DisposeHandle( handle
);
1546 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1548 DataBrowserTableViewRowIndex row
;
1549 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1550 wxASSERT( err
== noErr
);
1554 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1556 DataBrowserItemID id
;
1557 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1558 wxASSERT( err
== noErr
);
1559 return (wxMacDataItem
*) id
;
1562 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1563 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1565 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1566 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1569 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1570 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1572 unsigned int noItems
= itemArray
.GetCount();
1573 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1574 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1575 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1577 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1578 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1582 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1583 const wxString
& title
, SInt16 just
, int defaultWidth
)
1585 DataBrowserListViewColumnDesc columnDesc
;
1586 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1587 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1589 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1590 kControlUseFontMask
| kControlUseJustMask
;
1592 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1593 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1594 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1595 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1597 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1598 // defined for other modes?
1601 enc
= m_font
.GetEncoding();
1603 enc
= wxLocale::GetSystemEncoding();
1604 wxMacCFStringHolder cfTitle
;
1605 cfTitle
.Assign( title
, enc
);
1606 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1608 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1609 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1611 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1612 columnDesc
.propertyDesc
.propertyType
= colType
;
1613 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1614 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1615 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1617 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1619 if (defaultWidth
> 0){
1620 SetColumnWidth(colId
, defaultWidth
);
1625 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1627 DataBrowserPropertyID id
;
1628 GetColumnIDFromIndex(colId
, &id
);
1629 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1632 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1634 DataBrowserPropertyID id
;
1635 GetColumnIDFromIndex(colId
, &id
);
1637 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1641 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1643 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1644 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1647 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1649 unsigned int noItems
= itemArray
.GetCount();
1650 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1651 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1652 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1654 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1655 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1659 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1661 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1662 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1663 verify_noerr( err
);
1666 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1668 unsigned int noItems
= itemArray
.GetCount();
1669 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1670 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1671 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1673 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1674 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1675 verify_noerr( err
);
1679 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1681 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1682 verify_noerr( err
);
1685 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1687 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1690 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1692 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1695 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1697 unsigned int noItems
= itemArray
.GetCount();
1698 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1699 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1700 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1702 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1706 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1708 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1711 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1713 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1716 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1718 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1721 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1723 return m_clientDataItemsType
;
1725 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1727 m_clientDataItemsType
= clientDataItemsType
;
1730 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1732 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
1735 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1737 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1738 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1741 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
,
1742 const wxArrayStringsAdapter
& items
,
1745 size_t itemsCount
= items
.GetCount();
1746 if ( itemsCount
== 0 )
1749 SInt32 frontLineOrder
= 0;
1751 if ( m_sortOrder
== SortOrder_None
)
1753 // increase the order of the lines to be shifted
1754 unsigned int lines
= MacGetCount();
1755 for ( unsigned int i
= n
; i
< lines
; ++i
)
1757 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1758 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
1762 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1763 frontLineOrder
= iter
->GetOrder();
1767 wxArrayMacDataItemPtr ids
;
1768 ids
.SetCount( itemsCount
);
1770 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
1772 wxMacDataItem
* item
= CreateItem();
1773 item
->SetLabel( items
[i
]);
1775 item
->SetColumn( kMinColumnId
+ column
);
1777 if ( m_sortOrder
== SortOrder_None
)
1778 item
->SetOrder( frontLineOrder
+ 1 + i
);
1783 AddItems( wxMacDataBrowserRootContainer
, ids
);
1786 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
1788 wxMacDataItem
* item
= CreateItem();
1789 item
->SetLabel( text
);
1790 if ( m_sortOrder
== SortOrder_None
)
1792 unsigned int lines
= MacGetCount();
1794 item
->SetOrder( 1 );
1797 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
1798 item
->SetOrder( frontItem
->GetOrder() + 1 );
1801 AddItem( wxMacDataBrowserRootContainer
, item
);
1803 return GetLineFromItem(item
);
1806 void wxMacDataItemBrowserControl::MacClear()
1808 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1809 RemoveAllItems(wxMacDataBrowserRootContainer
);
1812 void wxMacDataItemBrowserControl::MacDeselectAll()
1814 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1815 SetSelectedAllItems( kDataBrowserItemsRemove
);
1818 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
1820 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1821 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1823 if ( IsItemSelected( item
) != select
)
1826 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
1828 SetSelectedItem( item
, kDataBrowserItemsRemove
);
1834 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
1836 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
1837 return IsItemSelected( item
);
1840 int wxMacDataItemBrowserControl::MacGetSelection() const
1842 wxMacDataItemPtr first
, last
;
1843 GetSelectionAnchor( &first
, &last
);
1845 if ( first
!= NULL
)
1847 return GetLineFromItem( first
);
1853 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
1855 aSelections
.Empty();
1856 wxArrayMacDataItemPtr selectedItems
;
1857 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
1859 int count
= selectedItems
.GetCount();
1861 for ( int i
= 0; i
< count
; ++i
)
1863 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
1869 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
1871 // as we don't store the strings we only have to issue a redraw
1872 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1873 item
->SetLabel( text
);
1874 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
1877 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
1879 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1880 return item
->GetLabel();
1883 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
1885 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1886 item
->SetData( data
);
1887 // not displayed, therefore no Update infos to DataBrowser
1890 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
1892 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1893 return item
->GetData();
1896 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
1899 GetScrollPosition( &top
, &left
) ;
1900 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
1902 // there is a bug in RevealItem that leads to situations
1903 // in large lists, where the item does not get scrolled
1904 // into sight, so we do a pre-scroll if necessary
1906 GetRowHeight( (DataBrowserItemID
) item
, &height
) ;
1907 UInt32 linetop
= n
* ((UInt32
) height
);
1908 UInt32 linebottom
= linetop
+ height
;
1912 if ( linetop
< top
|| linebottom
> (top
+ rect
.bottom
- rect
.top
) )
1913 SetScrollPosition( wxMax( n
-2, 0 ) * ((UInt32
)height
) , left
) ;
1915 RevealItem( item
, kDataBrowserRevealWithoutSelecting
);
1924 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1926 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
1936 Return the generic RGB color space. This is a 'get' function and the caller should
1937 not release the returned value unless the caller retains it first. Usually callers
1938 of this routine will immediately use the returned colorspace with CoreGraphics
1939 so they typically do not need to retain it themselves.
1941 This function creates the generic RGB color space once and hangs onto it so it can
1942 return it whenever this function is called.
1945 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
1947 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
1949 if (genericRGBColorSpace
== NULL
)
1951 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
1954 return genericRGBColorSpace
;
1957 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
1960 HIThemeBrushCreateCGColor( brush
, &color
);
1964 #if wxMAC_USE_QUICKDRAW
1966 static inline void PointFromHIPoint(const HIPoint
& p
, Point
*pt
)
1968 pt
->h
= wx_static_cast(short, p
.x
);
1969 pt
->v
= wx_static_cast(short, p
.y
);
1972 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
1974 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1975 HIViewRef contentView
;
1976 // TODO check toolbar offset
1977 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1978 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1979 PointFromHIPoint(p
, pt
);
1982 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
1984 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
1985 HIViewRef contentView
;
1986 // TODO check toolbar offset
1987 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
1988 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1989 PointFromHIPoint(p
, pt
);
1992 #endif // wxMAC_USE_QUICKDRAW