]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/toolbar.cpp
adding reference to technote
[wxWidgets.git] / src / mac / carbon / toolbar.cpp
index 88c664f9bc84e1ba57372c37ca088199dffbe020..f7bcdf598c404befb24f386612c9ce45d9fe8b8e 100644 (file)
@@ -66,7 +66,8 @@ END_EVENT_TABLE()
 // when this view is removed from the native toolbar its count gets decremented again
 // and when the HITooolbarItem wrapper object gets destroyed it is decremented as well
 // so in the end the control lives with a refcount of one and can be disposed of by the
-// wxControl code
+// wxControl code. For embedded controls on a non-native toolbar this ref count is less
+// so we can only test against a range, not a specific value of the refcount.
 
 class wxToolBarTool : public wxToolBarToolBase
 {
@@ -607,6 +608,7 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
 
                         item = (ControlToolbarItem*) malloc(sizeof(ControlToolbarItem)) ;
                         item->toolbarItem = toolbarItem ;
+                        item->lastValidSize = wxSize(-1,-1);
                         item->viewRef = NULL ;
 
                         SetEventParameter( inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof( void * ), &item );
@@ -641,7 +643,6 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
                 case kEventHIObjectDestruct:
                     {
                         HIViewRef viewRef = object->viewRef ;
-                        wxASSERT( IsValidControlHandle(viewRef) ) ;
                         if( viewRef && IsValidControlHandle( viewRef)  )
                         {
                             // depending whether the wxControl corresponding to this HIView has already been destroyed or
@@ -681,16 +682,21 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
                     wxWindow* wxwindow = wxFindControlFromMacControl(object->viewRef ) ;
                     if ( wxwindow )
                     {
-                        wxSize sz = wxwindow->GetSize() ;
-                        sz.x -= wxwindow->MacGetLeftBorderSize() + wxwindow->MacGetRightBorderSize();
-                        sz.y -= wxwindow->MacGetTopBorderSize() + wxwindow->MacGetBottomBorderSize();
-                        // during toolbar layout the native window sometimes gets negative sizes
-                        // so we always keep the last valid size here, to make sure we survive the
-                        // shuffle ...
-                        if ( sz.x > 0 && sz.y > 0 )
-                            object->lastValidSize = sz ;
-                        else
-                            sz = object->lastValidSize ;
+                        // during toolbar layout the native window sometimes gets negative sizes,
+                        // sometimes it just gets shrunk behind our back, so in order to avoid
+                        // ever shrinking more, once a valid size is captured, we keep it
+
+                        wxSize sz = object->lastValidSize;
+                        if ( sz.x <= 0 || sz.y <= 0 )
+                        {
+                            sz = wxwindow->GetSize() ;
+                            sz.x -= wxwindow->MacGetLeftBorderSize() + wxwindow->MacGetRightBorderSize();
+                            sz.y -= wxwindow->MacGetTopBorderSize() + wxwindow->MacGetBottomBorderSize();
+                            if ( sz.x > 0 && sz.y > 0 )
+                                object->lastValidSize = sz ;
+                            else
+                                sz = wxSize(0,0) ;
+                        }
 
                         HISize min, max;
                         min.width = max.width = sz.x ;
@@ -1186,7 +1192,7 @@ bool wxToolBar::Realize()
                                 if ( tool2->IsControl() )
                                 {
                                     CFIndex count = CFGetRetainCount( tool2->GetControl()->GetPeer()->GetControlRef() ) ;
-                                    wxASSERT_MSG( count == 3 , wxT("Reference Count of native tool was not 3 before removal") );
+                                    wxASSERT_MSG( count == 3 || count == 2 , wxT("Reference Count of native tool was illegal before removal") );
                                     wxASSERT( IsValidControlHandle(tool2->GetControl()->GetPeer()->GetControlRef() )) ;
                                 }
                                 err = HIToolbarRemoveItemAtIndex(refTB, idx);
@@ -1217,7 +1223,7 @@ bool wxToolBar::Realize()
                     if ( tool->IsControl() )
                     {
                         CFIndex count = CFGetRetainCount( tool->GetControl()->GetPeer()->GetControlRef() ) ;
-                        wxASSERT_MSG( count == 3 , wxT("Reference Count of native tool was not 3 after insertion") );
+                        wxASSERT_MSG( count == 3 || count == 2, wxT("Reference Count of native tool was illegal after insertion") );
                         wxASSERT( IsValidControlHandle(tool->GetControl()->GetPeer()->GetControlRef() )) ;
                     }
                 }