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

Bjoern Michaelsen (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 3 19:28:17 UTC 2019


 sw/source/core/unocore/unoidx.cxx |   67 +++++++++++++++++++++-----------------
 1 file changed, 38 insertions(+), 29 deletions(-)

New commits:
commit 17869ac7d5b18d6fdd026395ed53dc0d899f2fef
Author:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Wed Apr 3 00:01:11 2019 +0200
Commit:     Björn Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Wed Apr 3 21:27:53 2019 +0200

    DocumentIndex::Impl: SwClient no more
    
    Change-Id: I552acba206a3f35a450fc5331e3853e23a46cc10
    Reviewed-on: https://gerrit.libreoffice.org/70166
    Tested-by: Jenkins
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>

diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx
index d4d75324db8d..5e69d4a85fcf 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -311,29 +311,27 @@ lcl_TypeToPropertyMap_Index(const TOXTypes eType)
 }
 
 class SwXDocumentIndex::Impl
-    : public SwClient
+    : public SvtListener
 {
 private:
     ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
+    SwSectionFormat* m_pFormat;
 
 public:
     uno::WeakReference<uno::XInterface> m_wThis;
     ::cppu::OMultiTypeInterfaceContainerHelper m_Listeners;
-    SfxItemPropertySet const&   m_rPropSet;
-    const TOXTypes              m_eTOXType;
-    bool                        m_bIsDescriptor;
-    SwDoc *                     m_pDoc;
+    SfxItemPropertySet const& m_rPropSet;
+    const TOXTypes m_eTOXType;
+    bool m_bIsDescriptor;
+    SwDoc* m_pDoc;
     std::unique_ptr<SwDocIndexDescriptorProperties_Impl> m_pProps;
     uno::WeakReference<container::XIndexReplace> m_wStyleAccess;
     uno::WeakReference<container::XIndexReplace> m_wTokenAccess;
 
-    Impl(   SwDoc & rDoc,
-            const TOXTypes eType,
-            SwTOXBaseSection *const pBaseSection)
-        : SwClient(pBaseSection ? pBaseSection->GetFormat() : nullptr)
+    Impl(SwDoc& rDoc, const TOXTypes eType, SwTOXBaseSection *const pBaseSection)
+        : m_pFormat(pBaseSection ? pBaseSection->GetFormat() : nullptr)
         , m_Listeners(m_Mutex)
-        , m_rPropSet(
-            *aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Index(eType)))
+        , m_rPropSet(*aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Index(eType)))
         , m_eTOXType(eType)
         , m_bIsDescriptor(nullptr == pBaseSection)
         , m_pDoc(&rDoc)
@@ -341,11 +339,19 @@ public:
             ? new SwDocIndexDescriptorProperties_Impl(rDoc.GetTOXType(eType, 0))
             : nullptr)
     {
+        if(m_pFormat)
+            StartListening(m_pFormat->GetNotifier());
     }
 
-    SwSectionFormat * GetSectionFormat() const {
-        return static_cast<SwSectionFormat *>(
-                const_cast<SwModify *>(GetRegisteredIn()));
+    void SetSectionFormat(SwSectionFormat& rFormat)
+    {
+        EndListeningAll();
+        m_pFormat = &rFormat;
+        StartListening(rFormat.GetNotifier());
+    }
+
+    SwSectionFormat* GetSectionFormat() const {
+        return m_pFormat;
     }
 
     SwTOXBase & GetTOXSectionOrThrow() const
@@ -371,27 +377,30 @@ public:
             ? SwForm::GetFormMaxLevel(m_eTOXType)
             : rSection.GetTOXForm().GetFormMax();
     }
-protected:
-    // SwClient
-    virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override;
+    virtual void Notify(const SfxHint&) override;
 
 };
 
-void SwXDocumentIndex::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
+void SwXDocumentIndex::Impl::Notify(const SfxHint& rHint)
 {
-    ClientModify(this, pOld, pNew);
-    if (GetRegisteredIn())
+    if(auto pLegacy = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
     {
-        return; // core object still alive
+        if(pLegacy->m_pOld && pLegacy->m_pOld->Which() == RES_REMOVE_UNO_OBJECT)
+            m_pFormat = nullptr;
     }
-
-    uno::Reference<uno::XInterface> const xThis(m_wThis);
-    if (!xThis.is())
-    {   // fdo#72695: if UNO object is already dead, don't revive it with event
-        return;
+    else if(rHint.GetId() == SfxHintId::Dying)
+        m_pFormat = nullptr;
+    if(!m_pFormat)
+    {
+        EndListeningAll();
+        uno::Reference<uno::XInterface> const xThis(m_wThis);
+        if (!xThis.is())
+        {   // fdo#72695: if UNO object is already dead, don't revive it with event
+            return;
+        }
+        lang::EventObject const ev(xThis);
+        m_Listeners.disposeAndClear(ev);
     }
-    lang::EventObject const ev(xThis);
-    m_Listeners.disposeAndClear(ev);
 }
 
 SwXDocumentIndex::SwXDocumentIndex(
@@ -1356,7 +1365,7 @@ SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange)
     pDoc->SetTOXBaseName(*pTOX, m_pImpl->m_pProps->GetTOXBase().GetTOXName());
 
     // update page numbers
-    pTOX->GetFormat()->Add(m_pImpl.get());
+    m_pImpl->SetSectionFormat(*pTOX->GetFormat());
     pTOX->GetFormat()->SetXObject(static_cast< ::cppu::OWeakObject*>(this));
     pTOX->UpdatePageNum();
 


More information about the Libreoffice-commits mailing list