From d5b971f94245b32e8e1a884d0076ca4f1696d09a Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 18 Oct 2017 13:43:07 +0200 Subject: use rtl::Reference in forms instead of manual reference counting Change-Id: I5bad5b7b83049f5c018a1f2d5bbc37f03727c3ce Reviewed-on: https://gerrit.libreoffice.org/43497 Tested-by: Jenkins Reviewed-by: Noel Grandin --- forms/source/richtext/richtextcontrol.cxx | 16 ++++++---------- forms/source/richtext/richtextcontrol.hxx | 4 +--- forms/source/solar/component/navbarcontrol.cxx | 15 ++++++--------- forms/source/solar/component/navbarcontrol.hxx | 4 +--- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/forms/source/richtext/richtextcontrol.cxx b/forms/source/richtext/richtextcontrol.cxx index fcf1c7ee3d79..ab662fa1d078 100644 --- a/forms/source/richtext/richtextcontrol.cxx +++ b/forms/source/richtext/richtextcontrol.cxx @@ -180,15 +180,12 @@ namespace frm // create the peer Reference< XControlModel > xModel( getModel() ); - ORichTextPeer* pPeer = ORichTextPeer::Create( xModel, pParentWin, getWinBits( xModel ) ); + rtl::Reference pPeer = ORichTextPeer::Create( xModel, pParentWin, getWinBits( xModel ) ); DBG_ASSERT( pPeer, "ORichTextControl::createPeer: invalid peer returned!" ); if ( pPeer ) { - // by definition, the returned component is acquired once - pPeer->release(); - // announce the peer to the base class - setPeer( pPeer ); + setPeer( pPeer.get() ); // initialize ourself (and thus the peer) with the model properties updateFromModel(); @@ -254,7 +251,7 @@ namespace frm } // ORichTextPeer - ORichTextPeer* ORichTextPeer::Create( const Reference< XControlModel >& _rxModel, vcl::Window* _pParentWindow, WinBits _nStyle ) + rtl::Reference ORichTextPeer::Create( const Reference< XControlModel >& _rxModel, vcl::Window* _pParentWindow, WinBits _nStyle ) { DBG_TESTSOLARMUTEX(); @@ -265,14 +262,13 @@ namespace frm return nullptr; // the peer itself - ORichTextPeer* pPeer = new ORichTextPeer; - pPeer->acquire(); // by definition, the returned object is acquired once + rtl::Reference pPeer(new ORichTextPeer); // the VCL control for the peer - VclPtrInstance pRichTextControl( pEngine, _pParentWindow, _nStyle, nullptr, pPeer ); + VclPtrInstance pRichTextControl( pEngine, _pParentWindow, _nStyle, nullptr, pPeer.get() ); // some knittings - pRichTextControl->SetComponentInterface( pPeer ); + pRichTextControl->SetComponentInterface( pPeer.get() ); // outta here return pPeer; diff --git a/forms/source/richtext/richtextcontrol.hxx b/forms/source/richtext/richtextcontrol.hxx index e19d68b08d8e..c48fa618da62 100644 --- a/forms/source/richtext/richtextcontrol.hxx +++ b/forms/source/richtext/richtextcontrol.hxx @@ -86,10 +86,8 @@ namespace frm public: /** factory method - @return - a new ORichTextPeer instance, which has been acquired once! */ - static ORichTextPeer* Create( + static rtl::Reference Create( const css::uno::Reference< css::awt::XControlModel >& _rxModel, vcl::Window* _pParentWindow, WinBits _nStyle diff --git a/forms/source/solar/component/navbarcontrol.cxx b/forms/source/solar/component/navbarcontrol.cxx index e6aca3a50d95..01b798808720 100644 --- a/forms/source/solar/component/navbarcontrol.cxx +++ b/forms/source/solar/component/navbarcontrol.cxx @@ -131,13 +131,11 @@ namespace frm } // create the peer - ONavigationBarPeer* pPeer = ONavigationBarPeer::Create( m_xContext, pParentWin, getModel() ); + rtl::Reference pPeer = ONavigationBarPeer::Create( m_xContext, pParentWin, getModel() ); assert(pPeer && "ONavigationBarControl::createPeer: invalid peer returned!"); - // by definition, the returned component is acquired once - pPeer->release(); // announce the peer to the base class - setPeer( pPeer ); + setPeer( pPeer.get() ); // initialize ourself (and thus the peer) with the model properties updateFromModel(); @@ -198,14 +196,13 @@ namespace frm // ONavigationBarPeer - ONavigationBarPeer* ONavigationBarPeer::Create( const Reference< XComponentContext >& _rxORB, + rtl::Reference ONavigationBarPeer::Create( const Reference< XComponentContext >& _rxORB, vcl::Window* _pParentWindow, const Reference< XControlModel >& _rxModel ) { DBG_TESTSOLARMUTEX(); // the peer itself - ONavigationBarPeer* pPeer = new ONavigationBarPeer( _rxORB ); - pPeer->acquire(); // by definition, the returned object is acquired once + rtl::Reference pPeer(new ONavigationBarPeer( _rxORB )); // the VCL control for the peer Reference< XModel > xContextDocument( getXModel( _rxModel ) ); @@ -220,8 +217,8 @@ namespace frm ); // some knittings - pNavBar->setDispatcher( pPeer ); - pNavBar->SetComponentInterface( pPeer ); + pNavBar->setDispatcher( pPeer.get() ); + pNavBar->SetComponentInterface( pPeer.get() ); // we want a faster repeating rate for the slots in this // toolbox diff --git a/forms/source/solar/component/navbarcontrol.hxx b/forms/source/solar/component/navbarcontrol.hxx index 22ebb3046b2b..4f2463e652e5 100644 --- a/forms/source/solar/component/navbarcontrol.hxx +++ b/forms/source/solar/component/navbarcontrol.hxx @@ -78,10 +78,8 @@ namespace frm { public: /** factory method - @return - a new ONavigationBarPeer instance, which has been acquired once! */ - static ONavigationBarPeer* Create( + static rtl::Reference Create( const css::uno::Reference< css::uno::XComponentContext >& _rxORB, vcl::Window* _pParentWindow, const css::uno::Reference< css::awt::XControlModel >& _rxModel -- cgit