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 will be disposed of in the
112 // proper wxControl destructor
113 wxASSERT( IsValidControlHandle(GetControl()->GetPeer()->GetControlRef() )) ;
115 m_controlHandle
= NULL
;
119 #if wxMAC_USE_NATIVE_TOOLBAR
120 if ( m_toolbarItemRef
)
122 CFIndex count
= CFGetRetainCount( m_toolbarItemRef
) ;
123 // different behaviour under Leopard
124 if ( UMAGetSystemVersion() < 0x1050 )
126 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
128 wxTheApp
->MacAddToAutorelease(m_toolbarItemRef
);
129 CFRelease(m_toolbarItemRef
);
130 m_toolbarItemRef
= NULL
;
135 wxSize
GetSize() const
141 curSize
= GetControl()->GetSize();
143 else if ( IsButton() )
145 curSize
= GetToolBar()->GetToolSize();
150 curSize
= GetToolBar()->GetToolSize();
151 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
160 wxPoint
GetPosition() const
162 return wxPoint( m_x
, m_y
);
165 bool DoEnable( bool enable
);
167 void UpdateToggleImage( bool toggle
);
169 #if wxMAC_USE_NATIVE_TOOLBAR
170 void SetToolbarItemRef( HIToolbarItemRef ref
)
172 if ( m_controlHandle
)
173 HideControl( m_controlHandle
);
174 if ( m_toolbarItemRef
)
175 CFRelease( m_toolbarItemRef
);
177 m_toolbarItemRef
= ref
;
178 if ( m_toolbarItemRef
)
183 f
= GetToolBar()->GetFont();
185 enc
= f
.GetEncoding();
187 enc
= wxFont::GetDefaultEncoding();
189 HIToolbarItemSetHelpText(
191 wxMacCFStringHolder( GetShortHelp(), enc
),
192 wxMacCFStringHolder( GetLongHelp(), enc
) );
196 HIToolbarItemRef
GetToolbarItemRef() const
198 return m_toolbarItemRef
;
201 void SetIndex( CFIndex idx
)
206 CFIndex
GetIndex() const
215 m_controlHandle
= NULL
;
217 #if wxMAC_USE_NATIVE_TOOLBAR
218 m_toolbarItemRef
= NULL
;
223 ControlRef m_controlHandle
;
227 #if wxMAC_USE_NATIVE_TOOLBAR
228 HIToolbarItemRef m_toolbarItemRef
;
229 // position in its toolbar, -1 means not inserted
234 static const EventTypeSpec eventList
[] =
236 { kEventClassControl
, kEventControlHit
},
237 { kEventClassControl
, kEventControlHitTest
},
240 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
242 OSStatus result
= eventNotHandledErr
;
243 ControlRef controlRef
;
244 wxMacCarbonEvent
cEvent( event
);
246 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
248 switch ( GetEventKind( event
) )
250 case kEventControlHit
:
252 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
253 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
254 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
258 shouldToggle
= !tbartool
->IsToggled();
260 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
263 if (tbartool
!= NULL
)
264 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
269 case kEventControlHitTest
:
271 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
273 HIViewGetBounds( controlRef
, &rect
);
275 ControlPartCode pc
= kControlNoPart
;
276 if ( CGRectContainsPoint( rect
, pt
) )
277 pc
= kControlIconPart
;
278 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
290 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
292 OSStatus result
= eventNotHandledErr
;
294 switch ( GetEventClass( event
) )
296 case kEventClassControl
:
297 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
307 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
309 #if wxMAC_USE_NATIVE_TOOLBAR
311 static const EventTypeSpec toolBarEventList
[] =
313 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
316 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
318 OSStatus result
= eventNotHandledErr
;
320 switch ( GetEventKind( event
) )
322 case kEventToolbarItemPerformAction
:
324 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
325 if ( tbartool
!= NULL
)
327 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
328 int toolID
= tbartool
->GetId();
330 if ( tbartool
->CanBeToggled() )
333 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
337 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
350 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
352 OSStatus result
= eventNotHandledErr
;
354 switch ( GetEventClass( event
) )
356 case kEventClassToolbarItem
:
357 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
367 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
371 bool wxToolBarTool::DoEnable( bool enable
)
375 GetControl()->Enable( enable
);
377 else if ( IsButton() )
379 #if wxMAC_USE_NATIVE_TOOLBAR
380 if ( m_toolbarItemRef
!= NULL
)
381 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
384 if ( m_controlHandle
!= NULL
)
387 EnableControl( m_controlHandle
);
389 DisableControl( m_controlHandle
);
396 void wxToolBarTool::SetPosition( const wxPoint
& position
)
401 int mac_x
= position
.x
;
402 int mac_y
= position
.y
;
407 GetControlBounds( m_controlHandle
, &contrlRect
);
408 int former_mac_x
= contrlRect
.left
;
409 int former_mac_y
= contrlRect
.top
;
410 GetToolBar()->GetToolSize();
412 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
414 ::MoveControl( m_controlHandle
, mac_x
, mac_y
);
417 else if ( IsControl() )
419 // embedded native controls are moved by the OS
420 #if wxMAC_USE_NATIVE_TOOLBAR
421 if ( ((wxToolBar
*)GetToolBar())->MacWantsNativeToolbar() == false )
424 GetControl()->Move( position
);
431 GetControlBounds( m_controlHandle
, &contrlRect
);
432 int former_mac_x
= contrlRect
.left
;
433 int former_mac_y
= contrlRect
.top
;
435 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
436 ::MoveControl( m_controlHandle
, mac_x
, mac_y
);
440 void wxToolBarTool::UpdateToggleImage( bool toggle
)
444 int w
= m_bmpNormal
.GetWidth();
445 int h
= m_bmpNormal
.GetHeight();
446 wxBitmap
bmp( w
, h
);
449 dc
.SelectObject( bmp
);
450 dc
.SetPen( wxPen(*wxBLACK
) );
451 dc
.SetBrush( wxBrush( *wxLIGHT_GREY
));
452 dc
.DrawRectangle( 0, 0, w
, h
);
453 dc
.DrawBitmap( m_bmpNormal
, 0, 0, true );
454 dc
.SelectObject( wxNullBitmap
);
455 ControlButtonContentInfo info
;
456 wxMacCreateBitmapButton( &info
, bmp
);
457 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
458 #if wxMAC_USE_NATIVE_TOOLBAR
459 if (m_toolbarItemRef
!= NULL
)
461 ControlButtonContentInfo info2
;
462 wxMacCreateBitmapButton( &info2
, bmp
, kControlContentCGImageRef
);
463 HIToolbarItemSetImage( m_toolbarItemRef
, info2
.u
.imageRef
);
464 wxMacReleaseBitmapButton( &info2
);
467 wxMacReleaseBitmapButton( &info
);
471 ControlButtonContentInfo info
;
472 wxMacCreateBitmapButton( &info
, m_bmpNormal
);
473 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
474 #if wxMAC_USE_NATIVE_TOOLBAR
475 if (m_toolbarItemRef
!= NULL
)
477 ControlButtonContentInfo info2
;
478 wxMacCreateBitmapButton( &info2
, m_bmpNormal
, kControlContentCGImageRef
);
479 HIToolbarItemSetImage( m_toolbarItemRef
, info2
.u
.imageRef
);
480 wxMacReleaseBitmapButton( &info2
);
483 wxMacReleaseBitmapButton( &info
);
486 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
488 m_controlHandle
, 0, kControlIconTransformTag
,
489 sizeof(transform
), (Ptr
)&transform
);
490 HIViewSetNeedsDisplay( m_controlHandle
, true );
494 wxToolBarTool::wxToolBarTool(
497 const wxString
& label
,
498 const wxBitmap
& bmpNormal
,
499 const wxBitmap
& bmpDisabled
,
501 wxObject
*clientData
,
502 const wxString
& shortHelp
,
503 const wxString
& longHelp
)
506 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
507 clientData
, shortHelp
, longHelp
)
513 #pragma mark Toolbar Implementation
515 wxToolBarToolBase
*wxToolBar::CreateTool(
517 const wxString
& label
,
518 const wxBitmap
& bmpNormal
,
519 const wxBitmap
& bmpDisabled
,
521 wxObject
*clientData
,
522 const wxString
& shortHelp
,
523 const wxString
& longHelp
)
525 return new wxToolBarTool(
526 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
527 clientData
, shortHelp
, longHelp
);
531 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
533 return new wxToolBarTool(this, control
, label
);
536 void wxToolBar::Init()
540 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
541 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
543 #if wxMAC_USE_NATIVE_TOOLBAR
544 m_macHIToolbarRef
= NULL
;
545 m_macUsesNativeToolbar
= false;
549 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
551 const EventTypeSpec kEvents
[] =
553 { kEventClassHIObject
, kEventHIObjectConstruct
},
554 { kEventClassHIObject
, kEventHIObjectInitialize
},
555 { kEventClassHIObject
, kEventHIObjectDestruct
},
557 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
560 const EventTypeSpec kViewEvents
[] =
562 { kEventClassControl
, kEventControlGetSizeConstraints
}
565 struct ControlToolbarItem
567 HIToolbarItemRef toolbarItem
;
569 wxSize lastValidSize
;
572 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
574 OSStatus result
= eventNotHandledErr
;
575 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
577 switch ( GetEventClass( inEvent
) )
579 case kEventClassHIObject
:
580 switch ( GetEventKind( inEvent
) )
582 case kEventHIObjectConstruct
:
584 HIObjectRef toolbarItem
;
585 ControlToolbarItem
* item
;
587 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
588 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
590 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
591 item
->toolbarItem
= toolbarItem
;
592 item
->lastValidSize
= wxSize(-1,-1);
593 item
->viewRef
= NULL
;
595 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
601 case kEventHIObjectInitialize
:
602 result
= CallNextEventHandler( inCallRef
, inEvent
);
603 if ( result
== noErr
)
606 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
607 sizeof( CFTypeRef
), NULL
, &data
);
611 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
612 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
614 object
->viewRef
= (HIViewRef
) viewRef
;
615 // make sure we keep that control during our lifetime
616 CFRetain( object
->viewRef
) ;
618 verify_noerr(InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
619 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
));
624 case kEventHIObjectDestruct
:
626 HIViewRef viewRef
= object
->viewRef
;
627 if( viewRef
&& IsValidControlHandle( viewRef
) )
629 // depending whether the wxControl corresponding to this HIView has already been destroyed or
630 // not, ref counts differ, so we cannot assert a special value
631 CFIndex count
= CFGetRetainCount( viewRef
) ;
632 wxASSERT_MSG( count
>=1 , wxT("Reference Count of native tool was illegal before removal") );
634 CFRelease( viewRef
) ;
643 case kEventClassToolbarItem
:
644 switch ( GetEventKind( inEvent
) )
646 case kEventToolbarItemCreateCustomView
:
648 HIViewRef viewRef
= object
->viewRef
;
649 HIViewRemoveFromSuperview( viewRef
) ;
650 HIViewSetVisible(viewRef
, true) ;
651 CFRetain( viewRef
) ;
652 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
658 case kEventClassControl
:
659 switch ( GetEventKind( inEvent
) )
661 case kEventControlGetSizeConstraints
:
663 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
666 // during toolbar layout the native window sometimes gets negative sizes,
667 // sometimes it just gets shrunk behind our back, so in order to avoid
668 // ever shrinking more, once a valid size is captured, we keep it
670 wxSize sz
= object
->lastValidSize
;
671 if ( sz
.x
<= 0 || sz
.y
<= 0 )
673 sz
= wxwindow
->GetSize() ;
674 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
675 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
676 if ( sz
.x
> 0 && sz
.y
> 0 )
677 object
->lastValidSize
= sz
;
682 // Extra width to avoid edge of combobox being cut off
686 min
.width
= max
.width
= sz
.x
;
687 min
.height
= max
.height
= sz
.y
;
689 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
690 sizeof( HISize
), &min
);
692 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
693 sizeof( HISize
), &max
);
705 void RegisterControlToolbarItemClass()
707 static bool sRegistered
;
711 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
712 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
718 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
720 RegisterControlToolbarItemClass();
724 UInt32 options
= kHIToolbarItemAllowDuplicates
;
725 HIToolbarItemRef result
= NULL
;
727 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
728 require_noerr( err
, CantCreateEvent
);
730 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
731 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
734 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
736 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
739 ReleaseEvent( event
);
744 #if wxMAC_USE_NATIVE_TOOLBAR
745 static const EventTypeSpec kToolbarEvents
[] =
747 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
748 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
749 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
752 static OSStatus
ToolbarDelegateHandler(EventHandlerCallRef
WXUNUSED(inCallRef
),
754 void* WXUNUSED(inUserData
))
756 OSStatus result
= eventNotHandledErr
;
758 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
759 CFMutableArrayRef array
;
761 switch ( GetEventKind( inEvent
) )
763 case kEventToolbarGetDefaultIdentifiers
:
765 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
766 sizeof( CFMutableArrayRef
), NULL
, &array
);
767 // not implemented yet
768 // GetToolbarDefaultItems( array );
773 case kEventToolbarGetAllowedIdentifiers
:
775 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
776 sizeof( CFMutableArrayRef
), NULL
, &array
);
777 // not implemented yet
778 // GetToolbarAllowedItems( array );
782 case kEventToolbarCreateItemWithIdentifier
:
784 HIToolbarItemRef item
= NULL
;
785 CFTypeRef data
= NULL
;
786 CFStringRef identifier
= NULL
;
788 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
789 sizeof( CFStringRef
), NULL
, &identifier
);
791 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
792 sizeof( CFTypeRef
), NULL
, &data
);
794 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
796 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
799 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
800 sizeof( HIToolbarItemRef
), &item
);
810 #endif // wxMAC_USE_NATIVE_TOOLBAR
812 // also for the toolbar we have the dual implementation:
813 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
815 bool wxToolBar::Create(
821 const wxString
& name
)
823 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
828 OSStatus err
= noErr
;
830 #if wxMAC_USE_NATIVE_TOOLBAR
831 if (parent
->IsKindOf(CLASSINFO(wxFrame
)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1)
833 wxString labelStr
= wxString::Format( wxT("%p"), this );
834 err
= HIToolbarCreate(
835 wxMacCFStringHolder( labelStr
, wxFont::GetDefaultEncoding() ), 0,
836 (HIToolbarRef
*) &m_macHIToolbarRef
);
838 if (m_macHIToolbarRef
!= NULL
)
840 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
841 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
843 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
844 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
846 if ( style
& wxTB_NOICONS
)
847 mode
= kHIToolbarDisplayModeLabelOnly
;
848 else if ( style
& wxTB_TEXT
)
849 mode
= kHIToolbarDisplayModeIconAndLabel
;
851 mode
= kHIToolbarDisplayModeIconOnly
;
853 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
854 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
857 #endif // wxMAC_USE_NATIVE_TOOLBAR
859 return (err
== noErr
);
862 wxToolBar::~wxToolBar()
864 #if wxMAC_USE_NATIVE_TOOLBAR
865 if (m_macHIToolbarRef
!= NULL
)
867 // if this is the installed toolbar, then deinstall it
868 if (m_macUsesNativeToolbar
)
869 MacInstallNativeToolbar( false );
871 CFIndex count
= CFGetRetainCount( m_macHIToolbarRef
) ;
872 // Leopard seems to have one refcount more, so we cannot check reliably at the moment
873 if ( UMAGetSystemVersion() < 0x1050 )
875 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
877 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
878 m_macHIToolbarRef
= NULL
;
883 bool wxToolBar::Show( bool show
)
885 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
886 bool bResult
= (tlw
!= NULL
);
890 #if wxMAC_USE_NATIVE_TOOLBAR
891 bool ownToolbarInstalled
= false;
892 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
893 if (ownToolbarInstalled
)
895 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
897 ShowHideWindowToolbar( tlw
, show
, false );
900 bResult
= wxToolBarBase::Show( show
);
903 bResult
= wxToolBarBase::Show( show
);
910 bool wxToolBar::IsShown() const
914 #if wxMAC_USE_NATIVE_TOOLBAR
915 bool ownToolbarInstalled
;
917 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
918 if (ownToolbarInstalled
)
920 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
921 bResult
= IsWindowToolbarVisible( tlw
);
924 bResult
= wxToolBarBase::IsShown();
927 bResult
= wxToolBarBase::IsShown();
933 void wxToolBar::DoGetSize( int *width
, int *height
) const
935 #if wxMAC_USE_NATIVE_TOOLBAR
937 bool ownToolbarInstalled
;
939 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
940 if ( ownToolbarInstalled
)
942 // TODO: is this really a control ?
943 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
945 *width
= boundsR
.right
- boundsR
.left
;
946 if ( height
!= NULL
)
947 *height
= boundsR
.bottom
- boundsR
.top
;
950 wxToolBarBase::DoGetSize( width
, height
);
953 wxToolBarBase::DoGetSize( width
, height
);
957 wxSize
wxToolBar::DoGetBestSize() const
961 DoGetSize( &width
, &height
);
963 return wxSize( width
, height
);
966 void wxToolBar::SetWindowStyleFlag( long style
)
968 wxToolBarBase::SetWindowStyleFlag( style
);
970 #if wxMAC_USE_NATIVE_TOOLBAR
971 if (m_macHIToolbarRef
!= NULL
)
973 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
975 if ( style
& wxTB_NOICONS
)
976 mode
= kHIToolbarDisplayModeLabelOnly
;
977 else if ( style
& wxTB_TEXT
)
978 mode
= kHIToolbarDisplayModeIconAndLabel
;
980 mode
= kHIToolbarDisplayModeIconOnly
;
982 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
987 #if wxMAC_USE_NATIVE_TOOLBAR
988 bool wxToolBar::MacWantsNativeToolbar()
990 return m_macUsesNativeToolbar
;
993 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
995 bool bResultV
= false;
997 if (ownToolbarInstalled
!= NULL
)
998 *ownToolbarInstalled
= false;
1000 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1003 HIToolbarRef curToolbarRef
= NULL
;
1004 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1005 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
1006 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
1007 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
1013 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
1015 bool bResult
= false;
1017 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
1020 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
1023 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1027 // check the existing toolbar
1028 HIToolbarRef curToolbarRef
= NULL
;
1029 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1031 curToolbarRef
= NULL
;
1033 m_macUsesNativeToolbar
= usesNative
;
1035 if (m_macUsesNativeToolbar
)
1037 // only install toolbar if there isn't one installed already
1038 if (curToolbarRef
== NULL
)
1042 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1043 ShowHideWindowToolbar( tlw
, true, false );
1044 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1045 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1047 Rect r
= { 0, 0, 0, 0 };
1048 m_peer
->SetRect( &r
);
1049 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1050 m_peer
->SetVisibility( false, true );
1051 wxToolBarBase::Show( false );
1056 // only deinstall toolbar if this is the installed one
1057 if (m_macHIToolbarRef
== curToolbarRef
)
1061 ShowHideWindowToolbar( tlw
, false, false );
1062 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1063 SetWindowToolbar( tlw
, NULL
);
1065 m_peer
->SetVisibility( true, true );
1070 InvalidateBestSize();
1072 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1077 bool wxToolBar::Realize()
1079 if (m_tools
.GetCount() == 0)
1085 int maxToolWidth
= 0;
1086 int maxToolHeight
= 0;
1088 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1089 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1092 GetSize( &tw
, &th
);
1094 // find the maximum tool width and height
1095 wxToolBarTool
*tool
;
1096 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1099 tool
= (wxToolBarTool
*) node
->GetData();
1102 wxSize sz
= tool
->GetSize();
1104 if ( sz
.x
> maxToolWidth
)
1105 maxToolWidth
= sz
.x
;
1106 if ( sz
.y
> maxToolHeight
)
1107 maxToolHeight
= sz
.y
;
1110 node
= node
->GetNext();
1113 bool lastIsRadio
= false;
1114 bool curIsRadio
= false;
1116 #if wxMAC_USE_NATIVE_TOOLBAR
1117 CFIndex currentPosition
= 0;
1118 bool insertAll
= false;
1120 HIToolbarRef refTB
= (HIToolbarRef
)m_macHIToolbarRef
;
1123 node
= m_tools
.GetFirst();
1126 tool
= (wxToolBarTool
*) node
->GetData();
1129 node
= node
->GetNext();
1133 // set tool position:
1134 // for the moment just perform a single row/column alignment
1135 wxSize cursize
= tool
->GetSize();
1136 if ( x
+ cursize
.x
> maxWidth
)
1137 maxWidth
= x
+ cursize
.x
;
1138 if ( y
+ cursize
.y
> maxHeight
)
1139 maxHeight
= y
+ cursize
.y
;
1141 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1143 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1144 tool
->SetPosition( wxPoint(x1
, y
) );
1148 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1149 tool
->SetPosition( wxPoint(x
, y1
) );
1152 // update the item positioning state
1153 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1154 y
+= cursize
.y
+ kwxMacToolSpacing
;
1156 x
+= cursize
.x
+ kwxMacToolSpacing
;
1158 #if wxMAC_USE_NATIVE_TOOLBAR
1159 // install in native HIToolbar
1162 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1163 if ( hiItemRef
!= NULL
)
1165 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1167 OSStatus err
= noErr
;
1172 // if this is the first tool that gets newly inserted or repositioned
1173 // first remove all 'old' tools from here to the right, because of this
1174 // all following tools will have to be reinserted (insertAll).
1175 for ( wxToolBarToolsList::compatibility_iterator node2
= m_tools
.GetLast();
1177 node2
= node2
->GetPrevious() )
1179 wxToolBarTool
*tool2
= (wxToolBarTool
*) node2
->GetData();
1181 const long idx
= tool2
->GetIndex();
1184 if ( tool2
->IsControl() )
1186 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1187 wxASSERT_MSG( count
== 3 || count
== 2 , wxT("Reference Count of native tool was illegal before removal") );
1188 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1190 err
= HIToolbarRemoveItemAtIndex(refTB
, idx
);
1193 wxLogDebug(wxT("HIToolbarRemoveItemAtIndex(%ld) failed [%ld]"),
1196 if ( tool2
->IsControl() )
1198 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1199 wxASSERT_MSG( count
== 2 , wxT("Reference Count of native tool was not 2 after removal") );
1200 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1203 tool2
->SetIndex(-1);
1208 err
= HIToolbarInsertItemAtIndex( refTB
, hiItemRef
, currentPosition
);
1211 wxLogDebug( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1214 tool
->SetIndex( currentPosition
);
1215 if ( tool
->IsControl() )
1217 CFIndex count
= CFGetRetainCount( tool
->GetControl()->GetPeer()->GetControlRef() ) ;
1218 wxASSERT_MSG( count
== 3 || count
== 2, wxT("Reference Count of native tool was illegal after insertion") );
1219 wxASSERT( IsValidControlHandle(tool
->GetControl()->GetPeer()->GetControlRef() )) ;
1228 // update radio button (and group) state
1229 lastIsRadio
= curIsRadio
;
1230 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1234 if ( tool
->IsToggled() )
1235 DoToggleTool( tool
, true );
1241 if ( tool
->Toggle( true ) )
1243 DoToggleTool( tool
, true );
1246 else if ( tool
->IsToggled() )
1248 if ( tool
->IsToggled() )
1249 DoToggleTool( tool
, true );
1251 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1254 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1255 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1258 if ( toggleTool
->Toggle( false ) )
1259 DoToggleTool( toggleTool
, false );
1261 nodePrev
= nodePrev
->GetPrevious();
1266 node
= node
->GetNext();
1269 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1271 // if not set yet, only one row
1272 if ( m_maxRows
<= 0 )
1275 m_minWidth
= maxWidth
;
1277 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1278 m_minHeight
= m_maxHeight
= maxHeight
;
1282 // if not set yet, have one column
1283 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1284 SetRows( GetToolsCount() );
1286 m_minHeight
= maxHeight
;
1288 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1289 m_minWidth
= m_maxWidth
= maxWidth
;
1293 // FIXME: should this be OSX-only?
1295 bool wantNativeToolbar
, ownToolbarInstalled
;
1297 // attempt to install the native toolbar
1298 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1299 MacInstallNativeToolbar( wantNativeToolbar
);
1300 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1301 if (!ownToolbarInstalled
)
1303 SetSize( maxWidth
, maxHeight
);
1304 InvalidateBestSize();
1308 SetSize( maxWidth
, maxHeight
);
1309 InvalidateBestSize();
1317 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1319 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1320 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1322 #if wxMAC_USE_NATIVE_TOOLBAR
1323 if (m_macHIToolbarRef
!= NULL
)
1325 int maxs
= wxMax( size
.x
, size
.y
);
1326 HIToolbarDisplaySize sizeSpec
;
1328 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1329 else if ( maxs
> 24 )
1330 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1332 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1334 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1339 // The button size is bigger than the bitmap size
1340 wxSize
wxToolBar::GetToolSize() const
1342 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1345 void wxToolBar::SetRows(int nRows
)
1347 // avoid resizing the frame uselessly
1348 if ( nRows
!= m_maxRows
)
1352 void wxToolBar::MacSuperChangedPosition()
1354 wxWindow::MacSuperChangedPosition();
1356 #if wxMAC_USE_NATIVE_TOOLBAR
1357 if (! m_macUsesNativeToolbar
)
1365 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1367 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1370 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1372 tool
->SetNormalBitmap(bitmap
);
1374 // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
1375 tool
->UpdateToggleImage( tool
->CanBeToggled() && tool
->IsToggled() );
1379 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1381 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1384 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1386 tool
->SetDisabledBitmap(bitmap
);
1388 // TODO: what to do for this one?
1392 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1394 wxToolBarTool
*tool
;
1395 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1398 tool
= (wxToolBarTool
*)node
->GetData();
1401 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1402 if ( r
.Contains( wxPoint( x
, y
) ) )
1406 node
= node
->GetNext();
1409 return (wxToolBarToolBase
*)NULL
;
1412 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1414 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1416 return tool
->GetShortHelp();
1418 return wxEmptyString
;
1421 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1424 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1427 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1429 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1430 if ( ( tool
!= NULL
) && tool
->IsButton() )
1431 tool
->UpdateToggleImage( toggle
);
1434 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1436 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1440 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1441 wxSize toolSize
= GetToolSize();
1442 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1443 ControlRef controlHandle
= NULL
;
1445 tool
->Attach( this );
1447 #if wxMAC_USE_NATIVE_TOOLBAR
1448 wxString label
= tool
->GetLabel();
1449 if (m_macHIToolbarRef
&& !label
.empty() )
1451 // strip mnemonics from the label for compatibility
1452 // with the usual labels in wxStaticText sense
1453 label
= wxStripMenuCodes(label
);
1455 #endif // wxMAC_USE_NATIVE_TOOLBAR
1457 switch (tool
->GetStyle())
1459 case wxTOOL_STYLE_SEPARATOR
:
1461 wxASSERT( tool
->GetControlHandle() == NULL
);
1464 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1465 toolrect
.bottom
= toolSize
.y
;
1467 toolrect
.right
= toolSize
.x
;
1469 // in flat style we need a visual separator
1470 #if wxMAC_USE_NATIVE_TOOLBAR
1471 if (m_macHIToolbarRef
!= NULL
)
1473 HIToolbarItemRef item
;
1474 err
= HIToolbarItemCreate(
1475 kHIToolbarSeparatorIdentifier
,
1476 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1479 tool
->SetToolbarItemRef( item
);
1483 #endif // wxMAC_USE_NATIVE_TOOLBAR
1485 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1486 tool
->SetControlHandle( controlHandle
);
1490 case wxTOOL_STYLE_BUTTON
:
1492 wxASSERT( tool
->GetControlHandle() == NULL
);
1493 ControlButtonContentInfo info
;
1494 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap() );
1496 if ( UMAGetSystemVersion() >= 0x1000)
1498 // contrary to the docs this control only works with iconrefs
1499 ControlButtonContentInfo info
;
1500 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1501 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1502 wxMacReleaseBitmapButton( &info
);
1506 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1507 if ( tool
->CanBeToggled() )
1508 behaviour
|= kControlBehaviorToggles
;
1509 err
= CreateBevelButtonControl( window
,
1510 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1511 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1514 #if wxMAC_USE_NATIVE_TOOLBAR
1515 if (m_macHIToolbarRef
!= NULL
)
1517 HIToolbarItemRef item
;
1518 wxString labelStr
= wxString::Format(wxT("%p"), tool
);
1519 err
= HIToolbarItemCreate(
1520 wxMacCFStringHolder(labelStr
, wxFont::GetDefaultEncoding()),
1521 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1524 ControlButtonContentInfo info2
;
1525 wxMacCreateBitmapButton( &info2
, tool
->GetNormalBitmap(), kControlContentCGImageRef
);
1527 InstallEventHandler(
1528 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1529 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1530 HIToolbarItemSetLabel( item
, wxMacCFStringHolder(label
, m_font
.GetEncoding()) );
1531 HIToolbarItemSetImage( item
, info2
.u
.imageRef
);
1532 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1533 tool
->SetToolbarItemRef( item
);
1535 wxMacReleaseBitmapButton( &info2
);
1540 #endif // wxMAC_USE_NATIVE_TOOLBAR
1542 wxMacReleaseBitmapButton( &info
);
1545 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1546 SetControlTitleWithCFString( m_controlHandle
, wxMacCFStringHolder( 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") );
1563 HIToolbarItemRef item
;
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
1591 if ( controlHandle
)
1593 ControlRef container
= (ControlRef
) GetHandle();
1594 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1596 SetControlVisibility( controlHandle
, true, true );
1597 ::EmbedControl( controlHandle
, container
);
1600 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1601 tool
->UpdateToggleImage( true );
1603 // nothing special to do here - we relayout in Realize() later
1604 InvalidateBestSize();
1608 wxFAIL_MSG( wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
) );
1611 return (err
== noErr
);
1614 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1616 wxFAIL_MSG( wxT("not implemented") );
1619 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1621 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1622 wxToolBarToolsList::compatibility_iterator node
;
1623 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1625 wxToolBarToolBase
*tool2
= node
->GetData();
1626 if ( tool2
== tool
)
1628 // let node point to the next node in the list
1629 node
= node
->GetNext();
1635 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1639 #if wxMAC_USE_NATIVE_TOOLBAR
1640 CFIndex removeIndex
= tool
->GetIndex();
1643 #if wxMAC_USE_NATIVE_TOOLBAR
1644 if (m_macHIToolbarRef
!= NULL
)
1646 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1648 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1649 tool
->SetIndex( -1 );
1653 switch ( tool
->GetStyle() )
1655 case wxTOOL_STYLE_CONTROL
:
1656 if ( tool
->GetControl() )
1657 tool
->GetControl()->Destroy();
1660 case wxTOOL_STYLE_BUTTON
:
1661 case wxTOOL_STYLE_SEPARATOR
:
1668 tool
->ClearControl();
1670 // and finally reposition all the controls after this one
1672 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1674 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1675 wxPoint pt
= tool2
->GetPosition();
1677 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1682 tool2
->SetPosition( pt
);
1684 #if wxMAC_USE_NATIVE_TOOLBAR
1685 if (m_macHIToolbarRef
!= NULL
)
1687 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1688 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1693 InvalidateBestSize();
1698 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1700 #if wxMAC_USE_NATIVE_TOOLBAR
1701 if ( m_macUsesNativeToolbar
)
1713 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1715 if ( !drawMetalTheme
)
1717 HIThemePlacardDrawInfo info
;
1718 memset( &info
, 0, sizeof(info
) );
1720 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1722 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1723 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1724 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1728 // leave the background as it is (striped or metal)
1734 #endif // wxUSE_TOOLBAR