#include "wx/wx.h"
#endif
+#include "wx/app.h"
#include "wx/mac/uma.h"
#include "wx/geometry.h"
virtual ~wxToolBarTool()
{
ClearControl();
-
-#if wxMAC_USE_NATIVE_TOOLBAR
- if ( m_toolbarItemRef )
- CFRelease( m_toolbarItemRef );
-#endif
}
WXWidget GetControlHandle()
}
#if wxMAC_USE_NATIVE_TOOLBAR
- m_toolbarItemRef = NULL;
+ if ( m_toolbarItemRef )
+ {
+ CFIndex count = CFGetRetainCount( m_toolbarItemRef ) ;
+ wxASSERT_MSG( count == 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
+ wxTheApp->MacAddToAutorelease(m_toolbarItemRef);
+ CFRelease(m_toolbarItemRef);
+ m_toolbarItemRef = NULL;
+ }
#endif
}
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)
break;
case kEventHIObjectDestruct:
- free( object ) ;
- result = noErr;
+ {
+ // 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 && IsValidControlHandle( viewRef) )
+ {
+ CFIndex count = CFGetRetainCount( viewRef ) ;
+ if ( count >= 1 )
+ CFRelease( viewRef ) ;
+ }
+ free( object ) ;
+ result = noErr;
+ }
break;
}
break;
if ( !wxToolBarBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
return false;
+ FixupStyle();
+
OSStatus err = noErr;
#if wxMAC_USE_NATIVE_TOOLBAR
if (m_macUsesNativeToolbar)
MacInstallNativeToolbar( false );
+ CFIndex count = CFGetRetainCount( m_macHIToolbarRef ) ;
+ wxASSERT_MSG( count == 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
+
CFRelease( (HIToolbarRef)m_macHIToolbarRef );
m_macHIToolbarRef = NULL;
}
InvalidateBestSize();
#endif
- SetBestFittingSize();
+ SetInitialSize();
return true;
}
CFIndex removeIndex = tool->GetIndex();
#endif
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if ( removeIndex != -1 && m_macHIToolbarRef )
+ {
+ HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex );
+ tool->SetIndex( -1 );
+ }
+#endif
switch ( tool->GetStyle() )
{
case wxTOOL_STYLE_CONTROL:
- {
+ if ( tool->GetControl() )
tool->GetControl()->Destroy();
- tool->ClearControl();
- }
break;
case wxTOOL_STYLE_BUTTON:
case wxTOOL_STYLE_SEPARATOR:
- if ( tool->GetControlHandle() )
- {
-#if wxMAC_USE_NATIVE_TOOLBAR
- if ( removeIndex != -1 && m_macHIToolbarRef )
- {
- HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex );
- tool->SetIndex( -1 );
- }
-#endif
-
- tool->ClearControl();
- }
+ // nothing special
break;
default:
break;
}
+ tool->ClearControl();
// and finally reposition all the controls after this one
drawInfo.kind = kThemeBackgroundMetal;
HIThemeApplyBackground( &hiToolbarrect, &drawInfo, cgContext, kHIThemeOrientationNormal );
+#ifndef __LP64__
QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
+#endif
#endif
}
}