+void wxToolBar::SetToolBitmapSize(const wxSize& size)
+{
+ m_defaultWidth = size.x + kwxMacToolBorder;
+ m_defaultHeight = size.y + kwxMacToolBorder;
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if (m_macHIToolbarRef != NULL)
+ {
+ int maxs = wxMax( size.x, size.y );
+ HIToolbarDisplaySize sizeSpec;
+ if ( maxs > 32 )
+ sizeSpec = kHIToolbarDisplaySizeNormal;
+ else if ( maxs > 24 )
+ sizeSpec = kHIToolbarDisplaySizeDefault;
+ else
+ sizeSpec = kHIToolbarDisplaySizeSmall;
+
+ HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, sizeSpec );
+ }
+#endif
+}
+
+// The button size is bigger than the bitmap size
+wxSize wxToolBar::GetToolSize() const
+{
+ return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
+}
+
+void wxToolBar::SetRows(int nRows)
+{
+ // avoid resizing the frame uselessly
+ if ( nRows != m_maxRows )
+ m_maxRows = nRows;
+}
+
+void wxToolBar::MacSuperChangedPosition()
+{
+ wxWindow::MacSuperChangedPosition();
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if (! m_macUsesNativeToolbar )
+ Realize();
+#else
+
+ Realize();
+#endif
+}
+
+wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
+{
+ wxToolBarTool *tool;
+ wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
+ while ( node != NULL )
+ {
+ tool = (wxToolBarTool *)node->GetData();
+ if (tool != NULL)
+ {
+ wxRect2DInt r( tool->GetPosition(), tool->GetSize() );
+ if ( r.Contains( wxPoint( x, y ) ) )
+ return tool;
+ }
+
+ node = node->GetNext();
+ }
+
+ return (wxToolBarToolBase*)NULL;
+}
+
+wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
+{
+ wxToolBarToolBase *tool = FindToolForPosition( pt.x, pt.y );
+ if ( tool != NULL )
+ return tool->GetShortHelp();
+
+ return wxEmptyString;
+}
+
+void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
+{
+ if ( t != NULL )
+ ((wxToolBarTool*)t)->DoEnable( enable );
+}
+
+void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
+{
+ wxToolBarTool *tool = (wxToolBarTool *)t;
+ if ( ( tool != NULL ) && tool->IsButton() )
+ tool->UpdateToggleImage( toggle );
+}
+
+bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
+{
+ 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 );
+ wxASSERT_MSG( false, errMsg.c_str() );
+ }
+
+ return (err == noErr);
+}
+
+void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
+{
+ wxFAIL_MSG( wxT("not implemented") );
+}
+
+bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
+{
+ wxToolBarTool* tool = wx_static_cast( wxToolBarTool*, toolbase );
+ wxToolBarToolsList::compatibility_iterator node;
+ for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
+ {
+ wxToolBarToolBase *tool2 = node->GetData();
+ if ( tool2 == tool )
+ {
+ // let node point to the next node in the list
+ node = node->GetNext();
+
+ break;
+ }
+ }
+
+ wxSize sz = ((wxToolBarTool*)tool)->GetSize();
+
+ tool->Detach();
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ CFIndex removeIndex = tool->GetIndex();
+#endif
+
+ switch ( tool->GetStyle() )
+ {
+ case wxTOOL_STYLE_CONTROL:
+ {
+ tool->GetControl()->Destroy();
+ tool->ClearControl();
+ }
+ break;
+
+ case wxTOOL_STYLE_BUTTON:
+ case wxTOOL_STYLE_SEPARATOR:
+ if ( tool->GetControlHandle() )
+ {
+ DisposeControl( (ControlRef) tool->GetControlHandle() );
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if ( removeIndex != -1 && m_macHIToolbarRef )
+ {
+ HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex );
+ tool->SetIndex( -1 );
+ }
+#endif
+
+ tool->ClearControl();
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ // and finally reposition all the controls after this one
+
+ for ( /* node -> first after deleted */; node; node = node->GetNext() )
+ {
+ wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
+ wxPoint pt = tool2->GetPosition();
+
+ if ( GetWindowStyleFlag() & wxTB_VERTICAL )
+ pt.y -= sz.y;
+ else
+ pt.x -= sz.x;
+
+ tool2->SetPosition( pt );
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if ( removeIndex != -1 && tool2->GetIndex() > removeIndex )
+ tool2->SetIndex( tool2->GetIndex() - 1 );
+#endif
+ }