]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/toolbar.cpp
fixed wxGetTranslation() prototype in the !wxUSE_INTL case
[wxWidgets.git] / src / mac / carbon / toolbar.cpp
index d1f29edb1a191514dc08dbebe5036a2ba30db419..60e0a5cf9fccc300778f7656699138b46a813daa 100644 (file)
@@ -19,6 +19,7 @@
     #include "wx/wx.h"
 #endif
 
+#include "wx/app.h"
 #include "wx/mac/uma.h"
 #include "wx/geometry.h"
 
@@ -82,11 +83,6 @@ public:
     virtual ~wxToolBarTool()
     {
         ClearControl();
-
-#if wxMAC_USE_NATIVE_TOOLBAR
-        if ( m_toolbarItemRef )
-            CFRelease( m_toolbarItemRef );
-#endif
     }
 
     WXWidget GetControlHandle()
@@ -116,7 +112,14 @@ public:
         }
 
 #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
     }
 
@@ -450,7 +453,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)
@@ -463,7 +466,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)
@@ -610,8 +613,19 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
                     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;
@@ -792,6 +806,8 @@ bool wxToolBar::Create(
     if ( !wxToolBarBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
         return false;
 
+    FixupStyle();
+
     OSStatus err = noErr;
 
 #if wxMAC_USE_NATIVE_TOOLBAR
@@ -832,6 +848,9 @@ wxToolBar::~wxToolBar()
         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;
     }
@@ -1240,7 +1259,7 @@ bool wxToolBar::Realize()
     InvalidateBestSize();
 #endif
 
-    SetBestFittingSize();
+    SetInitialSize();
 
     return true;
 }
@@ -1516,34 +1535,29 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
     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
 
@@ -1648,7 +1662,9 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
             drawInfo.kind = kThemeBackgroundMetal;
             HIThemeApplyBackground( &hiToolbarrect, &drawInfo, cgContext, kHIThemeOrientationNormal );
 
+#ifndef __LP64__
             QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
+#endif
 #endif
         }
     }