X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/507d5748d644929440ccfa88ff6041f4cb1b847f..69ce77e25a8c6b3b1682b2f9ae7aeac1cecb4e6a:/src/mac/carbon/toolbar.cpp diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index d3fcb494ac..f65ba6d135 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -19,6 +19,7 @@ #include "wx/wx.h" #endif +#include "wx/app.h" #include "wx/mac/uma.h" #include "wx/geometry.h" @@ -115,7 +116,8 @@ public: { CFIndex count = CFGetRetainCount( m_toolbarItemRef ) ; wxASSERT_MSG( count == 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") ); - CFRelease( m_toolbarItemRef ); + wxTheApp->MacAddToAutorelease(m_toolbarItemRef); + CFRelease(m_toolbarItemRef); m_toolbarItemRef = NULL; } #endif @@ -166,10 +168,19 @@ public: m_toolbarItemRef = ref; if ( m_toolbarItemRef ) { + wxFont f; + wxFontEncoding enc; + if ( GetToolBar() ) + f = GetToolBar()->GetFont(); + if ( f.IsOk() ) + enc = f.GetEncoding(); + else + enc = wxFont::GetDefaultEncoding(); + HIToolbarItemSetHelpText( m_toolbarItemRef, - wxMacCFStringHolder( GetShortHelp(), GetToolBar()->GetFont().GetEncoding() ), - wxMacCFStringHolder( GetLongHelp(), GetToolBar()->GetFont().GetEncoding() ) ); + wxMacCFStringHolder( GetShortHelp(), enc ), + wxMacCFStringHolder( GetLongHelp(), enc ) ); } } @@ -451,7 +462,7 @@ void wxToolBarTool::UpdateToggleImage( bool toggle ) dc.DrawBitmap( m_bmpNormal, 0, 0, true ); dc.SelectObject( wxNullBitmap ); ControlButtonContentInfo info; - wxMacCreateBitmapButton( &info, bmp ); + wxMacCreateBitmapButton( &info, bmp, kControlContentIconRef ); SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info ); #if wxMAC_USE_NATIVE_TOOLBAR if (m_toolbarItemRef != NULL) @@ -464,7 +475,7 @@ void wxToolBarTool::UpdateToggleImage( bool toggle ) else { ControlButtonContentInfo info; - wxMacCreateBitmapButton( &info, m_bmpNormal ); + wxMacCreateBitmapButton( &info, m_bmpNormal, kControlContentIconRef ); SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info ); #if wxMAC_USE_NATIVE_TOOLBAR if (m_toolbarItemRef != NULL) @@ -615,9 +626,11 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, // we've increased the ref count when creating this, so we decrease manually again in case // it was never really installed and deinstalled HIViewRef viewRef = object->viewRef ; - if( viewRef && CFGetRetainCount( viewRef ) > 1 ) + if( viewRef && IsValidControlHandle( viewRef) ) { - CFRelease( viewRef ) ; + CFIndex count = CFGetRetainCount( viewRef ) ; + if ( count >= 1 ) + CFRelease( viewRef ) ; } free( object ) ; result = noErr; @@ -1308,6 +1321,33 @@ void wxToolBar::MacSuperChangedPosition() #endif } +void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) +{ + wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + if ( tool ) + { + wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); + + tool->SetNormalBitmap(bitmap); + + // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button. + tool->UpdateToggleImage( tool->CanBeToggled() && tool->IsToggled() ); + } +} + +void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) +{ + wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + if ( tool ) + { + wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); + + tool->SetDisabledBitmap(bitmap); + + // TODO: what to do for this one? + } +} + wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const { wxToolBarTool *tool; @@ -1361,6 +1401,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) Rect toolrect = { 0, 0, toolSize.y, toolSize.x }; ControlRef controlHandle = NULL; OSStatus err = 0; + tool->Attach( this ); switch (tool->GetStyle()) { @@ -1490,7 +1531,6 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) tool->UpdateToggleImage( true ); // nothing special to do here - we relayout in Realize() later - tool->Attach( this ); InvalidateBestSize(); } else