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 // when embedding native controls in the native toolbar we must make sure the
62 // control does not get deleted behind our backs, so the retain count gets increased
63 // (after creation it is 1), first be the creation of the custom HIToolbarItem wrapper
64 // object, and second by the code 'creating' the custom HIView (which is the same as the
65 // already existing native control, therefore we just increase the ref count)
66 // when this view is removed from the native toolbar its count gets decremented again
67 // and when the HITooolbarItem wrapper object gets destroyed it is decremented as well
68 // so in the end the control lives with a refcount of one and can be disposed of by the
69 // wxControl code. For embedded controls on a non-native toolbar this ref count is less
70 // so we can only test against a range, not a specific value of the refcount.
72 class wxToolBarTool
: public wxToolBarToolBase
78 const wxString
& label
,
79 const wxBitmap
& bmpNormal
,
80 const wxBitmap
& bmpDisabled
,
83 const wxString
& shortHelp
,
84 const wxString
& longHelp
);
86 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
, const wxString
& label
)
87 : wxToolBarToolBase(tbar
, control
, label
)
91 SetControlHandle( (ControlRef
) control
->GetHandle() );
94 virtual ~wxToolBarTool()
99 WXWidget
GetControlHandle()
101 return (WXWidget
) m_controlHandle
;
104 void SetControlHandle( ControlRef handle
)
106 m_controlHandle
= handle
;
109 void SetPosition( const wxPoint
& position
);
113 if ( m_controlHandle
)
116 DisposeControl( m_controlHandle
);
119 // the embedded control is not under the responsibility of the tool, it will be disposed of in the
120 // proper wxControl destructor
121 wxASSERT( IsValidControlHandle(GetControl()->GetPeer()->GetControlRef() )) ;
123 m_controlHandle
= NULL
;
127 #if wxMAC_USE_NATIVE_TOOLBAR
128 if ( m_toolbarItemRef
)
130 CFIndex count
= CFGetRetainCount( m_toolbarItemRef
) ;
131 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
132 wxTheApp
->MacAddToAutorelease(m_toolbarItemRef
);
133 CFRelease(m_toolbarItemRef
);
134 m_toolbarItemRef
= NULL
;
139 wxSize
GetSize() const
145 curSize
= GetControl()->GetSize();
147 else if ( IsButton() )
149 curSize
= GetToolBar()->GetToolSize();
154 curSize
= GetToolBar()->GetToolSize();
155 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
164 wxPoint
GetPosition() const
166 return wxPoint( m_x
, m_y
);
169 bool DoEnable( bool enable
);
171 void UpdateToggleImage( bool toggle
);
173 #if wxMAC_USE_NATIVE_TOOLBAR
174 void SetToolbarItemRef( HIToolbarItemRef ref
)
176 if ( m_controlHandle
)
177 HideControl( m_controlHandle
);
178 if ( m_toolbarItemRef
)
179 CFRelease( m_toolbarItemRef
);
181 m_toolbarItemRef
= ref
;
182 if ( m_toolbarItemRef
)
187 f
= GetToolBar()->GetFont();
189 enc
= f
.GetEncoding();
191 enc
= wxFont::GetDefaultEncoding();
193 HIToolbarItemSetHelpText(
195 wxMacCFStringHolder( GetShortHelp(), enc
),
196 wxMacCFStringHolder( GetLongHelp(), enc
) );
200 HIToolbarItemRef
GetToolbarItemRef() const
202 return m_toolbarItemRef
;
205 void SetIndex( CFIndex idx
)
210 CFIndex
GetIndex() const
219 m_controlHandle
= NULL
;
221 #if wxMAC_USE_NATIVE_TOOLBAR
222 m_toolbarItemRef
= NULL
;
227 ControlRef m_controlHandle
;
231 #if wxMAC_USE_NATIVE_TOOLBAR
232 HIToolbarItemRef m_toolbarItemRef
;
233 // position in its toolbar, -1 means not inserted
238 static const EventTypeSpec eventList
[] =
240 { kEventClassControl
, kEventControlHit
},
242 { kEventClassControl
, kEventControlHitTest
},
246 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
248 OSStatus result
= eventNotHandledErr
;
249 ControlRef controlRef
;
250 wxMacCarbonEvent
cEvent( event
);
252 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
254 switch ( GetEventKind( event
) )
256 case kEventControlHit
:
258 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
259 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
260 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
265 shouldToggle
= !tbartool
->IsToggled();
267 shouldToggle
= (GetControl32BitValue( (ControlRef
)(tbartool
->GetControlHandle()) ) != 0);
270 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
273 if (tbartool
!= NULL
)
274 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
280 case kEventControlHitTest
:
282 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
284 HIViewGetBounds( controlRef
, &rect
);
286 ControlPartCode pc
= kControlNoPart
;
287 if ( CGRectContainsPoint( rect
, pt
) )
288 pc
= kControlIconPart
;
289 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
302 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
304 OSStatus result
= eventNotHandledErr
;
306 switch ( GetEventClass( event
) )
308 case kEventClassControl
:
309 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
319 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
321 #if wxMAC_USE_NATIVE_TOOLBAR
323 static const EventTypeSpec toolBarEventList
[] =
325 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
328 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
330 OSStatus result
= eventNotHandledErr
;
332 switch ( GetEventKind( event
) )
334 case kEventToolbarItemPerformAction
:
336 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
337 if ( tbartool
!= NULL
)
339 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
340 int toolID
= tbartool
->GetId();
342 if ( tbartool
->CanBeToggled() )
345 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
349 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
362 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
364 OSStatus result
= eventNotHandledErr
;
366 switch ( GetEventClass( event
) )
368 case kEventClassToolbarItem
:
369 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
379 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
383 bool wxToolBarTool::DoEnable( bool enable
)
387 GetControl()->Enable( enable
);
389 else if ( IsButton() )
391 #if wxMAC_USE_NATIVE_TOOLBAR
392 if ( m_toolbarItemRef
!= NULL
)
393 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
396 if ( m_controlHandle
!= NULL
)
398 #if TARGET_API_MAC_OSX
400 EnableControl( m_controlHandle
);
402 DisableControl( m_controlHandle
);
405 ActivateControl( m_controlHandle
);
407 DeactivateControl( m_controlHandle
);
415 void wxToolBarTool::SetPosition( const wxPoint
& position
)
420 int mac_x
= position
.x
;
421 int mac_y
= position
.y
;
426 GetControlBounds( m_controlHandle
, &contrlRect
);
427 int former_mac_x
= contrlRect
.left
;
428 int former_mac_y
= contrlRect
.top
;
429 GetToolBar()->GetToolSize();
431 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
433 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
436 else if ( IsControl() )
438 // embedded native controls are moved by the OS
439 #if wxMAC_USE_NATIVE_TOOLBAR
440 if ( ((wxToolBar
*)GetToolBar())->MacWantsNativeToolbar() == false )
443 GetControl()->Move( position
);
451 GetControlBounds( m_controlHandle
, &contrlRect
);
452 int former_mac_x
= contrlRect
.left
;
453 int former_mac_y
= contrlRect
.top
;
455 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
456 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
461 void wxToolBarTool::UpdateToggleImage( bool toggle
)
466 int w
= m_bmpNormal
.GetWidth();
467 int h
= m_bmpNormal
.GetHeight();
468 wxBitmap
bmp( w
, h
);
471 dc
.SelectObject( bmp
);
472 dc
.SetPen( wxPen(*wxBLACK
) );
473 dc
.SetBrush( wxBrush( *wxLIGHT_GREY
));
474 dc
.DrawRectangle( 0, 0, w
, h
);
475 dc
.DrawBitmap( m_bmpNormal
, 0, 0, true );
476 dc
.SelectObject( wxNullBitmap
);
477 ControlButtonContentInfo info
;
478 wxMacCreateBitmapButton( &info
, bmp
, 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
);
490 ControlButtonContentInfo info
;
491 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
);
492 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
493 #if wxMAC_USE_NATIVE_TOOLBAR
494 if (m_toolbarItemRef
!= NULL
)
496 HIToolbarItemSetIconRef( m_toolbarItemRef
, info
.u
.iconRef
);
499 wxMacReleaseBitmapButton( &info
);
502 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
504 m_controlHandle
, 0, kControlIconTransformTag
,
505 sizeof(transform
), (Ptr
)&transform
);
506 HIViewSetNeedsDisplay( m_controlHandle
, true );
509 ::SetControl32BitValue( m_controlHandle
, toggle
);
513 wxToolBarTool::wxToolBarTool(
516 const wxString
& label
,
517 const wxBitmap
& bmpNormal
,
518 const wxBitmap
& bmpDisabled
,
520 wxObject
*clientData
,
521 const wxString
& shortHelp
,
522 const wxString
& longHelp
)
525 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
526 clientData
, shortHelp
, longHelp
)
532 #pragma mark Toolbar Implementation
534 wxToolBarToolBase
*wxToolBar::CreateTool(
536 const wxString
& label
,
537 const wxBitmap
& bmpNormal
,
538 const wxBitmap
& bmpDisabled
,
540 wxObject
*clientData
,
541 const wxString
& shortHelp
,
542 const wxString
& longHelp
)
544 return new wxToolBarTool(
545 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
546 clientData
, shortHelp
, longHelp
);
550 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
552 return new wxToolBarTool(this, control
, label
);
555 void wxToolBar::Init()
559 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
560 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
562 #if wxMAC_USE_NATIVE_TOOLBAR
563 m_macHIToolbarRef
= NULL
;
564 m_macUsesNativeToolbar
= false;
568 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
570 const EventTypeSpec kEvents
[] =
572 { kEventClassHIObject
, kEventHIObjectConstruct
},
573 { kEventClassHIObject
, kEventHIObjectInitialize
},
574 { kEventClassHIObject
, kEventHIObjectDestruct
},
576 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
579 const EventTypeSpec kViewEvents
[] =
581 { kEventClassControl
, kEventControlGetSizeConstraints
}
584 struct ControlToolbarItem
586 HIToolbarItemRef toolbarItem
;
588 wxSize lastValidSize
;
591 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
593 OSStatus result
= eventNotHandledErr
;
594 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
596 switch ( GetEventClass( inEvent
) )
598 case kEventClassHIObject
:
599 switch ( GetEventKind( inEvent
) )
601 case kEventHIObjectConstruct
:
603 HIObjectRef toolbarItem
;
604 ControlToolbarItem
* item
;
606 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
607 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
609 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
610 item
->toolbarItem
= toolbarItem
;
611 item
->lastValidSize
= wxSize(-1,-1);
612 item
->viewRef
= NULL
;
614 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
620 case kEventHIObjectInitialize
:
621 result
= CallNextEventHandler( inCallRef
, inEvent
);
622 if ( result
== noErr
)
625 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
626 sizeof( CFTypeRef
), NULL
, &data
);
630 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
631 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
633 object
->viewRef
= (HIViewRef
) viewRef
;
634 // make sure we keep that control during our lifetime
635 CFRetain( object
->viewRef
) ;
637 verify_noerr(InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
638 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
));
643 case kEventHIObjectDestruct
:
645 HIViewRef viewRef
= object
->viewRef
;
646 if( viewRef
&& IsValidControlHandle( viewRef
) )
648 // depending whether the wxControl corresponding to this HIView has already been destroyed or
649 // not, ref counts differ, so we cannot assert a special value
650 CFIndex count
= CFGetRetainCount( viewRef
) ;
651 wxASSERT_MSG( count
>=1 , wxT("Reference Count of native tool was illegal before removal") );
653 CFRelease( viewRef
) ;
662 case kEventClassToolbarItem
:
663 switch ( GetEventKind( inEvent
) )
665 case kEventToolbarItemCreateCustomView
:
667 HIViewRef viewRef
= object
->viewRef
;
668 HIViewRemoveFromSuperview( viewRef
) ;
669 HIViewSetVisible(viewRef
, true) ;
670 CFRetain( viewRef
) ;
671 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
677 case kEventClassControl
:
678 switch ( GetEventKind( inEvent
) )
680 case kEventControlGetSizeConstraints
:
682 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
685 // during toolbar layout the native window sometimes gets negative sizes,
686 // sometimes it just gets shrunk behind our back, so in order to avoid
687 // ever shrinking more, once a valid size is captured, we keep it
689 wxSize sz
= object
->lastValidSize
;
690 if ( sz
.x
<= 0 || sz
.y
<= 0 )
692 sz
= wxwindow
->GetSize() ;
693 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
694 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
695 if ( sz
.x
> 0 && sz
.y
> 0 )
696 object
->lastValidSize
= sz
;
702 min
.width
= max
.width
= sz
.x
;
703 min
.height
= max
.height
= sz
.y
;
705 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
706 sizeof( HISize
), &min
);
708 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
709 sizeof( HISize
), &max
);
721 void RegisterControlToolbarItemClass()
723 static bool sRegistered
;
727 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
728 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
734 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
736 RegisterControlToolbarItemClass();
740 UInt32 options
= kHIToolbarItemAllowDuplicates
;
741 HIToolbarItemRef result
= NULL
;
743 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
744 require_noerr( err
, CantCreateEvent
);
746 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
747 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
750 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
752 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
755 ReleaseEvent( event
);
760 #if wxMAC_USE_NATIVE_TOOLBAR
761 static const EventTypeSpec kToolbarEvents
[] =
763 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
764 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
765 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
768 static OSStatus
ToolbarDelegateHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
770 OSStatus result
= eventNotHandledErr
;
772 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
773 CFMutableArrayRef array
;
775 switch ( GetEventKind( inEvent
) )
777 case kEventToolbarGetDefaultIdentifiers
:
779 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
780 sizeof( CFMutableArrayRef
), NULL
, &array
);
781 // not implemented yet
782 // GetToolbarDefaultItems( array );
787 case kEventToolbarGetAllowedIdentifiers
:
789 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
790 sizeof( CFMutableArrayRef
), NULL
, &array
);
791 // not implemented yet
792 // GetToolbarAllowedItems( array );
796 case kEventToolbarCreateItemWithIdentifier
:
798 HIToolbarItemRef item
= NULL
;
799 CFTypeRef data
= NULL
;
800 CFStringRef identifier
= NULL
;
802 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
803 sizeof( CFStringRef
), NULL
, &identifier
);
805 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
806 sizeof( CFTypeRef
), NULL
, &data
);
808 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
810 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
813 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
814 sizeof( HIToolbarItemRef
), &item
);
824 #endif // wxMAC_USE_NATIVE_TOOLBAR
826 // also for the toolbar we have the dual implementation:
827 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
829 bool wxToolBar::Create(
835 const wxString
& name
)
837 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
842 OSStatus err
= noErr
;
844 #if wxMAC_USE_NATIVE_TOOLBAR
845 wxString labelStr
= wxString::Format( wxT("%xd"), (int)this );
846 err
= HIToolbarCreate(
847 wxMacCFStringHolder( labelStr
, wxFont::GetDefaultEncoding() ), 0,
848 (HIToolbarRef
*) &m_macHIToolbarRef
);
850 if (m_macHIToolbarRef
!= NULL
)
852 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
853 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
855 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
856 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
858 if ( style
& wxTB_NOICONS
)
859 mode
= kHIToolbarDisplayModeLabelOnly
;
860 else if ( style
& wxTB_TEXT
)
861 mode
= kHIToolbarDisplayModeIconAndLabel
;
863 mode
= kHIToolbarDisplayModeIconOnly
;
865 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
866 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
868 #endif // wxMAC_USE_NATIVE_TOOLBAR
870 return (err
== noErr
);
873 wxToolBar::~wxToolBar()
875 #if wxMAC_USE_NATIVE_TOOLBAR
876 if (m_macHIToolbarRef
!= NULL
)
878 // if this is the installed toolbar, then deinstall it
879 if (m_macUsesNativeToolbar
)
880 MacInstallNativeToolbar( false );
882 CFIndex count
= CFGetRetainCount( m_macHIToolbarRef
) ;
883 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
885 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
886 m_macHIToolbarRef
= NULL
;
891 bool wxToolBar::Show( bool show
)
893 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
894 bool bResult
= (tlw
!= NULL
);
898 #if wxMAC_USE_NATIVE_TOOLBAR
899 bool ownToolbarInstalled
= false;
900 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
901 if (ownToolbarInstalled
)
903 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
905 ShowHideWindowToolbar( tlw
, show
, false );
908 bResult
= wxToolBarBase::Show( show
);
911 bResult
= wxToolBarBase::Show( show
);
918 bool wxToolBar::IsShown() const
922 #if wxMAC_USE_NATIVE_TOOLBAR
923 bool ownToolbarInstalled
;
925 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
926 if (ownToolbarInstalled
)
928 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
929 bResult
= IsWindowToolbarVisible( tlw
);
932 bResult
= wxToolBarBase::IsShown();
935 bResult
= wxToolBarBase::IsShown();
941 void wxToolBar::DoGetSize( int *width
, int *height
) const
943 #if wxMAC_USE_NATIVE_TOOLBAR
945 bool ownToolbarInstalled
;
947 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
948 if ( ownToolbarInstalled
)
950 // TODO: is this really a control ?
951 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
953 *width
= boundsR
.right
- boundsR
.left
;
954 if ( height
!= NULL
)
955 *height
= boundsR
.bottom
- boundsR
.top
;
958 wxToolBarBase::DoGetSize( width
, height
);
961 wxToolBarBase::DoGetSize( width
, height
);
965 wxSize
wxToolBar::DoGetBestSize() const
969 DoGetSize( &width
, &height
);
971 return wxSize( width
, height
);
974 void wxToolBar::SetWindowStyleFlag( long style
)
976 wxToolBarBase::SetWindowStyleFlag( style
);
978 #if wxMAC_USE_NATIVE_TOOLBAR
979 if (m_macHIToolbarRef
!= NULL
)
981 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
983 if ( style
& wxTB_NOICONS
)
984 mode
= kHIToolbarDisplayModeLabelOnly
;
985 else if ( style
& wxTB_TEXT
)
986 mode
= kHIToolbarDisplayModeIconAndLabel
;
988 mode
= kHIToolbarDisplayModeIconOnly
;
990 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
995 #if wxMAC_USE_NATIVE_TOOLBAR
996 bool wxToolBar::MacWantsNativeToolbar()
998 return m_macUsesNativeToolbar
;
1001 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
1003 bool bResultV
= false;
1005 if (ownToolbarInstalled
!= NULL
)
1006 *ownToolbarInstalled
= false;
1008 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1011 HIToolbarRef curToolbarRef
= NULL
;
1012 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1013 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
1014 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
1015 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
1021 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
1023 bool bResult
= false;
1025 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
1028 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
1031 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1035 // check the existing toolbar
1036 HIToolbarRef curToolbarRef
= NULL
;
1037 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1039 curToolbarRef
= NULL
;
1041 m_macUsesNativeToolbar
= usesNative
;
1043 if (m_macUsesNativeToolbar
)
1045 // only install toolbar if there isn't one installed already
1046 if (curToolbarRef
== NULL
)
1050 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1051 ShowHideWindowToolbar( tlw
, true, false );
1052 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1053 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1055 Rect r
= { 0, 0, 0, 0 };
1056 m_peer
->SetRect( &r
);
1057 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1058 m_peer
->SetVisibility( false, true );
1059 wxToolBarBase::Show( false );
1064 // only deinstall toolbar if this is the installed one
1065 if (m_macHIToolbarRef
== curToolbarRef
)
1069 ShowHideWindowToolbar( tlw
, false, false );
1070 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1071 SetWindowToolbar( tlw
, NULL
);
1073 m_peer
->SetVisibility( true, true );
1078 InvalidateBestSize();
1080 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1085 bool wxToolBar::Realize()
1087 if (m_tools
.GetCount() == 0)
1093 int maxToolWidth
= 0;
1094 int maxToolHeight
= 0;
1096 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1097 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1100 GetSize( &tw
, &th
);
1102 // find the maximum tool width and height
1103 wxToolBarTool
*tool
;
1104 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1107 tool
= (wxToolBarTool
*) node
->GetData();
1110 wxSize sz
= tool
->GetSize();
1112 if ( sz
.x
> maxToolWidth
)
1113 maxToolWidth
= sz
.x
;
1114 if ( sz
.y
> maxToolHeight
)
1115 maxToolHeight
= sz
.y
;
1118 node
= node
->GetNext();
1121 bool lastIsRadio
= false;
1122 bool curIsRadio
= false;
1124 #if wxMAC_USE_NATIVE_TOOLBAR
1125 CFIndex currentPosition
= 0;
1126 bool insertAll
= false;
1128 HIToolbarRef refTB
= (HIToolbarRef
)m_macHIToolbarRef
;
1131 node
= m_tools
.GetFirst();
1134 tool
= (wxToolBarTool
*) node
->GetData();
1137 node
= node
->GetNext();
1141 // set tool position:
1142 // for the moment just perform a single row/column alignment
1143 wxSize cursize
= tool
->GetSize();
1144 if ( x
+ cursize
.x
> maxWidth
)
1145 maxWidth
= x
+ cursize
.x
;
1146 if ( y
+ cursize
.y
> maxHeight
)
1147 maxHeight
= y
+ cursize
.y
;
1149 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1151 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1152 tool
->SetPosition( wxPoint(x1
, y
) );
1156 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1157 tool
->SetPosition( wxPoint(x
, y1
) );
1160 // update the item positioning state
1161 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1162 y
+= cursize
.y
+ kwxMacToolSpacing
;
1164 x
+= cursize
.x
+ kwxMacToolSpacing
;
1166 #if wxMAC_USE_NATIVE_TOOLBAR
1167 // install in native HIToolbar
1170 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1171 if ( hiItemRef
!= NULL
)
1173 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1175 OSStatus err
= noErr
;
1180 // if this is the first tool that gets newly inserted or repositioned
1181 // first remove all 'old' tools from here to the right, because of this
1182 // all following tools will have to be reinserted (insertAll).
1183 for ( wxToolBarToolsList::compatibility_iterator node2
= m_tools
.GetLast();
1185 node2
= node2
->GetPrevious() )
1187 wxToolBarTool
*tool2
= (wxToolBarTool
*) node2
->GetData();
1189 const long idx
= tool2
->GetIndex();
1192 if ( tool2
->IsControl() )
1194 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1195 wxASSERT_MSG( count
== 3 || count
== 2 , wxT("Reference Count of native tool was illegal before removal") );
1196 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1198 err
= HIToolbarRemoveItemAtIndex(refTB
, idx
);
1201 wxLogDebug(wxT("HIToolbarRemoveItemAtIndex(%ld) failed [%ld]"),
1204 if ( tool2
->IsControl() )
1206 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1207 wxASSERT_MSG( count
== 2 , wxT("Reference Count of native tool was not 2 after removal") );
1208 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1211 tool2
->SetIndex(-1);
1216 err
= HIToolbarInsertItemAtIndex( refTB
, hiItemRef
, currentPosition
);
1219 wxLogDebug( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1222 tool
->SetIndex( currentPosition
);
1223 if ( tool
->IsControl() )
1225 CFIndex count
= CFGetRetainCount( tool
->GetControl()->GetPeer()->GetControlRef() ) ;
1226 wxASSERT_MSG( count
== 3 || count
== 2, wxT("Reference Count of native tool was illegal after insertion") );
1227 wxASSERT( IsValidControlHandle(tool
->GetControl()->GetPeer()->GetControlRef() )) ;
1236 // update radio button (and group) state
1237 lastIsRadio
= curIsRadio
;
1238 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1242 if ( tool
->IsToggled() )
1243 DoToggleTool( tool
, true );
1249 if ( tool
->Toggle( true ) )
1251 DoToggleTool( tool
, true );
1254 else if ( tool
->IsToggled() )
1256 if ( tool
->IsToggled() )
1257 DoToggleTool( tool
, true );
1259 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1262 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1263 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1266 if ( toggleTool
->Toggle( false ) )
1267 DoToggleTool( toggleTool
, false );
1269 nodePrev
= nodePrev
->GetPrevious();
1274 node
= node
->GetNext();
1277 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1279 // if not set yet, only one row
1280 if ( m_maxRows
<= 0 )
1283 m_minWidth
= maxWidth
;
1285 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1286 m_minHeight
= m_maxHeight
= maxHeight
;
1290 // if not set yet, have one column
1291 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1292 SetRows( GetToolsCount() );
1294 m_minHeight
= maxHeight
;
1296 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1297 m_minWidth
= m_maxWidth
= maxWidth
;
1301 // FIXME: should this be OSX-only?
1303 bool wantNativeToolbar
, ownToolbarInstalled
;
1305 // attempt to install the native toolbar
1306 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1307 MacInstallNativeToolbar( wantNativeToolbar
);
1308 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1309 if (!ownToolbarInstalled
)
1311 SetSize( maxWidth
, maxHeight
);
1312 InvalidateBestSize();
1316 SetSize( maxWidth
, maxHeight
);
1317 InvalidateBestSize();
1325 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1327 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1328 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1330 #if wxMAC_USE_NATIVE_TOOLBAR
1331 if (m_macHIToolbarRef
!= NULL
)
1333 int maxs
= wxMax( size
.x
, size
.y
);
1334 HIToolbarDisplaySize sizeSpec
;
1336 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1337 else if ( maxs
> 24 )
1338 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1340 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1342 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1347 // The button size is bigger than the bitmap size
1348 wxSize
wxToolBar::GetToolSize() const
1350 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1353 void wxToolBar::SetRows(int nRows
)
1355 // avoid resizing the frame uselessly
1356 if ( nRows
!= m_maxRows
)
1360 void wxToolBar::MacSuperChangedPosition()
1362 wxWindow::MacSuperChangedPosition();
1364 #if wxMAC_USE_NATIVE_TOOLBAR
1365 if (! m_macUsesNativeToolbar
)
1373 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1375 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1378 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1380 tool
->SetNormalBitmap(bitmap
);
1382 // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
1383 tool
->UpdateToggleImage( tool
->CanBeToggled() && tool
->IsToggled() );
1387 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1389 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1392 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1394 tool
->SetDisabledBitmap(bitmap
);
1396 // TODO: what to do for this one?
1400 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1402 wxToolBarTool
*tool
;
1403 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1406 tool
= (wxToolBarTool
*)node
->GetData();
1409 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1410 if ( r
.Contains( wxPoint( x
, y
) ) )
1414 node
= node
->GetNext();
1417 return (wxToolBarToolBase
*)NULL
;
1420 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1422 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1424 return tool
->GetShortHelp();
1426 return wxEmptyString
;
1429 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1432 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1435 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1437 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1438 if ( ( tool
!= NULL
) && tool
->IsButton() )
1439 tool
->UpdateToggleImage( toggle
);
1442 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1444 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1448 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1449 wxSize toolSize
= GetToolSize();
1450 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1451 ControlRef controlHandle
= NULL
;
1453 tool
->Attach( this );
1455 #if wxMAC_USE_NATIVE_TOOLBAR
1456 HIToolbarItemRef item
;
1459 switch (tool
->GetStyle())
1461 case wxTOOL_STYLE_SEPARATOR
:
1463 wxASSERT( tool
->GetControlHandle() == NULL
);
1466 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1467 toolrect
.bottom
= toolSize
.y
;
1469 toolrect
.right
= toolSize
.x
;
1471 // in flat style we need a visual separator
1472 #if wxMAC_USE_NATIVE_TOOLBAR
1473 err
= HIToolbarItemCreate(
1474 kHIToolbarSeparatorIdentifier
,
1475 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1478 tool
->SetToolbarItemRef( item
);
1479 #endif // wxMAC_USE_NATIVE_TOOLBAR
1481 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1482 tool
->SetControlHandle( controlHandle
);
1486 case wxTOOL_STYLE_BUTTON
:
1488 wxASSERT( tool
->GetControlHandle() == NULL
);
1489 ControlButtonContentInfo info
;
1490 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1492 if ( UMAGetSystemVersion() >= 0x1000)
1494 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1498 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1499 if ( tool
->CanBeToggled() )
1500 behaviour
|= kControlBehaviorToggles
;
1501 err
= CreateBevelButtonControl( window
,
1502 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1503 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1506 #if wxMAC_USE_NATIVE_TOOLBAR
1507 wxString labelStr
= wxString::Format(wxT("%xd"), (int)tool
);
1508 err
= HIToolbarItemCreate(
1509 wxMacCFStringHolder(labelStr
, wxFont::GetDefaultEncoding()),
1510 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1513 InstallEventHandler(
1514 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1515 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1517 HIToolbarItemSetIconRef( item
, info
.u
.iconRef
);
1518 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1519 tool
->SetToolbarItemRef( item
);
1521 #endif // wxMAC_USE_NATIVE_TOOLBAR
1523 wxMacReleaseBitmapButton( &info
);
1526 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1527 UMASetControlTitle( m_controlHandle
, label
, wxFont::GetDefaultEncoding() );
1530 InstallControlEventHandler(
1531 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1532 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1534 tool
->SetControlHandle( controlHandle
);
1538 case wxTOOL_STYLE_CONTROL
:
1540 #if wxMAC_USE_NATIVE_TOOLBAR
1542 wxCHECK_MSG( tool
->GetControl(), false, _T("control must be non-NULL") );
1544 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
1545 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1546 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1551 tool
->SetToolbarItemRef( item
);
1557 // right now there's nothing to do here
1565 #if wxMAC_USE_NATIVE_TOOLBAR
1566 wxString label
= tool
->GetLabel();
1567 if ( !label
.empty() )
1569 // strip mnemonics from the label for compatibility
1570 // with the usual labels in wxStaticText sense
1571 label
= wxStripMenuCodes(label
);
1573 HIToolbarItemSetLabel(item
,
1574 wxMacCFStringHolder(label
, m_font
.GetEncoding()));
1576 #endif // wxMAC_USE_NATIVE_TOOLBAR
1580 if ( controlHandle
)
1582 ControlRef container
= (ControlRef
) GetHandle();
1583 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1585 UMAShowControl( controlHandle
);
1586 ::EmbedControl( controlHandle
, container
);
1589 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1590 tool
->UpdateToggleImage( true );
1592 // nothing special to do here - we relayout in Realize() later
1593 InvalidateBestSize();
1597 wxFAIL_MSG( wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
) );
1600 return (err
== noErr
);
1603 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1605 wxFAIL_MSG( wxT("not implemented") );
1608 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1610 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1611 wxToolBarToolsList::compatibility_iterator node
;
1612 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1614 wxToolBarToolBase
*tool2
= node
->GetData();
1615 if ( tool2
== tool
)
1617 // let node point to the next node in the list
1618 node
= node
->GetNext();
1624 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1628 #if wxMAC_USE_NATIVE_TOOLBAR
1629 CFIndex removeIndex
= tool
->GetIndex();
1632 #if wxMAC_USE_NATIVE_TOOLBAR
1633 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1635 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1636 tool
->SetIndex( -1 );
1639 switch ( tool
->GetStyle() )
1641 case wxTOOL_STYLE_CONTROL
:
1642 if ( tool
->GetControl() )
1643 tool
->GetControl()->Destroy();
1646 case wxTOOL_STYLE_BUTTON
:
1647 case wxTOOL_STYLE_SEPARATOR
:
1654 tool
->ClearControl();
1656 // and finally reposition all the controls after this one
1658 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1660 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1661 wxPoint pt
= tool2
->GetPosition();
1663 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1668 tool2
->SetPosition( pt
);
1670 #if wxMAC_USE_NATIVE_TOOLBAR
1671 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1672 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1676 InvalidateBestSize();
1681 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1683 #if wxMAC_USE_NATIVE_TOOLBAR
1684 if ( m_macUsesNativeToolbar
)
1696 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1697 bool minimumUmaAvailable
= (UMAGetSystemVersion() >= 0x1030);
1699 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1700 if ( !drawMetalTheme
&& minimumUmaAvailable
)
1702 HIThemePlacardDrawInfo info
;
1703 memset( &info
, 0, sizeof(info
) );
1705 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1707 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1708 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1709 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1713 // leave the background as it is (striped or metal)
1718 const bool drawBorder
= true;
1722 wxMacPortSetter
helper( &dc
);
1724 if ( !drawMetalTheme
|| !minimumUmaAvailable
)
1726 Rect toolbarrect
= { dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1727 dc
.YLOG2DEVMAC(h
), dc
.XLOG2DEVMAC(w
) };
1730 if ( toolbarrect
.left
< 0 )
1731 toolbarrect
.left
= 0;
1732 if ( toolbarrect
.top
< 0 )
1733 toolbarrect
.top
= 0;
1736 UMADrawThemePlacard( &toolbarrect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
);
1740 #if TARGET_API_MAC_OSX
1741 HIRect hiToolbarrect
= CGRectMake(
1742 dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1743 dc
.YLOG2DEVREL(h
), dc
.XLOG2DEVREL(w
) );
1744 CGContextRef cgContext
;
1747 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
1748 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1750 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
1751 CGContextScaleCTM( cgContext
, 1, -1 );
1753 HIThemeBackgroundDrawInfo drawInfo
;
1754 drawInfo
.version
= 0;
1755 drawInfo
.state
= kThemeStateActive
;
1756 drawInfo
.kind
= kThemeBackgroundMetal
;
1757 HIThemeApplyBackground( &hiToolbarrect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
1760 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1770 #endif // wxUSE_TOOLBAR