+ wxToolBarTool *tool = wx_static_cast( wxToolBarTool*, toolBase );
+ if (tool == NULL)
+ return false;
+
+ WindowRef window = (WindowRef) MacGetTopLevelWindowRef();
+ wxSize toolSize = GetToolSize();
+ Rect toolrect = { 0, 0, toolSize.y, toolSize.x };
+ ControlRef controlHandle = NULL;
+ OSStatus err = 0;
+ tool->Attach( this );
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ wxString label = tool->GetLabel();
+ if (m_macHIToolbarRef && !label.empty() )
+ {
+ // strip mnemonics from the label for compatibility
+ // with the usual labels in wxStaticText sense
+ label = wxStripMenuCodes(label);
+ }
+#endif // wxMAC_USE_NATIVE_TOOLBAR
+
+ switch (tool->GetStyle())
+ {
+ case wxTOOL_STYLE_SEPARATOR:
+ {
+ wxASSERT( tool->GetControlHandle() == NULL );
+ toolSize.x /= 4;
+ toolSize.y /= 4;
+ if ( GetWindowStyleFlag() & wxTB_VERTICAL )
+ toolrect.bottom = toolSize.y;
+ else
+ toolrect.right = toolSize.x;
+
+ // in flat style we need a visual separator
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if (m_macHIToolbarRef != NULL)
+ {
+ HIToolbarItemRef item;
+ err = HIToolbarItemCreate(
+ kHIToolbarSeparatorIdentifier,
+ kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
+ &item );
+ if (err == noErr)
+ tool->SetToolbarItemRef( item );
+ }
+ else
+ err = noErr;
+#endif // wxMAC_USE_NATIVE_TOOLBAR
+
+ CreateSeparatorControl( window, &toolrect, &controlHandle );
+ tool->SetControlHandle( controlHandle );
+ }
+ break;
+
+ case wxTOOL_STYLE_BUTTON:
+ {
+ wxASSERT( tool->GetControlHandle() == NULL );
+ ControlButtonContentInfo info;
+ wxMacCreateBitmapButton( &info, tool->GetNormalBitmap() );
+
+ if ( UMAGetSystemVersion() >= 0x1000)
+ {
+ // contrary to the docs this control only works with iconrefs
+ ControlButtonContentInfo info;
+ wxMacCreateBitmapButton( &info, tool->GetNormalBitmap(), kControlContentIconRef );
+ CreateIconControl( window, &toolrect, &info, false, &controlHandle );
+ wxMacReleaseBitmapButton( &info );
+ }
+ else
+ {
+ SInt16 behaviour = kControlBehaviorOffsetContents;
+ if ( tool->CanBeToggled() )
+ behaviour |= kControlBehaviorToggles;
+ err = CreateBevelButtonControl( window,
+ &toolrect, CFSTR(""), kControlBevelButtonNormalBevel,
+ behaviour, &info, 0, 0, 0, &controlHandle );
+ }
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if (m_macHIToolbarRef != NULL)
+ {
+ HIToolbarItemRef item;
+ wxString labelStr = wxString::Format(wxT("%p"), tool);
+ err = HIToolbarItemCreate(
+ wxCFStringRef(labelStr, wxFont::GetDefaultEncoding()),
+ kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
+ if (err == noErr)
+ {
+ ControlButtonContentInfo info2;
+ wxMacCreateBitmapButton( &info2, tool->GetNormalBitmap(), kControlContentCGImageRef);
+
+ InstallEventHandler(
+ HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
+ GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
+ HIToolbarItemSetLabel( item, wxCFStringRef(label, GetFont().GetEncoding()) );
+ HIToolbarItemSetImage( item, info2.u.imageRef );
+ HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
+ tool->SetToolbarItemRef( item );
+
+ wxMacReleaseBitmapButton( &info2 );
+ }
+ }
+ else
+ err = noErr;
+#endif // wxMAC_USE_NATIVE_TOOLBAR
+
+ wxMacReleaseBitmapButton( &info );
+
+#if 0
+ SetBevelButtonTextPlacement( m_controlHandle, kControlBevelButtonPlaceBelowGraphic );
+ SetControlTitleWithCFString( m_controlHandle , wxCFStringRef( label, wxFont::GetDefaultEncoding() );
+#endif
+
+ InstallControlEventHandler(
+ (ControlRef) controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
+ GetEventTypeCount(eventList), eventList, tool, NULL );
+
+ tool->SetControlHandle( controlHandle );
+ }
+ break;
+
+ case wxTOOL_STYLE_CONTROL:
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if (m_macHIToolbarRef != NULL)
+ {
+ wxCHECK_MSG( tool->GetControl(), false, _T("control must be non-NULL") );
+ HIToolbarItemRef item;
+ HIViewRef viewRef = (HIViewRef) tool->GetControl()->GetHandle() ;
+ CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ;
+ err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macHIToolbarRef,kControlToolbarItemClassID,
+ data , &item ) ;
+
+ if (err == noErr)
+ {
+ tool->SetToolbarItemRef( item );
+ }
+ CFRelease( data ) ;
+ }
+ else
+ {
+ err = noErr;
+ break;
+ }
+#else
+ // right now there's nothing to do here
+#endif
+ break;
+
+ default:
+ break;
+ }
+
+ if ( err == noErr )
+ {
+ if ( controlHandle )
+ {
+ ControlRef container = (ControlRef) GetHandle();
+ wxASSERT_MSG( container != NULL, wxT("No valid Mac container control") );