From 9d5ccdd3263d210ccc3b728e7b3f9680577b74df Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 8 Sep 2006 08:46:05 +0000 Subject: [PATCH] fixing ownership and positioning of embedded controls in native toolbars git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41065 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/toolbar.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 6292291bdb..73667cb7e7 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -106,7 +106,12 @@ public: m_control = NULL; if ( m_controlHandle ) { - DisposeControl( m_controlHandle ); + if ( !IsControl() ) + DisposeControl( m_controlHandle ); + else + { + // the embedded control is not under the responsibility of the tool + } m_controlHandle = NULL ; } @@ -407,7 +412,13 @@ void wxToolBarTool::SetPosition( const wxPoint& position ) } else if ( IsControl() ) { - GetControl()->Move( position ); + // embedded native controls are moved by the OS +#if wxMAC_USE_NATIVE_TOOLBAR + if ( ((wxToolBar*)GetToolBar())->MacWantsNativeToolbar() == false ) +#endif + { + GetControl()->Move( position ); + } } else { @@ -728,7 +739,8 @@ static const EventTypeSpec kToolbarEvents[] = static OSStatus ToolbarDelegateHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData ) { OSStatus result = eventNotHandledErr; - wxToolBar* toolbar = (wxToolBar*) inUserData ; + // Not yet needed + // wxToolBar* toolbar = (wxToolBar*) inUserData ; CFMutableArrayRef array; switch ( GetEventKind( inEvent ) ) @@ -1444,6 +1456,9 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) wxASSERT( tool->GetControl() != NULL ); HIToolbarItemRef item; HIViewRef viewRef = (HIViewRef) tool->GetControl()->GetHandle() ; + // as this control now is part of both the wxToolBar children and the native toolbar, we have to increase the + // reference count to make sure we are not dealing with zombie controls after the native toolbar has released its views + CFRetain( viewRef ) ; CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ; err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macHIToolbarRef,kControlToolbarItemClassID, data , &item ) ; -- 2.45.2