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"
25 #include "wx/sysopt.h"
29 const short kwxMacToolBarToolDefaultWidth
= 16;
30 const short kwxMacToolBarToolDefaultHeight
= 16;
31 const short kwxMacToolBarTopMargin
= 4;
32 const short kwxMacToolBarLeftMargin
= 4;
33 const short kwxMacToolBorder
= 0;
34 const short kwxMacToolSpacing
= 6;
36 const short kwxMacToolBarToolDefaultWidth
= 24;
37 const short kwxMacToolBarToolDefaultHeight
= 22;
38 const short kwxMacToolBarTopMargin
= 2;
39 const short kwxMacToolBarLeftMargin
= 2;
40 const short kwxMacToolBorder
= 4;
41 const short kwxMacToolSpacing
= 0;
45 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
47 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
48 EVT_PAINT( wxToolBar::OnPaint
)
53 #pragma mark Tool Implementation
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // We have a dual implementation for each tool, ControlRef and HIToolbarItemRef
62 // when embedding native controls in the native toolbar we must make sure the
63 // control does not get deleted behind our backs, so the retain count gets increased
64 // (after creation it is 1), first be the creation of the custom HIToolbarItem wrapper
65 // object, and second by the code 'creating' the custom HIView (which is the same as the
66 // already existing native control, therefore we just increase the ref count)
67 // when this view is removed from the native toolbar its count gets decremented again
68 // and when the HITooolbarItem wrapper object gets destroyed it is decremented as well
69 // so in the end the control lives with a refcount of one and can be disposed of by the
70 // wxControl code. For embedded controls on a non-native toolbar this ref count is less
71 // so we can only test against a range, not a specific value of the refcount.
73 class wxToolBarTool
: public wxToolBarToolBase
79 const wxString
& label
,
80 const wxBitmap
& bmpNormal
,
81 const wxBitmap
& bmpDisabled
,
84 const wxString
& shortHelp
,
85 const wxString
& longHelp
);
87 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
, const wxString
& label
)
88 : wxToolBarToolBase(tbar
, control
, label
)
92 SetControlHandle( (ControlRef
) control
->GetHandle() );
95 virtual ~wxToolBarTool()
100 WXWidget
GetControlHandle()
102 return (WXWidget
) m_controlHandle
;
105 void SetControlHandle( ControlRef handle
)
107 m_controlHandle
= handle
;
110 void SetPosition( const wxPoint
& position
);
114 if ( m_controlHandle
)
117 DisposeControl( m_controlHandle
);
120 // the embedded control is not under the responsibility of the tool, it will be disposed of in the
121 // proper wxControl destructor
122 wxASSERT( IsValidControlHandle(GetControl()->GetPeer()->GetControlRef() )) ;
124 m_controlHandle
= NULL
;
128 #if wxMAC_USE_NATIVE_TOOLBAR
129 if ( m_toolbarItemRef
)
131 CFIndex count
= CFGetRetainCount( m_toolbarItemRef
) ;
132 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
133 wxTheApp
->MacAddToAutorelease(m_toolbarItemRef
);
134 CFRelease(m_toolbarItemRef
);
135 m_toolbarItemRef
= NULL
;
140 wxSize
GetSize() const
146 curSize
= GetControl()->GetSize();
148 else if ( IsButton() )
150 curSize
= GetToolBar()->GetToolSize();
155 curSize
= GetToolBar()->GetToolSize();
156 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
165 wxPoint
GetPosition() const
167 return wxPoint( m_x
, m_y
);
170 bool DoEnable( bool enable
);
172 void UpdateToggleImage( bool toggle
);
174 #if wxMAC_USE_NATIVE_TOOLBAR
175 void SetToolbarItemRef( HIToolbarItemRef ref
)
177 if ( m_controlHandle
)
178 HideControl( m_controlHandle
);
179 if ( m_toolbarItemRef
)
180 CFRelease( m_toolbarItemRef
);
182 m_toolbarItemRef
= ref
;
183 if ( m_toolbarItemRef
)
188 f
= GetToolBar()->GetFont();
190 enc
= f
.GetEncoding();
192 enc
= wxFont::GetDefaultEncoding();
194 HIToolbarItemSetHelpText(
196 wxMacCFStringHolder( GetShortHelp(), enc
),
197 wxMacCFStringHolder( GetLongHelp(), enc
) );
201 HIToolbarItemRef
GetToolbarItemRef() const
203 return m_toolbarItemRef
;
206 void SetIndex( CFIndex idx
)
211 CFIndex
GetIndex() const
220 m_controlHandle
= NULL
;
222 #if wxMAC_USE_NATIVE_TOOLBAR
223 m_toolbarItemRef
= NULL
;
228 ControlRef m_controlHandle
;
232 #if wxMAC_USE_NATIVE_TOOLBAR
233 HIToolbarItemRef m_toolbarItemRef
;
234 // position in its toolbar, -1 means not inserted
239 static const EventTypeSpec eventList
[] =
241 { kEventClassControl
, kEventControlHit
},
243 { kEventClassControl
, kEventControlHitTest
},
247 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
249 OSStatus result
= eventNotHandledErr
;
250 ControlRef controlRef
;
251 wxMacCarbonEvent
cEvent( event
);
253 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
255 switch ( GetEventKind( event
) )
257 case kEventControlHit
:
259 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
260 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
261 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
266 shouldToggle
= !tbartool
->IsToggled();
268 shouldToggle
= (GetControl32BitValue( (ControlRef
)(tbartool
->GetControlHandle()) ) != 0);
271 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
274 if (tbartool
!= NULL
)
275 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
281 case kEventControlHitTest
:
283 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
285 HIViewGetBounds( controlRef
, &rect
);
287 ControlPartCode pc
= kControlNoPart
;
288 if ( CGRectContainsPoint( rect
, pt
) )
289 pc
= kControlIconPart
;
290 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
303 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
305 OSStatus result
= eventNotHandledErr
;
307 switch ( GetEventClass( event
) )
309 case kEventClassControl
:
310 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
320 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
322 #if wxMAC_USE_NATIVE_TOOLBAR
324 static const EventTypeSpec toolBarEventList
[] =
326 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
329 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
331 OSStatus result
= eventNotHandledErr
;
333 switch ( GetEventKind( event
) )
335 case kEventToolbarItemPerformAction
:
337 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
338 if ( tbartool
!= NULL
)
340 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
341 int toolID
= tbartool
->GetId();
343 if ( tbartool
->CanBeToggled() )
346 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
350 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
363 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
365 OSStatus result
= eventNotHandledErr
;
367 switch ( GetEventClass( event
) )
369 case kEventClassToolbarItem
:
370 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
380 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
384 bool wxToolBarTool::DoEnable( bool enable
)
388 GetControl()->Enable( enable
);
390 else if ( IsButton() )
392 #if wxMAC_USE_NATIVE_TOOLBAR
393 if ( m_toolbarItemRef
!= NULL
)
394 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
397 if ( m_controlHandle
!= NULL
)
399 #if TARGET_API_MAC_OSX
401 EnableControl( m_controlHandle
);
403 DisableControl( m_controlHandle
);
406 ActivateControl( m_controlHandle
);
408 DeactivateControl( m_controlHandle
);
416 void wxToolBarTool::SetPosition( const wxPoint
& position
)
421 int mac_x
= position
.x
;
422 int mac_y
= position
.y
;
427 GetControlBounds( m_controlHandle
, &contrlRect
);
428 int former_mac_x
= contrlRect
.left
;
429 int former_mac_y
= contrlRect
.top
;
430 GetToolBar()->GetToolSize();
432 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
434 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
437 else if ( IsControl() )
439 // embedded native controls are moved by the OS
440 #if wxMAC_USE_NATIVE_TOOLBAR
441 if ( ((wxToolBar
*)GetToolBar())->MacWantsNativeToolbar() == false )
444 GetControl()->Move( position
);
452 GetControlBounds( m_controlHandle
, &contrlRect
);
453 int former_mac_x
= contrlRect
.left
;
454 int former_mac_y
= contrlRect
.top
;
456 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
457 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
462 void wxToolBarTool::UpdateToggleImage( bool toggle
)
467 int w
= m_bmpNormal
.GetWidth();
468 int h
= m_bmpNormal
.GetHeight();
469 wxBitmap
bmp( w
, h
);
472 dc
.SelectObject( bmp
);
473 dc
.SetPen( wxPen(*wxBLACK
) );
474 dc
.SetBrush( wxBrush( *wxLIGHT_GREY
));
475 dc
.DrawRectangle( 0, 0, w
, h
);
476 dc
.DrawBitmap( m_bmpNormal
, 0, 0, true );
477 dc
.SelectObject( wxNullBitmap
);
478 ControlButtonContentInfo info
;
479 wxMacCreateBitmapButton( &info
, bmp
, kControlContentIconRef
);
480 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
481 #if wxMAC_USE_NATIVE_TOOLBAR
482 if (m_toolbarItemRef
!= NULL
)
484 HIToolbarItemSetIconRef( m_toolbarItemRef
, info
.u
.iconRef
);
487 wxMacReleaseBitmapButton( &info
);
491 ControlButtonContentInfo info
;
492 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
);
493 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
494 #if wxMAC_USE_NATIVE_TOOLBAR
495 if (m_toolbarItemRef
!= NULL
)
497 HIToolbarItemSetIconRef( m_toolbarItemRef
, info
.u
.iconRef
);
500 wxMacReleaseBitmapButton( &info
);
503 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
505 m_controlHandle
, 0, kControlIconTransformTag
,
506 sizeof(transform
), (Ptr
)&transform
);
507 HIViewSetNeedsDisplay( m_controlHandle
, true );
510 ::SetControl32BitValue( m_controlHandle
, toggle
);
514 wxToolBarTool::wxToolBarTool(
517 const wxString
& label
,
518 const wxBitmap
& bmpNormal
,
519 const wxBitmap
& bmpDisabled
,
521 wxObject
*clientData
,
522 const wxString
& shortHelp
,
523 const wxString
& longHelp
)
526 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
527 clientData
, shortHelp
, longHelp
)
533 #pragma mark Toolbar Implementation
535 wxToolBarToolBase
*wxToolBar::CreateTool(
537 const wxString
& label
,
538 const wxBitmap
& bmpNormal
,
539 const wxBitmap
& bmpDisabled
,
541 wxObject
*clientData
,
542 const wxString
& shortHelp
,
543 const wxString
& longHelp
)
545 return new wxToolBarTool(
546 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
547 clientData
, shortHelp
, longHelp
);
551 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
553 return new wxToolBarTool(this, control
, label
);
556 void wxToolBar::Init()
560 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
561 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
563 #if wxMAC_USE_NATIVE_TOOLBAR
564 m_macHIToolbarRef
= NULL
;
565 m_macUsesNativeToolbar
= false;
569 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
571 const EventTypeSpec kEvents
[] =
573 { kEventClassHIObject
, kEventHIObjectConstruct
},
574 { kEventClassHIObject
, kEventHIObjectInitialize
},
575 { kEventClassHIObject
, kEventHIObjectDestruct
},
577 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
580 const EventTypeSpec kViewEvents
[] =
582 { kEventClassControl
, kEventControlGetSizeConstraints
}
585 struct ControlToolbarItem
587 HIToolbarItemRef toolbarItem
;
589 wxSize lastValidSize
;
592 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
594 OSStatus result
= eventNotHandledErr
;
595 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
597 switch ( GetEventClass( inEvent
) )
599 case kEventClassHIObject
:
600 switch ( GetEventKind( inEvent
) )
602 case kEventHIObjectConstruct
:
604 HIObjectRef toolbarItem
;
605 ControlToolbarItem
* item
;
607 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
608 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
610 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
611 item
->toolbarItem
= toolbarItem
;
612 item
->lastValidSize
= wxSize(-1,-1);
613 item
->viewRef
= NULL
;
615 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
621 case kEventHIObjectInitialize
:
622 result
= CallNextEventHandler( inCallRef
, inEvent
);
623 if ( result
== noErr
)
626 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
627 sizeof( CFTypeRef
), NULL
, &data
);
631 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
632 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
634 object
->viewRef
= (HIViewRef
) viewRef
;
635 // make sure we keep that control during our lifetime
636 CFRetain( object
->viewRef
) ;
638 verify_noerr(InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
639 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
));
644 case kEventHIObjectDestruct
:
646 HIViewRef viewRef
= object
->viewRef
;
647 if( viewRef
&& IsValidControlHandle( viewRef
) )
649 // depending whether the wxControl corresponding to this HIView has already been destroyed or
650 // not, ref counts differ, so we cannot assert a special value
651 CFIndex count
= CFGetRetainCount( viewRef
) ;
652 wxASSERT_MSG( count
>=1 , wxT("Reference Count of native tool was illegal before removal") );
654 CFRelease( viewRef
) ;
663 case kEventClassToolbarItem
:
664 switch ( GetEventKind( inEvent
) )
666 case kEventToolbarItemCreateCustomView
:
668 HIViewRef viewRef
= object
->viewRef
;
669 HIViewRemoveFromSuperview( viewRef
) ;
670 HIViewSetVisible(viewRef
, true) ;
671 CFRetain( viewRef
) ;
672 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
678 case kEventClassControl
:
679 switch ( GetEventKind( inEvent
) )
681 case kEventControlGetSizeConstraints
:
683 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
686 // during toolbar layout the native window sometimes gets negative sizes,
687 // sometimes it just gets shrunk behind our back, so in order to avoid
688 // ever shrinking more, once a valid size is captured, we keep it
690 wxSize sz
= object
->lastValidSize
;
691 if ( sz
.x
<= 0 || sz
.y
<= 0 )
693 sz
= wxwindow
->GetSize() ;
694 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
695 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
696 if ( sz
.x
> 0 && sz
.y
> 0 )
697 object
->lastValidSize
= sz
;
702 // Extra width to avoid edge of combobox being cut off
706 min
.width
= max
.width
= sz
.x
;
707 min
.height
= max
.height
= sz
.y
;
709 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
710 sizeof( HISize
), &min
);
712 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
713 sizeof( HISize
), &max
);
725 void RegisterControlToolbarItemClass()
727 static bool sRegistered
;
731 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
732 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
738 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
740 RegisterControlToolbarItemClass();
744 UInt32 options
= kHIToolbarItemAllowDuplicates
;
745 HIToolbarItemRef result
= NULL
;
747 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
748 require_noerr( err
, CantCreateEvent
);
750 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
751 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
754 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
756 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
759 ReleaseEvent( event
);
764 #if wxMAC_USE_NATIVE_TOOLBAR
765 static const EventTypeSpec kToolbarEvents
[] =
767 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
768 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
769 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
772 static OSStatus
ToolbarDelegateHandler(EventHandlerCallRef
WXUNUSED(inCallRef
),
774 void* WXUNUSED(inUserData
))
776 OSStatus result
= eventNotHandledErr
;
778 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
779 CFMutableArrayRef array
;
781 switch ( GetEventKind( inEvent
) )
783 case kEventToolbarGetDefaultIdentifiers
:
785 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
786 sizeof( CFMutableArrayRef
), NULL
, &array
);
787 // not implemented yet
788 // GetToolbarDefaultItems( array );
793 case kEventToolbarGetAllowedIdentifiers
:
795 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
796 sizeof( CFMutableArrayRef
), NULL
, &array
);
797 // not implemented yet
798 // GetToolbarAllowedItems( array );
802 case kEventToolbarCreateItemWithIdentifier
:
804 HIToolbarItemRef item
= NULL
;
805 CFTypeRef data
= NULL
;
806 CFStringRef identifier
= NULL
;
808 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
809 sizeof( CFStringRef
), NULL
, &identifier
);
811 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
812 sizeof( CFTypeRef
), NULL
, &data
);
814 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
816 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
819 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
820 sizeof( HIToolbarItemRef
), &item
);
830 #endif // wxMAC_USE_NATIVE_TOOLBAR
832 // also for the toolbar we have the dual implementation:
833 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
835 bool wxToolBar::Create(
841 const wxString
& name
)
843 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
848 OSStatus err
= noErr
;
850 #if wxMAC_USE_NATIVE_TOOLBAR
851 if (parent
->IsKindOf(CLASSINFO(wxFrame
)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1)
853 wxString labelStr
= wxString::Format( wxT("%xd"), (int)this );
854 err
= HIToolbarCreate(
855 wxMacCFStringHolder( labelStr
, wxFont::GetDefaultEncoding() ), 0,
856 (HIToolbarRef
*) &m_macHIToolbarRef
);
858 if (m_macHIToolbarRef
!= NULL
)
860 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
861 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
863 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
864 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
866 if ( style
& wxTB_NOICONS
)
867 mode
= kHIToolbarDisplayModeLabelOnly
;
868 else if ( style
& wxTB_TEXT
)
869 mode
= kHIToolbarDisplayModeIconAndLabel
;
871 mode
= kHIToolbarDisplayModeIconOnly
;
873 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
874 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
877 #endif // wxMAC_USE_NATIVE_TOOLBAR
879 return (err
== noErr
);
882 wxToolBar::~wxToolBar()
884 #if wxMAC_USE_NATIVE_TOOLBAR
885 if (m_macHIToolbarRef
!= NULL
)
887 // if this is the installed toolbar, then deinstall it
888 if (m_macUsesNativeToolbar
)
889 MacInstallNativeToolbar( false );
891 CFIndex count
= CFGetRetainCount( m_macHIToolbarRef
) ;
892 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
894 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
895 m_macHIToolbarRef
= NULL
;
900 bool wxToolBar::Show( bool show
)
902 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
903 bool bResult
= (tlw
!= NULL
);
907 #if wxMAC_USE_NATIVE_TOOLBAR
908 bool ownToolbarInstalled
= false;
909 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
910 if (ownToolbarInstalled
)
912 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
914 ShowHideWindowToolbar( tlw
, show
, false );
917 bResult
= wxToolBarBase::Show( show
);
920 bResult
= wxToolBarBase::Show( show
);
927 bool wxToolBar::IsShown() const
931 #if wxMAC_USE_NATIVE_TOOLBAR
932 bool ownToolbarInstalled
;
934 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
935 if (ownToolbarInstalled
)
937 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
938 bResult
= IsWindowToolbarVisible( tlw
);
941 bResult
= wxToolBarBase::IsShown();
944 bResult
= wxToolBarBase::IsShown();
950 void wxToolBar::DoGetSize( int *width
, int *height
) const
952 #if wxMAC_USE_NATIVE_TOOLBAR
954 bool ownToolbarInstalled
;
956 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
957 if ( ownToolbarInstalled
)
959 // TODO: is this really a control ?
960 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
962 *width
= boundsR
.right
- boundsR
.left
;
963 if ( height
!= NULL
)
964 *height
= boundsR
.bottom
- boundsR
.top
;
967 wxToolBarBase::DoGetSize( width
, height
);
970 wxToolBarBase::DoGetSize( width
, height
);
974 wxSize
wxToolBar::DoGetBestSize() const
978 DoGetSize( &width
, &height
);
980 return wxSize( width
, height
);
983 void wxToolBar::SetWindowStyleFlag( long style
)
985 wxToolBarBase::SetWindowStyleFlag( style
);
987 #if wxMAC_USE_NATIVE_TOOLBAR
988 if (m_macHIToolbarRef
!= NULL
)
990 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
992 if ( style
& wxTB_NOICONS
)
993 mode
= kHIToolbarDisplayModeLabelOnly
;
994 else if ( style
& wxTB_TEXT
)
995 mode
= kHIToolbarDisplayModeIconAndLabel
;
997 mode
= kHIToolbarDisplayModeIconOnly
;
999 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
1004 #if wxMAC_USE_NATIVE_TOOLBAR
1005 bool wxToolBar::MacWantsNativeToolbar()
1007 return m_macUsesNativeToolbar
;
1010 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
1012 bool bResultV
= false;
1014 if (ownToolbarInstalled
!= NULL
)
1015 *ownToolbarInstalled
= false;
1017 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1020 HIToolbarRef curToolbarRef
= NULL
;
1021 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1022 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
1023 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
1024 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
1030 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
1032 bool bResult
= false;
1034 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
1037 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
1040 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1044 // check the existing toolbar
1045 HIToolbarRef curToolbarRef
= NULL
;
1046 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1048 curToolbarRef
= NULL
;
1050 m_macUsesNativeToolbar
= usesNative
;
1052 if (m_macUsesNativeToolbar
)
1054 // only install toolbar if there isn't one installed already
1055 if (curToolbarRef
== NULL
)
1059 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1060 ShowHideWindowToolbar( tlw
, true, false );
1061 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1062 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1064 Rect r
= { 0, 0, 0, 0 };
1065 m_peer
->SetRect( &r
);
1066 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1067 m_peer
->SetVisibility( false, true );
1068 wxToolBarBase::Show( false );
1073 // only deinstall toolbar if this is the installed one
1074 if (m_macHIToolbarRef
== curToolbarRef
)
1078 ShowHideWindowToolbar( tlw
, false, false );
1079 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1080 SetWindowToolbar( tlw
, NULL
);
1082 m_peer
->SetVisibility( true, true );
1087 InvalidateBestSize();
1089 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1094 bool wxToolBar::Realize()
1096 if (m_tools
.GetCount() == 0)
1102 int maxToolWidth
= 0;
1103 int maxToolHeight
= 0;
1105 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1106 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1109 GetSize( &tw
, &th
);
1111 // find the maximum tool width and height
1112 wxToolBarTool
*tool
;
1113 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1116 tool
= (wxToolBarTool
*) node
->GetData();
1119 wxSize sz
= tool
->GetSize();
1121 if ( sz
.x
> maxToolWidth
)
1122 maxToolWidth
= sz
.x
;
1123 if ( sz
.y
> maxToolHeight
)
1124 maxToolHeight
= sz
.y
;
1127 node
= node
->GetNext();
1130 bool lastIsRadio
= false;
1131 bool curIsRadio
= false;
1133 #if wxMAC_USE_NATIVE_TOOLBAR
1134 CFIndex currentPosition
= 0;
1135 bool insertAll
= false;
1137 HIToolbarRef refTB
= (HIToolbarRef
)m_macHIToolbarRef
;
1140 node
= m_tools
.GetFirst();
1143 tool
= (wxToolBarTool
*) node
->GetData();
1146 node
= node
->GetNext();
1150 // set tool position:
1151 // for the moment just perform a single row/column alignment
1152 wxSize cursize
= tool
->GetSize();
1153 if ( x
+ cursize
.x
> maxWidth
)
1154 maxWidth
= x
+ cursize
.x
;
1155 if ( y
+ cursize
.y
> maxHeight
)
1156 maxHeight
= y
+ cursize
.y
;
1158 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1160 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1161 tool
->SetPosition( wxPoint(x1
, y
) );
1165 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1166 tool
->SetPosition( wxPoint(x
, y1
) );
1169 // update the item positioning state
1170 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1171 y
+= cursize
.y
+ kwxMacToolSpacing
;
1173 x
+= cursize
.x
+ kwxMacToolSpacing
;
1175 #if wxMAC_USE_NATIVE_TOOLBAR
1176 // install in native HIToolbar
1179 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1180 if ( hiItemRef
!= NULL
)
1182 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1184 OSStatus err
= noErr
;
1189 // if this is the first tool that gets newly inserted or repositioned
1190 // first remove all 'old' tools from here to the right, because of this
1191 // all following tools will have to be reinserted (insertAll).
1192 for ( wxToolBarToolsList::compatibility_iterator node2
= m_tools
.GetLast();
1194 node2
= node2
->GetPrevious() )
1196 wxToolBarTool
*tool2
= (wxToolBarTool
*) node2
->GetData();
1198 const long idx
= tool2
->GetIndex();
1201 if ( tool2
->IsControl() )
1203 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1204 wxASSERT_MSG( count
== 3 || count
== 2 , wxT("Reference Count of native tool was illegal before removal") );
1205 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1207 err
= HIToolbarRemoveItemAtIndex(refTB
, idx
);
1210 wxLogDebug(wxT("HIToolbarRemoveItemAtIndex(%ld) failed [%ld]"),
1213 if ( tool2
->IsControl() )
1215 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1216 wxASSERT_MSG( count
== 2 , wxT("Reference Count of native tool was not 2 after removal") );
1217 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1220 tool2
->SetIndex(-1);
1225 err
= HIToolbarInsertItemAtIndex( refTB
, hiItemRef
, currentPosition
);
1228 wxLogDebug( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1231 tool
->SetIndex( currentPosition
);
1232 if ( tool
->IsControl() )
1234 CFIndex count
= CFGetRetainCount( tool
->GetControl()->GetPeer()->GetControlRef() ) ;
1235 wxASSERT_MSG( count
== 3 || count
== 2, wxT("Reference Count of native tool was illegal after insertion") );
1236 wxASSERT( IsValidControlHandle(tool
->GetControl()->GetPeer()->GetControlRef() )) ;
1245 // update radio button (and group) state
1246 lastIsRadio
= curIsRadio
;
1247 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1251 if ( tool
->IsToggled() )
1252 DoToggleTool( tool
, true );
1258 if ( tool
->Toggle( true ) )
1260 DoToggleTool( tool
, true );
1263 else if ( tool
->IsToggled() )
1265 if ( tool
->IsToggled() )
1266 DoToggleTool( tool
, true );
1268 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1271 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1272 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1275 if ( toggleTool
->Toggle( false ) )
1276 DoToggleTool( toggleTool
, false );
1278 nodePrev
= nodePrev
->GetPrevious();
1283 node
= node
->GetNext();
1286 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1288 // if not set yet, only one row
1289 if ( m_maxRows
<= 0 )
1292 m_minWidth
= maxWidth
;
1294 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1295 m_minHeight
= m_maxHeight
= maxHeight
;
1299 // if not set yet, have one column
1300 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1301 SetRows( GetToolsCount() );
1303 m_minHeight
= maxHeight
;
1305 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1306 m_minWidth
= m_maxWidth
= maxWidth
;
1310 // FIXME: should this be OSX-only?
1312 bool wantNativeToolbar
, ownToolbarInstalled
;
1314 // attempt to install the native toolbar
1315 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1316 MacInstallNativeToolbar( wantNativeToolbar
);
1317 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1318 if (!ownToolbarInstalled
)
1320 SetSize( maxWidth
, maxHeight
);
1321 InvalidateBestSize();
1325 SetSize( maxWidth
, maxHeight
);
1326 InvalidateBestSize();
1334 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1336 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1337 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1339 #if wxMAC_USE_NATIVE_TOOLBAR
1340 if (m_macHIToolbarRef
!= NULL
)
1342 int maxs
= wxMax( size
.x
, size
.y
);
1343 HIToolbarDisplaySize sizeSpec
;
1345 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1346 else if ( maxs
> 24 )
1347 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1349 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1351 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1356 // The button size is bigger than the bitmap size
1357 wxSize
wxToolBar::GetToolSize() const
1359 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1362 void wxToolBar::SetRows(int nRows
)
1364 // avoid resizing the frame uselessly
1365 if ( nRows
!= m_maxRows
)
1369 void wxToolBar::MacSuperChangedPosition()
1371 wxWindow::MacSuperChangedPosition();
1373 #if wxMAC_USE_NATIVE_TOOLBAR
1374 if (! m_macUsesNativeToolbar
)
1382 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1384 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1387 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1389 tool
->SetNormalBitmap(bitmap
);
1391 // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
1392 tool
->UpdateToggleImage( tool
->CanBeToggled() && tool
->IsToggled() );
1396 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1398 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1401 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1403 tool
->SetDisabledBitmap(bitmap
);
1405 // TODO: what to do for this one?
1409 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1411 wxToolBarTool
*tool
;
1412 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1415 tool
= (wxToolBarTool
*)node
->GetData();
1418 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1419 if ( r
.Contains( wxPoint( x
, y
) ) )
1423 node
= node
->GetNext();
1426 return (wxToolBarToolBase
*)NULL
;
1429 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1431 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1433 return tool
->GetShortHelp();
1435 return wxEmptyString
;
1438 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1441 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1444 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1446 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1447 if ( ( tool
!= NULL
) && tool
->IsButton() )
1448 tool
->UpdateToggleImage( toggle
);
1451 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1453 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1457 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1458 wxSize toolSize
= GetToolSize();
1459 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1460 ControlRef controlHandle
= NULL
;
1462 tool
->Attach( this );
1464 #if wxMAC_USE_NATIVE_TOOLBAR
1465 HIToolbarItemRef item
;
1468 switch (tool
->GetStyle())
1470 case wxTOOL_STYLE_SEPARATOR
:
1472 wxASSERT( tool
->GetControlHandle() == NULL
);
1475 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1476 toolrect
.bottom
= toolSize
.y
;
1478 toolrect
.right
= toolSize
.x
;
1480 // in flat style we need a visual separator
1481 #if wxMAC_USE_NATIVE_TOOLBAR
1482 if (m_macHIToolbarRef
!= NULL
)
1484 err
= HIToolbarItemCreate(
1485 kHIToolbarSeparatorIdentifier
,
1486 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1489 tool
->SetToolbarItemRef( item
);
1493 #endif // wxMAC_USE_NATIVE_TOOLBAR
1495 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1496 tool
->SetControlHandle( controlHandle
);
1500 case wxTOOL_STYLE_BUTTON
:
1502 wxASSERT( tool
->GetControlHandle() == NULL
);
1503 ControlButtonContentInfo info
;
1504 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1506 if ( UMAGetSystemVersion() >= 0x1000)
1508 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1512 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1513 if ( tool
->CanBeToggled() )
1514 behaviour
|= kControlBehaviorToggles
;
1515 err
= CreateBevelButtonControl( window
,
1516 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1517 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1520 #if wxMAC_USE_NATIVE_TOOLBAR
1521 if (m_macHIToolbarRef
!= NULL
)
1523 wxString labelStr
= wxString::Format(wxT("%xd"), (int)tool
);
1524 err
= HIToolbarItemCreate(
1525 wxMacCFStringHolder(labelStr
, wxFont::GetDefaultEncoding()),
1526 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1529 InstallEventHandler(
1530 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1531 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1533 HIToolbarItemSetIconRef( item
, info
.u
.iconRef
);
1534 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1535 tool
->SetToolbarItemRef( item
);
1540 #endif // wxMAC_USE_NATIVE_TOOLBAR
1542 wxMacReleaseBitmapButton( &info
);
1545 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1546 UMASetControlTitle( m_controlHandle
, label
, wxFont::GetDefaultEncoding() );
1549 InstallControlEventHandler(
1550 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1551 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1553 tool
->SetControlHandle( controlHandle
);
1557 case wxTOOL_STYLE_CONTROL
:
1559 #if wxMAC_USE_NATIVE_TOOLBAR
1560 if (m_macHIToolbarRef
!= NULL
)
1562 wxCHECK_MSG( tool
->GetControl(), false, _T("control must be non-NULL") );
1564 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
1565 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1566 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1571 tool
->SetToolbarItemRef( item
);
1581 // right now there's nothing to do here
1589 #if wxMAC_USE_NATIVE_TOOLBAR
1590 wxString label
= tool
->GetLabel();
1591 if (m_macHIToolbarRef
&& !label
.empty() )
1593 // strip mnemonics from the label for compatibility
1594 // with the usual labels in wxStaticText sense
1595 label
= wxStripMenuCodes(label
);
1597 HIToolbarItemSetLabel(item
,
1598 wxMacCFStringHolder(label
, m_font
.GetEncoding()));
1600 #endif // wxMAC_USE_NATIVE_TOOLBAR
1604 if ( controlHandle
)
1606 ControlRef container
= (ControlRef
) GetHandle();
1607 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1609 UMAShowControl( controlHandle
);
1610 ::EmbedControl( controlHandle
, container
);
1613 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1614 tool
->UpdateToggleImage( true );
1616 // nothing special to do here - we relayout in Realize() later
1617 InvalidateBestSize();
1621 wxFAIL_MSG( wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
) );
1624 return (err
== noErr
);
1627 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1629 wxFAIL_MSG( wxT("not implemented") );
1632 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1634 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1635 wxToolBarToolsList::compatibility_iterator node
;
1636 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1638 wxToolBarToolBase
*tool2
= node
->GetData();
1639 if ( tool2
== tool
)
1641 // let node point to the next node in the list
1642 node
= node
->GetNext();
1648 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1652 #if wxMAC_USE_NATIVE_TOOLBAR
1653 CFIndex removeIndex
= tool
->GetIndex();
1656 #if wxMAC_USE_NATIVE_TOOLBAR
1657 if (m_macHIToolbarRef
!= NULL
)
1659 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1661 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1662 tool
->SetIndex( -1 );
1666 switch ( tool
->GetStyle() )
1668 case wxTOOL_STYLE_CONTROL
:
1669 if ( tool
->GetControl() )
1670 tool
->GetControl()->Destroy();
1673 case wxTOOL_STYLE_BUTTON
:
1674 case wxTOOL_STYLE_SEPARATOR
:
1681 tool
->ClearControl();
1683 // and finally reposition all the controls after this one
1685 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1687 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1688 wxPoint pt
= tool2
->GetPosition();
1690 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1695 tool2
->SetPosition( pt
);
1697 #if wxMAC_USE_NATIVE_TOOLBAR
1698 if (m_macHIToolbarRef
!= NULL
)
1700 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1701 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1706 InvalidateBestSize();
1711 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1713 #if wxMAC_USE_NATIVE_TOOLBAR
1714 if ( m_macUsesNativeToolbar
)
1726 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1727 bool minimumUmaAvailable
= (UMAGetSystemVersion() >= 0x1030);
1729 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1730 if ( !drawMetalTheme
&& minimumUmaAvailable
)
1732 HIThemePlacardDrawInfo info
;
1733 memset( &info
, 0, sizeof(info
) );
1735 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1737 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1738 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1739 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1743 // leave the background as it is (striped or metal)
1748 const bool drawBorder
= true;
1752 wxMacPortSetter
helper( &dc
);
1754 if ( !drawMetalTheme
|| !minimumUmaAvailable
)
1756 Rect toolbarrect
= { dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1757 dc
.YLOG2DEVMAC(h
), dc
.XLOG2DEVMAC(w
) };
1760 if ( toolbarrect
.left
< 0 )
1761 toolbarrect
.left
= 0;
1762 if ( toolbarrect
.top
< 0 )
1763 toolbarrect
.top
= 0;
1766 UMADrawThemePlacard( &toolbarrect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
);
1770 #if TARGET_API_MAC_OSX
1771 HIRect hiToolbarrect
= CGRectMake(
1772 dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1773 dc
.YLOG2DEVREL(h
), dc
.XLOG2DEVREL(w
) );
1774 CGContextRef cgContext
;
1777 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
1778 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1780 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
1781 CGContextScaleCTM( cgContext
, 1, -1 );
1783 HIThemeBackgroundDrawInfo drawInfo
;
1784 drawInfo
.version
= 0;
1785 drawInfo
.state
= kThemeStateActive
;
1786 drawInfo
.kind
= kThemeBackgroundMetal
;
1787 HIThemeApplyBackground( &hiToolbarrect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
1790 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1800 #endif // wxUSE_TOOLBAR