+bool wxToolBarTool::DoEnable(bool enable)
+{
+ if ( IsControl() )
+ {
+ GetControl()->Enable( enable ) ;
+ }
+ else if ( IsButton() )
+ {
+#if TARGET_API_MAC_OSX
+ if ( enable )
+ EnableControl( m_controlHandle ) ;
+ else
+ DisableControl( m_controlHandle ) ;
+#else
+ if ( enable )
+ ActivateControl( m_controlHandle ) ;
+ else
+ DeactivateControl( m_controlHandle ) ;
+#endif
+ }
+ return true ;
+}
+void wxToolBarTool::SetSize(const wxSize& size)
+{
+ if ( IsControl() )
+ {
+ GetControl()->SetSize( size ) ;
+ }
+}
+
+void wxToolBarTool::SetPosition(const wxPoint& position)
+{
+ m_x = position.x;
+ m_y = position.y;
+
+ if ( IsButton() )
+ {
+ int x , y ;
+ x = y = 0 ;
+ int mac_x = position.x ;
+ int mac_y = position.y ;
+#ifdef __WXMAC_OSX__
+ // already correctly set up
+#else
+ WindowRef rootwindow = (WindowRef) GetToolBar()->MacGetTopLevelWindowRef() ;
+ GetToolBar()->MacWindowToRootWindow( &x , &y ) ;
+ mac_x += x;
+ mac_y += y;
+#endif
+ Rect contrlRect ;
+ GetControlBounds( m_controlHandle , &contrlRect ) ;
+ int former_mac_x = contrlRect.left ;
+ int former_mac_y = contrlRect.top ;
+ GetToolBar()->GetToolSize() ;
+
+ if ( mac_x != former_mac_x || mac_y != former_mac_y )
+ {
+ UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
+ }
+ }
+ else if ( IsControl() )
+ {
+ GetControl()->Move( position ) ;
+ }
+ else
+ {
+ // separator
+#ifdef __WXMAC_OSX__
+ int x , y ;
+ x = y = 0 ;
+ int mac_x = position.x ;
+ int mac_y = position.y ;
+
+ Rect contrlRect ;
+ GetControlBounds( m_controlHandle , &contrlRect ) ;
+ int former_mac_x = contrlRect.left ;
+ int former_mac_y = contrlRect.top ;
+
+ if ( mac_x != former_mac_x || mac_y != former_mac_y )
+ {
+ UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
+ }
+#endif
+ }
+}
+
+void wxToolBarTool::UpdateToggleImage( bool toggle )
+{
+#ifdef __WXMAC_OSX__
+ if ( toggle )
+ {
+ int w = m_bmpNormal.GetWidth() ;
+ int h = m_bmpNormal.GetHeight() ;
+ wxBitmap bmp( w , h ) ;
+ wxMemoryDC dc ;
+ dc.SelectObject( bmp ) ;
+ dc.SetPen( wxNullPen ) ;
+ dc.SetBackground( *wxWHITE ) ;
+ dc.DrawRectangle( 0 , 0 , w , h ) ;
+ dc.DrawBitmap( m_bmpNormal , 0 , 0 , true) ;
+ dc.SelectObject( wxNullBitmap ) ;
+ ControlButtonContentInfo info ;
+ wxMacCreateBitmapButton( &info , bmp ) ;
+ SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
+ (Ptr)&info );
+ wxMacReleaseBitmapButton( &info ) ;
+ }
+ else
+ {
+ ControlButtonContentInfo info ;
+ wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
+ SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
+ (Ptr)&info );
+ wxMacReleaseBitmapButton( &info ) ;
+ }
+
+ IconTransformType transform = toggle ? kTransformSelected : kTransformNone ;
+ SetControlData( m_controlHandle, 0, kControlIconTransformTag, sizeof( transform ),
+ (Ptr)&transform );
+ HIViewSetNeedsDisplay( m_controlHandle , true ) ;
+
+#else
+ ::SetControl32BitValue( m_controlHandle , toggle ) ;
+#endif
+}
+
+wxToolBarTool::wxToolBarTool(wxToolBar *tbar,
+ int id,
+ const wxString& label,
+ const wxBitmap& bmpNormal,
+ const wxBitmap& bmpDisabled,
+ wxItemKind kind,
+ wxObject *clientData,
+ const wxString& shortHelp,
+ const wxString& longHelp)
+ : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
+ clientData, shortHelp, longHelp)
+{
+ Init();
+
+ WindowRef window = (WindowRef) tbar->MacGetTopLevelWindowRef() ;
+ wxSize toolSize = tbar->GetToolSize() ;
+ Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ;
+
+ if ( id == wxID_SEPARATOR )
+ {
+ toolSize.x /= 4 ;
+ toolSize.y /= 4 ;
+ if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
+ {
+ toolrect.bottom = toolSize.y ;
+ }
+ else
+ {
+ toolrect.right = toolSize.x ;
+ }
+#ifdef __WXMAC_OSX__
+ // in flat style we need a visual separator
+ CreateSeparatorControl( window , &toolrect , &m_controlHandle ) ;
+#endif
+ }
+ else
+ {
+ ControlButtonContentInfo info ;
+ wxMacCreateBitmapButton( &info , GetNormalBitmap() ) ;
+
+#ifdef __WXMAC_OSX__
+ CreateIconControl( window , &toolrect , &info , false , &m_controlHandle ) ;
+#else
+ SInt16 behaviour = kControlBehaviorOffsetContents ;
+ if ( CanBeToggled() )
+ behaviour += kControlBehaviorToggles ;
+ CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
+ 0 , 0 , 0 , &m_controlHandle ) ;
+#endif
+
+ wxMacReleaseBitmapButton( &info ) ;
+ /*
+ SetBevelButtonTextPlacement( m_controlHandle , kControlBevelButtonPlaceBelowGraphic ) ;
+ UMASetControlTitle( m_controlHandle , label , wxFont::GetDefaultEncoding() ) ;
+ */
+
+ InstallControlEventHandler( (ControlRef) m_controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
+ GetEventTypeCount(eventList), eventList, this,NULL);
+
+ }
+ ControlRef container = (ControlRef) tbar->GetHandle() ;
+ wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
+ if ( m_controlHandle )
+ {
+ UMAShowControl( m_controlHandle ) ;
+ ::EmbedControl( m_controlHandle , container ) ;
+ }
+ if ( CanBeToggled() && IsToggled() )
+ {
+ UpdateToggleImage( true ) ;
+ }
+}