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
71 class wxToolBarTool
: public wxToolBarToolBase
77 const wxString
& label
,
78 const wxBitmap
& bmpNormal
,
79 const wxBitmap
& bmpDisabled
,
82 const wxString
& shortHelp
,
83 const wxString
& longHelp
);
85 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
, const wxString
& label
)
86 : wxToolBarToolBase(tbar
, control
, label
)
90 SetControlHandle( (ControlRef
) control
->GetHandle() );
93 virtual ~wxToolBarTool()
98 WXWidget
GetControlHandle()
100 return (WXWidget
) m_controlHandle
;
103 void SetControlHandle( ControlRef handle
)
105 m_controlHandle
= handle
;
108 void SetPosition( const wxPoint
& position
);
112 if ( m_controlHandle
)
115 DisposeControl( m_controlHandle
);
118 // the embedded control is not under the responsibility of the tool, it will be disposed of in the
119 // proper wxControl destructor
120 wxASSERT( IsValidControlHandle(GetControl()->GetPeer()->GetControlRef() )) ;
122 m_controlHandle
= NULL
;
126 #if wxMAC_USE_NATIVE_TOOLBAR
127 if ( m_toolbarItemRef
)
129 CFIndex count
= CFGetRetainCount( m_toolbarItemRef
) ;
130 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
131 wxTheApp
->MacAddToAutorelease(m_toolbarItemRef
);
132 CFRelease(m_toolbarItemRef
);
133 m_toolbarItemRef
= NULL
;
138 wxSize
GetSize() const
144 curSize
= GetControl()->GetSize();
146 else if ( IsButton() )
148 curSize
= GetToolBar()->GetToolSize();
153 curSize
= GetToolBar()->GetToolSize();
154 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
163 wxPoint
GetPosition() const
165 return wxPoint( m_x
, m_y
);
168 bool DoEnable( bool enable
);
170 void UpdateToggleImage( bool toggle
);
172 #if wxMAC_USE_NATIVE_TOOLBAR
173 void SetToolbarItemRef( HIToolbarItemRef ref
)
175 if ( m_controlHandle
)
176 HideControl( m_controlHandle
);
177 if ( m_toolbarItemRef
)
178 CFRelease( m_toolbarItemRef
);
180 m_toolbarItemRef
= ref
;
181 if ( m_toolbarItemRef
)
186 f
= GetToolBar()->GetFont();
188 enc
= f
.GetEncoding();
190 enc
= wxFont::GetDefaultEncoding();
192 HIToolbarItemSetHelpText(
194 wxMacCFStringHolder( GetShortHelp(), enc
),
195 wxMacCFStringHolder( GetLongHelp(), enc
) );
199 HIToolbarItemRef
GetToolbarItemRef() const
201 return m_toolbarItemRef
;
204 void SetIndex( CFIndex idx
)
209 CFIndex
GetIndex() const
218 m_controlHandle
= NULL
;
220 #if wxMAC_USE_NATIVE_TOOLBAR
221 m_toolbarItemRef
= NULL
;
226 ControlRef m_controlHandle
;
230 #if wxMAC_USE_NATIVE_TOOLBAR
231 HIToolbarItemRef m_toolbarItemRef
;
232 // position in its toolbar, -1 means not inserted
237 static const EventTypeSpec eventList
[] =
239 { kEventClassControl
, kEventControlHit
},
241 { kEventClassControl
, kEventControlHitTest
},
245 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
247 OSStatus result
= eventNotHandledErr
;
248 ControlRef controlRef
;
249 wxMacCarbonEvent
cEvent( event
);
251 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
253 switch ( GetEventKind( event
) )
255 case kEventControlHit
:
257 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
258 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
259 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
264 shouldToggle
= !tbartool
->IsToggled();
266 shouldToggle
= (GetControl32BitValue( (ControlRef
)(tbartool
->GetControlHandle()) ) != 0);
269 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
272 if (tbartool
!= NULL
)
273 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
279 case kEventControlHitTest
:
281 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
283 HIViewGetBounds( controlRef
, &rect
);
285 ControlPartCode pc
= kControlNoPart
;
286 if ( CGRectContainsPoint( rect
, pt
) )
287 pc
= kControlIconPart
;
288 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
301 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
303 OSStatus result
= eventNotHandledErr
;
305 switch ( GetEventClass( event
) )
307 case kEventClassControl
:
308 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
318 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
320 #if wxMAC_USE_NATIVE_TOOLBAR
322 static const EventTypeSpec toolBarEventList
[] =
324 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
327 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
329 OSStatus result
= eventNotHandledErr
;
331 switch ( GetEventKind( event
) )
333 case kEventToolbarItemPerformAction
:
335 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
336 if ( tbartool
!= NULL
)
338 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
339 int toolID
= tbartool
->GetId();
341 if ( tbartool
->CanBeToggled() )
344 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
348 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
361 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
363 OSStatus result
= eventNotHandledErr
;
365 switch ( GetEventClass( event
) )
367 case kEventClassToolbarItem
:
368 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
378 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
382 bool wxToolBarTool::DoEnable( bool enable
)
386 GetControl()->Enable( enable
);
388 else if ( IsButton() )
390 #if wxMAC_USE_NATIVE_TOOLBAR
391 if ( m_toolbarItemRef
!= NULL
)
392 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
395 if ( m_controlHandle
!= NULL
)
397 #if TARGET_API_MAC_OSX
399 EnableControl( m_controlHandle
);
401 DisableControl( m_controlHandle
);
404 ActivateControl( m_controlHandle
);
406 DeactivateControl( m_controlHandle
);
414 void wxToolBarTool::SetPosition( const wxPoint
& position
)
419 int mac_x
= position
.x
;
420 int mac_y
= position
.y
;
425 GetControlBounds( m_controlHandle
, &contrlRect
);
426 int former_mac_x
= contrlRect
.left
;
427 int former_mac_y
= contrlRect
.top
;
428 GetToolBar()->GetToolSize();
430 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
432 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
435 else if ( IsControl() )
437 // embedded native controls are moved by the OS
438 #if wxMAC_USE_NATIVE_TOOLBAR
439 if ( ((wxToolBar
*)GetToolBar())->MacWantsNativeToolbar() == false )
442 GetControl()->Move( position
);
450 GetControlBounds( m_controlHandle
, &contrlRect
);
451 int former_mac_x
= contrlRect
.left
;
452 int former_mac_y
= contrlRect
.top
;
454 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
455 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
460 void wxToolBarTool::UpdateToggleImage( bool toggle
)
465 int w
= m_bmpNormal
.GetWidth();
466 int h
= m_bmpNormal
.GetHeight();
467 wxBitmap
bmp( w
, h
);
470 dc
.SelectObject( bmp
);
471 dc
.SetPen( wxPen(*wxBLACK
) );
472 dc
.SetBrush( wxBrush( *wxLIGHT_GREY
));
473 dc
.DrawRectangle( 0, 0, w
, h
);
474 dc
.DrawBitmap( m_bmpNormal
, 0, 0, true );
475 dc
.SelectObject( wxNullBitmap
);
476 ControlButtonContentInfo info
;
477 wxMacCreateBitmapButton( &info
, bmp
, kControlContentIconRef
);
478 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
479 #if wxMAC_USE_NATIVE_TOOLBAR
480 if (m_toolbarItemRef
!= NULL
)
482 HIToolbarItemSetIconRef( m_toolbarItemRef
, info
.u
.iconRef
);
485 wxMacReleaseBitmapButton( &info
);
489 ControlButtonContentInfo info
;
490 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
);
491 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
492 #if wxMAC_USE_NATIVE_TOOLBAR
493 if (m_toolbarItemRef
!= NULL
)
495 HIToolbarItemSetIconRef( m_toolbarItemRef
, info
.u
.iconRef
);
498 wxMacReleaseBitmapButton( &info
);
501 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
503 m_controlHandle
, 0, kControlIconTransformTag
,
504 sizeof(transform
), (Ptr
)&transform
);
505 HIViewSetNeedsDisplay( m_controlHandle
, true );
508 ::SetControl32BitValue( m_controlHandle
, toggle
);
512 wxToolBarTool::wxToolBarTool(
515 const wxString
& label
,
516 const wxBitmap
& bmpNormal
,
517 const wxBitmap
& bmpDisabled
,
519 wxObject
*clientData
,
520 const wxString
& shortHelp
,
521 const wxString
& longHelp
)
524 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
525 clientData
, shortHelp
, longHelp
)
531 #pragma mark Toolbar Implementation
533 wxToolBarToolBase
*wxToolBar::CreateTool(
535 const wxString
& label
,
536 const wxBitmap
& bmpNormal
,
537 const wxBitmap
& bmpDisabled
,
539 wxObject
*clientData
,
540 const wxString
& shortHelp
,
541 const wxString
& longHelp
)
543 return new wxToolBarTool(
544 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
545 clientData
, shortHelp
, longHelp
);
549 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
551 return new wxToolBarTool(this, control
, label
);
554 void wxToolBar::Init()
558 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
559 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
561 #if wxMAC_USE_NATIVE_TOOLBAR
562 m_macHIToolbarRef
= NULL
;
563 m_macUsesNativeToolbar
= false;
567 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
569 const EventTypeSpec kEvents
[] =
571 { kEventClassHIObject
, kEventHIObjectConstruct
},
572 { kEventClassHIObject
, kEventHIObjectInitialize
},
573 { kEventClassHIObject
, kEventHIObjectDestruct
},
575 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
578 const EventTypeSpec kViewEvents
[] =
580 { kEventClassControl
, kEventControlGetSizeConstraints
}
583 struct ControlToolbarItem
585 HIToolbarItemRef toolbarItem
;
587 wxSize lastValidSize
;
590 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
592 OSStatus result
= eventNotHandledErr
;
593 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
595 switch ( GetEventClass( inEvent
) )
597 case kEventClassHIObject
:
598 switch ( GetEventKind( inEvent
) )
600 case kEventHIObjectConstruct
:
602 HIObjectRef toolbarItem
;
603 ControlToolbarItem
* item
;
605 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
606 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
608 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
609 item
->toolbarItem
= toolbarItem
;
610 item
->viewRef
= NULL
;
612 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
618 case kEventHIObjectInitialize
:
619 result
= CallNextEventHandler( inCallRef
, inEvent
);
620 if ( result
== noErr
)
623 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
624 sizeof( CFTypeRef
), NULL
, &data
);
628 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
629 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
631 object
->viewRef
= (HIViewRef
) viewRef
;
632 // make sure we keep that control during our lifetime
633 CFRetain( object
->viewRef
) ;
635 verify_noerr(InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
636 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
));
641 case kEventHIObjectDestruct
:
643 HIViewRef viewRef
= object
->viewRef
;
644 wxASSERT( IsValidControlHandle(viewRef
) ) ;
645 if( viewRef
&& IsValidControlHandle( viewRef
) )
647 // depending whether the wxControl corresponding to this HIView has already been destroyed or
648 // not, ref counts differ, so we cannot assert a special value
649 CFIndex count
= CFGetRetainCount( viewRef
) ;
650 wxASSERT_MSG( count
>=1 , wxT("Reference Count of native tool was illegal before removal") );
652 CFRelease( viewRef
) ;
661 case kEventClassToolbarItem
:
662 switch ( GetEventKind( inEvent
) )
664 case kEventToolbarItemCreateCustomView
:
666 HIViewRef viewRef
= object
->viewRef
;
667 HIViewRemoveFromSuperview( viewRef
) ;
668 HIViewSetVisible(viewRef
, true) ;
669 CFRetain( viewRef
) ;
670 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
676 case kEventClassControl
:
677 switch ( GetEventKind( inEvent
) )
679 case kEventControlGetSizeConstraints
:
681 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
684 wxSize sz
= wxwindow
->GetSize() ;
685 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
686 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
687 // during toolbar layout the native window sometimes gets negative sizes
688 // so we always keep the last valid size here, to make sure we survive the
690 if ( sz
.x
> 0 && sz
.y
> 0 )
691 object
->lastValidSize
= sz
;
693 sz
= object
->lastValidSize
;
696 min
.width
= max
.width
= sz
.x
;
697 min
.height
= max
.height
= sz
.y
;
699 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
700 sizeof( HISize
), &min
);
702 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
703 sizeof( HISize
), &max
);
715 void RegisterControlToolbarItemClass()
717 static bool sRegistered
;
721 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
722 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
728 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
730 RegisterControlToolbarItemClass();
734 UInt32 options
= kHIToolbarItemAllowDuplicates
;
735 HIToolbarItemRef result
= NULL
;
737 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
738 require_noerr( err
, CantCreateEvent
);
740 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
741 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
744 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
746 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
749 ReleaseEvent( event
);
754 #if wxMAC_USE_NATIVE_TOOLBAR
755 static const EventTypeSpec kToolbarEvents
[] =
757 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
758 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
759 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
762 static OSStatus
ToolbarDelegateHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
764 OSStatus result
= eventNotHandledErr
;
766 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
767 CFMutableArrayRef array
;
769 switch ( GetEventKind( inEvent
) )
771 case kEventToolbarGetDefaultIdentifiers
:
773 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
774 sizeof( CFMutableArrayRef
), NULL
, &array
);
775 // not implemented yet
776 // GetToolbarDefaultItems( array );
781 case kEventToolbarGetAllowedIdentifiers
:
783 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
784 sizeof( CFMutableArrayRef
), NULL
, &array
);
785 // not implemented yet
786 // GetToolbarAllowedItems( array );
790 case kEventToolbarCreateItemWithIdentifier
:
792 HIToolbarItemRef item
= NULL
;
793 CFTypeRef data
= NULL
;
794 CFStringRef identifier
= NULL
;
796 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
797 sizeof( CFStringRef
), NULL
, &identifier
);
799 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
800 sizeof( CFTypeRef
), NULL
, &data
);
802 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
804 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
807 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
808 sizeof( HIToolbarItemRef
), &item
);
818 #endif // wxMAC_USE_NATIVE_TOOLBAR
820 // also for the toolbar we have the dual implementation:
821 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
823 bool wxToolBar::Create(
829 const wxString
& name
)
831 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
836 OSStatus err
= noErr
;
838 #if wxMAC_USE_NATIVE_TOOLBAR
839 wxString labelStr
= wxString::Format( wxT("%xd"), (int)this );
840 err
= HIToolbarCreate(
841 wxMacCFStringHolder( labelStr
, wxFont::GetDefaultEncoding() ), 0,
842 (HIToolbarRef
*) &m_macHIToolbarRef
);
844 if (m_macHIToolbarRef
!= NULL
)
846 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
847 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
849 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
850 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
852 if ( style
& wxTB_NOICONS
)
853 mode
= kHIToolbarDisplayModeLabelOnly
;
854 else if ( style
& wxTB_TEXT
)
855 mode
= kHIToolbarDisplayModeIconAndLabel
;
857 mode
= kHIToolbarDisplayModeIconOnly
;
859 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
860 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
862 #endif // wxMAC_USE_NATIVE_TOOLBAR
864 return (err
== noErr
);
867 wxToolBar::~wxToolBar()
869 #if wxMAC_USE_NATIVE_TOOLBAR
870 if (m_macHIToolbarRef
!= NULL
)
872 // if this is the installed toolbar, then deinstall it
873 if (m_macUsesNativeToolbar
)
874 MacInstallNativeToolbar( false );
876 CFIndex count
= CFGetRetainCount( m_macHIToolbarRef
) ;
877 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
879 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
880 m_macHIToolbarRef
= NULL
;
885 bool wxToolBar::Show( bool show
)
887 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
888 bool bResult
= (tlw
!= NULL
);
892 #if wxMAC_USE_NATIVE_TOOLBAR
893 bool ownToolbarInstalled
= false;
894 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
895 if (ownToolbarInstalled
)
897 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
899 ShowHideWindowToolbar( tlw
, show
, false );
902 bResult
= wxToolBarBase::Show( show
);
905 bResult
= wxToolBarBase::Show( show
);
912 bool wxToolBar::IsShown() const
916 #if wxMAC_USE_NATIVE_TOOLBAR
917 bool ownToolbarInstalled
;
919 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
920 if (ownToolbarInstalled
)
922 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
923 bResult
= IsWindowToolbarVisible( tlw
);
926 bResult
= wxToolBarBase::IsShown();
929 bResult
= wxToolBarBase::IsShown();
935 void wxToolBar::DoGetSize( int *width
, int *height
) const
937 #if wxMAC_USE_NATIVE_TOOLBAR
939 bool ownToolbarInstalled
;
941 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
942 if ( ownToolbarInstalled
)
944 // TODO: is this really a control ?
945 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
947 *width
= boundsR
.right
- boundsR
.left
;
948 if ( height
!= NULL
)
949 *height
= boundsR
.bottom
- boundsR
.top
;
952 wxToolBarBase::DoGetSize( width
, height
);
955 wxToolBarBase::DoGetSize( width
, height
);
959 wxSize
wxToolBar::DoGetBestSize() const
963 DoGetSize( &width
, &height
);
965 return wxSize( width
, height
);
968 void wxToolBar::SetWindowStyleFlag( long style
)
970 wxToolBarBase::SetWindowStyleFlag( style
);
972 #if wxMAC_USE_NATIVE_TOOLBAR
973 if (m_macHIToolbarRef
!= NULL
)
975 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
977 if ( style
& wxTB_NOICONS
)
978 mode
= kHIToolbarDisplayModeLabelOnly
;
979 else if ( style
& wxTB_TEXT
)
980 mode
= kHIToolbarDisplayModeIconAndLabel
;
982 mode
= kHIToolbarDisplayModeIconOnly
;
984 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
989 #if wxMAC_USE_NATIVE_TOOLBAR
990 bool wxToolBar::MacWantsNativeToolbar()
992 return m_macUsesNativeToolbar
;
995 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
997 bool bResultV
= false;
999 if (ownToolbarInstalled
!= NULL
)
1000 *ownToolbarInstalled
= false;
1002 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1005 HIToolbarRef curToolbarRef
= NULL
;
1006 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1007 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
1008 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
1009 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
1015 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
1017 bool bResult
= false;
1019 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
1022 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
1025 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1029 // check the existing toolbar
1030 HIToolbarRef curToolbarRef
= NULL
;
1031 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1033 curToolbarRef
= NULL
;
1035 m_macUsesNativeToolbar
= usesNative
;
1037 if (m_macUsesNativeToolbar
)
1039 // only install toolbar if there isn't one installed already
1040 if (curToolbarRef
== NULL
)
1044 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1045 ShowHideWindowToolbar( tlw
, true, false );
1046 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1047 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1049 Rect r
= { 0, 0, 0, 0 };
1050 m_peer
->SetRect( &r
);
1051 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1052 m_peer
->SetVisibility( false, true );
1053 wxToolBarBase::Show( false );
1058 // only deinstall toolbar if this is the installed one
1059 if (m_macHIToolbarRef
== curToolbarRef
)
1063 ShowHideWindowToolbar( tlw
, false, false );
1064 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1065 SetWindowToolbar( tlw
, NULL
);
1067 m_peer
->SetVisibility( true, true );
1072 InvalidateBestSize();
1074 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1079 bool wxToolBar::Realize()
1081 if (m_tools
.GetCount() == 0)
1087 int maxToolWidth
= 0;
1088 int maxToolHeight
= 0;
1090 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1091 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1094 GetSize( &tw
, &th
);
1096 // find the maximum tool width and height
1097 wxToolBarTool
*tool
;
1098 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1099 while ( node
!= NULL
)
1101 tool
= (wxToolBarTool
*) node
->GetData();
1104 wxSize sz
= tool
->GetSize();
1106 if ( sz
.x
> maxToolWidth
)
1107 maxToolWidth
= sz
.x
;
1108 if ( sz
.y
> maxToolHeight
)
1109 maxToolHeight
= sz
.y
;
1112 node
= node
->GetNext();
1115 bool lastIsRadio
= false;
1116 bool curIsRadio
= false;
1118 #if wxMAC_USE_NATIVE_TOOLBAR
1119 CFIndex currentPosition
= 0;
1120 bool insertAll
= false;
1122 HIToolbarRef refTB
= (HIToolbarRef
)m_macHIToolbarRef
;
1125 node
= m_tools
.GetFirst();
1126 while ( node
!= NULL
)
1128 tool
= (wxToolBarTool
*) node
->GetData();
1131 node
= node
->GetNext();
1135 // set tool position:
1136 // for the moment just perform a single row/column alignment
1137 wxSize cursize
= tool
->GetSize();
1138 if ( x
+ cursize
.x
> maxWidth
)
1139 maxWidth
= x
+ cursize
.x
;
1140 if ( y
+ cursize
.y
> maxHeight
)
1141 maxHeight
= y
+ cursize
.y
;
1143 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1145 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1146 tool
->SetPosition( wxPoint(x1
, y
) );
1150 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1151 tool
->SetPosition( wxPoint(x
, y1
) );
1154 // update the item positioning state
1155 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1156 y
+= cursize
.y
+ kwxMacToolSpacing
;
1158 x
+= cursize
.x
+ kwxMacToolSpacing
;
1160 #if wxMAC_USE_NATIVE_TOOLBAR
1161 // install in native HIToolbar
1164 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1165 if ( hiItemRef
!= NULL
)
1167 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1169 OSStatus err
= noErr
;
1174 // if this is the first tool that gets newly inserted or repositioned
1175 // first remove all 'old' tools from here to the right, because of this
1176 // all following tools will have to be reinserted (insertAll).
1177 for ( wxToolBarToolsList::compatibility_iterator node2
= m_tools
.GetLast();
1179 node2
= node2
->GetPrevious() )
1181 wxToolBarTool
*tool2
= (wxToolBarTool
*) node2
->GetData();
1183 const long idx
= tool2
->GetIndex();
1186 if ( tool2
->IsControl() )
1188 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1189 wxASSERT_MSG( count
== 3 , wxT("Reference Count of native tool was not 3 before removal") );
1190 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1192 err
= HIToolbarRemoveItemAtIndex(refTB
, idx
);
1195 wxLogDebug(wxT("HIToolbarRemoveItemAtIndex(%ld) failed [%ld]"),
1198 if ( tool2
->IsControl() )
1200 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1201 wxASSERT_MSG( count
== 2 , wxT("Reference Count of native tool was not 2 after removal") );
1202 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1205 tool2
->SetIndex(-1);
1210 err
= HIToolbarInsertItemAtIndex( refTB
, hiItemRef
, currentPosition
);
1213 wxLogDebug( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1216 tool
->SetIndex( currentPosition
);
1217 if ( tool
->IsControl() )
1219 CFIndex count
= CFGetRetainCount( tool
->GetControl()->GetPeer()->GetControlRef() ) ;
1220 wxASSERT_MSG( count
== 3 , wxT("Reference Count of native tool was not 3 after insertion") );
1221 wxASSERT( IsValidControlHandle(tool
->GetControl()->GetPeer()->GetControlRef() )) ;
1230 // update radio button (and group) state
1231 lastIsRadio
= curIsRadio
;
1232 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1236 if ( tool
->IsToggled() )
1237 DoToggleTool( tool
, true );
1243 if ( tool
->Toggle( true ) )
1245 DoToggleTool( tool
, true );
1248 else if ( tool
->IsToggled() )
1250 if ( tool
->IsToggled() )
1251 DoToggleTool( tool
, true );
1253 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1254 while ( nodePrev
!= NULL
)
1256 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1257 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1260 if ( toggleTool
->Toggle( false ) )
1261 DoToggleTool( toggleTool
, false );
1263 nodePrev
= nodePrev
->GetPrevious();
1268 node
= node
->GetNext();
1271 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1273 // if not set yet, only one row
1274 if ( m_maxRows
<= 0 )
1277 m_minWidth
= maxWidth
;
1279 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1280 m_minHeight
= m_maxHeight
= maxHeight
;
1284 // if not set yet, have one column
1285 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1286 SetRows( GetToolsCount() );
1288 m_minHeight
= maxHeight
;
1290 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1291 m_minWidth
= m_maxWidth
= maxWidth
;
1295 // FIXME: should this be OSX-only?
1297 bool wantNativeToolbar
, ownToolbarInstalled
;
1299 // attempt to install the native toolbar
1300 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1301 MacInstallNativeToolbar( wantNativeToolbar
);
1302 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1303 if (!ownToolbarInstalled
)
1305 SetSize( maxWidth
, maxHeight
);
1306 InvalidateBestSize();
1310 SetSize( maxWidth
, maxHeight
);
1311 InvalidateBestSize();
1319 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1321 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1322 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1324 #if wxMAC_USE_NATIVE_TOOLBAR
1325 if (m_macHIToolbarRef
!= NULL
)
1327 int maxs
= wxMax( size
.x
, size
.y
);
1328 HIToolbarDisplaySize sizeSpec
;
1330 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1331 else if ( maxs
> 24 )
1332 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1334 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1336 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1341 // The button size is bigger than the bitmap size
1342 wxSize
wxToolBar::GetToolSize() const
1344 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1347 void wxToolBar::SetRows(int nRows
)
1349 // avoid resizing the frame uselessly
1350 if ( nRows
!= m_maxRows
)
1354 void wxToolBar::MacSuperChangedPosition()
1356 wxWindow::MacSuperChangedPosition();
1358 #if wxMAC_USE_NATIVE_TOOLBAR
1359 if (! m_macUsesNativeToolbar
)
1367 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1369 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1372 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1374 tool
->SetNormalBitmap(bitmap
);
1376 // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
1377 tool
->UpdateToggleImage( tool
->CanBeToggled() && tool
->IsToggled() );
1381 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1383 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1386 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1388 tool
->SetDisabledBitmap(bitmap
);
1390 // TODO: what to do for this one?
1394 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1396 wxToolBarTool
*tool
;
1397 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1398 while ( node
!= NULL
)
1400 tool
= (wxToolBarTool
*)node
->GetData();
1403 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1404 if ( r
.Contains( wxPoint( x
, y
) ) )
1408 node
= node
->GetNext();
1411 return (wxToolBarToolBase
*)NULL
;
1414 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1416 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1418 return tool
->GetShortHelp();
1420 return wxEmptyString
;
1423 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1426 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1429 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1431 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1432 if ( ( tool
!= NULL
) && tool
->IsButton() )
1433 tool
->UpdateToggleImage( toggle
);
1436 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1438 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1442 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1443 wxSize toolSize
= GetToolSize();
1444 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1445 ControlRef controlHandle
= NULL
;
1447 tool
->Attach( this );
1449 #if wxMAC_USE_NATIVE_TOOLBAR
1450 HIToolbarItemRef item
;
1453 switch (tool
->GetStyle())
1455 case wxTOOL_STYLE_SEPARATOR
:
1457 wxASSERT( tool
->GetControlHandle() == NULL
);
1460 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1461 toolrect
.bottom
= toolSize
.y
;
1463 toolrect
.right
= toolSize
.x
;
1465 // in flat style we need a visual separator
1466 #if wxMAC_USE_NATIVE_TOOLBAR
1467 err
= HIToolbarItemCreate(
1468 kHIToolbarSeparatorIdentifier
,
1469 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1472 tool
->SetToolbarItemRef( item
);
1473 #endif // wxMAC_USE_NATIVE_TOOLBAR
1475 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1476 tool
->SetControlHandle( controlHandle
);
1480 case wxTOOL_STYLE_BUTTON
:
1482 wxASSERT( tool
->GetControlHandle() == NULL
);
1483 ControlButtonContentInfo info
;
1484 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1486 if ( UMAGetSystemVersion() >= 0x1000)
1488 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1492 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1493 if ( tool
->CanBeToggled() )
1494 behaviour
|= kControlBehaviorToggles
;
1495 err
= CreateBevelButtonControl( window
,
1496 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1497 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1500 #if wxMAC_USE_NATIVE_TOOLBAR
1501 wxString labelStr
= wxString::Format(wxT("%xd"), (int)tool
);
1502 err
= HIToolbarItemCreate(
1503 wxMacCFStringHolder(labelStr
, wxFont::GetDefaultEncoding()),
1504 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1507 InstallEventHandler(
1508 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1509 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1511 HIToolbarItemSetIconRef( item
, info
.u
.iconRef
);
1512 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1513 tool
->SetToolbarItemRef( item
);
1515 #endif // wxMAC_USE_NATIVE_TOOLBAR
1517 wxMacReleaseBitmapButton( &info
);
1520 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1521 UMASetControlTitle( m_controlHandle
, label
, wxFont::GetDefaultEncoding() );
1524 InstallControlEventHandler(
1525 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1526 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1528 tool
->SetControlHandle( controlHandle
);
1532 case wxTOOL_STYLE_CONTROL
:
1534 #if wxMAC_USE_NATIVE_TOOLBAR
1536 wxCHECK_MSG( tool
->GetControl(), false, _T("control must be non-NULL") );
1538 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
1539 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1540 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1545 tool
->SetToolbarItemRef( item
);
1551 // right now there's nothing to do here
1559 #if wxMAC_USE_NATIVE_TOOLBAR
1560 wxString label
= tool
->GetLabel();
1561 if ( !label
.empty() )
1563 // strip mnemonics from the label for compatibility
1564 // with the usual labels in wxStaticText sense
1565 label
= wxStripMenuCodes(label
);
1567 HIToolbarItemSetLabel(item
,
1568 wxMacCFStringHolder(label
, m_font
.GetEncoding()));
1570 #endif // wxMAC_USE_NATIVE_TOOLBAR
1574 if ( controlHandle
)
1576 ControlRef container
= (ControlRef
) GetHandle();
1577 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1579 UMAShowControl( controlHandle
);
1580 ::EmbedControl( controlHandle
, container
);
1583 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1584 tool
->UpdateToggleImage( true );
1586 // nothing special to do here - we relayout in Realize() later
1587 InvalidateBestSize();
1591 wxString errMsg
= wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
);
1592 wxFAIL_MSG( errMsg
.c_str() );
1595 return (err
== noErr
);
1598 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1600 wxFAIL_MSG( wxT("not implemented") );
1603 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1605 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1606 wxToolBarToolsList::compatibility_iterator node
;
1607 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1609 wxToolBarToolBase
*tool2
= node
->GetData();
1610 if ( tool2
== tool
)
1612 // let node point to the next node in the list
1613 node
= node
->GetNext();
1619 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1623 #if wxMAC_USE_NATIVE_TOOLBAR
1624 CFIndex removeIndex
= tool
->GetIndex();
1627 #if wxMAC_USE_NATIVE_TOOLBAR
1628 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1630 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1631 tool
->SetIndex( -1 );
1634 switch ( tool
->GetStyle() )
1636 case wxTOOL_STYLE_CONTROL
:
1637 if ( tool
->GetControl() )
1638 tool
->GetControl()->Destroy();
1641 case wxTOOL_STYLE_BUTTON
:
1642 case wxTOOL_STYLE_SEPARATOR
:
1649 tool
->ClearControl();
1651 // and finally reposition all the controls after this one
1653 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1655 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1656 wxPoint pt
= tool2
->GetPosition();
1658 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1663 tool2
->SetPosition( pt
);
1665 #if wxMAC_USE_NATIVE_TOOLBAR
1666 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1667 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1671 InvalidateBestSize();
1676 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1678 #if wxMAC_USE_NATIVE_TOOLBAR
1679 if ( m_macUsesNativeToolbar
)
1691 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1692 bool minimumUmaAvailable
= (UMAGetSystemVersion() >= 0x1030);
1694 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1695 if ( !drawMetalTheme
&& minimumUmaAvailable
)
1697 HIThemePlacardDrawInfo info
;
1698 memset( &info
, 0, sizeof(info
) );
1700 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1702 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1703 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1704 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1708 // leave the background as it is (striped or metal)
1713 const bool drawBorder
= true;
1717 wxMacPortSetter
helper( &dc
);
1719 if ( !drawMetalTheme
|| !minimumUmaAvailable
)
1721 Rect toolbarrect
= { dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1722 dc
.YLOG2DEVMAC(h
), dc
.XLOG2DEVMAC(w
) };
1725 if ( toolbarrect
.left
< 0 )
1726 toolbarrect
.left
= 0;
1727 if ( toolbarrect
.top
< 0 )
1728 toolbarrect
.top
= 0;
1731 UMADrawThemePlacard( &toolbarrect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
);
1735 #if TARGET_API_MAC_OSX
1736 HIRect hiToolbarrect
= CGRectMake(
1737 dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1738 dc
.YLOG2DEVREL(h
), dc
.XLOG2DEVREL(w
) );
1739 CGContextRef cgContext
;
1742 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
1743 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1745 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
1746 CGContextScaleCTM( cgContext
, 1, -1 );
1748 HIThemeBackgroundDrawInfo drawInfo
;
1749 drawInfo
.version
= 0;
1750 drawInfo
.state
= kThemeStateActive
;
1751 drawInfo
.kind
= kThemeBackgroundMetal
;
1752 HIThemeApplyBackground( &hiToolbarrect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
1755 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1765 #endif // wxUSE_TOOLBAR