[Libreoffice-commits] core.git: include/svx reportdesign/source sc/source sd/source svx/source sw/source

Noel Grandin noel.grandin at collabora.co.uk
Mon Oct 16 11:39:55 UTC 2017


 include/svx/xmlgrhlp.hxx                                |    6 --
 reportdesign/source/core/api/ReportDefinition.cxx       |   20 +++---
 sc/source/filter/xml/xmlwrap.cxx                        |   11 ++-
 sd/source/filter/xml/sdxmlwrp.cxx                       |   22 ++++---
 svx/source/accessibility/svxrectctaccessiblecontext.cxx |   46 ++++------------
 svx/source/inc/svxrectctaccessiblecontext.hxx           |    3 -
 svx/source/unodraw/unomod.cxx                           |    5 -
 svx/source/xml/xmlexport.cxx                            |   22 ++++---
 svx/source/xml/xmlgrhlp.cxx                             |   28 ++-------
 svx/source/xml/xmlxtexp.cxx                             |   17 +++--
 svx/source/xml/xmlxtimp.cxx                             |   18 +++---
 sw/source/filter/xml/swxml.cxx                          |   11 ++-
 sw/source/filter/xml/wrtxml.cxx                         |   11 ++-
 sw/source/filter/xml/xmlexp.cxx                         |   12 ++--
 sw/source/filter/xml/xmlimp.cxx                         |   11 +--
 sw/source/filter/xml/xmlimp.hxx                         |    3 -
 16 files changed, 109 insertions(+), 137 deletions(-)

New commits:
commit 32eb4d56a4ea93e7dbfd947b62e18f05d8215421
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Oct 16 11:40:16 2017 +0200

    use rtl::Reference for SvXMLGraphicHelper
    
    Change-Id: I0052b29660fb6157f7e98c4e124f030ba439d304
    Reviewed-on: https://gerrit.libreoffice.org/43417
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/xmlgrhlp.hxx b/include/svx/xmlgrhlp.hxx
index 70128ebb87f6..787cc0e4f95f 100644
--- a/include/svx/xmlgrhlp.hxx
+++ b/include/svx/xmlgrhlp.hxx
@@ -92,12 +92,10 @@ protected:
 public:
                                 SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode );
 
-    static SvXMLGraphicHelper*  Create( const css::uno::Reference < css::embed::XStorage >& rXMLStorage,
+    static rtl::Reference<SvXMLGraphicHelper> Create( const css::uno::Reference < css::embed::XStorage >& rXMLStorage,
                                         SvXMLGraphicHelperMode eCreateMode,
                                         bool bDirect = true );
-    static SvXMLGraphicHelper*  Create( SvXMLGraphicHelperMode eCreateMode );
-
-    static void                 Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper );
+    static rtl::Reference<SvXMLGraphicHelper> Create( SvXMLGraphicHelperMode eCreateMode );
 
 public:
 
diff --git a/reportdesign/source/core/api/ReportDefinition.cxx b/reportdesign/source/core/api/ReportDefinition.cxx
index d26f42962e44..d5be7e28e698 100644
--- a/reportdesign/source/core/api/ReportDefinition.cxx
+++ b/reportdesign/source/core/api/ReportDefinition.cxx
@@ -1335,11 +1335,11 @@ void SAL_CALL OReportDefinition::storeToStorage( const uno::Reference< embed::XS
     aDelegatorArguments.realloc(nArgsLen+1);
     aDelegatorArguments[nArgsLen++] <<= xInfoSet;
 
-     uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
-    uno::Reference< document::XGraphicObjectResolver >      xGrfResolver;
-    SvXMLGraphicHelper* pGraphicHelper = SvXMLGraphicHelper::Create(_xStorageToSaveTo,SvXMLGraphicHelperMode::Write);
-    xGrfResolver = pGraphicHelper;
-    pGraphicHelper->release();
+    uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
+    uno::Reference< document::XGraphicObjectResolver >  xGrfResolver;
+    rtl::Reference<SvXMLGraphicHelper> xGraphicHelper = SvXMLGraphicHelper::Create(_xStorageToSaveTo,SvXMLGraphicHelperMode::Write);
+    xGrfResolver = xGraphicHelper.get();
+    xGraphicHelper.clear();
     xObjectResolver = SvXMLEmbeddedObjectHelper::Create( _xStorageToSaveTo,*this, SvXMLEmbeddedObjectHelperMode::Write ).get();
 
     aDelegatorArguments.realloc(nArgsLen+2);
@@ -2126,16 +2126,14 @@ uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::createInstance( co
         return static_cast< ::cppu::OWeakObject* >(SvXMLEmbeddedObjectHelper::Create( m_pImpl->m_xStorage,*this, SvXMLEmbeddedObjectHelperMode::Write ).get());
     else if ( aServiceSpecifier == "com.sun.star.document.ImportGraphicObjectResolver" )
     {
-        SvXMLGraphicHelper* pGraphicHelper = SvXMLGraphicHelper::Create(m_pImpl->m_xStorage,SvXMLGraphicHelperMode::Write);
-        uno::Reference< uno::XInterface> xRet(static_cast< ::cppu::OWeakObject* >(pGraphicHelper));
-        pGraphicHelper->release();
+        rtl::Reference<SvXMLGraphicHelper> xGraphicHelper = SvXMLGraphicHelper::Create(m_pImpl->m_xStorage,SvXMLGraphicHelperMode::Write);
+        uno::Reference< uno::XInterface> xRet(static_cast< ::cppu::OWeakObject* >(xGraphicHelper.get()));
         return xRet;
     }
     else if ( aServiceSpecifier == "com.sun.star.document.ExportGraphicObjectResolver" )
     {
-        SvXMLGraphicHelper* pGraphicHelper = SvXMLGraphicHelper::Create(m_pImpl->m_xStorage,SvXMLGraphicHelperMode::Write);
-        uno::Reference< uno::XInterface> xRet(static_cast< ::cppu::OWeakObject* >(pGraphicHelper));
-        pGraphicHelper->release();
+        rtl::Reference<SvXMLGraphicHelper> xGraphicHelper = SvXMLGraphicHelper::Create(m_pImpl->m_xStorage,SvXMLGraphicHelperMode::Write);
+        uno::Reference< uno::XInterface> xRet(static_cast< ::cppu::OWeakObject* >(xGraphicHelper.get()));
         return xRet;
     }
     else if ( aServiceSpecifier == "com.sun.star.chart2.data.DataProvider" )
diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx
index 7e35690aed86..398f27e14ba8 100644
--- a/sc/source/filter/xml/xmlwrap.cxx
+++ b/sc/source/filter/xml/xmlwrap.cxx
@@ -867,12 +867,12 @@ bool ScXMLImportWrapper::Export(bool bStylesOnly)
         rtl::Reference<SvXMLEmbeddedObjectHelper> xObjectHelper;
 
         uno::Reference< document::XGraphicObjectResolver > xGrfContainer;
-        SvXMLGraphicHelper* pGraphicHelper = nullptr;
+        rtl::Reference<SvXMLGraphicHelper> xGraphicHelper;
 
         if( xStorage.is() )
         {
-            pGraphicHelper = SvXMLGraphicHelper::Create( xStorage, SvXMLGraphicHelperMode::Write, false );
-            xGrfContainer = pGraphicHelper;
+            xGraphicHelper = SvXMLGraphicHelper::Create( xStorage, SvXMLGraphicHelperMode::Write, false );
+            xGrfContainer = xGraphicHelper.get();
         }
 
         if( pObjSh )
@@ -928,8 +928,9 @@ bool ScXMLImportWrapper::Export(bool bStylesOnly)
             SAL_INFO( "sc.filter", "content export end" );
         }
 
-        if( pGraphicHelper )
-            SvXMLGraphicHelper::Destroy( pGraphicHelper );
+        if( xGraphicHelper )
+            xGraphicHelper->dispose();
+        xGraphicHelper.clear();
 
         if( xObjectHelper )
             xObjectHelper->dispose();
diff --git a/sd/source/filter/xml/sdxmlwrp.cxx b/sd/source/filter/xml/sdxmlwrp.cxx
index 00b61eb92859..efcb9ed9ccd0 100644
--- a/sd/source/filter/xml/sdxmlwrp.cxx
+++ b/sd/source/filter/xml/sdxmlwrp.cxx
@@ -507,7 +507,7 @@ bool SdXMLFilter::Import( ErrCode& nError )
     }
 
     Reference< document::XGraphicObjectResolver > xGraphicResolver;
-    SvXMLGraphicHelper *pGraphicHelper = nullptr;
+    rtl::Reference<SvXMLGraphicHelper> xGraphicHelper;
     Reference< document::XEmbeddedObjectResolver > xObjectResolver;
     rtl::Reference<SvXMLEmbeddedObjectHelper> xObjectHelper;
 
@@ -556,10 +556,10 @@ bool SdXMLFilter::Import( ErrCode& nError )
 
     if( ERRCODE_NONE == nRet )
     {
-        pGraphicHelper = SvXMLGraphicHelper::Create( xStorage,
+        xGraphicHelper = SvXMLGraphicHelper::Create( xStorage,
                                                      SvXMLGraphicHelperMode::Read,
                                                      false );
-        xGraphicResolver = pGraphicHelper;
+        xGraphicResolver = xGraphicHelper.get();
         xObjectHelper = SvXMLEmbeddedObjectHelper::Create(
                                     xStorage, *pDoc->GetPersist(),
                                     SvXMLEmbeddedObjectHelperMode::Read );
@@ -649,8 +649,9 @@ bool SdXMLFilter::Import( ErrCode& nError )
         }
     }
 
-    if( pGraphicHelper )
-        SvXMLGraphicHelper::Destroy( pGraphicHelper );
+    if( xGraphicHelper )
+        xGraphicHelper->dispose();
+    xGraphicHelper.clear();
     xGraphicResolver = nullptr;
     if( xObjectHelper.is() )
         xObjectHelper->dispose();
@@ -785,7 +786,7 @@ bool SdXMLFilter::Import( ErrCode& nError )
 bool SdXMLFilter::Export()
 {
     rtl::Reference<SvXMLEmbeddedObjectHelper> xObjectHelper;
-    SvXMLGraphicHelper*         pGraphicHelper = nullptr;
+    rtl::Reference<SvXMLGraphicHelper> xGraphicHelper;
     bool                    bDocRet = false;
 
     if( !mxModel.is() )
@@ -878,8 +879,8 @@ bool SdXMLFilter::Export()
                 xObjectHelper = SvXMLEmbeddedObjectHelper::Create( xStorage, *mrDocShell.GetDoc()->GetPersist(), SvXMLEmbeddedObjectHelperMode::Write );
                 xObjectResolver = xObjectHelper.get();
 
-                pGraphicHelper = SvXMLGraphicHelper::Create( xStorage, SvXMLGraphicHelperMode::Write, false );
-                xGrfResolver = pGraphicHelper;
+                xGraphicHelper = SvXMLGraphicHelper::Create( xStorage, SvXMLGraphicHelperMode::Write, false );
+                xGrfResolver = xGraphicHelper.get();
             }
 
             CreateStatusIndicator();
@@ -997,8 +998,9 @@ bool SdXMLFilter::Export()
     if ( !bLocked )
         mxModel->unlockControllers();
 
-    if( pGraphicHelper )
-        SvXMLGraphicHelper::Destroy( pGraphicHelper );
+    if( xGraphicHelper )
+        xGraphicHelper->dispose();
+    xGraphicHelper.clear();
 
     if( xObjectHelper )
         xObjectHelper->dispose();
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 (...)
     {
diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx
index 6ddeb64b8f3e..652e84ef5ab8 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -474,7 +474,7 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
             comphelper::getProcessComponentContext();
 
     uno::Reference< document::XGraphicObjectResolver > xGraphicResolver;
-    SvXMLGraphicHelper *pGraphicHelper = nullptr;
+    rtl::Reference<SvXMLGraphicHelper> xGraphicHelper;
     uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
     rtl::Reference<SvXMLEmbeddedObjectHelper> xObjectHelper;
 
@@ -488,10 +488,10 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
     if( !xStorage.is() )
         return ERR_SWG_READ_ERROR;
 
-    pGraphicHelper = SvXMLGraphicHelper::Create( xStorage,
+    xGraphicHelper = SvXMLGraphicHelper::Create( xStorage,
                                                  SvXMLGraphicHelperMode::Read,
                                                  false );
-    xGraphicResolver = pGraphicHelper;
+    xGraphicResolver = xGraphicHelper.get();
     SfxObjectShell *pPersist = rDoc.GetPersist();
     if( pPersist )
     {
@@ -888,8 +888,9 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
 
     lcl_EnsureValidPam( rPaM ); // move Pam into valid content
 
-    if( pGraphicHelper )
-        SvXMLGraphicHelper::Destroy( pGraphicHelper );
+    if( xGraphicHelper )
+        xGraphicHelper->dispose();
+    xGraphicHelper.clear();
     xGraphicResolver = nullptr;
     if( xObjectHelper )
         xObjectHelper->dispose();
diff --git a/sw/source/filter/xml/wrtxml.cxx b/sw/source/filter/xml/wrtxml.cxx
index e7469aec35dc..b0afdaf0baa1 100644
--- a/sw/source/filter/xml/wrtxml.cxx
+++ b/sw/source/filter/xml/wrtxml.cxx
@@ -80,15 +80,15 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS
     // Get data sink ...
     tools::SvRef<SotStorageStream> xDocStream;
     uno::Reference< document::XGraphicObjectResolver > xGraphicResolver;
-    SvXMLGraphicHelper *pGraphicHelper = nullptr;
+    rtl::Reference<SvXMLGraphicHelper> xGraphicHelper ;
     uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
     rtl::Reference<SvXMLEmbeddedObjectHelper> xObjectHelper;
 
     OSL_ENSURE( xStg.is(), "Where is my storage?" );
-    pGraphicHelper = SvXMLGraphicHelper::Create( xStg,
+    xGraphicHelper = SvXMLGraphicHelper::Create( xStg,
                                                  SvXMLGraphicHelperMode::Write,
                                                  false );
-    xGraphicResolver = pGraphicHelper;
+    xGraphicResolver = xGraphicHelper.get();
 
     SfxObjectShell *pPersist = pDoc->GetPersist();
     if( pPersist )
@@ -388,8 +388,9 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS
         }
     }
 
-    if( pGraphicHelper )
-        SvXMLGraphicHelper::Destroy( pGraphicHelper );
+    if( xGraphicHelper )
+        xGraphicHelper->dispose();
+    xGraphicHelper.clear();
     xGraphicResolver = nullptr;
 
     if( xObjectHelper )
diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx
index 7838281e699c..ac6fbe5f5f6a 100644
--- a/sw/source/filter/xml/xmlexp.cxx
+++ b/sw/source/filter/xml/xmlexp.cxx
@@ -238,12 +238,11 @@ ErrCode SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
     // we don't need it here.
     // else: keep default pClass that we received
 
-    SvXMLGraphicHelper *pGraphicResolver = nullptr;
+    rtl::Reference<SvXMLGraphicHelper> xGraphicResolver;
     if( !GetGraphicResolver().is() )
     {
-        pGraphicResolver = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Write );
-        Reference< XGraphicObjectResolver > xGraphicResolver( pGraphicResolver );
-        SetGraphicResolver( xGraphicResolver );
+        xGraphicResolver = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Write );
+        SetGraphicResolver( xGraphicResolver.get() );
     }
 
     rtl::Reference<SvXMLEmbeddedObjectHelper> xEmbeddedResolver;
@@ -293,8 +292,9 @@ ErrCode SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
       pDoc->getIDocumentRedlineAccess().SetRedlineFlags( nRedlineFlags );
     }
 
-    if( pGraphicResolver )
-        SvXMLGraphicHelper::Destroy( pGraphicResolver );
+    if( xGraphicResolver )
+        xGraphicResolver->dispose();
+    xGraphicResolver.clear();
     if( xEmbeddedResolver )
         xEmbeddedResolver->dispose();
     xEmbeddedResolver.clear();
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index 03e0edaac60f..d266fac6c5d5 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -394,7 +394,6 @@ SwXMLImport::SwXMLImport(
     m_pDocElemTokenMap( nullptr ),
     m_pTableElemTokenMap( nullptr ),
     m_pTableCellAttrTokenMap( nullptr ),
-    m_pGraphicResolver( nullptr ),
     m_nStyleFamilyMask( SfxStyleFamily::All ),
     m_bLoadDoc( true ),
     m_bInsert( false ),
@@ -662,9 +661,8 @@ void SwXMLImport::startDocument()
 
     if( !GetGraphicResolver().is() )
     {
-        m_pGraphicResolver = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Read );
-        Reference< document::XGraphicObjectResolver > xGraphicResolver( m_pGraphicResolver );
-        SetGraphicResolver( xGraphicResolver );
+        m_xGraphicResolver = SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Read );
+        SetGraphicResolver( m_xGraphicResolver.get() );
     }
 
     if( !GetEmbeddedResolver().is() )
@@ -690,8 +688,9 @@ void SwXMLImport::endDocument()
     // this method will modify the document directly -> lock SolarMutex
     SolarMutexGuard aGuard;
 
-    if( m_pGraphicResolver )
-        SvXMLGraphicHelper::Destroy( m_pGraphicResolver );
+    if( m_xGraphicResolver )
+        m_xGraphicResolver->dispose();
+    m_xGraphicResolver.clear();
     if( m_xEmbeddedResolver )
         m_xEmbeddedResolver->dispose();
     m_xEmbeddedResolver.clear();
diff --git a/sw/source/filter/xml/xmlimp.hxx b/sw/source/filter/xml/xmlimp.hxx
index 1afa89ac1650..444186992c34 100644
--- a/sw/source/filter/xml/xmlimp.hxx
+++ b/sw/source/filter/xml/xmlimp.hxx
@@ -68,7 +68,8 @@ class SwXMLImport: public SvXMLImport
     SvXMLTokenMap           *m_pDocElemTokenMap;
     SvXMLTokenMap           *m_pTableElemTokenMap;
     SvXMLTokenMap           *m_pTableCellAttrTokenMap;
-    SvXMLGraphicHelper      *m_pGraphicResolver;
+    rtl::Reference<SvXMLGraphicHelper>
+                             m_xGraphicResolver;
     rtl::Reference<SvXMLEmbeddedObjectHelper>
                             m_xEmbeddedResolver;
 


More information about the Libreoffice-commits mailing list