+ 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;
+
+ 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;
+
+#ifdef __WXMAC_OSX__
+ // in flat style we need a visual separator
+#if wxMAC_USE_NATIVE_TOOLBAR
+ HIToolbarItemRef item;
+ err = HIToolbarItemCreate(
+ kHIToolbarSeparatorIdentifier,
+ kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
+ &item );
+ if (err == noErr)
+ tool->SetToolbarItemRef( item );
+#endif
+
+ CreateSeparatorControl( window, &toolrect, &controlHandle );
+ tool->SetControlHandle( controlHandle );
+#endif
+ }
+ break;
+
+ case wxTOOL_STYLE_BUTTON:
+ {
+ wxASSERT( tool->GetControlHandle() == NULL );
+ ControlButtonContentInfo info;
+ wxMacCreateBitmapButton( &info, tool->GetNormalBitmap(), kControlContentIconRef );
+
+ if ( UMAGetSystemVersion() >= 0x1000)
+ {
+ CreateIconControl( window, &toolrect, &info, false, &controlHandle );
+ }
+ 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
+ HIToolbarItemRef item;
+ wxString labelStr = wxString::Format(wxT("%xd"), (int)tool);
+ err = HIToolbarItemCreate(
+ wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
+ kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
+ if (err == noErr)
+ {
+ InstallEventHandler(
+ HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
+ GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
+ HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
+ HIToolbarItemSetIconRef( item, info.u.iconRef );
+ HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
+ tool->SetToolbarItemRef( item );
+ }
+#endif
+
+ wxMacReleaseBitmapButton( &info );
+
+#if 0
+ SetBevelButtonTextPlacement( m_controlHandle, kControlBevelButtonPlaceBelowGraphic );
+ UMASetControlTitle( m_controlHandle, label, wxFont::GetDefaultEncoding() );
+#endif
+
+ InstallControlEventHandler(
+ (ControlRef) controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
+ GetEventTypeCount(eventList), eventList, tool, NULL );
+
+ tool->SetControlHandle( controlHandle );
+ }
+ break;
+
+ case wxTOOL_STYLE_CONTROL:
+ wxASSERT( tool->GetControl() != NULL );
+
+#if 0 // wxMAC_USE_NATIVE_TOOLBAR
+ // FIXME: doesn't work yet...
+ {
+ HIToolbarItemRef item;
+ wxString labelStr = wxString::Format( wxT("%xd"), (int)tool );
+ result = HIToolbarItemCreate(
+ wxMacCFStringHolder( labelStr, wxFont::GetDefaultEncoding() ),
+ kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates,
+ &item );
+ if ( result == noErr )
+ {
+ HIToolbarItemSetLabel( item, wxMacCFStringHolder( tool->GetLabel(), m_font.GetEncoding() ) );
+ HIToolbarItemSetCommandID( item, tool->GetId() );
+ tool->SetToolbarItemRef( item );
+
+ controlHandle = ( ControlRef ) tool->GetControlHandle();
+ wxASSERT_MSG( controlHandle != NULL, wxT("NULL tool control") );
+
+ // FIXME: is this necessary ??
+ ::GetControlBounds( controlHandle, &toolrect );
+ UMAMoveControl( controlHandle, -toolrect.left, -toolrect.top );
+
+ // FIXME: is this necessary ??
+ InstallControlEventHandler(
+ controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
+ GetEventTypeCount(eventList), eventList, tool, NULL );
+ }
+ }
+
+#else
+ // FIXME: 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") );
+
+ UMAShowControl( controlHandle );
+ ::EmbedControl( controlHandle, container );
+ }
+
+ if ( tool->CanBeToggled() && tool->IsToggled() )
+ tool->UpdateToggleImage( true );
+
+ // nothing special to do here - we relayout in Realize() later
+ tool->Attach( this );
+ InvalidateBestSize();
+ }
+ else
+ {
+ wxString errMsg = wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err );
+ wxFAIL_MSG( errMsg.c_str() );
+ }