+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 ;
+#if !TARGET_API_MAC_OSX
+ 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 ) ;
+ }
+}
+
+const short kwxMacToolBarToolDefaultWidth = 24 ;
+const short kwxMacToolBarToolDefaultHeight = 22 ;
+const short kwxMacToolBarTopMargin = 2 ;
+const short kwxMacToolBarLeftMargin = 2 ;
+
+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();
+
+ if (id == wxID_SEPARATOR) return;
+
+ WindowRef window = (WindowRef) tbar->MacGetTopLevelWindowRef() ;
+ wxSize toolSize = tbar->GetToolSize() ;
+ Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ;
+
+ ControlButtonContentInfo info ;
+ wxMacCreateBitmapButton( &info , GetNormalBitmap() ) ;
+
+ SInt16 behaviour = kControlBehaviorOffsetContents ;
+ if ( CanBeToggled() )
+ behaviour += kControlBehaviorToggles ;
+
+ CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
+ 0 , 0 , 0 , &m_controlHandle ) ;
+
+ InstallControlEventHandler( (ControlRef) m_controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
+ GetEventTypeCount(eventList), eventList, this,NULL);
+
+ UMAShowControl( m_controlHandle ) ;
+
+ if ( CanBeToggled() && IsToggled() )
+ ::SetControl32BitValue( m_controlHandle , 1 ) ;
+ else
+ ::SetControl32BitValue( m_controlHandle , 0 ) ;
+
+ ControlRef container = (ControlRef) tbar->GetHandle() ;
+ wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
+ ::EmbedControl( m_controlHandle , container ) ;
+}
+