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 )
125 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
127 wxTheApp
->MacAddToAutorelease(m_toolbarItemRef
);
128 CFRelease(m_toolbarItemRef
);
129 m_toolbarItemRef
= NULL
;
134 wxSize
GetSize() const
140 curSize
= GetControl()->GetSize();
142 else if ( IsButton() )
144 curSize
= GetToolBar()->GetToolSize();
149 curSize
= GetToolBar()->GetToolSize();
150 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
159 wxPoint
GetPosition() const
161 return wxPoint( m_x
, m_y
);
164 bool DoEnable( bool enable
);
166 void UpdateToggleImage( bool toggle
);
168 #if wxMAC_USE_NATIVE_TOOLBAR
169 void SetToolbarItemRef( HIToolbarItemRef ref
)
171 if ( m_controlHandle
)
172 HideControl( m_controlHandle
);
173 if ( m_toolbarItemRef
)
174 CFRelease( m_toolbarItemRef
);
176 m_toolbarItemRef
= ref
;
177 if ( m_toolbarItemRef
)
182 f
= GetToolBar()->GetFont();
184 enc
= f
.GetEncoding();
186 enc
= wxFont::GetDefaultEncoding();
188 HIToolbarItemSetHelpText(
190 wxCFStringRef( GetShortHelp(), enc
),
191 wxCFStringRef( GetLongHelp(), enc
) );
195 HIToolbarItemRef
GetToolbarItemRef() const
197 return m_toolbarItemRef
;
200 void SetIndex( CFIndex idx
)
205 CFIndex
GetIndex() const
214 m_controlHandle
= NULL
;
216 #if wxMAC_USE_NATIVE_TOOLBAR
217 m_toolbarItemRef
= NULL
;
222 ControlRef m_controlHandle
;
226 #if wxMAC_USE_NATIVE_TOOLBAR
227 HIToolbarItemRef m_toolbarItemRef
;
228 // position in its toolbar, -1 means not inserted
233 static const EventTypeSpec eventList
[] =
235 { kEventClassControl
, kEventControlHit
},
236 { kEventClassControl
, kEventControlHitTest
},
239 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
241 OSStatus result
= eventNotHandledErr
;
242 ControlRef controlRef
;
243 wxMacCarbonEvent
cEvent( event
);
245 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
247 switch ( GetEventKind( event
) )
249 case kEventControlHit
:
251 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
252 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
253 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
257 shouldToggle
= !tbartool
->IsToggled();
259 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
262 if (tbartool
!= NULL
)
263 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
268 case kEventControlHitTest
:
270 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
272 HIViewGetBounds( controlRef
, &rect
);
274 ControlPartCode pc
= kControlNoPart
;
275 if ( CGRectContainsPoint( rect
, pt
) )
276 pc
= kControlIconPart
;
277 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
289 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
291 OSStatus result
= eventNotHandledErr
;
293 switch ( GetEventClass( event
) )
295 case kEventClassControl
:
296 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
306 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
308 #if wxMAC_USE_NATIVE_TOOLBAR
310 static const EventTypeSpec toolBarEventList
[] =
312 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
315 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef
WXUNUSED(handler
), EventRef event
, void *data
)
317 OSStatus result
= eventNotHandledErr
;
319 switch ( GetEventKind( event
) )
321 case kEventToolbarItemPerformAction
:
323 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
324 if ( tbartool
!= NULL
)
326 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
327 int toolID
= tbartool
->GetId();
329 if ( tbartool
->CanBeToggled() )
332 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
336 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
349 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
351 OSStatus result
= eventNotHandledErr
;
353 switch ( GetEventClass( event
) )
355 case kEventClassToolbarItem
:
356 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
366 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
370 bool wxToolBarTool::DoEnable( bool enable
)
374 GetControl()->Enable( enable
);
376 else if ( IsButton() )
378 #if wxMAC_USE_NATIVE_TOOLBAR
379 if ( m_toolbarItemRef
!= NULL
)
380 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
383 if ( m_controlHandle
!= NULL
)
386 EnableControl( m_controlHandle
);
388 DisableControl( m_controlHandle
);
395 void wxToolBarTool::SetPosition( const wxPoint
& position
)
400 int mac_x
= position
.x
;
401 int mac_y
= position
.y
;
406 GetControlBounds( m_controlHandle
, &contrlRect
);
407 int former_mac_x
= contrlRect
.left
;
408 int former_mac_y
= contrlRect
.top
;
409 GetToolBar()->GetToolSize();
411 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
413 ::MoveControl( m_controlHandle
, mac_x
, mac_y
);
416 else if ( IsControl() )
418 // embedded native controls are moved by the OS
419 #if wxMAC_USE_NATIVE_TOOLBAR
420 if ( ((wxToolBar
*)GetToolBar())->MacWantsNativeToolbar() == false )
423 GetControl()->Move( position
);
430 GetControlBounds( m_controlHandle
, &contrlRect
);
431 int former_mac_x
= contrlRect
.left
;
432 int former_mac_y
= contrlRect
.top
;
434 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
435 ::MoveControl( m_controlHandle
, mac_x
, mac_y
);
439 void wxToolBarTool::UpdateToggleImage( bool toggle
)
443 int w
= m_bmpNormal
.GetWidth();
444 int h
= m_bmpNormal
.GetHeight();
445 wxBitmap
bmp( w
, h
);
448 dc
.SelectObject( bmp
);
449 dc
.SetPen( wxPen(*wxBLACK
) );
450 dc
.SetBrush( wxBrush( *wxLIGHT_GREY
));
451 dc
.DrawRectangle( 0, 0, w
, h
);
452 dc
.DrawBitmap( m_bmpNormal
, 0, 0, true );
453 dc
.SelectObject( wxNullBitmap
);
454 ControlButtonContentInfo info
;
455 wxMacCreateBitmapButton( &info
, bmp
);
456 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
457 #if wxMAC_USE_NATIVE_TOOLBAR
458 if (m_toolbarItemRef
!= NULL
)
460 ControlButtonContentInfo info2
;
461 wxMacCreateBitmapButton( &info2
, bmp
, kControlContentCGImageRef
);
462 HIToolbarItemSetImage( m_toolbarItemRef
, info2
.u
.imageRef
);
463 wxMacReleaseBitmapButton( &info2
);
466 wxMacReleaseBitmapButton( &info
);
470 ControlButtonContentInfo info
;
471 wxMacCreateBitmapButton( &info
, m_bmpNormal
);
472 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
473 #if wxMAC_USE_NATIVE_TOOLBAR
474 if (m_toolbarItemRef
!= NULL
)
476 ControlButtonContentInfo info2
;
477 wxMacCreateBitmapButton( &info2
, m_bmpNormal
, kControlContentCGImageRef
);
478 HIToolbarItemSetImage( m_toolbarItemRef
, info2
.u
.imageRef
);
479 wxMacReleaseBitmapButton( &info2
);
482 wxMacReleaseBitmapButton( &info
);
485 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
487 m_controlHandle
, 0, kControlIconTransformTag
,
488 sizeof(transform
), (Ptr
)&transform
);
489 HIViewSetNeedsDisplay( m_controlHandle
, true );
493 wxToolBarTool::wxToolBarTool(
496 const wxString
& label
,
497 const wxBitmap
& bmpNormal
,
498 const wxBitmap
& bmpDisabled
,
500 wxObject
*clientData
,
501 const wxString
& shortHelp
,
502 const wxString
& longHelp
)
505 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
506 clientData
, shortHelp
, longHelp
)
512 #pragma mark Toolbar Implementation
514 wxToolBarToolBase
*wxToolBar::CreateTool(
516 const wxString
& label
,
517 const wxBitmap
& bmpNormal
,
518 const wxBitmap
& bmpDisabled
,
520 wxObject
*clientData
,
521 const wxString
& shortHelp
,
522 const wxString
& longHelp
)
524 return new wxToolBarTool(
525 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
526 clientData
, shortHelp
, longHelp
);
530 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
532 return new wxToolBarTool(this, control
, label
);
535 void wxToolBar::Init()
539 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
540 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
542 #if wxMAC_USE_NATIVE_TOOLBAR
543 m_macHIToolbarRef
= NULL
;
544 m_macUsesNativeToolbar
= false;
548 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
550 const EventTypeSpec kEvents
[] =
552 { kEventClassHIObject
, kEventHIObjectConstruct
},
553 { kEventClassHIObject
, kEventHIObjectInitialize
},
554 { kEventClassHIObject
, kEventHIObjectDestruct
},
556 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
559 const EventTypeSpec kViewEvents
[] =
561 { kEventClassControl
, kEventControlGetSizeConstraints
}
564 struct ControlToolbarItem
566 HIToolbarItemRef toolbarItem
;
568 wxSize lastValidSize
;
571 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
573 OSStatus result
= eventNotHandledErr
;
574 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
576 switch ( GetEventClass( inEvent
) )
578 case kEventClassHIObject
:
579 switch ( GetEventKind( inEvent
) )
581 case kEventHIObjectConstruct
:
583 HIObjectRef toolbarItem
;
584 ControlToolbarItem
* item
;
586 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
587 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
589 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
590 item
->toolbarItem
= toolbarItem
;
591 item
->lastValidSize
= wxSize(-1,-1);
592 item
->viewRef
= NULL
;
594 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
600 case kEventHIObjectInitialize
:
601 result
= CallNextEventHandler( inCallRef
, inEvent
);
602 if ( result
== noErr
)
605 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
606 sizeof( CFTypeRef
), NULL
, &data
);
610 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
611 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
613 object
->viewRef
= (HIViewRef
) viewRef
;
614 // make sure we keep that control during our lifetime
615 CFRetain( object
->viewRef
) ;
617 verify_noerr(InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
618 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
));
623 case kEventHIObjectDestruct
:
625 HIViewRef viewRef
= object
->viewRef
;
626 if( viewRef
&& IsValidControlHandle( viewRef
) )
628 // depending whether the wxControl corresponding to this HIView has already been destroyed or
629 // not, ref counts differ, so we cannot assert a special value
630 CFIndex count
= CFGetRetainCount( viewRef
) ;
631 wxASSERT_MSG( count
>=1 , wxT("Reference Count of native tool was illegal before removal") );
633 CFRelease( viewRef
) ;
642 case kEventClassToolbarItem
:
643 switch ( GetEventKind( inEvent
) )
645 case kEventToolbarItemCreateCustomView
:
647 HIViewRef viewRef
= object
->viewRef
;
648 HIViewRemoveFromSuperview( viewRef
) ;
649 HIViewSetVisible(viewRef
, true) ;
650 CFRetain( viewRef
) ;
651 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
657 case kEventClassControl
:
658 switch ( GetEventKind( inEvent
) )
660 case kEventControlGetSizeConstraints
:
662 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
665 // during toolbar layout the native window sometimes gets negative sizes,
666 // sometimes it just gets shrunk behind our back, so in order to avoid
667 // ever shrinking more, once a valid size is captured, we keep it
669 wxSize sz
= object
->lastValidSize
;
670 if ( sz
.x
<= 0 || sz
.y
<= 0 )
672 sz
= wxwindow
->GetSize() ;
673 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
674 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
675 if ( sz
.x
> 0 && sz
.y
> 0 )
676 object
->lastValidSize
= sz
;
681 // Extra width to avoid edge of combobox being cut off
685 min
.width
= max
.width
= sz
.x
;
686 min
.height
= max
.height
= sz
.y
;
688 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
689 sizeof( HISize
), &min
);
691 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
692 sizeof( HISize
), &max
);
704 void RegisterControlToolbarItemClass()
706 static bool sRegistered
;
710 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
711 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
717 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
719 RegisterControlToolbarItemClass();
723 UInt32 options
= kHIToolbarItemAllowDuplicates
;
724 HIToolbarItemRef result
= NULL
;
726 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
727 require_noerr( err
, CantCreateEvent
);
729 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
730 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
733 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
735 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
738 ReleaseEvent( event
);
743 #if wxMAC_USE_NATIVE_TOOLBAR
744 static const EventTypeSpec kToolbarEvents
[] =
746 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
747 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
748 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
751 static OSStatus
ToolbarDelegateHandler(EventHandlerCallRef
WXUNUSED(inCallRef
),
753 void* WXUNUSED(inUserData
))
755 OSStatus result
= eventNotHandledErr
;
757 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
758 CFMutableArrayRef array
;
760 switch ( GetEventKind( inEvent
) )
762 case kEventToolbarGetDefaultIdentifiers
:
764 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
765 sizeof( CFMutableArrayRef
), NULL
, &array
);
766 // not implemented yet
767 // GetToolbarDefaultItems( array );
772 case kEventToolbarGetAllowedIdentifiers
:
774 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
775 sizeof( CFMutableArrayRef
), NULL
, &array
);
776 // not implemented yet
777 // GetToolbarAllowedItems( array );
781 case kEventToolbarCreateItemWithIdentifier
:
783 HIToolbarItemRef item
= NULL
;
784 CFTypeRef data
= NULL
;
785 CFStringRef identifier
= NULL
;
787 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
788 sizeof( CFStringRef
), NULL
, &identifier
);
790 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
791 sizeof( CFTypeRef
), NULL
, &data
);
793 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
795 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
798 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
799 sizeof( HIToolbarItemRef
), &item
);
809 #endif // wxMAC_USE_NATIVE_TOOLBAR
811 // also for the toolbar we have the dual implementation:
812 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
814 bool wxToolBar::Create(
820 const wxString
& name
)
822 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
827 OSStatus err
= noErr
;
829 #if wxMAC_USE_NATIVE_TOOLBAR
830 if (parent
->IsKindOf(CLASSINFO(wxFrame
)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1)
832 wxString labelStr
= wxString::Format( wxT("%p"), this );
833 err
= HIToolbarCreate(
834 wxCFStringRef( labelStr
, wxFont::GetDefaultEncoding() ), 0,
835 (HIToolbarRef
*) &m_macHIToolbarRef
);
837 if (m_macHIToolbarRef
!= NULL
)
839 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
840 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
842 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
843 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
845 if ( style
& wxTB_NOICONS
)
846 mode
= kHIToolbarDisplayModeLabelOnly
;
847 else if ( style
& wxTB_TEXT
)
848 mode
= kHIToolbarDisplayModeIconAndLabel
;
850 mode
= kHIToolbarDisplayModeIconOnly
;
852 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
853 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
856 #endif // wxMAC_USE_NATIVE_TOOLBAR
858 return (err
== noErr
);
861 wxToolBar::~wxToolBar()
863 #if wxMAC_USE_NATIVE_TOOLBAR
864 if (m_macHIToolbarRef
!= NULL
)
866 // if this is the installed toolbar, then deinstall it
867 if (m_macUsesNativeToolbar
)
868 MacInstallNativeToolbar( false );
870 CFIndex count
= CFGetRetainCount( m_macHIToolbarRef
) ;
871 // Leopard seems to have one refcount more, so we cannot check reliably at the moment
872 if ( UMAGetSystemVersion() < 0x1050 )
874 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
876 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
877 m_macHIToolbarRef
= NULL
;
882 bool wxToolBar::Show( bool show
)
884 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
885 bool bResult
= (tlw
!= NULL
);
889 #if wxMAC_USE_NATIVE_TOOLBAR
890 bool ownToolbarInstalled
= false;
891 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
892 if (ownToolbarInstalled
)
894 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
896 ShowHideWindowToolbar( tlw
, show
, false );
899 bResult
= wxToolBarBase::Show( show
);
902 bResult
= wxToolBarBase::Show( show
);
909 bool wxToolBar::IsShown() const
913 #if wxMAC_USE_NATIVE_TOOLBAR
914 bool ownToolbarInstalled
;
916 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
917 if (ownToolbarInstalled
)
919 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
920 bResult
= IsWindowToolbarVisible( tlw
);
923 bResult
= wxToolBarBase::IsShown();
926 bResult
= wxToolBarBase::IsShown();
932 void wxToolBar::DoGetSize( int *width
, int *height
) const
934 #if wxMAC_USE_NATIVE_TOOLBAR
936 bool ownToolbarInstalled
;
938 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
939 if ( ownToolbarInstalled
)
941 // TODO: is this really a control ?
942 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
944 *width
= boundsR
.right
- boundsR
.left
;
945 if ( height
!= NULL
)
946 *height
= boundsR
.bottom
- boundsR
.top
;
949 wxToolBarBase::DoGetSize( width
, height
);
952 wxToolBarBase::DoGetSize( width
, height
);
956 wxSize
wxToolBar::DoGetBestSize() const
960 DoGetSize( &width
, &height
);
962 return wxSize( width
, height
);
965 void wxToolBar::SetWindowStyleFlag( long style
)
967 wxToolBarBase::SetWindowStyleFlag( style
);
969 #if wxMAC_USE_NATIVE_TOOLBAR
970 if (m_macHIToolbarRef
!= NULL
)
972 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
974 if ( style
& wxTB_NOICONS
)
975 mode
= kHIToolbarDisplayModeLabelOnly
;
976 else if ( style
& wxTB_TEXT
)
977 mode
= kHIToolbarDisplayModeIconAndLabel
;
979 mode
= kHIToolbarDisplayModeIconOnly
;
981 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
986 #if wxMAC_USE_NATIVE_TOOLBAR
987 bool wxToolBar::MacWantsNativeToolbar()
989 return m_macUsesNativeToolbar
;
992 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
994 bool bResultV
= false;
996 if (ownToolbarInstalled
!= NULL
)
997 *ownToolbarInstalled
= false;
999 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1002 HIToolbarRef curToolbarRef
= NULL
;
1003 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1004 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
1005 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
1006 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
1012 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
1014 bool bResult
= false;
1016 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
1019 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
1022 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1026 // check the existing toolbar
1027 HIToolbarRef curToolbarRef
= NULL
;
1028 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1030 curToolbarRef
= NULL
;
1032 m_macUsesNativeToolbar
= usesNative
;
1034 if (m_macUsesNativeToolbar
)
1036 // only install toolbar if there isn't one installed already
1037 if (curToolbarRef
== NULL
)
1041 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1042 ShowHideWindowToolbar( tlw
, true, false );
1043 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1044 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1046 Rect r
= { 0, 0, 0, 0 };
1047 m_peer
->SetRect( &r
);
1048 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1049 m_peer
->SetVisibility( false, true );
1050 wxToolBarBase::Show( false );
1055 // only deinstall toolbar if this is the installed one
1056 if (m_macHIToolbarRef
== curToolbarRef
)
1060 ShowHideWindowToolbar( tlw
, false, false );
1061 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1062 SetWindowToolbar( tlw
, NULL
);
1064 m_peer
->SetVisibility( true, true );
1069 InvalidateBestSize();
1071 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1076 bool wxToolBar::Realize()
1078 if (m_tools
.GetCount() == 0)
1084 int maxToolWidth
= 0;
1085 int maxToolHeight
= 0;
1087 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1088 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1091 GetSize( &tw
, &th
);
1093 // find the maximum tool width and height
1094 wxToolBarTool
*tool
;
1095 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1098 tool
= (wxToolBarTool
*) node
->GetData();
1101 wxSize sz
= tool
->GetSize();
1103 if ( sz
.x
> maxToolWidth
)
1104 maxToolWidth
= sz
.x
;
1105 if ( sz
.y
> maxToolHeight
)
1106 maxToolHeight
= sz
.y
;
1109 node
= node
->GetNext();
1112 bool lastIsRadio
= false;
1113 bool curIsRadio
= false;
1115 #if wxMAC_USE_NATIVE_TOOLBAR
1116 CFIndex currentPosition
= 0;
1117 bool insertAll
= false;
1119 HIToolbarRef refTB
= (HIToolbarRef
)m_macHIToolbarRef
;
1122 node
= m_tools
.GetFirst();
1125 tool
= (wxToolBarTool
*) node
->GetData();
1128 node
= node
->GetNext();
1132 // set tool position:
1133 // for the moment just perform a single row/column alignment
1134 wxSize cursize
= tool
->GetSize();
1135 if ( x
+ cursize
.x
> maxWidth
)
1136 maxWidth
= x
+ cursize
.x
;
1137 if ( y
+ cursize
.y
> maxHeight
)
1138 maxHeight
= y
+ cursize
.y
;
1140 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1142 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1143 tool
->SetPosition( wxPoint(x1
, y
) );
1147 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1148 tool
->SetPosition( wxPoint(x
, y1
) );
1151 // update the item positioning state
1152 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1153 y
+= cursize
.y
+ kwxMacToolSpacing
;
1155 x
+= cursize
.x
+ kwxMacToolSpacing
;
1157 #if wxMAC_USE_NATIVE_TOOLBAR
1158 // install in native HIToolbar
1161 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1162 if ( hiItemRef
!= NULL
)
1164 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1166 OSStatus err
= noErr
;
1171 // if this is the first tool that gets newly inserted or repositioned
1172 // first remove all 'old' tools from here to the right, because of this
1173 // all following tools will have to be reinserted (insertAll).
1174 for ( wxToolBarToolsList::compatibility_iterator node2
= m_tools
.GetLast();
1176 node2
= node2
->GetPrevious() )
1178 wxToolBarTool
*tool2
= (wxToolBarTool
*) node2
->GetData();
1180 const long idx
= tool2
->GetIndex();
1183 if ( tool2
->IsControl() )
1185 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1186 wxASSERT_MSG( count
== 3 || count
== 2 , wxT("Reference Count of native tool was illegal before removal") );
1187 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1189 err
= HIToolbarRemoveItemAtIndex(refTB
, idx
);
1192 wxLogDebug(wxT("HIToolbarRemoveItemAtIndex(%ld) failed [%ld]"),
1195 if ( tool2
->IsControl() )
1197 CFIndex count
= CFGetRetainCount( tool2
->GetControl()->GetPeer()->GetControlRef() ) ;
1198 wxASSERT_MSG( count
== 2 , wxT("Reference Count of native tool was not 2 after removal") );
1199 wxASSERT( IsValidControlHandle(tool2
->GetControl()->GetPeer()->GetControlRef() )) ;
1202 tool2
->SetIndex(-1);
1207 err
= HIToolbarInsertItemAtIndex( refTB
, hiItemRef
, currentPosition
);
1210 wxLogDebug( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1213 tool
->SetIndex( currentPosition
);
1214 if ( tool
->IsControl() )
1216 CFIndex count
= CFGetRetainCount( tool
->GetControl()->GetPeer()->GetControlRef() ) ;
1217 wxASSERT_MSG( count
== 3 || count
== 2, wxT("Reference Count of native tool was illegal after insertion") );
1218 wxASSERT( IsValidControlHandle(tool
->GetControl()->GetPeer()->GetControlRef() )) ;
1227 // update radio button (and group) state
1228 lastIsRadio
= curIsRadio
;
1229 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1233 if ( tool
->IsToggled() )
1234 DoToggleTool( tool
, true );
1240 if ( tool
->Toggle( true ) )
1242 DoToggleTool( tool
, true );
1245 else if ( tool
->IsToggled() )
1247 if ( tool
->IsToggled() )
1248 DoToggleTool( tool
, true );
1250 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1253 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1254 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1257 if ( toggleTool
->Toggle( false ) )
1258 DoToggleTool( toggleTool
, false );
1260 nodePrev
= nodePrev
->GetPrevious();
1265 node
= node
->GetNext();
1268 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1270 // if not set yet, only one row
1271 if ( m_maxRows
<= 0 )
1274 m_minWidth
= maxWidth
;
1276 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1277 m_minHeight
= m_maxHeight
= maxHeight
;
1281 // if not set yet, have one column
1282 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1283 SetRows( GetToolsCount() );
1285 m_minHeight
= maxHeight
;
1287 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1288 m_minWidth
= m_maxWidth
= maxWidth
;
1292 // FIXME: should this be OSX-only?
1294 bool wantNativeToolbar
, ownToolbarInstalled
;
1296 // attempt to install the native toolbar
1297 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1298 MacInstallNativeToolbar( wantNativeToolbar
);
1299 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1300 if (!ownToolbarInstalled
)
1302 SetSize( maxWidth
, maxHeight
);
1303 InvalidateBestSize();
1307 SetSize( maxWidth
, maxHeight
);
1308 InvalidateBestSize();
1316 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1318 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1319 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1321 #if wxMAC_USE_NATIVE_TOOLBAR
1322 if (m_macHIToolbarRef
!= NULL
)
1324 int maxs
= wxMax( size
.x
, size
.y
);
1325 HIToolbarDisplaySize sizeSpec
;
1327 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1328 else if ( maxs
> 24 )
1329 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1331 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1333 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1338 // The button size is bigger than the bitmap size
1339 wxSize
wxToolBar::GetToolSize() const
1341 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1344 void wxToolBar::SetRows(int nRows
)
1346 // avoid resizing the frame uselessly
1347 if ( nRows
!= m_maxRows
)
1351 void wxToolBar::MacSuperChangedPosition()
1353 wxWindow::MacSuperChangedPosition();
1355 #if wxMAC_USE_NATIVE_TOOLBAR
1356 if (! m_macUsesNativeToolbar
)
1364 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1366 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1369 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1371 tool
->SetNormalBitmap(bitmap
);
1373 // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
1374 tool
->UpdateToggleImage( tool
->CanBeToggled() && tool
->IsToggled() );
1378 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1380 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1383 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1385 tool
->SetDisabledBitmap(bitmap
);
1387 // TODO: what to do for this one?
1391 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1393 wxToolBarTool
*tool
;
1394 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1397 tool
= (wxToolBarTool
*)node
->GetData();
1400 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1401 if ( r
.Contains( wxPoint( x
, y
) ) )
1405 node
= node
->GetNext();
1408 return (wxToolBarToolBase
*)NULL
;
1411 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1413 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1415 return tool
->GetShortHelp();
1417 return wxEmptyString
;
1420 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1423 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1426 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1428 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1429 if ( ( tool
!= NULL
) && tool
->IsButton() )
1430 tool
->UpdateToggleImage( toggle
);
1433 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1435 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1439 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1440 wxSize toolSize
= GetToolSize();
1441 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1442 ControlRef controlHandle
= NULL
;
1444 tool
->Attach( this );
1446 #if wxMAC_USE_NATIVE_TOOLBAR
1447 wxString label
= tool
->GetLabel();
1448 if (m_macHIToolbarRef
&& !label
.empty() )
1450 // strip mnemonics from the label for compatibility
1451 // with the usual labels in wxStaticText sense
1452 label
= wxStripMenuCodes(label
);
1454 #endif // wxMAC_USE_NATIVE_TOOLBAR
1456 switch (tool
->GetStyle())
1458 case wxTOOL_STYLE_SEPARATOR
:
1460 wxASSERT( tool
->GetControlHandle() == NULL
);
1463 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1464 toolrect
.bottom
= toolSize
.y
;
1466 toolrect
.right
= toolSize
.x
;
1468 // in flat style we need a visual separator
1469 #if wxMAC_USE_NATIVE_TOOLBAR
1470 if (m_macHIToolbarRef
!= NULL
)
1472 HIToolbarItemRef item
;
1473 err
= HIToolbarItemCreate(
1474 kHIToolbarSeparatorIdentifier
,
1475 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1478 tool
->SetToolbarItemRef( item
);
1482 #endif // wxMAC_USE_NATIVE_TOOLBAR
1484 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1485 tool
->SetControlHandle( controlHandle
);
1489 case wxTOOL_STYLE_BUTTON
:
1491 wxASSERT( tool
->GetControlHandle() == NULL
);
1492 ControlButtonContentInfo info
;
1493 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap() );
1495 if ( UMAGetSystemVersion() >= 0x1000)
1497 // contrary to the docs this control only works with iconrefs
1498 ControlButtonContentInfo info
;
1499 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1500 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1501 wxMacReleaseBitmapButton( &info
);
1505 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1506 if ( tool
->CanBeToggled() )
1507 behaviour
|= kControlBehaviorToggles
;
1508 err
= CreateBevelButtonControl( window
,
1509 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1510 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1513 #if wxMAC_USE_NATIVE_TOOLBAR
1514 if (m_macHIToolbarRef
!= NULL
)
1516 HIToolbarItemRef item
;
1517 wxString labelStr
= wxString::Format(wxT("%p"), tool
);
1518 err
= HIToolbarItemCreate(
1519 wxCFStringRef(labelStr
, wxFont::GetDefaultEncoding()),
1520 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1523 ControlButtonContentInfo info2
;
1524 wxMacCreateBitmapButton( &info2
, tool
->GetNormalBitmap(), kControlContentCGImageRef
);
1526 InstallEventHandler(
1527 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1528 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1529 HIToolbarItemSetLabel( item
, wxCFStringRef(label
, GetFont().GetEncoding()) );
1530 HIToolbarItemSetImage( item
, info2
.u
.imageRef
);
1531 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1532 tool
->SetToolbarItemRef( item
);
1534 wxMacReleaseBitmapButton( &info2
);
1539 #endif // wxMAC_USE_NATIVE_TOOLBAR
1541 wxMacReleaseBitmapButton( &info
);
1544 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1545 SetControlTitleWithCFString( m_controlHandle
, wxCFStringRef( label
, wxFont::GetDefaultEncoding() );
1548 InstallControlEventHandler(
1549 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1550 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1552 tool
->SetControlHandle( controlHandle
);
1556 case wxTOOL_STYLE_CONTROL
:
1558 #if wxMAC_USE_NATIVE_TOOLBAR
1559 if (m_macHIToolbarRef
!= NULL
)
1561 wxCHECK_MSG( tool
->GetControl(), false, _T("control must be non-NULL") );
1562 HIToolbarItemRef item
;
1563 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
1564 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1565 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1570 tool
->SetToolbarItemRef( item
);
1580 // right now there's nothing to do here
1590 if ( controlHandle
)
1592 ControlRef container
= (ControlRef
) GetHandle();
1593 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1595 SetControlVisibility( controlHandle
, true, true );
1596 ::EmbedControl( controlHandle
, container
);
1599 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1600 tool
->UpdateToggleImage( true );
1602 // nothing special to do here - we relayout in Realize() later
1603 InvalidateBestSize();
1607 wxFAIL_MSG( wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
) );
1610 return (err
== noErr
);
1613 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1615 wxFAIL_MSG( wxT("not implemented") );
1618 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1620 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1621 wxToolBarToolsList::compatibility_iterator node
;
1622 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1624 wxToolBarToolBase
*tool2
= node
->GetData();
1625 if ( tool2
== tool
)
1627 // let node point to the next node in the list
1628 node
= node
->GetNext();
1634 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1638 #if wxMAC_USE_NATIVE_TOOLBAR
1639 CFIndex removeIndex
= tool
->GetIndex();
1642 #if wxMAC_USE_NATIVE_TOOLBAR
1643 if (m_macHIToolbarRef
!= NULL
)
1645 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1647 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1648 tool
->SetIndex( -1 );
1652 switch ( tool
->GetStyle() )
1654 case wxTOOL_STYLE_CONTROL
:
1655 if ( tool
->GetControl() )
1656 tool
->GetControl()->Destroy();
1659 case wxTOOL_STYLE_BUTTON
:
1660 case wxTOOL_STYLE_SEPARATOR
:
1667 tool
->ClearControl();
1669 // and finally reposition all the controls after this one
1671 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1673 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1674 wxPoint pt
= tool2
->GetPosition();
1676 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1681 tool2
->SetPosition( pt
);
1683 #if wxMAC_USE_NATIVE_TOOLBAR
1684 if (m_macHIToolbarRef
!= NULL
)
1686 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1687 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1692 InvalidateBestSize();
1697 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1699 #if wxMAC_USE_NATIVE_TOOLBAR
1700 if ( m_macUsesNativeToolbar
)
1712 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1714 if ( !drawMetalTheme
)
1716 HIThemePlacardDrawInfo info
;
1717 memset( &info
, 0, sizeof(info
) );
1719 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1721 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1722 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1723 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1727 // leave the background as it is (striped or metal)
1733 #endif // wxUSE_TOOLBAR