#include "wx/wx.h"
#endif
+#include "wx/app.h"
#include "wx/mac/uma.h"
#include "wx/geometry.h"
{
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
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 ) );
}
}
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)
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)
// 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;
#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;
Rect toolrect = { 0, 0, toolSize.y, toolSize.x };
ControlRef controlHandle = NULL;
OSStatus err = 0;
+ tool->Attach( this );
switch (tool->GetStyle())
{
tool->UpdateToggleImage( true );
// nothing special to do here - we relayout in Realize() later
- tool->Attach( this );
InvalidateBestSize();
}
else