[Libreoffice-commits] core.git: sw/inc sw/source

Noel Grandin noel.grandin at collabora.co.uk
Tue Oct 17 06:58:47 UTC 2017


 sw/inc/ndole.hxx             |    3 ++-
 sw/source/core/ole/ndole.cxx |   26 +++++++++++---------------
 2 files changed, 13 insertions(+), 16 deletions(-)

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

    use rtl::Reference in SwOLEObj
    
    instead of manual ref-counting
    
    Change-Id: I26e55ec7803e60f090f093b5584faec74ebbb8bb
    Reviewed-on: https://gerrit.libreoffice.org/43419
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/inc/ndole.hxx b/sw/inc/ndole.hxx
index 6330793a45f1..94ec0131158f 100644
--- a/sw/inc/ndole.hxx
+++ b/sw/inc/ndole.hxx
@@ -22,6 +22,7 @@
 #include <ndnotxt.hxx>
 #include <svtools/embedhlp.hxx>
 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
+#include <rtl/ref.hxx>
 
 class SwGrfFormatColl;
 class SwDoc;
@@ -35,7 +36,7 @@ class SW_DLLPUBLIC SwOLEObj
     friend class SwOLENode;
 
     const SwOLENode* m_pOLENode;
-    SwOLEListener_Impl* m_pListener;
+    rtl::Reference<SwOLEListener_Impl> m_xListener;
 
     /** Either ref or name are known. If only name is known, ref is obtained
        on demand by GetOleRef() from Sfx. */
diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index d4b9b0a74a40..e0131579c99c 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -90,7 +90,7 @@ class SwOLEListener_Impl : public ::cppu::WeakImplHelper< embed::XStateChangeLis
     SwOLEObj* mpObj;
 public:
     explicit SwOLEListener_Impl( SwOLEObj* pObj );
-    void Release();
+    void dispose();
     virtual void SAL_CALL changingState( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
     virtual void SAL_CALL stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
     virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) override;
@@ -128,12 +128,11 @@ void SAL_CALL SwOLEListener_Impl::stateChanged( const lang::EventObject&, ::sal_
     }
 }
 
-void SwOLEListener_Impl::Release()
+void SwOLEListener_Impl::dispose()
 {
     if (mpObj && g_pOLELRU_Cache)
         g_pOLELRU_Cache->RemoveObj( *mpObj );
-    mpObj=nullptr;
-    release();
+    mpObj = nullptr;
 }
 
 void SAL_CALL SwOLEListener_Impl::disposing( const lang::EventObject& )
@@ -733,7 +732,6 @@ private:
 
 SwOLEObj::SwOLEObj( const svt::EmbeddedObjectRef& xObj ) :
     m_pOLENode( nullptr ),
-    m_pListener( nullptr ),
     m_xOLERef( xObj ),
     m_aPrimitive2DSequence(),
     m_aRange(),
@@ -742,15 +740,13 @@ SwOLEObj::SwOLEObj( const svt::EmbeddedObjectRef& xObj ) :
     m_xOLERef.Lock();
     if ( xObj.is() )
     {
-        m_pListener = new SwOLEListener_Impl( this );
-        m_pListener->acquire();
-        xObj->addStateChangeListener( m_pListener );
+        m_xListener = new SwOLEListener_Impl( this );
+        xObj->addStateChangeListener( m_xListener.get() );
     }
 }
 
 SwOLEObj::SwOLEObj( const OUString &rString, sal_Int64 nAspect ) :
     m_pOLENode( nullptr ),
-    m_pListener( nullptr ),
     m_aName( rString ),
     m_aPrimitive2DSequence(),
     m_aRange(),
@@ -770,11 +766,12 @@ SwOLEObj::~SwOLEObj() COVERITY_NOEXCEPT_FALSE
         m_pDeflateData = nullptr;
     }
 
-    if( m_pListener )
+    if( m_xListener )
     {
         if ( m_xOLERef.is() )
-            m_xOLERef->removeStateChangeListener( m_pListener );
-        m_pListener->Release();
+            m_xOLERef->removeStateChangeListener( m_xListener.get() );
+        m_xListener->dispose();
+        m_xListener.clear();
     }
 
     if( m_pOLENode && !m_pOLENode->GetDoc()->IsInDtor() )
@@ -910,9 +907,8 @@ const uno::Reference < embed::XEmbeddedObject > SwOLEObj::GetOleRef()
         {
             m_xOLERef.Assign( xObj, m_xOLERef.GetViewAspect() );
             m_xOLERef.AssignToContainer( &p->GetEmbeddedObjectContainer(), m_aName );
-            m_pListener = new SwOLEListener_Impl( this );
-            m_pListener->acquire();
-            xObj->addStateChangeListener( m_pListener );
+            m_xListener = new SwOLEListener_Impl( this );
+            xObj->addStateChangeListener( m_xListener.get() );
         }
 
         const_cast<SwOLENode*>(m_pOLENode)->CheckFileLink_Impl(); // for this notification nonconst access is required


More information about the Libreoffice-commits mailing list