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
;
117 #if wxMAC_USE_NATIVE_TOOLBAR
118 if ( m_toolbarItemRef
)
120 CFIndex count
= CFGetRetainCount( m_toolbarItemRef
) ;
121 // different behaviour under Leopard
122 if ( UMAGetSystemVersion() < 0x1050 )
126 wxFAIL_MSG("Reference count of native tool was not 1 in wxToolBarTool destructor");
129 wxTheApp
->MacAddToAutorelease(m_toolbarItemRef
);
130 CFRelease(m_toolbarItemRef
);
131 m_toolbarItemRef
= NULL
;
133 #endif // wxMAC_USE_NATIVE_TOOLBAR
136 wxSize
GetSize() const
142 curSize
= GetControl()->GetSize();
144 else if ( IsButton() )
146 curSize
= GetToolBar()->GetToolSize();
151 curSize
= GetToolBar()->GetToolSize();
152 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
161 wxPoint
GetPosition() const
163 return wxPoint( m_x
, m_y
);
166 bool DoEnable( bool enable
);
168 void UpdateToggleImage( bool toggle
);
170 #if wxMAC_USE_NATIVE_TOOLBAR
171 void SetToolbarItemRef( HIToolbarItemRef ref
)
173 if ( m_controlHandle
)
174 HideControl( m_controlHandle
);
175 if ( m_toolbarItemRef
)
176 CFRelease( m_toolbarItemRef
);
178 m_toolbarItemRef
= ref
;
179 if ( m_toolbarItemRef
)
184 f
= GetToolBar()->GetFont();
186 enc
= f
.GetEncoding();
188 enc
= wxFont::GetDefaultEncoding();
190 HIToolbarItemSetHelpText(
192 wxCFStringRef( GetShortHelp(), enc
),
193 wxCFStringRef( GetLongHelp(), enc
) );
197 HIToolbarItemRef
GetToolbarItemRef() const
199 return m_toolbarItemRef
;
202 void SetIndex( CFIndex idx
)
207 CFIndex
GetIndex() const
216 m_controlHandle
= NULL
;
218 #if wxMAC_USE_NATIVE_TOOLBAR
219 m_toolbarItemRef
= NULL
;
224 ControlRef m_controlHandle
;
228 #if wxMAC_USE_NATIVE_TOOLBAR
229 HIToolbarItemRef m_toolbarItemRef
;
230 // position in its toolbar, -1 means not inserted
235 static const EventTypeSpec eventList
[] =
237 { kEventClassControl
, kEventControlHit
},
238 { kEventClassControl
, kEventControlHitTest
},
241 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
243 OSStatus result
= eventNotHandledErr
;
244 ControlRef controlRef
;
245 wxMacCarbonEvent
cEvent( event
);
247 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
249 switch ( GetEventKind( event
) )
251 case kEventControlHit
:
253 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
254 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
255 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
259 shouldToggle
= !tbartool
->IsToggled();
261 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
264 if (tbartool
!= NULL
)
265 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
270 case kEventControlHitTest
:
272 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
274 HIViewGetBounds( controlRef
, &rect
);
276 ControlPartCode pc
= kControlNoPart
;
277 if ( CGRectContainsPoint( rect
, pt
) )
278 pc
= kControlIconPart
;
279 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
291 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
293 OSStatus result
= eventNotHandledErr
;
295 switch ( GetEventClass( event
) )
297 case kEventClassControl
:
298 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
308 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
310 #if wxMAC_USE_NATIVE_TOOLBAR
312 static const EventTypeSpec toolBarEventList
[] =
314 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
317 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
319 OSStatus result
= eventNotHandledErr
;
321 switch ( GetEventKind( event
) )
323 case kEventToolbarItemPerformAction
:
325 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
326 if ( tbartool
!= NULL
)
328 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
329 int toolID
= tbartool
->GetId();
331 if ( tbartool
->CanBeToggled() )
334 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
338 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
351 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
353 OSStatus result
= eventNotHandledErr
;
355 switch ( GetEventClass( event
) )
357 case kEventClassToolbarItem
:
358 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
368 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
372 bool wxToolBarTool::DoEnable( bool enable
)
376 GetControl()->Enable( enable
);
378 else if ( IsButton() )
380 #if wxMAC_USE_NATIVE_TOOLBAR
381 if ( m_toolbarItemRef
!= NULL
)
382 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
385 if ( m_controlHandle
!= NULL
)
388 EnableControl( m_controlHandle
);
390 DisableControl( m_controlHandle
);
397 void wxToolBarTool::SetPosition( const wxPoint
& position
)
402 int mac_x
= position
.x
;
403 int mac_y
= position
.y
;
408 GetControlBounds( m_controlHandle
, &contrlRect
);
409 int former_mac_x
= contrlRect
.left
;
410 int former_mac_y
= contrlRect
.top
;
411 GetToolBar()->GetToolSize();
413 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
415 ::MoveControl( m_controlHandle
, mac_x
, mac_y
);
418 else if ( IsControl() )
420 // embedded native controls are moved by the OS
421 #if wxMAC_USE_NATIVE_TOOLBAR
422 if ( ((wxToolBar
*)GetToolBar())->MacWantsNativeToolbar() == false )
425 GetControl()->Move( position
);
432 GetControlBounds( m_controlHandle
, &contrlRect
);
433 int former_mac_x
= contrlRect
.left
;
434 int former_mac_y
= contrlRect
.top
;
436 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
437 ::MoveControl( m_controlHandle
, mac_x
, mac_y
);
441 void wxToolBarTool::UpdateToggleImage( bool toggle
)
445 int w
= m_bmpNormal
.GetWidth();
446 int h
= m_bmpNormal
.GetHeight();
447 wxBitmap
bmp( w
, h
);
450 dc
.SelectObject( bmp
);
451 dc
.SetPen( wxPen(*wxBLACK
) );
452 dc
.SetBrush( wxBrush( *wxLIGHT_GREY
));
453 dc
.DrawRectangle( 0, 0, w
, h
);
454 dc
.DrawBitmap( m_bmpNormal
, 0, 0, true );
455 dc
.SelectObject( wxNullBitmap
);
456 ControlButtonContentInfo info
;
457 wxMacCreateBitmapButton( &info
, bmp
);
458 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
459 #if wxMAC_USE_NATIVE_TOOLBAR
460 if (m_toolbarItemRef
!= NULL
)
462 ControlButtonContentInfo info2
;
463 wxMacCreateBitmapButton( &info2
, bmp
, kControlContentCGImageRef
);
464 HIToolbarItemSetImage( m_toolbarItemRef
, info2
.u
.imageRef
);
465 wxMacReleaseBitmapButton( &info2
);
468 wxMacReleaseBitmapButton( &info
);
472 ControlButtonContentInfo info
;
473 wxMacCreateBitmapButton( &info
, m_bmpNormal
);
474 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
475 #if wxMAC_USE_NATIVE_TOOLBAR
476 if (m_toolbarItemRef
!= NULL
)
478 ControlButtonContentInfo info2
;
479 wxMacCreateBitmapButton( &info2
, m_bmpNormal
, kControlContentCGImageRef
);
480 HIToolbarItemSetImage( m_toolbarItemRef
, info2
.u
.imageRef
);
481 wxMacReleaseBitmapButton( &info2
);
484 wxMacReleaseBitmapButton( &info
);
487 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
489 m_controlHandle
, 0, kControlIconTransformTag
,
490 sizeof(transform
), (Ptr
)&transform
);
491 HIViewSetNeedsDisplay( m_controlHandle
, true );
495 wxToolBarTool::wxToolBarTool(
498 const wxString
& label
,
499 const wxBitmap
& bmpNormal
,
500 const wxBitmap
& bmpDisabled
,
502 wxObject
*clientData
,
503 const wxString
& shortHelp
,
504 const wxString
& longHelp
)
507 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
508 clientData
, shortHelp
, longHelp
)
514 #pragma mark Toolbar Implementation
516 wxToolBarToolBase
*wxToolBar::CreateTool(
518 const wxString
& label
,
519 const wxBitmap
& bmpNormal
,
520 const wxBitmap
& bmpDisabled
,
522 wxObject
*clientData
,
523 const wxString
& shortHelp
,
524 const wxString
& longHelp
)
526 return new wxToolBarTool(
527 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
528 clientData
, shortHelp
, longHelp
);
532 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
534 return new wxToolBarTool(this, control
, label
);
537 void wxToolBar::Init()
541 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
542 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
544 #if wxMAC_USE_NATIVE_TOOLBAR
545 m_macHIToolbarRef
= NULL
;
546 m_macUsesNativeToolbar
= false;
550 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
552 const EventTypeSpec kEvents
[] =
554 { kEventClassHIObject
, kEventHIObjectConstruct
},
555 { kEventClassHIObject
, kEventHIObjectInitialize
},
556 { kEventClassHIObject
, kEventHIObjectDestruct
},
558 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
561 const EventTypeSpec kViewEvents
[] =
563 { kEventClassControl
, kEventControlGetSizeConstraints
}
566 struct ControlToolbarItem
568 HIToolbarItemRef toolbarItem
;
570 wxSize lastValidSize
;
573 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
575 OSStatus result
= eventNotHandledErr
;
576 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
578 switch ( GetEventClass( inEvent
) )
580 case kEventClassHIObject
:
581 switch ( GetEventKind( inEvent
) )
583 case kEventHIObjectConstruct
:
585 HIObjectRef toolbarItem
;
586 ControlToolbarItem
* item
;
588 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
589 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
591 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
592 item
->toolbarItem
= toolbarItem
;
593 item
->lastValidSize
= wxSize(-1,-1);
594 item
->viewRef
= NULL
;
596 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
602 case kEventHIObjectInitialize
:
603 result
= CallNextEventHandler( inCallRef
, inEvent
);
604 if ( result
== noErr
)
607 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
608 sizeof( CFTypeRef
), NULL
, &data
);
612 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
613 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
615 object
->viewRef
= (HIViewRef
) viewRef
;
616 // make sure we keep that control during our lifetime
617 CFRetain( object
->viewRef
) ;
619 verify_noerr(InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
620 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
));
625 case kEventHIObjectDestruct
:
627 HIViewRef viewRef
= object
->viewRef
;
628 if( viewRef
&& IsValidControlHandle( viewRef
) )
630 // depending whether the wxControl corresponding to this HIView has already been destroyed or
631 // not, ref counts differ, so we cannot assert a special value
632 CFIndex count
= CFGetRetainCount( viewRef
) ;
635 wxFAIL_MSG("Reference count of native tool was illegal before removal");
637 CFRelease( viewRef
) ;
647 case kEventClassToolbarItem
:
648 switch ( GetEventKind( inEvent
) )
650 case kEventToolbarItemCreateCustomView
:
652 HIViewRef viewRef
= object
->viewRef
;
653 HIViewRemoveFromSuperview( viewRef
) ;
654 HIViewSetVisible(viewRef
, true) ;
655 CFRetain( viewRef
) ;
656 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
662 case kEventClassControl
:
663 switch ( GetEventKind( inEvent
) )
665 case kEventControlGetSizeConstraints
:
667 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
670 // during toolbar layout the native window sometimes gets negative sizes,
671 // sometimes it just gets shrunk behind our back, so in order to avoid
672 // ever shrinking more, once a valid size is captured, we keep it
674 wxSize sz
= object
->lastValidSize
;
675 if ( sz
.x
<= 0 || sz
.y
<= 0 )
677 sz
= wxwindow
->GetSize() ;
678 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
679 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
680 if ( sz
.x
> 0 && sz
.y
> 0 )
681 object
->lastValidSize
= sz
;
686 // Extra width to avoid edge of combobox being cut off
690 min
.width
= max
.width
= sz
.x
;
691 min
.height
= max
.height
= sz
.y
;
693 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
694 sizeof( HISize
), &min
);
696 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
697 sizeof( HISize
), &max
);
709 void RegisterControlToolbarItemClass()
711 static bool sRegistered
;
715 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
716 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
722 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
724 RegisterControlToolbarItemClass();
728 UInt32 options
= kHIToolbarItemAllowDuplicates
;
729 HIToolbarItemRef result
= NULL
;
731 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
732 require_noerr( err
, CantCreateEvent
);
734 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
735 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
738 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
740 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
743 ReleaseEvent( event
);
748 #if wxMAC_USE_NATIVE_TOOLBAR
749 static const EventTypeSpec kToolbarEvents
[] =
751 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
752 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
753 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
756 static OSStatus
ToolbarDelegateHandler(EventHandlerCallRef
WXUNUSED(inCallRef
),
758 void* WXUNUSED(inUserData
))
760 OSStatus result
= eventNotHandledErr
;
762 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
763 CFMutableArrayRef array
;
765 switch ( GetEventKind( inEvent
) )
767 case kEventToolbarGetDefaultIdentifiers
:
769 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
770 sizeof( CFMutableArrayRef
), NULL
, &array
);
771 // not implemented yet
772 // GetToolbarDefaultItems( array );
777 case kEventToolbarGetAllowedIdentifiers
:
779 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
780 sizeof( CFMutableArrayRef
), NULL
, &array
);
781 // not implemented yet
782 // GetToolbarAllowedItems( array );
786 case kEventToolbarCreateItemWithIdentifier
:
788 HIToolbarItemRef item
= NULL
;
789 CFTypeRef data
= NULL
;
790 CFStringRef identifier
= NULL
;
792 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
793 sizeof( CFStringRef
), NULL
, &identifier
);
795 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
796 sizeof( CFTypeRef
), NULL
, &data
);
798 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
800 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
803 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
804 sizeof( HIToolbarItemRef
), &item
);
814 #endif // wxMAC_USE_NATIVE_TOOLBAR
816 // also for the toolbar we have the dual implementation:
817 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
819 bool wxToolBar::Create(
825 const wxString
& name
)
827 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
832 OSStatus err
= noErr
;
834 #if wxMAC_USE_NATIVE_TOOLBAR
835 if (parent
->IsKindOf(CLASSINFO(wxFrame
)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1)
837 wxString labelStr
= wxString::Format( wxT("%p"), this );
838 err
= HIToolbarCreate(
839 wxCFStringRef( labelStr
, wxFont::GetDefaultEncoding() ), 0,
840 (HIToolbarRef
*) &m_macHIToolbarRef
);
842 if (m_macHIToolbarRef
!= NULL
)
844 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
845 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
847 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
848 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
850 if ( style
& wxTB_NOICONS
)
851 mode
= kHIToolbarDisplayModeLabelOnly
;
852 else if ( style
& wxTB_TEXT
)
853 mode
= kHIToolbarDisplayModeIconAndLabel
;
855 mode
= kHIToolbarDisplayModeIconOnly
;
857 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
858 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
861 #endif // wxMAC_USE_NATIVE_TOOLBAR
863 return (err
== noErr
);
866 wxToolBar::~wxToolBar()
868 #if wxMAC_USE_NATIVE_TOOLBAR
869 if (m_macHIToolbarRef
!= NULL
)
871 // if this is the installed toolbar, then deinstall it
872 if (m_macUsesNativeToolbar
)
873 MacInstallNativeToolbar( false );
875 CFIndex count
= CFGetRetainCount( m_macHIToolbarRef
) ;
876 // Leopard seems to have one refcount more, so we cannot check reliably at the moment
877 if ( UMAGetSystemVersion() < 0x1050 )
881 wxFAIL_MSG("Reference count of native control was not 1 in wxToolBar destructor");
884 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
885 m_macHIToolbarRef
= NULL
;
890 bool wxToolBar::Show( bool show
)
892 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
893 bool bResult
= (tlw
!= NULL
);
897 #if wxMAC_USE_NATIVE_TOOLBAR
898 bool ownToolbarInstalled
= false;
899 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
900 if (ownToolbarInstalled
)
902 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
904 ShowHideWindowToolbar( tlw
, show
, false );
907 bResult
= wxToolBarBase::Show( show
);
910 bResult
= wxToolBarBase::Show( show
);
917 bool wxToolBar::IsShown() const
921 #if wxMAC_USE_NATIVE_TOOLBAR
922 bool ownToolbarInstalled
;
924 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
925 if (ownToolbarInstalled
)
927 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
928 bResult
= IsWindowToolbarVisible( tlw
);
931 bResult
= wxToolBarBase::IsShown();
934 bResult
= wxToolBarBase::IsShown();
940 void wxToolBar::DoGetSize( int *width
, int *height
) const
942 #if wxMAC_USE_NATIVE_TOOLBAR
944 bool ownToolbarInstalled
;
946 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
947 if ( ownToolbarInstalled
)
949 // TODO: is this really a control ?
950 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
952 *width
= boundsR
.right
- boundsR
.left
;
953 if ( height
!= NULL
)
954 *height
= boundsR
.bottom
- boundsR
.top
;
957 wxToolBarBase::DoGetSize( width
, height
);
960 wxToolBarBase::DoGetSize( width
, height
);
964 wxSize
wxToolBar::DoGetBestSize() const
968 DoGetSize( &width
, &height
);
970 return wxSize( width
, height
);
973 void wxToolBar::SetWindowStyleFlag( long style
)
975 wxToolBarBase::SetWindowStyleFlag( style
);
977 #if wxMAC_USE_NATIVE_TOOLBAR
978 if (m_macHIToolbarRef
!= NULL
)
980 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
982 if ( style
& wxTB_NOICONS
)
983 mode
= kHIToolbarDisplayModeLabelOnly
;
984 else if ( style
& wxTB_TEXT
)
985 mode
= kHIToolbarDisplayModeIconAndLabel
;
987 mode
= kHIToolbarDisplayModeIconOnly
;
989 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
994 #if wxMAC_USE_NATIVE_TOOLBAR
995 bool wxToolBar::MacWantsNativeToolbar()
997 return m_macUsesNativeToolbar
;
1000 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
1002 bool bResultV
= false;
1004 if (ownToolbarInstalled
!= NULL
)
1005 *ownToolbarInstalled
= false;
1007 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1010 HIToolbarRef curToolbarRef
= NULL
;
1011 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1012 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
1013 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
1014 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
1020 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
1022 bool bResult
= false;
1024 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
1027 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
1030 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1034 // check the existing toolbar
1035 HIToolbarRef curToolbarRef
= NULL
;
1036 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1038 curToolbarRef
= NULL
;
1040 m_macUsesNativeToolbar
= usesNative
;
1042 if (m_macUsesNativeToolbar
)
1044 // only install toolbar if there isn't one installed already
1045 if (curToolbarRef
== NULL
)
1049 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1050 ShowHideWindowToolbar( tlw
, true, false );
1051 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1052 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1054 Rect r
= { 0, 0, 0, 0 };
1055 m_peer
->SetRect( &r
);
1056 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1057 m_peer
->SetVisibility( false, true );
1058 wxToolBarBase::Show( false );
1063 // only deinstall toolbar if this is the installed one
1064 if (m_macHIToolbarRef
== curToolbarRef
)
1068 ShowHideWindowToolbar( tlw
, false, false );
1069 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1070 SetWindowToolbar( tlw
, NULL
);
1072 m_peer
->SetVisibility( true, true );
1077 InvalidateBestSize();
1079 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1084 bool wxToolBar::Realize()
1086 if (m_tools
.GetCount() == 0)
1092 int maxToolWidth
= 0;
1093 int maxToolHeight
= 0;
1095 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1096 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1099 GetSize( &tw
, &th
);
1101 // find the maximum tool width and height
1102 wxToolBarTool
*tool
;
1103 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1106 tool
= (wxToolBarTool
*) node
->GetData();
1109 wxSize sz
= tool
->GetSize();
1111 if ( sz
.x
> maxToolWidth
)
1112 maxToolWidth
= sz
.x
;
1113 if ( sz
.y
> maxToolHeight
)
1114 maxToolHeight
= sz
.y
;
1117 node
= node
->GetNext();
1120 bool lastIsRadio
= false;
1121 bool curIsRadio
= false;
1123 #if wxMAC_USE_NATIVE_TOOLBAR
1124 CFIndex currentPosition
= 0;
1125 bool insertAll
= false;
1127 HIToolbarRef refTB
= (HIToolbarRef
)m_macHIToolbarRef
;
1130 node
= m_tools
.GetFirst();
1133 tool
= (wxToolBarTool
*) node
->GetData();
1136 node
= node
->GetNext();
1140 // set tool position:
1141 // for the moment just perform a single row/column alignment
1142 wxSize cursize
= tool
->GetSize();
1143 if ( x
+ cursize
.x
> maxWidth
)
1144 maxWidth
= x
+ cursize
.x
;
1145 if ( y
+ cursize
.y
> maxHeight
)
1146 maxHeight
= y
+ cursize
.y
;
1148 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1150 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1151 tool
->SetPosition( wxPoint(x1
, y
) );
1155 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1156 tool
->SetPosition( wxPoint(x
, y1
) );
1159 // update the item positioning state
1160 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1161 y
+= cursize
.y
+ kwxMacToolSpacing
;
1163 x
+= cursize
.x
+ kwxMacToolSpacing
;
1165 #if wxMAC_USE_NATIVE_TOOLBAR
1166 // install in native HIToolbar
1169 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1170 if ( hiItemRef
!= NULL
)
1172 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1174 OSStatus err
= noErr
;
1179 // if this is the first tool that gets newly inserted or repositioned
1180 // first remove all 'old' tools from here to the right, because of this
1181 // all following tools will have to be reinserted (insertAll).
1182 for ( wxToolBarToolsList::compatibility_iterator node2
= m_tools
.GetLast();
1184 node2
= node2
->GetPrevious() )
1186 wxToolBarTool
*tool2
= (wxToolBarTool
*) node2
->GetData();
1188 const long idx
= tool2
->GetIndex();
1191 if ( tool2
->IsControl() )
1193 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1194 if ( count
!= 3 && count
!= 2 )
1196 wxFAIL_MSG("Reference count of native tool was illegal before removal");
1199 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1201 err
= HIToolbarRemoveItemAtIndex(refTB
, idx
);
1204 wxLogDebug(wxT("HIToolbarRemoveItemAtIndex(%ld) failed [%ld]"),
1207 if ( tool2
->IsControl() )
1209 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1212 wxFAIL_MSG("Reference count of native tool was not 2 after removal");
1215 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1218 tool2
->SetIndex(-1);
1223 err
= HIToolbarInsertItemAtIndex( refTB
, hiItemRef
, currentPosition
);
1226 wxLogDebug( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1229 tool
->SetIndex( currentPosition
);
1230 if ( tool
->IsControl() )
1232 CFIndex count
= CFGetRetainCount( tool
->GetControl()->GetPeer()->GetControlRef() ) ;
1233 if ( count
!= 3 && count
!= 2 )
1235 wxFAIL_MSG("Reference count of native tool was illegal before removal");
1237 wxASSERT( IsValidControlHandle(tool
->GetControl()->GetPeer()->GetControlRef() )) ;
1246 // update radio button (and group) state
1247 lastIsRadio
= curIsRadio
;
1248 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1252 if ( tool
->IsToggled() )
1253 DoToggleTool( tool
, true );
1259 if ( tool
->Toggle( true ) )
1261 DoToggleTool( tool
, true );
1264 else if ( tool
->IsToggled() )
1266 if ( tool
->IsToggled() )
1267 DoToggleTool( tool
, true );
1269 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1272 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1273 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1276 if ( toggleTool
->Toggle( false ) )
1277 DoToggleTool( toggleTool
, false );
1279 nodePrev
= nodePrev
->GetPrevious();
1284 node
= node
->GetNext();
1287 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1289 // if not set yet, only one row
1290 if ( m_maxRows
<= 0 )
1293 m_minWidth
= maxWidth
;
1295 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1296 m_minHeight
= m_maxHeight
= maxHeight
;
1300 // if not set yet, have one column
1301 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1302 SetRows( GetToolsCount() );
1304 m_minHeight
= maxHeight
;
1306 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1307 m_minWidth
= m_maxWidth
= maxWidth
;
1311 // FIXME: should this be OSX-only?
1313 bool wantNativeToolbar
, ownToolbarInstalled
;
1315 // attempt to install the native toolbar
1316 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1317 MacInstallNativeToolbar( wantNativeToolbar
);
1318 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1319 if (!ownToolbarInstalled
)
1321 SetSize( maxWidth
, maxHeight
);
1322 InvalidateBestSize();
1326 SetSize( maxWidth
, maxHeight
);
1327 InvalidateBestSize();
1335 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1337 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1338 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1340 #if wxMAC_USE_NATIVE_TOOLBAR
1341 if (m_macHIToolbarRef
!= NULL
)
1343 int maxs
= wxMax( size
.x
, size
.y
);
1344 HIToolbarDisplaySize sizeSpec
;
1346 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1347 else if ( maxs
> 24 )
1348 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1350 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1352 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1357 // The button size is bigger than the bitmap size
1358 wxSize
wxToolBar::GetToolSize() const
1360 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1363 void wxToolBar::SetRows(int nRows
)
1365 // avoid resizing the frame uselessly
1366 if ( nRows
!= m_maxRows
)
1370 void wxToolBar::MacSuperChangedPosition()
1372 wxWindow::MacSuperChangedPosition();
1374 #if wxMAC_USE_NATIVE_TOOLBAR
1375 if (! m_macUsesNativeToolbar
)
1383 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1385 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1388 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1390 tool
->SetNormalBitmap(bitmap
);
1392 // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
1393 tool
->UpdateToggleImage( tool
->CanBeToggled() && tool
->IsToggled() );
1397 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1399 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1402 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1404 tool
->SetDisabledBitmap(bitmap
);
1406 // TODO: what to do for this one?
1410 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1412 wxToolBarTool
*tool
;
1413 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1416 tool
= (wxToolBarTool
*)node
->GetData();
1419 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1420 if ( r
.Contains( wxPoint( x
, y
) ) )
1424 node
= node
->GetNext();
1427 return (wxToolBarToolBase
*)NULL
;
1430 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1432 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1434 return tool
->GetShortHelp();
1436 return wxEmptyString
;
1439 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1442 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1445 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1447 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1448 if ( ( tool
!= NULL
) && tool
->IsButton() )
1449 tool
->UpdateToggleImage( toggle
);
1452 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1454 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1458 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1459 wxSize toolSize
= GetToolSize();
1460 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1461 ControlRef controlHandle
= NULL
;
1464 #if wxMAC_USE_NATIVE_TOOLBAR
1465 wxString label
= tool
->GetLabel();
1466 if (m_macHIToolbarRef
&& !label
.empty() )
1468 // strip mnemonics from the label for compatibility
1469 // with the usual labels in wxStaticText sense
1470 label
= wxStripMenuCodes(label
);
1472 #endif // wxMAC_USE_NATIVE_TOOLBAR
1474 switch (tool
->GetStyle())
1476 case wxTOOL_STYLE_SEPARATOR
:
1478 wxASSERT( tool
->GetControlHandle() == NULL
);
1481 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1482 toolrect
.bottom
= toolSize
.y
;
1484 toolrect
.right
= toolSize
.x
;
1486 // in flat style we need a visual separator
1487 #if wxMAC_USE_NATIVE_TOOLBAR
1488 if (m_macHIToolbarRef
!= NULL
)
1490 HIToolbarItemRef item
;
1491 err
= HIToolbarItemCreate(
1492 kHIToolbarSeparatorIdentifier
,
1493 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1496 tool
->SetToolbarItemRef( item
);
1500 #endif // wxMAC_USE_NATIVE_TOOLBAR
1502 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1503 tool
->SetControlHandle( controlHandle
);
1507 case wxTOOL_STYLE_BUTTON
:
1509 wxASSERT( tool
->GetControlHandle() == NULL
);
1510 ControlButtonContentInfo info
;
1511 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap() );
1513 if ( UMAGetSystemVersion() >= 0x1000)
1515 // contrary to the docs this control only works with iconrefs
1516 ControlButtonContentInfo info
;
1517 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1518 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1519 wxMacReleaseBitmapButton( &info
);
1523 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1524 if ( tool
->CanBeToggled() )
1525 behaviour
|= kControlBehaviorToggles
;
1526 err
= CreateBevelButtonControl( window
,
1527 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1528 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1531 #if wxMAC_USE_NATIVE_TOOLBAR
1532 if (m_macHIToolbarRef
!= NULL
)
1534 HIToolbarItemRef item
;
1535 wxString labelStr
= wxString::Format(wxT("%p"), tool
);
1536 err
= HIToolbarItemCreate(
1537 wxCFStringRef(labelStr
, wxFont::GetDefaultEncoding()),
1538 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1541 ControlButtonContentInfo info2
;
1542 wxMacCreateBitmapButton( &info2
, tool
->GetNormalBitmap(), kControlContentCGImageRef
);
1544 InstallEventHandler(
1545 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1546 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1547 HIToolbarItemSetLabel( item
, wxCFStringRef(label
, GetFont().GetEncoding()) );
1548 HIToolbarItemSetImage( item
, info2
.u
.imageRef
);
1549 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1550 tool
->SetToolbarItemRef( item
);
1552 wxMacReleaseBitmapButton( &info2
);
1557 #endif // wxMAC_USE_NATIVE_TOOLBAR
1559 wxMacReleaseBitmapButton( &info
);
1562 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1563 SetControlTitleWithCFString( m_controlHandle
, wxCFStringRef( label
, wxFont::GetDefaultEncoding() );
1566 InstallControlEventHandler(
1567 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1568 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1570 tool
->SetControlHandle( controlHandle
);
1574 case wxTOOL_STYLE_CONTROL
:
1576 #if wxMAC_USE_NATIVE_TOOLBAR
1577 if (m_macHIToolbarRef
!= NULL
)
1579 wxCHECK_MSG( tool
->GetControl(), false, _T("control must be non-NULL") );
1580 HIToolbarItemRef item
;
1581 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
1582 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1583 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1588 tool
->SetToolbarItemRef( item
);
1598 // right now there's nothing to do here
1608 if ( controlHandle
)
1610 ControlRef container
= (ControlRef
) GetHandle();
1611 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1613 SetControlVisibility( controlHandle
, true, true );
1614 ::EmbedControl( controlHandle
, container
);
1617 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1618 tool
->UpdateToggleImage( true );
1620 // nothing special to do here - we relayout in Realize() later
1621 InvalidateBestSize();
1625 wxFAIL_MSG( wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
) );
1628 return (err
== noErr
);
1631 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1633 wxFAIL_MSG( wxT("not implemented") );
1636 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1638 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1639 wxToolBarToolsList::compatibility_iterator node
;
1640 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1642 wxToolBarToolBase
*tool2
= node
->GetData();
1643 if ( tool2
== tool
)
1645 // let node point to the next node in the list
1646 node
= node
->GetNext();
1652 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1654 #if wxMAC_USE_NATIVE_TOOLBAR
1655 CFIndex removeIndex
= tool
->GetIndex();
1658 #if wxMAC_USE_NATIVE_TOOLBAR
1659 if (m_macHIToolbarRef
!= NULL
)
1661 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1663 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1664 tool
->SetIndex( -1 );
1669 tool
->ClearControl();
1671 // and finally reposition all the controls after this one
1673 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1675 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1676 wxPoint pt
= tool2
->GetPosition();
1678 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1683 tool2
->SetPosition( pt
);
1685 #if wxMAC_USE_NATIVE_TOOLBAR
1686 if (m_macHIToolbarRef
!= NULL
)
1688 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1689 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1694 InvalidateBestSize();
1699 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1701 #if wxMAC_USE_NATIVE_TOOLBAR
1702 if ( m_macUsesNativeToolbar
)
1714 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1716 if ( !drawMetalTheme
)
1718 HIThemePlacardDrawInfo info
;
1719 memset( &info
, 0, sizeof(info
) );
1721 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1723 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1724 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1725 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1729 // leave the background as it is (striped or metal)
1735 #endif // wxUSE_TOOLBAR