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
, const wxString
& label
)
76 : wxToolBarToolBase(tbar
, control
, label
)
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
);
537 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
539 return new wxToolBarTool(this, control
, label
);
542 void wxToolBar::Init()
546 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
547 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
549 #if wxMAC_USE_NATIVE_TOOLBAR
550 m_macHIToolbarRef
= NULL
;
551 m_macUsesNativeToolbar
= false;
555 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
557 const EventTypeSpec kEvents
[] =
559 { kEventClassHIObject
, kEventHIObjectConstruct
},
560 { kEventClassHIObject
, kEventHIObjectInitialize
},
561 { kEventClassHIObject
, kEventHIObjectDestruct
},
563 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
566 const EventTypeSpec kViewEvents
[] =
568 { kEventClassControl
, kEventControlGetSizeConstraints
}
571 struct ControlToolbarItem
573 HIToolbarItemRef toolbarItem
;
575 wxSize lastValidSize
;
578 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
580 OSStatus result
= eventNotHandledErr
;
581 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
583 switch ( GetEventClass( inEvent
) )
585 case kEventClassHIObject
:
586 switch ( GetEventKind( inEvent
) )
588 case kEventHIObjectConstruct
:
590 HIObjectRef toolbarItem
;
591 ControlToolbarItem
* item
;
593 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
594 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
596 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
597 item
->toolbarItem
= toolbarItem
;
598 item
->viewRef
= NULL
;
600 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
606 case kEventHIObjectInitialize
:
607 result
= CallNextEventHandler( inCallRef
, inEvent
);
608 if ( result
== noErr
)
611 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
612 sizeof( CFTypeRef
), NULL
, &data
);
616 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
617 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
619 object
->viewRef
= (HIViewRef
) viewRef
;
625 case kEventHIObjectDestruct
:
627 // we've increased the ref count when creating this, so we decrease manually again in case
628 // it was never really installed and deinstalled
629 HIViewRef viewRef
= object
->viewRef
;
630 if( viewRef
&& IsValidControlHandle( viewRef
) )
632 CFIndex count
= CFGetRetainCount( viewRef
) ;
634 CFRelease( viewRef
) ;
643 case kEventClassToolbarItem
:
644 switch ( GetEventKind( inEvent
) )
646 case kEventToolbarItemCreateCustomView
:
648 HIViewRef viewRef
= object
->viewRef
;
650 HIViewRemoveFromSuperview( viewRef
) ;
651 HIViewSetVisible(viewRef
, true) ;
652 InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
653 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
);
655 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
661 case kEventClassControl
:
662 switch ( GetEventKind( inEvent
) )
664 case kEventControlGetSizeConstraints
:
666 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
669 wxSize sz
= wxwindow
->GetSize() ;
670 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
671 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
672 // during toolbar layout the native window sometimes gets negative sizes
673 // so we always keep the last valid size here, to make sure we survive the
675 if ( sz
.x
> 0 && sz
.y
> 0 )
676 object
->lastValidSize
= sz
;
678 sz
= object
->lastValidSize
;
681 min
.width
= max
.width
= sz
.x
;
682 min
.height
= max
.height
= sz
.y
;
684 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
685 sizeof( HISize
), &min
);
687 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
688 sizeof( HISize
), &max
);
700 void RegisterControlToolbarItemClass()
702 static bool sRegistered
;
706 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
707 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
713 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
715 RegisterControlToolbarItemClass();
719 UInt32 options
= kHIToolbarItemAllowDuplicates
;
720 HIToolbarItemRef result
= NULL
;
722 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
723 require_noerr( err
, CantCreateEvent
);
725 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
726 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
729 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
731 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
734 ReleaseEvent( event
);
739 #if wxMAC_USE_NATIVE_TOOLBAR
740 static const EventTypeSpec kToolbarEvents
[] =
742 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
743 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
744 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
747 static OSStatus
ToolbarDelegateHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
749 OSStatus result
= eventNotHandledErr
;
751 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
752 CFMutableArrayRef array
;
754 switch ( GetEventKind( inEvent
) )
756 case kEventToolbarGetDefaultIdentifiers
:
758 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
759 sizeof( CFMutableArrayRef
), NULL
, &array
);
760 // not implemented yet
761 // GetToolbarDefaultItems( array );
766 case kEventToolbarGetAllowedIdentifiers
:
768 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
769 sizeof( CFMutableArrayRef
), NULL
, &array
);
770 // not implemented yet
771 // GetToolbarAllowedItems( array );
775 case kEventToolbarCreateItemWithIdentifier
:
777 HIToolbarItemRef item
= NULL
;
778 CFTypeRef data
= NULL
;
779 CFStringRef identifier
= NULL
;
781 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
782 sizeof( CFStringRef
), NULL
, &identifier
);
784 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
785 sizeof( CFTypeRef
), NULL
, &data
);
787 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
789 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
792 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
793 sizeof( HIToolbarItemRef
), &item
);
803 #endif // wxMAC_USE_NATIVE_TOOLBAR
805 // also for the toolbar we have the dual implementation:
806 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
808 bool wxToolBar::Create(
814 const wxString
& name
)
816 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
821 OSStatus err
= noErr
;
823 #if wxMAC_USE_NATIVE_TOOLBAR
824 wxString labelStr
= wxString::Format( wxT("%xd"), (int)this );
825 err
= HIToolbarCreate(
826 wxMacCFStringHolder( labelStr
, wxFont::GetDefaultEncoding() ), 0,
827 (HIToolbarRef
*) &m_macHIToolbarRef
);
829 if (m_macHIToolbarRef
!= NULL
)
831 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
832 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
834 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
835 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
837 if ( style
& wxTB_NOICONS
)
838 mode
= kHIToolbarDisplayModeLabelOnly
;
839 else if ( style
& wxTB_TEXT
)
840 mode
= kHIToolbarDisplayModeIconAndLabel
;
842 mode
= kHIToolbarDisplayModeIconOnly
;
844 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
845 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
847 #endif // wxMAC_USE_NATIVE_TOOLBAR
849 return (err
== noErr
);
852 wxToolBar::~wxToolBar()
854 #if wxMAC_USE_NATIVE_TOOLBAR
855 if (m_macHIToolbarRef
!= NULL
)
857 // if this is the installed toolbar, then deinstall it
858 if (m_macUsesNativeToolbar
)
859 MacInstallNativeToolbar( false );
861 CFIndex count
= CFGetRetainCount( m_macHIToolbarRef
) ;
862 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
864 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
865 m_macHIToolbarRef
= NULL
;
870 bool wxToolBar::Show( bool show
)
872 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
873 bool bResult
= (tlw
!= NULL
);
877 #if wxMAC_USE_NATIVE_TOOLBAR
878 bool ownToolbarInstalled
= false;
879 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
880 if (ownToolbarInstalled
)
882 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
884 ShowHideWindowToolbar( tlw
, show
, false );
887 bResult
= wxToolBarBase::Show( show
);
890 bResult
= wxToolBarBase::Show( show
);
897 bool wxToolBar::IsShown() const
901 #if wxMAC_USE_NATIVE_TOOLBAR
902 bool ownToolbarInstalled
;
904 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
905 if (ownToolbarInstalled
)
907 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
908 bResult
= IsWindowToolbarVisible( tlw
);
911 bResult
= wxToolBarBase::IsShown();
914 bResult
= wxToolBarBase::IsShown();
920 void wxToolBar::DoGetSize( int *width
, int *height
) const
922 #if wxMAC_USE_NATIVE_TOOLBAR
924 bool ownToolbarInstalled
;
926 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
927 if ( ownToolbarInstalled
)
929 // TODO: is this really a control ?
930 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
932 *width
= boundsR
.right
- boundsR
.left
;
933 if ( height
!= NULL
)
934 *height
= boundsR
.bottom
- boundsR
.top
;
937 wxToolBarBase::DoGetSize( width
, height
);
940 wxToolBarBase::DoGetSize( width
, height
);
944 wxSize
wxToolBar::DoGetBestSize() const
948 DoGetSize( &width
, &height
);
950 return wxSize( width
, height
);
953 void wxToolBar::SetWindowStyleFlag( long style
)
955 wxToolBarBase::SetWindowStyleFlag( style
);
957 #if wxMAC_USE_NATIVE_TOOLBAR
958 if (m_macHIToolbarRef
!= NULL
)
960 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
962 if ( style
& wxTB_NOICONS
)
963 mode
= kHIToolbarDisplayModeLabelOnly
;
964 else if ( style
& wxTB_TEXT
)
965 mode
= kHIToolbarDisplayModeIconAndLabel
;
967 mode
= kHIToolbarDisplayModeIconOnly
;
969 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
974 #if wxMAC_USE_NATIVE_TOOLBAR
975 bool wxToolBar::MacWantsNativeToolbar()
977 return m_macUsesNativeToolbar
;
980 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
982 bool bResultV
= false;
984 if (ownToolbarInstalled
!= NULL
)
985 *ownToolbarInstalled
= false;
987 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
990 HIToolbarRef curToolbarRef
= NULL
;
991 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
992 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
993 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
994 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
1000 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
1002 bool bResult
= false;
1004 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
1007 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
1010 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1014 // check the existing toolbar
1015 HIToolbarRef curToolbarRef
= NULL
;
1016 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1018 curToolbarRef
= NULL
;
1020 m_macUsesNativeToolbar
= usesNative
;
1022 if (m_macUsesNativeToolbar
)
1024 // only install toolbar if there isn't one installed already
1025 if (curToolbarRef
== NULL
)
1029 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1030 ShowHideWindowToolbar( tlw
, true, false );
1031 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1032 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1034 Rect r
= { 0, 0, 0, 0 };
1035 m_peer
->SetRect( &r
);
1036 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1037 m_peer
->SetVisibility( false, true );
1038 wxToolBarBase::Show( false );
1043 // only deinstall toolbar if this is the installed one
1044 if (m_macHIToolbarRef
== curToolbarRef
)
1048 ShowHideWindowToolbar( tlw
, false, false );
1049 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1050 SetWindowToolbar( tlw
, NULL
);
1052 m_peer
->SetVisibility( true, true );
1057 InvalidateBestSize();
1059 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1064 bool wxToolBar::Realize()
1066 if (m_tools
.GetCount() == 0)
1072 int maxToolWidth
= 0;
1073 int maxToolHeight
= 0;
1075 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1076 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1079 GetSize( &tw
, &th
);
1081 // find the maximum tool width and height
1082 wxToolBarTool
*tool
;
1083 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1084 while ( node
!= NULL
)
1086 tool
= (wxToolBarTool
*) node
->GetData();
1089 wxSize sz
= tool
->GetSize();
1091 if ( sz
.x
> maxToolWidth
)
1092 maxToolWidth
= sz
.x
;
1093 if ( sz
.y
> maxToolHeight
)
1094 maxToolHeight
= sz
.y
;
1097 node
= node
->GetNext();
1100 bool lastIsRadio
= false;
1101 bool curIsRadio
= false;
1103 #if wxMAC_USE_NATIVE_TOOLBAR
1104 CFIndex currentPosition
= 0;
1105 bool insertAll
= false;
1108 node
= m_tools
.GetFirst();
1109 while ( node
!= NULL
)
1111 tool
= (wxToolBarTool
*) node
->GetData();
1114 node
= node
->GetNext();
1118 // set tool position:
1119 // for the moment just perform a single row/column alignment
1120 wxSize cursize
= tool
->GetSize();
1121 if ( x
+ cursize
.x
> maxWidth
)
1122 maxWidth
= x
+ cursize
.x
;
1123 if ( y
+ cursize
.y
> maxHeight
)
1124 maxHeight
= y
+ cursize
.y
;
1126 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1128 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1129 tool
->SetPosition( wxPoint(x1
, y
) );
1133 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1134 tool
->SetPosition( wxPoint(x
, y1
) );
1137 // update the item positioning state
1138 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1139 y
+= cursize
.y
+ kwxMacToolSpacing
;
1141 x
+= cursize
.x
+ kwxMacToolSpacing
;
1143 #if wxMAC_USE_NATIVE_TOOLBAR
1144 // install in native HIToolbar
1145 if ( m_macHIToolbarRef
!= NULL
)
1147 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1148 if ( hiItemRef
!= NULL
)
1150 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1152 OSStatus err
= noErr
;
1157 // if this is the first tool that gets newly inserted or repositioned
1158 // first remove all 'old' tools from here to the right, because of this
1159 // all following tools will have to be reinserted (insertAll). i = 100 because there's
1160 // no way to determine how many there are in a toolbar, so just a high number :-(
1161 for ( CFIndex i
= 100; i
>= currentPosition
; --i
)
1163 err
= HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, i
);
1168 wxString errMsg
= wxString::Format( wxT("HIToolbarRemoveItemAtIndex failed [%ld]"), (long)err
);
1169 wxFAIL_MSG( errMsg
.c_str() );
1173 err
= HIToolbarInsertItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, hiItemRef
, currentPosition
);
1176 wxString errMsg
= wxString::Format( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1177 wxFAIL_MSG( errMsg
.c_str() );
1180 tool
->SetIndex( currentPosition
);
1188 // update radio button (and group) state
1189 lastIsRadio
= curIsRadio
;
1190 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1194 if ( tool
->IsToggled() )
1195 DoToggleTool( tool
, true );
1201 if ( tool
->Toggle( true ) )
1203 DoToggleTool( tool
, true );
1206 else if ( tool
->IsToggled() )
1208 if ( tool
->IsToggled() )
1209 DoToggleTool( tool
, true );
1211 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1212 while ( nodePrev
!= NULL
)
1214 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1215 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1218 if ( toggleTool
->Toggle( false ) )
1219 DoToggleTool( toggleTool
, false );
1221 nodePrev
= nodePrev
->GetPrevious();
1226 node
= node
->GetNext();
1229 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1231 // if not set yet, only one row
1232 if ( m_maxRows
<= 0 )
1235 m_minWidth
= maxWidth
;
1237 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1238 m_minHeight
= m_maxHeight
= maxHeight
;
1242 // if not set yet, have one column
1243 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1244 SetRows( GetToolsCount() );
1246 m_minHeight
= maxHeight
;
1248 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1249 m_minWidth
= m_maxWidth
= maxWidth
;
1253 // FIXME: should this be OSX-only?
1255 bool wantNativeToolbar
, ownToolbarInstalled
;
1257 // attempt to install the native toolbar
1258 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1259 MacInstallNativeToolbar( wantNativeToolbar
);
1260 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1261 if (!ownToolbarInstalled
)
1263 SetSize( maxWidth
, maxHeight
);
1264 InvalidateBestSize();
1268 SetSize( maxWidth
, maxHeight
);
1269 InvalidateBestSize();
1277 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1279 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1280 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1282 #if wxMAC_USE_NATIVE_TOOLBAR
1283 if (m_macHIToolbarRef
!= NULL
)
1285 int maxs
= wxMax( size
.x
, size
.y
);
1286 HIToolbarDisplaySize sizeSpec
;
1288 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1289 else if ( maxs
> 24 )
1290 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1292 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1294 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1299 // The button size is bigger than the bitmap size
1300 wxSize
wxToolBar::GetToolSize() const
1302 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1305 void wxToolBar::SetRows(int nRows
)
1307 // avoid resizing the frame uselessly
1308 if ( nRows
!= m_maxRows
)
1312 void wxToolBar::MacSuperChangedPosition()
1314 wxWindow::MacSuperChangedPosition();
1316 #if wxMAC_USE_NATIVE_TOOLBAR
1317 if (! m_macUsesNativeToolbar
)
1325 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1327 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1330 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1332 tool
->SetNormalBitmap(bitmap
);
1334 // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
1335 tool
->UpdateToggleImage( tool
->CanBeToggled() && tool
->IsToggled() );
1339 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1341 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1344 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1346 tool
->SetDisabledBitmap(bitmap
);
1348 // TODO: what to do for this one?
1352 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1354 wxToolBarTool
*tool
;
1355 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1356 while ( node
!= NULL
)
1358 tool
= (wxToolBarTool
*)node
->GetData();
1361 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1362 if ( r
.Contains( wxPoint( x
, y
) ) )
1366 node
= node
->GetNext();
1369 return (wxToolBarToolBase
*)NULL
;
1372 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1374 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1376 return tool
->GetShortHelp();
1378 return wxEmptyString
;
1381 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1384 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1387 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1389 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1390 if ( ( tool
!= NULL
) && tool
->IsButton() )
1391 tool
->UpdateToggleImage( toggle
);
1394 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1396 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1400 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1401 wxSize toolSize
= GetToolSize();
1402 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1403 ControlRef controlHandle
= NULL
;
1405 tool
->Attach( this );
1407 #if wxMAC_USE_NATIVE_TOOLBAR
1408 HIToolbarItemRef item
;
1411 switch (tool
->GetStyle())
1413 case wxTOOL_STYLE_SEPARATOR
:
1415 wxASSERT( tool
->GetControlHandle() == NULL
);
1418 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1419 toolrect
.bottom
= toolSize
.y
;
1421 toolrect
.right
= toolSize
.x
;
1423 // in flat style we need a visual separator
1424 #if wxMAC_USE_NATIVE_TOOLBAR
1425 err
= HIToolbarItemCreate(
1426 kHIToolbarSeparatorIdentifier
,
1427 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1430 tool
->SetToolbarItemRef( item
);
1431 #endif // wxMAC_USE_NATIVE_TOOLBAR
1433 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1434 tool
->SetControlHandle( controlHandle
);
1438 case wxTOOL_STYLE_BUTTON
:
1440 wxASSERT( tool
->GetControlHandle() == NULL
);
1441 ControlButtonContentInfo info
;
1442 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1444 if ( UMAGetSystemVersion() >= 0x1000)
1446 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1450 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1451 if ( tool
->CanBeToggled() )
1452 behaviour
|= kControlBehaviorToggles
;
1453 err
= CreateBevelButtonControl( window
,
1454 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1455 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1458 #if wxMAC_USE_NATIVE_TOOLBAR
1459 wxString labelStr
= wxString::Format(wxT("%xd"), (int)tool
);
1460 err
= HIToolbarItemCreate(
1461 wxMacCFStringHolder(labelStr
, wxFont::GetDefaultEncoding()),
1462 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1465 InstallEventHandler(
1466 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1467 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1469 HIToolbarItemSetIconRef( item
, info
.u
.iconRef
);
1470 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1471 tool
->SetToolbarItemRef( item
);
1473 #endif // wxMAC_USE_NATIVE_TOOLBAR
1475 wxMacReleaseBitmapButton( &info
);
1478 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1479 UMASetControlTitle( m_controlHandle
, label
, wxFont::GetDefaultEncoding() );
1482 InstallControlEventHandler(
1483 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1484 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1486 tool
->SetControlHandle( controlHandle
);
1490 case wxTOOL_STYLE_CONTROL
:
1492 #if wxMAC_USE_NATIVE_TOOLBAR
1494 wxCHECK_MSG( tool
->GetControl(), false, _T("control must be non-NULL") );
1496 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
1497 // as this control now is part of both the wxToolBar children and the native toolbar, we have to increase the
1498 // reference count to make sure we are not dealing with zombie controls after the native toolbar has released its views
1499 CFRetain( viewRef
) ;
1500 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1501 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1506 tool
->SetToolbarItemRef( item
);
1512 // right now there's nothing to do here
1520 #if wxMAC_USE_NATIVE_TOOLBAR
1521 wxString label
= tool
->GetLabel();
1522 if ( !label
.empty() )
1524 // strip mnemonics from the label for compatibility
1525 // with the usual labels in wxStaticText sense
1526 label
= wxStripMenuCodes(label
);
1528 HIToolbarItemSetLabel(item
,
1529 wxMacCFStringHolder(label
, m_font
.GetEncoding()));
1531 #endif // wxMAC_USE_NATIVE_TOOLBAR
1535 if ( controlHandle
)
1537 ControlRef container
= (ControlRef
) GetHandle();
1538 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1540 UMAShowControl( controlHandle
);
1541 ::EmbedControl( controlHandle
, container
);
1544 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1545 tool
->UpdateToggleImage( true );
1547 // nothing special to do here - we relayout in Realize() later
1548 InvalidateBestSize();
1552 wxString errMsg
= wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
);
1553 wxFAIL_MSG( errMsg
.c_str() );
1556 return (err
== noErr
);
1559 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1561 wxFAIL_MSG( wxT("not implemented") );
1564 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1566 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1567 wxToolBarToolsList::compatibility_iterator node
;
1568 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1570 wxToolBarToolBase
*tool2
= node
->GetData();
1571 if ( tool2
== tool
)
1573 // let node point to the next node in the list
1574 node
= node
->GetNext();
1580 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1584 #if wxMAC_USE_NATIVE_TOOLBAR
1585 CFIndex removeIndex
= tool
->GetIndex();
1588 #if wxMAC_USE_NATIVE_TOOLBAR
1589 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1591 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1592 tool
->SetIndex( -1 );
1595 switch ( tool
->GetStyle() )
1597 case wxTOOL_STYLE_CONTROL
:
1598 if ( tool
->GetControl() )
1599 tool
->GetControl()->Destroy();
1602 case wxTOOL_STYLE_BUTTON
:
1603 case wxTOOL_STYLE_SEPARATOR
:
1610 tool
->ClearControl();
1612 // and finally reposition all the controls after this one
1614 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1616 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1617 wxPoint pt
= tool2
->GetPosition();
1619 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1624 tool2
->SetPosition( pt
);
1626 #if wxMAC_USE_NATIVE_TOOLBAR
1627 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1628 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1632 InvalidateBestSize();
1637 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1639 #if wxMAC_USE_NATIVE_TOOLBAR
1640 if ( m_macUsesNativeToolbar
)
1652 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1653 bool minimumUmaAvailable
= (UMAGetSystemVersion() >= 0x1030);
1655 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1656 if ( !drawMetalTheme
&& minimumUmaAvailable
)
1658 HIThemePlacardDrawInfo info
;
1659 memset( &info
, 0, sizeof(info
) );
1661 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1663 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1664 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1665 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1669 // leave the background as it is (striped or metal)
1674 const bool drawBorder
= true;
1678 wxMacPortSetter
helper( &dc
);
1680 if ( !drawMetalTheme
|| !minimumUmaAvailable
)
1682 Rect toolbarrect
= { dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1683 dc
.YLOG2DEVMAC(h
), dc
.XLOG2DEVMAC(w
) };
1686 if ( toolbarrect
.left
< 0 )
1687 toolbarrect
.left
= 0;
1688 if ( toolbarrect
.top
< 0 )
1689 toolbarrect
.top
= 0;
1692 UMADrawThemePlacard( &toolbarrect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
);
1696 #if TARGET_API_MAC_OSX
1697 HIRect hiToolbarrect
= CGRectMake(
1698 dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1699 dc
.YLOG2DEVREL(h
), dc
.XLOG2DEVREL(w
) );
1700 CGContextRef cgContext
;
1703 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
1704 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1706 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
1707 CGContextScaleCTM( cgContext
, 1, -1 );
1709 HIThemeBackgroundDrawInfo drawInfo
;
1710 drawInfo
.version
= 0;
1711 drawInfo
.state
= kThemeStateActive
;
1712 drawInfo
.kind
= kThemeBackgroundMetal
;
1713 HIThemeApplyBackground( &hiToolbarrect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
1716 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1726 #endif // wxUSE_TOOLBAR