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"
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;
36 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
38 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
39 EVT_PAINT( wxToolBar::OnPaint
)
44 #pragma mark Tool Implementation
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // We have a dual implementation for each tool, ControlRef and HIToolbarItemRef
53 // when embedding native controls in the native toolbar we must make sure the
54 // control does not get deleted behind our backs, so the retain count gets increased
55 // (after creation it is 1), first be the creation of the custom HIToolbarItem wrapper
56 // object, and second by the code 'creating' the custom HIView (which is the same as the
57 // already existing native control, therefore we just increase the ref count)
58 // when this view is removed from the native toolbar its count gets decremented again
59 // and when the HITooolbarItem wrapper object gets destroyed it is decremented as well
60 // so in the end the control lives with a refcount of one and can be disposed of by the
61 // wxControl code. For embedded controls on a non-native toolbar this ref count is less
62 // so we can only test against a range, not a specific value of the refcount.
64 class wxToolBarTool
: public wxToolBarToolBase
70 const wxString
& label
,
71 const wxBitmap
& bmpNormal
,
72 const wxBitmap
& bmpDisabled
,
75 const wxString
& shortHelp
,
76 const wxString
& longHelp
);
78 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
, const wxString
& label
)
79 : wxToolBarToolBase(tbar
, control
, label
)
83 SetControlHandle( (ControlRef
) control
->GetHandle() );
86 virtual ~wxToolBarTool()
91 WXWidget
GetControlHandle()
93 return (WXWidget
) m_controlHandle
;
96 void SetControlHandle( ControlRef handle
)
98 m_controlHandle
= handle
;
101 void SetPosition( const wxPoint
& position
);
105 if ( m_controlHandle
)
108 DisposeControl( m_controlHandle
);
111 // the embedded control is not under the responsibility of the tool, it gets disposed of in the
112 // proper wxControl destructor
114 m_controlHandle
= NULL
;
118 #if wxMAC_USE_NATIVE_TOOLBAR
119 if ( m_toolbarItemRef
)
121 CFIndex count
= CFGetRetainCount( m_toolbarItemRef
) ;
122 // different behaviour under Leopard
123 if ( UMAGetSystemVersion() < 0x1050 )
127 wxFAIL_MSG("Reference count of native tool was not 1 in wxToolBarTool destructor");
130 wxTheApp
->MacAddToAutorelease(m_toolbarItemRef
);
131 CFRelease(m_toolbarItemRef
);
132 m_toolbarItemRef
= NULL
;
134 #endif // wxMAC_USE_NATIVE_TOOLBAR
137 wxSize
GetSize() const
143 curSize
= GetControl()->GetSize();
145 else if ( IsButton() )
147 curSize
= GetToolBar()->GetToolSize();
152 curSize
= GetToolBar()->GetToolSize();
153 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
162 wxPoint
GetPosition() const
164 return wxPoint( m_x
, m_y
);
167 bool DoEnable( bool enable
);
169 void UpdateToggleImage( bool toggle
);
171 #if wxMAC_USE_NATIVE_TOOLBAR
172 void SetToolbarItemRef( HIToolbarItemRef ref
)
174 if ( m_controlHandle
)
175 HideControl( m_controlHandle
);
176 if ( m_toolbarItemRef
)
177 CFRelease( m_toolbarItemRef
);
179 m_toolbarItemRef
= ref
;
180 if ( m_toolbarItemRef
)
185 f
= GetToolBar()->GetFont();
187 enc
= f
.GetEncoding();
189 enc
= wxFont::GetDefaultEncoding();
191 HIToolbarItemSetHelpText(
193 wxCFStringRef( GetShortHelp(), enc
),
194 wxCFStringRef( GetLongHelp(), enc
) );
198 HIToolbarItemRef
GetToolbarItemRef() const
200 return m_toolbarItemRef
;
203 void SetIndex( CFIndex idx
)
208 CFIndex
GetIndex() const
217 m_controlHandle
= NULL
;
219 #if wxMAC_USE_NATIVE_TOOLBAR
220 m_toolbarItemRef
= NULL
;
225 ControlRef m_controlHandle
;
229 #if wxMAC_USE_NATIVE_TOOLBAR
230 HIToolbarItemRef m_toolbarItemRef
;
231 // position in its toolbar, -1 means not inserted
236 static const EventTypeSpec eventList
[] =
238 { kEventClassControl
, kEventControlHit
},
239 { kEventClassControl
, kEventControlHitTest
},
242 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
244 OSStatus result
= eventNotHandledErr
;
245 ControlRef controlRef
;
246 wxMacCarbonEvent
cEvent( event
);
248 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
250 switch ( GetEventKind( event
) )
252 case kEventControlHit
:
254 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
255 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
256 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
260 shouldToggle
= !tbartool
->IsToggled();
262 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
265 if (tbartool
!= NULL
)
266 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
271 case kEventControlHitTest
:
273 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
275 HIViewGetBounds( controlRef
, &rect
);
277 ControlPartCode pc
= kControlNoPart
;
278 if ( CGRectContainsPoint( rect
, pt
) )
279 pc
= kControlIconPart
;
280 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
292 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
294 OSStatus result
= eventNotHandledErr
;
296 switch ( GetEventClass( event
) )
298 case kEventClassControl
:
299 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
309 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
311 #if wxMAC_USE_NATIVE_TOOLBAR
313 static const EventTypeSpec toolBarEventList
[] =
315 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
318 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
320 OSStatus result
= eventNotHandledErr
;
322 switch ( GetEventKind( event
) )
324 case kEventToolbarItemPerformAction
:
326 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
327 if ( tbartool
!= NULL
)
329 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
330 int toolID
= tbartool
->GetId();
332 if ( tbartool
->CanBeToggled() )
335 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
339 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
352 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
354 OSStatus result
= eventNotHandledErr
;
356 switch ( GetEventClass( event
) )
358 case kEventClassToolbarItem
:
359 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
369 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
373 bool wxToolBarTool::DoEnable( bool enable
)
377 GetControl()->Enable( enable
);
379 else if ( IsButton() )
381 #if wxMAC_USE_NATIVE_TOOLBAR
382 if ( m_toolbarItemRef
!= NULL
)
383 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
386 if ( m_controlHandle
!= NULL
)
389 EnableControl( m_controlHandle
);
391 DisableControl( m_controlHandle
);
398 void wxToolBarTool::SetPosition( const wxPoint
& position
)
403 int mac_x
= position
.x
;
404 int mac_y
= position
.y
;
409 GetControlBounds( m_controlHandle
, &contrlRect
);
410 int former_mac_x
= contrlRect
.left
;
411 int former_mac_y
= contrlRect
.top
;
412 GetToolBar()->GetToolSize();
414 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
416 ::MoveControl( m_controlHandle
, mac_x
, mac_y
);
419 else if ( IsControl() )
421 // embedded native controls are moved by the OS
422 #if wxMAC_USE_NATIVE_TOOLBAR
423 if ( ((wxToolBar
*)GetToolBar())->MacWantsNativeToolbar() == false )
426 GetControl()->Move( position
);
433 GetControlBounds( m_controlHandle
, &contrlRect
);
434 int former_mac_x
= contrlRect
.left
;
435 int former_mac_y
= contrlRect
.top
;
437 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
438 ::MoveControl( m_controlHandle
, mac_x
, mac_y
);
442 void wxToolBarTool::UpdateToggleImage( bool toggle
)
446 int w
= m_bmpNormal
.GetWidth();
447 int h
= m_bmpNormal
.GetHeight();
448 wxBitmap
bmp( w
, h
);
451 dc
.SelectObject( bmp
);
452 dc
.SetPen( wxPen(*wxBLACK
) );
453 dc
.SetBrush( wxBrush( *wxLIGHT_GREY
));
454 dc
.DrawRectangle( 0, 0, w
, h
);
455 dc
.DrawBitmap( m_bmpNormal
, 0, 0, true );
456 dc
.SelectObject( wxNullBitmap
);
457 ControlButtonContentInfo info
;
458 wxMacCreateBitmapButton( &info
, bmp
);
459 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
460 #if wxMAC_USE_NATIVE_TOOLBAR
461 if (m_toolbarItemRef
!= NULL
)
463 ControlButtonContentInfo info2
;
464 wxMacCreateBitmapButton( &info2
, bmp
, kControlContentCGImageRef
);
465 HIToolbarItemSetImage( m_toolbarItemRef
, info2
.u
.imageRef
);
466 wxMacReleaseBitmapButton( &info2
);
469 wxMacReleaseBitmapButton( &info
);
473 ControlButtonContentInfo info
;
474 wxMacCreateBitmapButton( &info
, m_bmpNormal
);
475 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
476 #if wxMAC_USE_NATIVE_TOOLBAR
477 if (m_toolbarItemRef
!= NULL
)
479 ControlButtonContentInfo info2
;
480 wxMacCreateBitmapButton( &info2
, m_bmpNormal
, kControlContentCGImageRef
);
481 HIToolbarItemSetImage( m_toolbarItemRef
, info2
.u
.imageRef
);
482 wxMacReleaseBitmapButton( &info2
);
485 wxMacReleaseBitmapButton( &info
);
488 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
490 m_controlHandle
, 0, kControlIconTransformTag
,
491 sizeof(transform
), (Ptr
)&transform
);
492 HIViewSetNeedsDisplay( m_controlHandle
, true );
496 wxToolBarTool::wxToolBarTool(
499 const wxString
& label
,
500 const wxBitmap
& bmpNormal
,
501 const wxBitmap
& bmpDisabled
,
503 wxObject
*clientData
,
504 const wxString
& shortHelp
,
505 const wxString
& longHelp
)
508 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
509 clientData
, shortHelp
, longHelp
)
515 #pragma mark Toolbar Implementation
517 wxToolBarToolBase
*wxToolBar::CreateTool(
519 const wxString
& label
,
520 const wxBitmap
& bmpNormal
,
521 const wxBitmap
& bmpDisabled
,
523 wxObject
*clientData
,
524 const wxString
& shortHelp
,
525 const wxString
& longHelp
)
527 return new wxToolBarTool(
528 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
529 clientData
, shortHelp
, longHelp
);
533 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
535 return new wxToolBarTool(this, control
, label
);
538 void wxToolBar::Init()
542 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
543 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
545 #if wxMAC_USE_NATIVE_TOOLBAR
546 m_macHIToolbarRef
= NULL
;
547 m_macUsesNativeToolbar
= false;
551 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
553 const EventTypeSpec kEvents
[] =
555 { kEventClassHIObject
, kEventHIObjectConstruct
},
556 { kEventClassHIObject
, kEventHIObjectInitialize
},
557 { kEventClassHIObject
, kEventHIObjectDestruct
},
559 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
562 const EventTypeSpec kViewEvents
[] =
564 { kEventClassControl
, kEventControlGetSizeConstraints
}
567 struct ControlToolbarItem
569 HIToolbarItemRef toolbarItem
;
571 wxSize lastValidSize
;
574 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
576 OSStatus result
= eventNotHandledErr
;
577 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
579 switch ( GetEventClass( inEvent
) )
581 case kEventClassHIObject
:
582 switch ( GetEventKind( inEvent
) )
584 case kEventHIObjectConstruct
:
586 HIObjectRef toolbarItem
;
587 ControlToolbarItem
* item
;
589 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
590 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
592 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
593 item
->toolbarItem
= toolbarItem
;
594 item
->lastValidSize
= wxSize(-1,-1);
595 item
->viewRef
= NULL
;
597 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
603 case kEventHIObjectInitialize
:
604 result
= CallNextEventHandler( inCallRef
, inEvent
);
605 if ( result
== noErr
)
608 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
609 sizeof( CFTypeRef
), NULL
, &data
);
613 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
614 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
616 object
->viewRef
= (HIViewRef
) viewRef
;
617 // make sure we keep that control during our lifetime
618 CFRetain( object
->viewRef
) ;
620 verify_noerr(InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
621 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
));
626 case kEventHIObjectDestruct
:
628 HIViewRef viewRef
= object
->viewRef
;
629 if( viewRef
&& IsValidControlHandle( viewRef
) )
631 // depending whether the wxControl corresponding to this HIView has already been destroyed or
632 // not, ref counts differ, so we cannot assert a special value
633 CFIndex count
= CFGetRetainCount( viewRef
) ;
636 wxFAIL_MSG("Reference count of native tool was illegal before removal");
638 CFRelease( viewRef
) ;
648 case kEventClassToolbarItem
:
649 switch ( GetEventKind( inEvent
) )
651 case kEventToolbarItemCreateCustomView
:
653 HIViewRef viewRef
= object
->viewRef
;
654 HIViewRemoveFromSuperview( viewRef
) ;
655 HIViewSetVisible(viewRef
, true) ;
656 CFRetain( viewRef
) ;
657 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
663 case kEventClassControl
:
664 switch ( GetEventKind( inEvent
) )
666 case kEventControlGetSizeConstraints
:
668 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
671 // during toolbar layout the native window sometimes gets negative sizes,
672 // sometimes it just gets shrunk behind our back, so in order to avoid
673 // ever shrinking more, once a valid size is captured, we keep it
675 wxSize sz
= object
->lastValidSize
;
676 if ( sz
.x
<= 0 || sz
.y
<= 0 )
678 sz
= wxwindow
->GetSize() ;
679 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
680 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
681 if ( sz
.x
> 0 && sz
.y
> 0 )
682 object
->lastValidSize
= sz
;
687 // Extra width to avoid edge of combobox being cut off
691 min
.width
= max
.width
= sz
.x
;
692 min
.height
= max
.height
= sz
.y
;
694 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
695 sizeof( HISize
), &min
);
697 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
698 sizeof( HISize
), &max
);
710 void RegisterControlToolbarItemClass()
712 static bool sRegistered
;
716 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
717 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
723 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
725 RegisterControlToolbarItemClass();
729 UInt32 options
= kHIToolbarItemAllowDuplicates
;
730 HIToolbarItemRef result
= NULL
;
732 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
733 require_noerr( err
, CantCreateEvent
);
735 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
736 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
739 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
741 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
744 ReleaseEvent( event
);
749 #if wxMAC_USE_NATIVE_TOOLBAR
750 static const EventTypeSpec kToolbarEvents
[] =
752 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
753 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
754 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
757 static OSStatus
ToolbarDelegateHandler(EventHandlerCallRef
WXUNUSED(inCallRef
),
759 void* WXUNUSED(inUserData
))
761 OSStatus result
= eventNotHandledErr
;
763 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
764 CFMutableArrayRef array
;
766 switch ( GetEventKind( inEvent
) )
768 case kEventToolbarGetDefaultIdentifiers
:
770 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
771 sizeof( CFMutableArrayRef
), NULL
, &array
);
772 // not implemented yet
773 // GetToolbarDefaultItems( array );
778 case kEventToolbarGetAllowedIdentifiers
:
780 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
781 sizeof( CFMutableArrayRef
), NULL
, &array
);
782 // not implemented yet
783 // GetToolbarAllowedItems( array );
787 case kEventToolbarCreateItemWithIdentifier
:
789 HIToolbarItemRef item
= NULL
;
790 CFTypeRef data
= NULL
;
791 CFStringRef identifier
= NULL
;
793 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
794 sizeof( CFStringRef
), NULL
, &identifier
);
796 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
797 sizeof( CFTypeRef
), NULL
, &data
);
799 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
801 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
804 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
805 sizeof( HIToolbarItemRef
), &item
);
815 #endif // wxMAC_USE_NATIVE_TOOLBAR
817 // also for the toolbar we have the dual implementation:
818 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
820 bool wxToolBar::Create(
826 const wxString
& name
)
828 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
833 OSStatus err
= noErr
;
835 #if wxMAC_USE_NATIVE_TOOLBAR
836 if (parent
->IsKindOf(CLASSINFO(wxFrame
)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1)
838 wxString labelStr
= wxString::Format( wxT("%p"), this );
839 err
= HIToolbarCreate(
840 wxCFStringRef( labelStr
, wxFont::GetDefaultEncoding() ), 0,
841 (HIToolbarRef
*) &m_macHIToolbarRef
);
843 if (m_macHIToolbarRef
!= NULL
)
845 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
846 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
848 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
849 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
851 if ( style
& wxTB_NOICONS
)
852 mode
= kHIToolbarDisplayModeLabelOnly
;
853 else if ( style
& wxTB_TEXT
)
854 mode
= kHIToolbarDisplayModeIconAndLabel
;
856 mode
= kHIToolbarDisplayModeIconOnly
;
858 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
859 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 // Leopard seems to have one refcount more, so we cannot check reliably at the moment
878 if ( UMAGetSystemVersion() < 0x1050 )
882 wxFAIL_MSG("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 if ( count
!= 3 && count
!= 2 )
1197 wxFAIL_MSG("Reference count of native tool was illegal before removal");
1200 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1202 err
= HIToolbarRemoveItemAtIndex(refTB
, idx
);
1205 wxLogDebug(wxT("HIToolbarRemoveItemAtIndex(%ld) failed [%ld]"),
1208 if ( tool2
->IsControl() )
1210 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1213 wxFAIL_MSG("Reference count of native tool was not 2 after removal");
1216 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1219 tool2
->SetIndex(-1);
1224 err
= HIToolbarInsertItemAtIndex( refTB
, hiItemRef
, currentPosition
);
1227 wxLogDebug( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1230 tool
->SetIndex( currentPosition
);
1231 if ( tool
->IsControl() )
1233 CFIndex count
= CFGetRetainCount( tool
->GetControl()->GetPeer()->GetControlRef() ) ;
1234 if ( count
!= 3 && count
!= 2 )
1236 wxFAIL_MSG("Reference count of native tool was illegal before removal");
1238 wxASSERT( IsValidControlHandle(tool
->GetControl()->GetPeer()->GetControlRef() )) ;
1247 // update radio button (and group) state
1248 lastIsRadio
= curIsRadio
;
1249 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1253 if ( tool
->IsToggled() )
1254 DoToggleTool( tool
, true );
1260 if ( tool
->Toggle( true ) )
1262 DoToggleTool( tool
, true );
1265 else if ( tool
->IsToggled() )
1267 if ( tool
->IsToggled() )
1268 DoToggleTool( tool
, true );
1270 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1273 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1274 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1277 if ( toggleTool
->Toggle( false ) )
1278 DoToggleTool( toggleTool
, false );
1280 nodePrev
= nodePrev
->GetPrevious();
1285 node
= node
->GetNext();
1288 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1290 // if not set yet, only one row
1291 if ( m_maxRows
<= 0 )
1294 m_minWidth
= maxWidth
;
1296 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1297 m_minHeight
= m_maxHeight
= maxHeight
;
1301 // if not set yet, have one column
1302 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1303 SetRows( GetToolsCount() );
1305 m_minHeight
= maxHeight
;
1307 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1308 m_minWidth
= m_maxWidth
= maxWidth
;
1312 // FIXME: should this be OSX-only?
1314 bool wantNativeToolbar
, ownToolbarInstalled
;
1316 // attempt to install the native toolbar
1317 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1318 MacInstallNativeToolbar( wantNativeToolbar
);
1319 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1320 if (!ownToolbarInstalled
)
1322 SetSize( maxWidth
, maxHeight
);
1323 InvalidateBestSize();
1327 SetSize( maxWidth
, maxHeight
);
1328 InvalidateBestSize();
1336 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1338 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1339 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1341 #if wxMAC_USE_NATIVE_TOOLBAR
1342 if (m_macHIToolbarRef
!= NULL
)
1344 int maxs
= wxMax( size
.x
, size
.y
);
1345 HIToolbarDisplaySize sizeSpec
;
1347 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1348 else if ( maxs
> 24 )
1349 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1351 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1353 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1358 // The button size is bigger than the bitmap size
1359 wxSize
wxToolBar::GetToolSize() const
1361 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1364 void wxToolBar::SetRows(int nRows
)
1366 // avoid resizing the frame uselessly
1367 if ( nRows
!= m_maxRows
)
1371 void wxToolBar::MacSuperChangedPosition()
1373 wxWindow::MacSuperChangedPosition();
1375 #if wxMAC_USE_NATIVE_TOOLBAR
1376 if (! m_macUsesNativeToolbar
)
1384 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1386 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1389 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1391 tool
->SetNormalBitmap(bitmap
);
1393 // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
1394 tool
->UpdateToggleImage( tool
->CanBeToggled() && tool
->IsToggled() );
1398 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1400 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1403 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1405 tool
->SetDisabledBitmap(bitmap
);
1407 // TODO: what to do for this one?
1411 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1413 wxToolBarTool
*tool
;
1414 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1417 tool
= (wxToolBarTool
*)node
->GetData();
1420 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1421 if ( r
.Contains( wxPoint( x
, y
) ) )
1425 node
= node
->GetNext();
1428 return (wxToolBarToolBase
*)NULL
;
1431 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1433 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1435 return tool
->GetShortHelp();
1437 return wxEmptyString
;
1440 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1443 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1446 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1448 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1449 if ( ( tool
!= NULL
) && tool
->IsButton() )
1450 tool
->UpdateToggleImage( toggle
);
1453 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1455 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1459 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1460 wxSize toolSize
= GetToolSize();
1461 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1462 ControlRef controlHandle
= NULL
;
1464 tool
->Attach( this );
1466 #if wxMAC_USE_NATIVE_TOOLBAR
1467 wxString label
= tool
->GetLabel();
1468 if (m_macHIToolbarRef
&& !label
.empty() )
1470 // strip mnemonics from the label for compatibility
1471 // with the usual labels in wxStaticText sense
1472 label
= wxStripMenuCodes(label
);
1474 #endif // wxMAC_USE_NATIVE_TOOLBAR
1476 switch (tool
->GetStyle())
1478 case wxTOOL_STYLE_SEPARATOR
:
1480 wxASSERT( tool
->GetControlHandle() == NULL
);
1483 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1484 toolrect
.bottom
= toolSize
.y
;
1486 toolrect
.right
= toolSize
.x
;
1488 // in flat style we need a visual separator
1489 #if wxMAC_USE_NATIVE_TOOLBAR
1490 if (m_macHIToolbarRef
!= NULL
)
1492 HIToolbarItemRef item
;
1493 err
= HIToolbarItemCreate(
1494 kHIToolbarSeparatorIdentifier
,
1495 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1498 tool
->SetToolbarItemRef( item
);
1502 #endif // wxMAC_USE_NATIVE_TOOLBAR
1504 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1505 tool
->SetControlHandle( controlHandle
);
1509 case wxTOOL_STYLE_BUTTON
:
1511 wxASSERT( tool
->GetControlHandle() == NULL
);
1512 ControlButtonContentInfo info
;
1513 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap() );
1515 if ( UMAGetSystemVersion() >= 0x1000)
1517 // contrary to the docs this control only works with iconrefs
1518 ControlButtonContentInfo info
;
1519 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1520 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1521 wxMacReleaseBitmapButton( &info
);
1525 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1526 if ( tool
->CanBeToggled() )
1527 behaviour
|= kControlBehaviorToggles
;
1528 err
= CreateBevelButtonControl( window
,
1529 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1530 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1533 #if wxMAC_USE_NATIVE_TOOLBAR
1534 if (m_macHIToolbarRef
!= NULL
)
1536 HIToolbarItemRef item
;
1537 wxString labelStr
= wxString::Format(wxT("%p"), tool
);
1538 err
= HIToolbarItemCreate(
1539 wxCFStringRef(labelStr
, wxFont::GetDefaultEncoding()),
1540 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1543 ControlButtonContentInfo info2
;
1544 wxMacCreateBitmapButton( &info2
, tool
->GetNormalBitmap(), kControlContentCGImageRef
);
1546 InstallEventHandler(
1547 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1548 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1549 HIToolbarItemSetLabel( item
, wxCFStringRef(label
, GetFont().GetEncoding()) );
1550 HIToolbarItemSetImage( item
, info2
.u
.imageRef
);
1551 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1552 tool
->SetToolbarItemRef( item
);
1554 wxMacReleaseBitmapButton( &info2
);
1559 #endif // wxMAC_USE_NATIVE_TOOLBAR
1561 wxMacReleaseBitmapButton( &info
);
1564 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1565 SetControlTitleWithCFString( m_controlHandle
, wxCFStringRef( label
, wxFont::GetDefaultEncoding() );
1568 InstallControlEventHandler(
1569 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1570 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1572 tool
->SetControlHandle( controlHandle
);
1576 case wxTOOL_STYLE_CONTROL
:
1578 #if wxMAC_USE_NATIVE_TOOLBAR
1579 if (m_macHIToolbarRef
!= NULL
)
1581 wxCHECK_MSG( tool
->GetControl(), false, _T("control must be non-NULL") );
1582 HIToolbarItemRef item
;
1583 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
1584 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1585 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1590 tool
->SetToolbarItemRef( item
);
1600 // right now there's nothing to do here
1610 if ( controlHandle
)
1612 ControlRef container
= (ControlRef
) GetHandle();
1613 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1615 SetControlVisibility( controlHandle
, true, true );
1616 ::EmbedControl( controlHandle
, container
);
1619 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1620 tool
->UpdateToggleImage( true );
1622 // nothing special to do here - we relayout in Realize() later
1623 InvalidateBestSize();
1627 wxFAIL_MSG( wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
) );
1630 return (err
== noErr
);
1633 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1635 wxFAIL_MSG( wxT("not implemented") );
1638 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1640 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1641 wxToolBarToolsList::compatibility_iterator node
;
1642 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1644 wxToolBarToolBase
*tool2
= node
->GetData();
1645 if ( tool2
== tool
)
1647 // let node point to the next node in the list
1648 node
= node
->GetNext();
1654 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1658 #if wxMAC_USE_NATIVE_TOOLBAR
1659 CFIndex removeIndex
= tool
->GetIndex();
1662 #if wxMAC_USE_NATIVE_TOOLBAR
1663 if (m_macHIToolbarRef
!= NULL
)
1665 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1667 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1668 tool
->SetIndex( -1 );
1672 switch ( tool
->GetStyle() )
1674 case wxTOOL_STYLE_CONTROL
:
1675 if ( tool
->GetControl() )
1676 tool
->GetControl()->Destroy();
1679 case wxTOOL_STYLE_BUTTON
:
1680 case wxTOOL_STYLE_SEPARATOR
:
1687 tool
->ClearControl();
1689 // and finally reposition all the controls after this one
1691 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1693 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1694 wxPoint pt
= tool2
->GetPosition();
1696 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1701 tool2
->SetPosition( pt
);
1703 #if wxMAC_USE_NATIVE_TOOLBAR
1704 if (m_macHIToolbarRef
!= NULL
)
1706 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1707 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1712 InvalidateBestSize();
1717 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1719 #if wxMAC_USE_NATIVE_TOOLBAR
1720 if ( m_macUsesNativeToolbar
)
1732 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1734 if ( !drawMetalTheme
)
1736 HIThemePlacardDrawInfo info
;
1737 memset( &info
, 0, sizeof(info
) );
1739 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1741 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1742 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1743 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1747 // leave the background as it is (striped or metal)
1753 #endif // wxUSE_TOOLBAR