diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-16 11:40:16 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-16 13:39:33 +0200 |
commit | 32eb4d56a4ea93e7dbfd947b62e18f05d8215421 (patch) | |
tree | 4594949fcc3cc52878f63f491b9d9bc402975a3b /svx | |
parent | 0c44f702a04db0fffd6884dcb014b28cdff5b21c (diff) |
use rtl::Reference for SvXMLGraphicHelper
Change-Id: I0052b29660fb6157f7e98c4e124f030ba439d304
Reviewed-on: https://gerrit.libreoffice.org/43417
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/accessibility/svxrectctaccessiblecontext.cxx | 46 | ||||
-rw-r--r-- | svx/source/inc/svxrectctaccessiblecontext.hxx | 3 | ||||
-rw-r--r-- | svx/source/unodraw/unomod.cxx | 5 | ||||
-rw-r--r-- | svx/source/xml/xmlexport.cxx | 22 | ||||
-rw-r--r-- | svx/source/xml/xmlgrhlp.cxx | 28 | ||||
-rw-r--r-- | svx/source/xml/xmlxtexp.cxx | 17 | ||||
-rw-r--r-- | svx/source/xml/xmlxtimp.cxx | 18 |
7 files changed, 55 insertions, 84 deletions
diff --git a/svx/source/accessibility/svxrectctaccessiblecontext.cxx b/svx/source/accessibility/svxrectctaccessiblecontext.cxx index bc80c48efd79..7b2f9df5d44c 100644 --- a/svx/source/accessibility/svxrectctaccessiblecontext.cxx +++ b/svx/source/accessibility/svxrectctaccessiblecontext.cxx @@ -106,7 +106,6 @@ SvxRectCtlAccessibleContext::SvxRectCtlAccessibleContext( SvxRectCtlAccessibleContext_Base( m_aMutex ), mxParent( rxParent ), mpRepr( &rRepr ), - mpChildren( nullptr ), mnClientId( 0 ), mnSelectedChild( NOCHILDSELECTED ) { @@ -116,11 +115,7 @@ SvxRectCtlAccessibleContext::SvxRectCtlAccessibleContext( msDescription = SvxResId( RID_SVXSTR_RECTCTL_ACC_CORN_DESCR ); } - mpChildren = new SvxRectCtlChildAccessibleContext*[ MAX_NUM_OF_CHILDREN ]; - - SvxRectCtlChildAccessibleContext** p = mpChildren; - for( int i = MAX_NUM_OF_CHILDREN ; i ; --i, ++p ) - *p = nullptr; + mvChildren.resize(MAX_NUM_OF_CHILDREN); } @@ -211,7 +206,7 @@ Reference< XAccessible > SAL_CALL SvxRectCtlAccessibleContext::getAccessibleChil { checkChildIndex( nIndex ); - Reference< XAccessible > xChild = mpChildren[ nIndex ]; + Reference< XAccessible > xChild(mvChildren[ nIndex ].get()); if( !xChild.is() ) { ::SolarMutexGuard aSolarGuard; @@ -220,7 +215,7 @@ Reference< XAccessible > SAL_CALL SvxRectCtlAccessibleContext::getAccessibleChil ThrowExceptionIfNotAlive(); - xChild = mpChildren[ nIndex ]; + xChild = mvChildren[ nIndex ].get(); if( !xChild.is() ) { @@ -232,8 +227,8 @@ Reference< XAccessible > SAL_CALL SvxRectCtlAccessibleContext::getAccessibleChil SvxRectCtlChildAccessibleContext* pChild = new SvxRectCtlChildAccessibleContext( this, *mpRepr, aName, aDescr, aFocusRect, nIndex ); - xChild = mpChildren[ nIndex ] = pChild; - pChild->acquire(); + mvChildren[ nIndex ] = pChild; + xChild = pChild; // set actual state if( mnSelectedChild == nIndex ) @@ -522,11 +517,8 @@ void SvxRectCtlAccessibleContext::FireChildFocus( RectPoint eButton ) mnSelectedChild = nNew; if( nNew != NOCHILDSELECTED ) { - SvxRectCtlChildAccessibleContext* pChild = mpChildren[ nNew ]; - if( pChild ) - { - pChild->FireFocusEvent(); - } + if( mvChildren[ nNew ].is() ) + mvChildren[ nNew ]->FireFocusEvent(); } else { @@ -553,7 +545,7 @@ void SvxRectCtlAccessibleContext::selectChild( long nNew ) SvxRectCtlChildAccessibleContext* pChild; if( mnSelectedChild != NOCHILDSELECTED ) { // deselect old selected child if one is selected - pChild = mpChildren[ mnSelectedChild ]; + pChild = mvChildren[ mnSelectedChild ].get(); if( pChild ) pChild->setStateChecked( false ); } @@ -563,9 +555,8 @@ void SvxRectCtlAccessibleContext::selectChild( long nNew ) if( nNew != NOCHILDSELECTED ) { - pChild = mpChildren[ nNew ]; - if( pChild ) - pChild->setStateChecked( true ); + if( mvChildren[ nNew ].is() ) + mvChildren[ nNew ]->setStateChecked( true ); } } else @@ -587,20 +578,11 @@ void SAL_CALL SvxRectCtlAccessibleContext::disposing() ::osl::MutexGuard aGuard( m_aMutex ); mpRepr = nullptr; // object dies with representation - SvxRectCtlChildAccessibleContext** p = mpChildren; - for( int i = MAX_NUM_OF_CHILDREN ; i ; --i, ++p ) - { - SvxRectCtlChildAccessibleContext* pChild = *p; - if( pChild ) - { - pChild->dispose(); - pChild->release(); - *p = nullptr; - } - } + for (auto & rxChild : mvChildren) + if( rxChild.is() ) + rxChild->dispose(); - delete[] mpChildren; - mpChildren = nullptr; + mvChildren.clear(); } { diff --git a/svx/source/inc/svxrectctaccessiblecontext.hxx b/svx/source/inc/svxrectctaccessiblecontext.hxx index 5cfe6f87d288..96c2fe581914 100644 --- a/svx/source/inc/svxrectctaccessiblecontext.hxx +++ b/svx/source/inc/svxrectctaccessiblecontext.hxx @@ -46,6 +46,7 @@ #include <svx/rectenum.hxx> #include <vcl/vclptr.hxx> #include <tools/gen.hxx> +#include <vector> namespace com { namespace sun { namespace star { namespace awt { struct Point; @@ -256,7 +257,7 @@ private: VclPtr<SvxRectCtl> mpRepr; /// array for all possible children - SvxRectCtlChildAccessibleContext** mpChildren; + std::vector<rtl::Reference<SvxRectCtlChildAccessibleContext>> mvChildren; /// client id in the AccessibleEventNotifier queue sal_uInt32 mnClientId; diff --git a/svx/source/unodraw/unomod.cxx b/svx/source/unodraw/unomod.cxx index bcd80e1a6412..814c81cdc9b7 100644 --- a/svx/source/unodraw/unomod.cxx +++ b/svx/source/unodraw/unomod.cxx @@ -182,9 +182,8 @@ css::uno::Reference<css::uno::XInterface> create( } else if ( rServiceSpecifier == "com.sun.star.document.ImportGraphicObjectResolver" ) { - SvXMLGraphicHelper* pGraphicHelper = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Read ); - uno::Reference< uno::XInterface> xRet( static_cast< ::cppu::OWeakObject* >( pGraphicHelper ) ); - pGraphicHelper->release(); + rtl::Reference<SvXMLGraphicHelper> pGraphicHelper = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Read ); + uno::Reference< uno::XInterface> xRet( static_cast< ::cppu::OWeakObject* >( pGraphicHelper.get() ) ); return xRet; } diff --git a/svx/source/xml/xmlexport.cxx b/svx/source/xml/xmlexport.cxx index be47ff334b92..5af7d92cb36d 100644 --- a/svx/source/xml/xmlexport.cxx +++ b/svx/source/xml/xmlexport.cxx @@ -53,7 +53,7 @@ bool SvxDrawingLayerExport( SdrModel* pModel, const uno::Reference<io::XOutputSt bool bDocRet = xOut.is(); Reference< document::XGraphicObjectResolver > xGraphicResolver; - SvXMLGraphicHelper *pGraphicHelper = nullptr; + rtl::Reference<SvXMLGraphicHelper> xGraphicHelper; Reference< document::XEmbeddedObjectResolver > xObjectResolver; rtl::Reference<SvXMLEmbeddedObjectHelper> xObjectHelper; @@ -80,8 +80,8 @@ bool SvxDrawingLayerExport( SdrModel* pModel, const uno::Reference<io::XOutputSt xObjectResolver = xObjectHelper.get(); } - pGraphicHelper = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Write ); - xGraphicResolver = pGraphicHelper; + xGraphicHelper = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Write ); + xGraphicResolver = xGraphicHelper.get(); if( bDocRet ) { @@ -124,8 +124,9 @@ bool SvxDrawingLayerExport( SdrModel* pModel, const uno::Reference<io::XOutputSt bDocRet = false; } - if( pGraphicHelper ) - SvXMLGraphicHelper::Destroy( pGraphicHelper ); + if( xGraphicHelper ) + xGraphicHelper->dispose(); + xGraphicHelper.clear(); xGraphicResolver = nullptr; if( xObjectHelper.is() ) @@ -152,7 +153,7 @@ bool SvxDrawingLayerImport( SdrModel* pModel, const uno::Reference<io::XInputStr bool bRet = true; Reference< document::XGraphicObjectResolver > xGraphicResolver; - SvXMLGraphicHelper *pGraphicHelper = nullptr; + rtl::Reference<SvXMLGraphicHelper> xGraphicHelper; Reference< document::XEmbeddedObjectResolver > xObjectResolver; rtl::Reference<SvXMLEmbeddedObjectHelper> xObjectHelper; @@ -175,8 +176,8 @@ bool SvxDrawingLayerImport( SdrModel* pModel, const uno::Reference<io::XInputStr xTargetModel->lockControllers(); - pGraphicHelper = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Read ); - xGraphicResolver = pGraphicHelper; + xGraphicHelper = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Read ); + xGraphicResolver = xGraphicHelper.get(); ::comphelper::IEmbeddedHelper *pPersist = pModel->GetPersist(); if( pPersist ) @@ -226,8 +227,9 @@ bool SvxDrawingLayerImport( SdrModel* pModel, const uno::Reference<io::XInputStr DBG_UNHANDLED_EXCEPTION(); } - if( pGraphicHelper ) - SvXMLGraphicHelper::Destroy( pGraphicHelper ); + if( xGraphicHelper ) + xGraphicHelper->dispose(); + xGraphicHelper.clear(); xGraphicResolver = nullptr; if( xObjectHelper.is() ) diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index 1065fa4d6fea..171138e98050 100644 --- a/svx/source/xml/xmlgrhlp.cxx +++ b/svx/source/xml/xmlgrhlp.cxx @@ -773,37 +773,26 @@ void SvXMLGraphicHelper::Init( const uno::Reference < embed::XStorage >& rXMLSto mbDirect = meCreateMode != SvXMLGraphicHelperMode::Read || bDirect; } -SvXMLGraphicHelper* SvXMLGraphicHelper::Create( const uno::Reference < embed::XStorage >& rXMLStorage, +rtl::Reference<SvXMLGraphicHelper> SvXMLGraphicHelper::Create( const uno::Reference < embed::XStorage >& rXMLStorage, SvXMLGraphicHelperMode eCreateMode, bool bDirect ) { - SvXMLGraphicHelper* pThis = new SvXMLGraphicHelper; + rtl::Reference<SvXMLGraphicHelper> pThis = new SvXMLGraphicHelper; - pThis->acquire(); pThis->Init( rXMLStorage, eCreateMode, bDirect ); return pThis; } -SvXMLGraphicHelper* SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode eCreateMode ) +rtl::Reference<SvXMLGraphicHelper> SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode eCreateMode ) { - SvXMLGraphicHelper* pThis = new SvXMLGraphicHelper; + rtl::Reference<SvXMLGraphicHelper> pThis = new SvXMLGraphicHelper; - pThis->acquire(); pThis->Init( nullptr, eCreateMode, false ); return pThis; } -void SvXMLGraphicHelper::Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper ) -{ - if( pSvXMLGraphicHelper ) - { - pSvXMLGraphicHelper->dispose(); - pSvXMLGraphicHelper->release(); - } -} - // XGraphicObjectResolver OUString SAL_CALL SvXMLGraphicHelper::resolveGraphicObjectURL( const OUString& rURL ) { @@ -994,12 +983,9 @@ void SAL_CALL SvXMLGraphicImportExportHelper::initialize( if( aArguments.getLength() > 0 ) aArguments[0] >>= xStorage; - SvXMLGraphicHelper * pHelper( SvXMLGraphicHelper::Create( xStorage, m_eGraphicHelperMode )); - m_xGraphicObjectResolver.set( pHelper ); - m_xBinaryStreamResolver.set( pHelper ); - // SvXMLGraphicHelper::Create calls acquire. Since we have two references - // now it is safe (and necessary) to undo this acquire - pHelper->release(); + rtl::Reference<SvXMLGraphicHelper> pHelper( SvXMLGraphicHelper::Create( xStorage, m_eGraphicHelperMode )); + m_xGraphicObjectResolver.set( pHelper.get() ); + m_xBinaryStreamResolver.set( pHelper.get() ); } // ____ XGraphicObjectResolver ____ diff --git a/svx/source/xml/xmlxtexp.cxx b/svx/source/xml/xmlxtexp.cxx index 4bb2e7484709..645cc47ef175 100644 --- a/svx/source/xml/xmlxtexp.cxx +++ b/svx/source/xml/xmlxtexp.cxx @@ -177,14 +177,14 @@ static void initializeStreamMetadata( const uno::Reference< uno::XInterface > &x } static void createStorageStream( uno::Reference < io::XOutputStream > *xOut, - SvXMLGraphicHelper **ppGraphicHelper, + rtl::Reference<SvXMLGraphicHelper>& rxGraphicHelper, const uno::Reference < embed::XStorage >& xSubStorage ) { uno::Reference < io::XStream > xStream; xStream = xSubStorage->openStreamElement( "Content.xml", embed::ElementModes::WRITE ); - *ppGraphicHelper = SvXMLGraphicHelper::Create( xSubStorage, SvXMLGraphicHelperMode::Write ); + rxGraphicHelper = SvXMLGraphicHelper::Create( xSubStorage, SvXMLGraphicHelperMode::Write ); initializeStreamMetadata( xStream ); *xOut = xStream->getOutputStream(); } @@ -197,7 +197,7 @@ bool SvxXMLXTableExportComponent::save( { bool bRet = false; std::unique_ptr<SfxMedium> pMedium; - SvXMLGraphicHelper* pGraphicHelper = nullptr; + rtl::Reference<SvXMLGraphicHelper> xGraphicHelper; sal_Int32 eCreate = embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE; INetURLObject aURLObj( rURL ); @@ -271,22 +271,23 @@ bool SvxXMLXTableExportComponent::save( } if( !xOut.is() && xSubStorage.is() ) - createStorageStream( &xOut, &pGraphicHelper, xSubStorage ); + createStorageStream( &xOut, xGraphicHelper, xSubStorage ); if( !xOut.is() ) return false; uno::Reference<io::XActiveDataSource> xMetaSrc( xWriter, uno::UNO_QUERY ); xMetaSrc->setOutputStream( xOut ); - if( pGraphicHelper ) - xGrfResolver = pGraphicHelper; + if( xGraphicHelper.is() ) + xGrfResolver = xGraphicHelper.get(); // Finally do the export const OUString aName; rtl::Reference< SvxXMLXTableExportComponent > xExporter( new SvxXMLXTableExportComponent( xContext, aName, xHandler, xTable, xGrfResolver ) ); bRet = xExporter->exportTable(); - if( pGraphicHelper ) - SvXMLGraphicHelper::Destroy( pGraphicHelper ); + if( xGraphicHelper ) + xGraphicHelper->dispose(); + xGraphicHelper.clear(); if( xSubStorage.is() ) { diff --git a/svx/source/xml/xmlxtimp.cxx b/svx/source/xml/xmlxtimp.cxx index f69b54a0c775..937c544a085c 100644 --- a/svx/source/xml/xmlxtimp.cxx +++ b/svx/source/xml/xmlxtimp.cxx @@ -313,7 +313,7 @@ SvxXMLXTableImport::~SvxXMLXTableImport() throw () } static void openStorageStream( xml::sax::InputSource *pParserInput, - SvXMLGraphicHelper **ppGraphicHelper, + rtl::Reference<SvXMLGraphicHelper>& rxGraphicHelper, const uno::Reference < embed::XStorage >& xStorage ) { uno::Reference < io::XStream > xIStm; @@ -324,7 +324,7 @@ static void openStorageStream( xml::sax::InputSource *pParserInput, return; } pParserInput->aInputStream = xIStm->getInputStream(); - *ppGraphicHelper = SvXMLGraphicHelper::Create( xStorage, SvXMLGraphicHelperMode::Read ); + rxGraphicHelper = SvXMLGraphicHelper::Create( xStorage, SvXMLGraphicHelperMode::Read ); } bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer, @@ -333,7 +333,7 @@ bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer, bool *bOptLoadedFromStorage ) throw() { bool bRet = true; - SvXMLGraphicHelper* pGraphicHelper = nullptr; + rtl::Reference<SvXMLGraphicHelper> xGraphicHelper; INetURLObject aURLObj( rPath ); bool bUseStorage = aURLObj.GetProtocol() == INetProtocol::NotValid; // a relative path @@ -355,7 +355,7 @@ bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer, if( aMedium.IsStorage() ) { uno::Reference < embed::XStorage > xMediumStorage( aMedium.GetStorage( false ), uno::UNO_QUERY_THROW ); - openStorageStream( &aParserInput, &pGraphicHelper, xMediumStorage ); + openStorageStream( &aParserInput, xGraphicHelper, xMediumStorage ); } else aParserInput.aInputStream = aMedium.GetInputStream(); @@ -372,7 +372,7 @@ bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer, { } if( xSubStorage.is() ) - openStorageStream( &aParserInput, &pGraphicHelper, xSubStorage ); + openStorageStream( &aParserInput, xGraphicHelper, xSubStorage ); else { css::uno::Reference< css::io::XStream > xStream; @@ -387,8 +387,8 @@ bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer, } uno::Reference< XGraphicObjectResolver > xGrfResolver; - if (pGraphicHelper) - xGrfResolver = pGraphicHelper; + if (xGraphicHelper.is()) + xGrfResolver = xGraphicHelper.get(); try { @@ -403,8 +403,8 @@ bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer, xParser->setDocumentHandler( xHandler ); xParser->parseStream( aParserInput ); - if( pGraphicHelper ) - SvXMLGraphicHelper::Destroy( pGraphicHelper ); + if( xGraphicHelper ) + xGraphicHelper->dispose(); } catch (...) { |