1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toolbar.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/toolbar.h"
23 #include "wx/mac/uma.h"
24 #include "wx/geometry.h"
28 const short kwxMacToolBarToolDefaultWidth
= 16;
29 const short kwxMacToolBarToolDefaultHeight
= 16;
30 const short kwxMacToolBarTopMargin
= 4;
31 const short kwxMacToolBarLeftMargin
= 4;
32 const short kwxMacToolBorder
= 0;
33 const short kwxMacToolSpacing
= 6;
35 const short kwxMacToolBarToolDefaultWidth
= 24;
36 const short kwxMacToolBarToolDefaultHeight
= 22;
37 const short kwxMacToolBarTopMargin
= 2;
38 const short kwxMacToolBarLeftMargin
= 2;
39 const short kwxMacToolBorder
= 4;
40 const short kwxMacToolSpacing
= 0;
44 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
46 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
47 EVT_PAINT( wxToolBar::OnPaint
)
52 #pragma mark Tool Implementation
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 // We have a dual implementation for each tool, ControlRef and HIToolbarItemRef
61 class wxToolBarTool
: public wxToolBarToolBase
67 const wxString
& label
,
68 const wxBitmap
& bmpNormal
,
69 const wxBitmap
& bmpDisabled
,
72 const wxString
& shortHelp
,
73 const wxString
& longHelp
);
75 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
)
76 : wxToolBarToolBase(tbar
, control
)
80 SetControlHandle( (ControlRef
) control
->GetHandle() );
83 virtual ~wxToolBarTool()
88 WXWidget
GetControlHandle()
90 return (WXWidget
) m_controlHandle
;
93 void SetControlHandle( ControlRef handle
)
95 m_controlHandle
= handle
;
98 void SetPosition( const wxPoint
& position
);
103 if ( m_controlHandle
)
106 DisposeControl( m_controlHandle
);
109 // the embedded control is not under the responsibility of the tool
111 m_controlHandle
= NULL
;
114 #if wxMAC_USE_NATIVE_TOOLBAR
115 if ( m_toolbarItemRef
)
117 CFIndex count
= CFGetRetainCount( m_toolbarItemRef
) ;
118 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
119 wxTheApp
->MacAddToAutorelease(m_toolbarItemRef
);
120 CFRelease(m_toolbarItemRef
);
121 m_toolbarItemRef
= NULL
;
126 wxSize
GetSize() const
132 curSize
= GetControl()->GetSize();
134 else if ( IsButton() )
136 curSize
= GetToolBar()->GetToolSize();
141 curSize
= GetToolBar()->GetToolSize();
142 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
151 wxPoint
GetPosition() const
153 return wxPoint( m_x
, m_y
);
156 bool DoEnable( bool enable
);
158 void UpdateToggleImage( bool toggle
);
160 #if wxMAC_USE_NATIVE_TOOLBAR
161 void SetToolbarItemRef( HIToolbarItemRef ref
)
163 if ( m_controlHandle
)
164 HideControl( m_controlHandle
);
165 if ( m_toolbarItemRef
)
166 CFRelease( m_toolbarItemRef
);
168 m_toolbarItemRef
= ref
;
169 if ( m_toolbarItemRef
)
174 f
= GetToolBar()->GetFont();
176 enc
= f
.GetEncoding();
178 enc
= wxFont::GetDefaultEncoding();
180 HIToolbarItemSetHelpText(
182 wxMacCFStringHolder( GetShortHelp(), enc
),
183 wxMacCFStringHolder( GetLongHelp(), enc
) );
187 HIToolbarItemRef
GetToolbarItemRef() const
189 return m_toolbarItemRef
;
192 void SetIndex( CFIndex idx
)
197 CFIndex
GetIndex() const
206 m_controlHandle
= NULL
;
208 #if wxMAC_USE_NATIVE_TOOLBAR
209 m_toolbarItemRef
= NULL
;
214 ControlRef m_controlHandle
;
218 #if wxMAC_USE_NATIVE_TOOLBAR
219 HIToolbarItemRef m_toolbarItemRef
;
220 // position in its toolbar, -1 means not inserted
225 static const EventTypeSpec eventList
[] =
227 { kEventClassControl
, kEventControlHit
},
229 { kEventClassControl
, kEventControlHitTest
},
233 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
235 OSStatus result
= eventNotHandledErr
;
236 ControlRef controlRef
;
237 wxMacCarbonEvent
cEvent( event
);
239 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
241 switch ( GetEventKind( event
) )
243 case kEventControlHit
:
245 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
246 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
247 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
252 shouldToggle
= !tbartool
->IsToggled();
254 shouldToggle
= (GetControl32BitValue( (ControlRef
)(tbartool
->GetControlHandle()) ) != 0);
257 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
260 if (tbartool
!= NULL
)
261 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
267 case kEventControlHitTest
:
269 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
271 HIViewGetBounds( controlRef
, &rect
);
273 ControlPartCode pc
= kControlNoPart
;
274 if ( CGRectContainsPoint( rect
, pt
) )
275 pc
= kControlIconPart
;
276 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
289 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
291 OSStatus result
= eventNotHandledErr
;
293 switch ( GetEventClass( event
) )
295 case kEventClassControl
:
296 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
306 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
308 #if wxMAC_USE_NATIVE_TOOLBAR
310 static const EventTypeSpec toolBarEventList
[] =
312 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
315 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
317 OSStatus result
= eventNotHandledErr
;
319 switch ( GetEventKind( event
) )
321 case kEventToolbarItemPerformAction
:
323 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
324 if ( tbartool
!= NULL
)
326 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
327 int toolID
= tbartool
->GetId();
329 if ( tbartool
->CanBeToggled() )
332 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
336 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
349 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
351 OSStatus result
= eventNotHandledErr
;
353 switch ( GetEventClass( event
) )
355 case kEventClassToolbarItem
:
356 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
366 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
370 bool wxToolBarTool::DoEnable( bool enable
)
374 GetControl()->Enable( enable
);
376 else if ( IsButton() )
378 #if wxMAC_USE_NATIVE_TOOLBAR
379 if ( m_toolbarItemRef
!= NULL
)
380 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
383 if ( m_controlHandle
!= NULL
)
385 #if TARGET_API_MAC_OSX
387 EnableControl( m_controlHandle
);
389 DisableControl( m_controlHandle
);
392 ActivateControl( m_controlHandle
);
394 DeactivateControl( m_controlHandle
);
402 void wxToolBarTool::SetPosition( const wxPoint
& position
)
407 int mac_x
= position
.x
;
408 int mac_y
= position
.y
;
413 GetControlBounds( m_controlHandle
, &contrlRect
);
414 int former_mac_x
= contrlRect
.left
;
415 int former_mac_y
= contrlRect
.top
;
416 GetToolBar()->GetToolSize();
418 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
420 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
423 else if ( IsControl() )
425 // embedded native controls are moved by the OS
426 #if wxMAC_USE_NATIVE_TOOLBAR
427 if ( ((wxToolBar
*)GetToolBar())->MacWantsNativeToolbar() == false )
430 GetControl()->Move( position
);
438 GetControlBounds( m_controlHandle
, &contrlRect
);
439 int former_mac_x
= contrlRect
.left
;
440 int former_mac_y
= contrlRect
.top
;
442 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
443 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
448 void wxToolBarTool::UpdateToggleImage( bool toggle
)
453 int w
= m_bmpNormal
.GetWidth();
454 int h
= m_bmpNormal
.GetHeight();
455 wxBitmap
bmp( w
, h
);
458 dc
.SelectObject( bmp
);
459 dc
.SetPen( wxPen(*wxBLACK
) );
460 dc
.SetBrush( wxBrush( *wxLIGHT_GREY
));
461 dc
.DrawRectangle( 0, 0, w
, h
);
462 dc
.DrawBitmap( m_bmpNormal
, 0, 0, true );
463 dc
.SelectObject( wxNullBitmap
);
464 ControlButtonContentInfo info
;
465 wxMacCreateBitmapButton( &info
, bmp
, kControlContentIconRef
);
466 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
467 #if wxMAC_USE_NATIVE_TOOLBAR
468 if (m_toolbarItemRef
!= NULL
)
470 HIToolbarItemSetIconRef( m_toolbarItemRef
, info
.u
.iconRef
);
473 wxMacReleaseBitmapButton( &info
);
477 ControlButtonContentInfo info
;
478 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
);
479 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
480 #if wxMAC_USE_NATIVE_TOOLBAR
481 if (m_toolbarItemRef
!= NULL
)
483 HIToolbarItemSetIconRef( m_toolbarItemRef
, info
.u
.iconRef
);
486 wxMacReleaseBitmapButton( &info
);
489 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
491 m_controlHandle
, 0, kControlIconTransformTag
,
492 sizeof(transform
), (Ptr
)&transform
);
493 HIViewSetNeedsDisplay( m_controlHandle
, true );
496 ::SetControl32BitValue( m_controlHandle
, toggle
);
500 wxToolBarTool::wxToolBarTool(
503 const wxString
& label
,
504 const wxBitmap
& bmpNormal
,
505 const wxBitmap
& bmpDisabled
,
507 wxObject
*clientData
,
508 const wxString
& shortHelp
,
509 const wxString
& longHelp
)
512 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
513 clientData
, shortHelp
, longHelp
)
519 #pragma mark Toolbar Implementation
521 wxToolBarToolBase
*wxToolBar::CreateTool(
523 const wxString
& label
,
524 const wxBitmap
& bmpNormal
,
525 const wxBitmap
& bmpDisabled
,
527 wxObject
*clientData
,
528 const wxString
& shortHelp
,
529 const wxString
& longHelp
)
531 return new wxToolBarTool(
532 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
533 clientData
, shortHelp
, longHelp
);
536 wxToolBarToolBase
* wxToolBar::CreateTool( wxControl
*control
)
538 return new wxToolBarTool( this, control
);
541 void wxToolBar::Init()
545 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
546 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
548 #if wxMAC_USE_NATIVE_TOOLBAR
549 m_macHIToolbarRef
= NULL
;
550 m_macUsesNativeToolbar
= false;
554 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
556 const EventTypeSpec kEvents
[] =
558 { kEventClassHIObject
, kEventHIObjectConstruct
},
559 { kEventClassHIObject
, kEventHIObjectInitialize
},
560 { kEventClassHIObject
, kEventHIObjectDestruct
},
562 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
565 const EventTypeSpec kViewEvents
[] =
567 { kEventClassControl
, kEventControlGetSizeConstraints
}
570 struct ControlToolbarItem
572 HIToolbarItemRef toolbarItem
;
574 wxSize lastValidSize
;
577 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
579 OSStatus result
= eventNotHandledErr
;
580 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
582 switch ( GetEventClass( inEvent
) )
584 case kEventClassHIObject
:
585 switch ( GetEventKind( inEvent
) )
587 case kEventHIObjectConstruct
:
589 HIObjectRef toolbarItem
;
590 ControlToolbarItem
* item
;
592 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
593 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
595 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
596 item
->toolbarItem
= toolbarItem
;
597 item
->viewRef
= NULL
;
599 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
605 case kEventHIObjectInitialize
:
606 result
= CallNextEventHandler( inCallRef
, inEvent
);
607 if ( result
== noErr
)
610 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
611 sizeof( CFTypeRef
), NULL
, &data
);
615 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
616 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
618 object
->viewRef
= (HIViewRef
) viewRef
;
624 case kEventHIObjectDestruct
:
626 // we've increased the ref count when creating this, so we decrease manually again in case
627 // it was never really installed and deinstalled
628 HIViewRef viewRef
= object
->viewRef
;
629 if( viewRef
&& IsValidControlHandle( viewRef
) )
631 CFIndex count
= CFGetRetainCount( viewRef
) ;
633 CFRelease( viewRef
) ;
642 case kEventClassToolbarItem
:
643 switch ( GetEventKind( inEvent
) )
645 case kEventToolbarItemCreateCustomView
:
647 HIViewRef viewRef
= object
->viewRef
;
649 HIViewRemoveFromSuperview( viewRef
) ;
650 HIViewSetVisible(viewRef
, true) ;
651 InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
652 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
);
654 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
660 case kEventClassControl
:
661 switch ( GetEventKind( inEvent
) )
663 case kEventControlGetSizeConstraints
:
665 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
668 wxSize sz
= wxwindow
->GetSize() ;
669 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
670 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
671 // during toolbar layout the native window sometimes gets negative sizes
672 // so we always keep the last valid size here, to make sure we survive the
674 if ( sz
.x
> 0 && sz
.y
> 0 )
675 object
->lastValidSize
= sz
;
677 sz
= object
->lastValidSize
;
680 min
.width
= max
.width
= sz
.x
;
681 min
.height
= max
.height
= sz
.y
;
683 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
684 sizeof( HISize
), &min
);
686 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
687 sizeof( HISize
), &max
);
699 void RegisterControlToolbarItemClass()
701 static bool sRegistered
;
705 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
706 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
712 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
714 RegisterControlToolbarItemClass();
718 UInt32 options
= kHIToolbarItemAllowDuplicates
;
719 HIToolbarItemRef result
= NULL
;
721 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
722 require_noerr( err
, CantCreateEvent
);
724 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
725 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
728 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
730 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
733 ReleaseEvent( event
);
738 #if wxMAC_USE_NATIVE_TOOLBAR
739 static const EventTypeSpec kToolbarEvents
[] =
741 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
742 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
743 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
746 static OSStatus
ToolbarDelegateHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
748 OSStatus result
= eventNotHandledErr
;
750 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
751 CFMutableArrayRef array
;
753 switch ( GetEventKind( inEvent
) )
755 case kEventToolbarGetDefaultIdentifiers
:
757 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
758 sizeof( CFMutableArrayRef
), NULL
, &array
);
759 // not implemented yet
760 // GetToolbarDefaultItems( array );
765 case kEventToolbarGetAllowedIdentifiers
:
767 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
768 sizeof( CFMutableArrayRef
), NULL
, &array
);
769 // not implemented yet
770 // GetToolbarAllowedItems( array );
774 case kEventToolbarCreateItemWithIdentifier
:
776 HIToolbarItemRef item
= NULL
;
777 CFTypeRef data
= NULL
;
778 CFStringRef identifier
= NULL
;
780 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
781 sizeof( CFStringRef
), NULL
, &identifier
);
783 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
784 sizeof( CFTypeRef
), NULL
, &data
);
786 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
788 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
791 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
792 sizeof( HIToolbarItemRef
), &item
);
802 #endif // wxMAC_USE_NATIVE_TOOLBAR
804 // also for the toolbar we have the dual implementation:
805 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
807 bool wxToolBar::Create(
813 const wxString
& name
)
815 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
820 OSStatus err
= noErr
;
822 #if wxMAC_USE_NATIVE_TOOLBAR
823 wxString labelStr
= wxString::Format( wxT("%xd"), (int)this );
824 err
= HIToolbarCreate(
825 wxMacCFStringHolder( labelStr
, wxFont::GetDefaultEncoding() ), 0,
826 (HIToolbarRef
*) &m_macHIToolbarRef
);
828 if (m_macHIToolbarRef
!= NULL
)
830 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
831 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
833 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
834 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
836 if ( style
& wxTB_NOICONS
)
837 mode
= kHIToolbarDisplayModeLabelOnly
;
838 else if ( style
& wxTB_TEXT
)
839 mode
= kHIToolbarDisplayModeIconAndLabel
;
841 mode
= kHIToolbarDisplayModeIconOnly
;
843 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
844 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
848 return (err
== noErr
);
851 wxToolBar::~wxToolBar()
853 #if wxMAC_USE_NATIVE_TOOLBAR
854 if (m_macHIToolbarRef
!= NULL
)
856 // if this is the installed toolbar, then deinstall it
857 if (m_macUsesNativeToolbar
)
858 MacInstallNativeToolbar( false );
860 CFIndex count
= CFGetRetainCount( m_macHIToolbarRef
) ;
861 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
863 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
864 m_macHIToolbarRef
= NULL
;
869 bool wxToolBar::Show( bool show
)
871 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
872 bool bResult
= (tlw
!= NULL
);
876 #if wxMAC_USE_NATIVE_TOOLBAR
877 bool ownToolbarInstalled
= false;
878 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
879 if (ownToolbarInstalled
)
881 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
883 ShowHideWindowToolbar( tlw
, show
, false );
886 bResult
= wxToolBarBase::Show( show
);
889 bResult
= wxToolBarBase::Show( show
);
896 bool wxToolBar::IsShown() const
900 #if wxMAC_USE_NATIVE_TOOLBAR
901 bool ownToolbarInstalled
;
903 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
904 if (ownToolbarInstalled
)
906 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
907 bResult
= IsWindowToolbarVisible( tlw
);
910 bResult
= wxToolBarBase::IsShown();
913 bResult
= wxToolBarBase::IsShown();
919 void wxToolBar::DoGetSize( int *width
, int *height
) const
921 #if wxMAC_USE_NATIVE_TOOLBAR
923 bool ownToolbarInstalled
;
925 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
926 if ( ownToolbarInstalled
)
928 // TODO: is this really a control ?
929 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
931 *width
= boundsR
.right
- boundsR
.left
;
932 if ( height
!= NULL
)
933 *height
= boundsR
.bottom
- boundsR
.top
;
936 wxToolBarBase::DoGetSize( width
, height
);
939 wxToolBarBase::DoGetSize( width
, height
);
943 wxSize
wxToolBar::DoGetBestSize() const
947 DoGetSize( &width
, &height
);
949 return wxSize( width
, height
);
952 void wxToolBar::SetWindowStyleFlag( long style
)
954 wxToolBarBase::SetWindowStyleFlag( style
);
956 #if wxMAC_USE_NATIVE_TOOLBAR
957 if (m_macHIToolbarRef
!= NULL
)
959 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
961 if ( style
& wxTB_NOICONS
)
962 mode
= kHIToolbarDisplayModeLabelOnly
;
963 else if ( style
& wxTB_TEXT
)
964 mode
= kHIToolbarDisplayModeIconAndLabel
;
966 mode
= kHIToolbarDisplayModeIconOnly
;
968 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
973 #if wxMAC_USE_NATIVE_TOOLBAR
974 bool wxToolBar::MacWantsNativeToolbar()
976 return m_macUsesNativeToolbar
;
979 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
981 bool bResultV
= false;
983 if (ownToolbarInstalled
!= NULL
)
984 *ownToolbarInstalled
= false;
986 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
989 HIToolbarRef curToolbarRef
= NULL
;
990 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
991 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
992 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
993 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
999 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
1001 bool bResult
= false;
1003 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
1006 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
1009 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1013 // check the existing toolbar
1014 HIToolbarRef curToolbarRef
= NULL
;
1015 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1017 curToolbarRef
= NULL
;
1019 m_macUsesNativeToolbar
= usesNative
;
1021 if (m_macUsesNativeToolbar
)
1023 // only install toolbar if there isn't one installed already
1024 if (curToolbarRef
== NULL
)
1028 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1029 ShowHideWindowToolbar( tlw
, true, false );
1030 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1031 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1033 Rect r
= { 0, 0, 0, 0 };
1034 m_peer
->SetRect( &r
);
1035 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1036 m_peer
->SetVisibility( false, true );
1037 wxToolBarBase::Show( false );
1042 // only deinstall toolbar if this is the installed one
1043 if (m_macHIToolbarRef
== curToolbarRef
)
1047 ShowHideWindowToolbar( tlw
, false, false );
1048 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1049 SetWindowToolbar( tlw
, NULL
);
1051 m_peer
->SetVisibility( true, true );
1056 InvalidateBestSize();
1058 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1063 bool wxToolBar::Realize()
1065 if (m_tools
.GetCount() == 0)
1071 int maxToolWidth
= 0;
1072 int maxToolHeight
= 0;
1074 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1075 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1078 GetSize( &tw
, &th
);
1080 // find the maximum tool width and height
1081 wxToolBarTool
*tool
;
1082 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1083 while ( node
!= NULL
)
1085 tool
= (wxToolBarTool
*) node
->GetData();
1088 wxSize sz
= tool
->GetSize();
1090 if ( sz
.x
> maxToolWidth
)
1091 maxToolWidth
= sz
.x
;
1092 if ( sz
.y
> maxToolHeight
)
1093 maxToolHeight
= sz
.y
;
1096 node
= node
->GetNext();
1099 bool lastIsRadio
= false;
1100 bool curIsRadio
= false;
1102 #if wxMAC_USE_NATIVE_TOOLBAR
1103 CFIndex currentPosition
= 0;
1104 bool insertAll
= false;
1107 node
= m_tools
.GetFirst();
1108 while ( node
!= NULL
)
1110 tool
= (wxToolBarTool
*) node
->GetData();
1113 node
= node
->GetNext();
1117 // set tool position:
1118 // for the moment just perform a single row/column alignment
1119 wxSize cursize
= tool
->GetSize();
1120 if ( x
+ cursize
.x
> maxWidth
)
1121 maxWidth
= x
+ cursize
.x
;
1122 if ( y
+ cursize
.y
> maxHeight
)
1123 maxHeight
= y
+ cursize
.y
;
1125 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1127 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1128 tool
->SetPosition( wxPoint(x1
, y
) );
1132 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1133 tool
->SetPosition( wxPoint(x
, y1
) );
1136 // update the item positioning state
1137 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1138 y
+= cursize
.y
+ kwxMacToolSpacing
;
1140 x
+= cursize
.x
+ kwxMacToolSpacing
;
1142 #if wxMAC_USE_NATIVE_TOOLBAR
1143 // install in native HIToolbar
1144 if ( m_macHIToolbarRef
!= NULL
)
1146 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1147 if ( hiItemRef
!= NULL
)
1149 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1151 OSStatus err
= noErr
;
1156 // if this is the first tool that gets newly inserted or repositioned
1157 // first remove all 'old' tools from here to the right, because of this
1158 // all following tools will have to be reinserted (insertAll). i = 100 because there's
1159 // no way to determine how many there are in a toolbar, so just a high number :-(
1160 for ( CFIndex i
= 100; i
>= currentPosition
; --i
)
1162 err
= HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, i
);
1167 wxString errMsg
= wxString::Format( wxT("HIToolbarRemoveItemAtIndex failed [%ld]"), (long)err
);
1168 wxFAIL_MSG( errMsg
.c_str() );
1172 err
= HIToolbarInsertItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, hiItemRef
, currentPosition
);
1175 wxString errMsg
= wxString::Format( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1176 wxFAIL_MSG( errMsg
.c_str() );
1179 tool
->SetIndex( currentPosition
);
1187 // update radio button (and group) state
1188 lastIsRadio
= curIsRadio
;
1189 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1193 if ( tool
->IsToggled() )
1194 DoToggleTool( tool
, true );
1200 if ( tool
->Toggle( true ) )
1202 DoToggleTool( tool
, true );
1205 else if ( tool
->IsToggled() )
1207 if ( tool
->IsToggled() )
1208 DoToggleTool( tool
, true );
1210 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1211 while ( nodePrev
!= NULL
)
1213 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1214 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1217 if ( toggleTool
->Toggle( false ) )
1218 DoToggleTool( toggleTool
, false );
1220 nodePrev
= nodePrev
->GetPrevious();
1225 node
= node
->GetNext();
1228 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1230 // if not set yet, only one row
1231 if ( m_maxRows
<= 0 )
1234 m_minWidth
= maxWidth
;
1236 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1237 m_minHeight
= m_maxHeight
= maxHeight
;
1241 // if not set yet, have one column
1242 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1243 SetRows( GetToolsCount() );
1245 m_minHeight
= maxHeight
;
1247 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1248 m_minWidth
= m_maxWidth
= maxWidth
;
1252 // FIXME: should this be OSX-only?
1254 bool wantNativeToolbar
, ownToolbarInstalled
;
1256 // attempt to install the native toolbar
1257 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1258 MacInstallNativeToolbar( wantNativeToolbar
);
1259 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1260 if (!ownToolbarInstalled
)
1262 SetSize( maxWidth
, maxHeight
);
1263 InvalidateBestSize();
1267 SetSize( maxWidth
, maxHeight
);
1268 InvalidateBestSize();
1276 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1278 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1279 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1281 #if wxMAC_USE_NATIVE_TOOLBAR
1282 if (m_macHIToolbarRef
!= NULL
)
1284 int maxs
= wxMax( size
.x
, size
.y
);
1285 HIToolbarDisplaySize sizeSpec
;
1287 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1288 else if ( maxs
> 24 )
1289 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1291 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1293 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1298 // The button size is bigger than the bitmap size
1299 wxSize
wxToolBar::GetToolSize() const
1301 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1304 void wxToolBar::SetRows(int nRows
)
1306 // avoid resizing the frame uselessly
1307 if ( nRows
!= m_maxRows
)
1311 void wxToolBar::MacSuperChangedPosition()
1313 wxWindow::MacSuperChangedPosition();
1315 #if wxMAC_USE_NATIVE_TOOLBAR
1316 if (! m_macUsesNativeToolbar
)
1324 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1326 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1329 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1331 tool
->SetNormalBitmap(bitmap
);
1333 // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
1334 tool
->UpdateToggleImage( tool
->CanBeToggled() && tool
->IsToggled() );
1338 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1340 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1343 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1345 tool
->SetDisabledBitmap(bitmap
);
1347 // TODO: what to do for this one?
1351 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1353 wxToolBarTool
*tool
;
1354 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1355 while ( node
!= NULL
)
1357 tool
= (wxToolBarTool
*)node
->GetData();
1360 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1361 if ( r
.Contains( wxPoint( x
, y
) ) )
1365 node
= node
->GetNext();
1368 return (wxToolBarToolBase
*)NULL
;
1371 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1373 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1375 return tool
->GetShortHelp();
1377 return wxEmptyString
;
1380 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1383 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1386 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1388 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1389 if ( ( tool
!= NULL
) && tool
->IsButton() )
1390 tool
->UpdateToggleImage( toggle
);
1393 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1395 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1399 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1400 wxSize toolSize
= GetToolSize();
1401 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1402 ControlRef controlHandle
= NULL
;
1404 tool
->Attach( this );
1406 switch (tool
->GetStyle())
1408 case wxTOOL_STYLE_SEPARATOR
:
1410 wxASSERT( tool
->GetControlHandle() == NULL
);
1413 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1414 toolrect
.bottom
= toolSize
.y
;
1416 toolrect
.right
= toolSize
.x
;
1418 #ifdef __WXMAC_OSX__
1419 // in flat style we need a visual separator
1420 #if wxMAC_USE_NATIVE_TOOLBAR
1421 HIToolbarItemRef item
;
1422 err
= HIToolbarItemCreate(
1423 kHIToolbarSeparatorIdentifier
,
1424 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1427 tool
->SetToolbarItemRef( item
);
1430 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1431 tool
->SetControlHandle( controlHandle
);
1436 case wxTOOL_STYLE_BUTTON
:
1438 wxASSERT( tool
->GetControlHandle() == NULL
);
1439 ControlButtonContentInfo info
;
1440 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1442 if ( UMAGetSystemVersion() >= 0x1000)
1444 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1448 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1449 if ( tool
->CanBeToggled() )
1450 behaviour
|= kControlBehaviorToggles
;
1451 err
= CreateBevelButtonControl( window
,
1452 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1453 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1456 #if wxMAC_USE_NATIVE_TOOLBAR
1457 HIToolbarItemRef item
;
1458 wxString labelStr
= wxString::Format(wxT("%xd"), (int)tool
);
1459 err
= HIToolbarItemCreate(
1460 wxMacCFStringHolder(labelStr
, wxFont::GetDefaultEncoding()),
1461 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1464 InstallEventHandler(
1465 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1466 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1467 HIToolbarItemSetLabel( item
, wxMacCFStringHolder(tool
->GetLabel(), m_font
.GetEncoding()) );
1468 HIToolbarItemSetIconRef( item
, info
.u
.iconRef
);
1469 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1470 tool
->SetToolbarItemRef( item
);
1474 wxMacReleaseBitmapButton( &info
);
1477 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1478 UMASetControlTitle( m_controlHandle
, label
, wxFont::GetDefaultEncoding() );
1481 InstallControlEventHandler(
1482 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1483 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1485 tool
->SetControlHandle( controlHandle
);
1489 case wxTOOL_STYLE_CONTROL
:
1491 #if wxMAC_USE_NATIVE_TOOLBAR
1493 wxASSERT( tool
->GetControl() != NULL
);
1494 HIToolbarItemRef item
;
1495 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
1496 // as this control now is part of both the wxToolBar children and the native toolbar, we have to increase the
1497 // reference count to make sure we are not dealing with zombie controls after the native toolbar has released its views
1498 CFRetain( viewRef
) ;
1499 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1500 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1505 tool
->SetToolbarItemRef( item
);
1511 // right now there's nothing to do here
1521 if ( controlHandle
)
1523 ControlRef container
= (ControlRef
) GetHandle();
1524 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1526 UMAShowControl( controlHandle
);
1527 ::EmbedControl( controlHandle
, container
);
1530 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1531 tool
->UpdateToggleImage( true );
1533 // nothing special to do here - we relayout in Realize() later
1534 InvalidateBestSize();
1538 wxString errMsg
= wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
);
1539 wxFAIL_MSG( errMsg
.c_str() );
1542 return (err
== noErr
);
1545 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1547 wxFAIL_MSG( wxT("not implemented") );
1550 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1552 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1553 wxToolBarToolsList::compatibility_iterator node
;
1554 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1556 wxToolBarToolBase
*tool2
= node
->GetData();
1557 if ( tool2
== tool
)
1559 // let node point to the next node in the list
1560 node
= node
->GetNext();
1566 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1570 #if wxMAC_USE_NATIVE_TOOLBAR
1571 CFIndex removeIndex
= tool
->GetIndex();
1574 #if wxMAC_USE_NATIVE_TOOLBAR
1575 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1577 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1578 tool
->SetIndex( -1 );
1581 switch ( tool
->GetStyle() )
1583 case wxTOOL_STYLE_CONTROL
:
1584 if ( tool
->GetControl() )
1585 tool
->GetControl()->Destroy();
1588 case wxTOOL_STYLE_BUTTON
:
1589 case wxTOOL_STYLE_SEPARATOR
:
1596 tool
->ClearControl();
1598 // and finally reposition all the controls after this one
1600 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1602 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1603 wxPoint pt
= tool2
->GetPosition();
1605 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1610 tool2
->SetPosition( pt
);
1612 #if wxMAC_USE_NATIVE_TOOLBAR
1613 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1614 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1618 InvalidateBestSize();
1623 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1625 #if wxMAC_USE_NATIVE_TOOLBAR
1626 if ( m_macUsesNativeToolbar
)
1638 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1639 bool minimumUmaAvailable
= (UMAGetSystemVersion() >= 0x1030);
1641 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1642 if ( !drawMetalTheme
&& minimumUmaAvailable
)
1644 HIThemePlacardDrawInfo info
;
1645 memset( &info
, 0, sizeof(info
) );
1647 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1649 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1650 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1651 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1655 // leave the background as it is (striped or metal)
1660 const bool drawBorder
= true;
1664 wxMacPortSetter
helper( &dc
);
1666 if ( !drawMetalTheme
|| !minimumUmaAvailable
)
1668 Rect toolbarrect
= { dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1669 dc
.YLOG2DEVMAC(h
), dc
.XLOG2DEVMAC(w
) };
1672 if ( toolbarrect
.left
< 0 )
1673 toolbarrect
.left
= 0;
1674 if ( toolbarrect
.top
< 0 )
1675 toolbarrect
.top
= 0;
1678 UMADrawThemePlacard( &toolbarrect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
);
1682 #if TARGET_API_MAC_OSX
1683 HIRect hiToolbarrect
= CGRectMake(
1684 dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1685 dc
.YLOG2DEVREL(h
), dc
.XLOG2DEVREL(w
) );
1686 CGContextRef cgContext
;
1689 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
1690 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1692 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
1693 CGContextScaleCTM( cgContext
, 1, -1 );
1695 HIThemeBackgroundDrawInfo drawInfo
;
1696 drawInfo
.version
= 0;
1697 drawInfo
.state
= kThemeStateActive
;
1698 drawInfo
.kind
= kThemeBackgroundMetal
;
1699 HIThemeApplyBackground( &hiToolbarrect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
1702 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1712 #endif // wxUSE_TOOLBAR