+ ::MoveControl( m_controlHandle, mac_x, mac_y );
+ }
+ }
+ else if ( IsControl() )
+ {
+ // embedded native controls are moved by the OS
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if ( ((wxToolBar*)GetToolBar())->MacWantsNativeToolbar() == false )
+#endif
+ {
+ GetControl()->Move( position );
+ }
+ }
+ else
+ {
+ // separator
+ 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 )
+ ::MoveControl( m_controlHandle, mac_x, mac_y );
+ }
+}
+
+void wxToolBarTool::UpdateToggleImage( bool toggle )
+{
+ if ( toggle )
+ {
+ int w = m_bmpNormal.GetWidth();
+ int h = m_bmpNormal.GetHeight();
+ wxBitmap bmp( w, h );
+ wxMemoryDC dc;
+
+ dc.SelectObject( bmp );
+ dc.SetPen( wxPen(*wxBLACK) );
+ dc.SetBrush( wxBrush( *wxLIGHT_GREY ));
+ 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 );
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if (m_toolbarItemRef != NULL)
+ {
+ ControlButtonContentInfo info2;
+ wxMacCreateBitmapButton( &info2, bmp, kControlContentCGImageRef);
+ HIToolbarItemSetImage( m_toolbarItemRef, info2.u.imageRef );
+ wxMacReleaseBitmapButton( &info2 );
+ }
+#endif
+ wxMacReleaseBitmapButton( &info );
+ }
+ else
+ {
+ ControlButtonContentInfo info;
+ wxMacCreateBitmapButton( &info, m_bmpNormal );
+ SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info );
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if (m_toolbarItemRef != NULL)
+ {
+ ControlButtonContentInfo info2;
+ wxMacCreateBitmapButton( &info2, m_bmpNormal, kControlContentCGImageRef);
+ HIToolbarItemSetImage( m_toolbarItemRef, info2.u.imageRef );
+ wxMacReleaseBitmapButton( &info2 );
+ }
+#endif
+ wxMacReleaseBitmapButton( &info );
+ }
+
+ IconTransformType transform = toggle ? kTransformSelected : kTransformNone;
+ SetControlData(
+ m_controlHandle, 0, kControlIconTransformTag,
+ sizeof(transform), (Ptr)&transform );
+ HIViewSetNeedsDisplay( m_controlHandle, true );
+
+}
+
+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();
+}
+
+#pragma mark -
+#pragma mark Toolbar Implementation
+
+wxToolBarToolBase *wxToolBar::CreateTool(
+ int id,
+ const wxString& label,
+ const wxBitmap& bmpNormal,
+ const wxBitmap& bmpDisabled,
+ wxItemKind kind,
+ wxObject *clientData,
+ const wxString& shortHelp,
+ const wxString& longHelp )
+{
+ return new wxToolBarTool(
+ this, id, label, bmpNormal, bmpDisabled, kind,
+ clientData, shortHelp, longHelp );
+}
+
+wxToolBarToolBase *
+wxToolBar::CreateTool(wxControl *control, const wxString& label)
+{
+ return new wxToolBarTool(this, control, label);
+}
+
+void wxToolBar::Init()
+{
+ m_maxWidth = -1;
+ m_maxHeight = -1;
+ m_defaultWidth = kwxMacToolBarToolDefaultWidth;
+ m_defaultHeight = kwxMacToolBarToolDefaultHeight;
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ m_macHIToolbarRef = NULL;
+ m_macUsesNativeToolbar = false;
+#endif
+}
+
+#define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
+
+const EventTypeSpec kEvents[] =
+{
+ { kEventClassHIObject, kEventHIObjectConstruct },
+ { kEventClassHIObject, kEventHIObjectInitialize },
+ { kEventClassHIObject, kEventHIObjectDestruct },
+
+ { kEventClassToolbarItem, kEventToolbarItemCreateCustomView }
+};
+
+const EventTypeSpec kViewEvents[] =
+{
+ { kEventClassControl, kEventControlGetSizeConstraints }
+};
+
+struct ControlToolbarItem
+{
+ HIToolbarItemRef toolbarItem;
+ HIViewRef viewRef;
+ wxSize lastValidSize ;
+};
+
+static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
+{
+ OSStatus result = eventNotHandledErr;
+ ControlToolbarItem* object = (ControlToolbarItem*)inUserData;
+
+ switch ( GetEventClass( inEvent ) )
+ {
+ case kEventClassHIObject:
+ switch ( GetEventKind( inEvent ) )