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

Bjoern Michaelsen (via logerrit) logerrit at kemper.freedesktop.org
Sat Sep 21 22:16:27 UTC 2019


 sw/inc/tox.hxx                    |    4 +-
 sw/source/core/tox/tox.cxx        |   74 +++++++++++++++++---------------------
 sw/source/core/unocore/unoidx.cxx |   49 ++++++++++++-------------
 3 files changed, 62 insertions(+), 65 deletions(-)

New commits:
commit a5081700bacb90d8560959a4d65d94a2d4e8dadd
Author:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Fri Sep 20 10:31:40 2019 +0200
Commit:     Björn Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Sun Sep 22 00:15:09 2019 +0200

    SwXDocumentIndexMark::Impl: MultiWriterListener no more
    
    Change-Id: I9c167c5b56c098cfd85693a3bf5f16da51b6033c
    Reviewed-on: https://gerrit.libreoffice.org/79290
    Tested-by: Jenkins
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>

diff --git a/sw/inc/tox.hxx b/sw/inc/tox.hxx
index f4d05b3f1246..d5248f5fee87 100644
--- a/sw/inc/tox.hxx
+++ b/sw/inc/tox.hxx
@@ -53,7 +53,7 @@ extern const OUString S_PAGE_DELI;
 
 class SW_DLLPUBLIC SwTOXMark
     : public SfxPoolItem
-    , public SwModify
+    , public sw::BroadcastingModify
 {
     friend void InitCore();
     friend class SwTextTOXMark;
@@ -146,7 +146,7 @@ public:
 };
 
 // index types
-class SwTOXType : public SwModify
+class SwTOXType final: public sw::BroadcastingModify
 {
 public:
     SwTOXType(TOXTypes eTyp, const OUString& aName);
diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx
index 8591b3fb7a89..d34c145979e6 100644
--- a/sw/source/core/tox/tox.cxx
+++ b/sw/source/core/tox/tox.cxx
@@ -96,36 +96,34 @@ void lcl_FillAuthPattern(SwFormTokens &rAuthTokens, sal_uInt16 nTypeId)
 /// pool default constructor
 SwTOXMark::SwTOXMark()
     : SfxPoolItem( RES_TXTATR_TOXMARK )
-    , SwModify( nullptr )
-    ,
-    m_pTextAttr( nullptr ), m_nLevel( 0 ),
-    m_bAutoGenerated(false),
-    m_bMainEntry(false)
-{
-}
-
-SwTOXMark::SwTOXMark( const SwTOXType* pTyp )
-    : SfxPoolItem( RES_TXTATR_TOXMARK )
-    , SwModify( const_cast<SwTOXType*>(pTyp) )
-    ,
-    m_pTextAttr( nullptr ), m_nLevel( 0 ),
-    m_bAutoGenerated(false),
-    m_bMainEntry(false)
-{
-}
-
-SwTOXMark::SwTOXMark( const SwTOXMark& rCopy )
-    : SfxPoolItem( RES_TXTATR_TOXMARK )
-    , SwModify(rCopy.GetRegisteredInNonConst())
-    ,
-    m_aPrimaryKey( rCopy.m_aPrimaryKey ), m_aSecondaryKey( rCopy.m_aSecondaryKey ),
-    m_aTextReading( rCopy.m_aTextReading ),
-    m_aPrimaryKeyReading( rCopy.m_aPrimaryKeyReading ),
-    m_aSecondaryKeyReading( rCopy.m_aSecondaryKeyReading ),
-    m_pTextAttr( nullptr ), m_nLevel( rCopy.m_nLevel ),
-    m_bAutoGenerated( rCopy.m_bAutoGenerated),
-    m_bMainEntry(rCopy.m_bMainEntry)
-{
+    , m_pTextAttr( nullptr ), m_nLevel( 0 )
+    , m_bAutoGenerated(false)
+    , m_bMainEntry(false)
+{ }
+
+SwTOXMark::SwTOXMark(const SwTOXType* pTyp)
+    : SfxPoolItem(RES_TXTATR_TOXMARK )
+    , m_pTextAttr( nullptr )
+    , m_nLevel( 0 )
+    , m_bAutoGenerated(false)
+    , m_bMainEntry(false)
+{ 
+    const_cast<SwTOXType*>(pTyp)->Add(this);
+}
+
+SwTOXMark::SwTOXMark(const SwTOXMark& rCopy)
+    : SfxPoolItem(RES_TXTATR_TOXMARK)
+    , m_aPrimaryKey(rCopy.m_aPrimaryKey)
+    , m_aSecondaryKey(rCopy.m_aSecondaryKey)
+    , m_aTextReading(rCopy.m_aTextReading)
+    , m_aPrimaryKeyReading(rCopy.m_aPrimaryKeyReading)
+    , m_aSecondaryKeyReading(rCopy.m_aSecondaryKeyReading)
+    , m_pTextAttr(nullptr)
+    , m_nLevel(rCopy.m_nLevel)
+    , m_bAutoGenerated(rCopy.m_bAutoGenerated)
+    , m_bMainEntry(rCopy.m_bMainEntry)
+{
+    const_cast<SwTOXMark*>(&rCopy)->GetRegisteredIn()->Add(this);
     // Copy AlternativString
     m_aAltText = rCopy.m_aAltText;
 }
@@ -198,18 +196,16 @@ void SwTOXMark::InsertTOXMarks( SwTOXMarks& aMarks, const SwTOXType& rType )
 }
 
 // Manage types of TOX
-SwTOXType::SwTOXType( TOXTypes eTyp, const OUString& rName )
-    : SwModify(nullptr),
-    m_aName(rName),
-    m_eType(eTyp)
-{
-}
+SwTOXType::SwTOXType(TOXTypes eTyp, const OUString& rName)
+    : m_aName(rName)
+    , m_eType(eTyp)
+{ } 
 
 SwTOXType::SwTOXType(const SwTOXType& rCopy)
-    : SwModify( const_cast<SwModify*>(rCopy.GetRegisteredIn()) ),
-    m_aName(rCopy.m_aName),
-    m_eType(rCopy.m_eType)
+    : m_aName(rCopy.m_aName)
+    , m_eType(rCopy.m_eType)
 {
+    const_cast<SwTOXType*>(&rCopy)->GetRegisteredIn()->Add(this);
 }
 
 static const char* STR_POOLCOLL_TOX_ARY[] =
diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx
index fac4fcec2dc4..ac2197c36583 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -67,6 +67,7 @@
 #include <comphelper/string.hxx>
 #include <cppuhelper/implbase.hxx>
 #include <svl/itemprop.hxx>
+#include <svl/listener.hxx>
 
 using namespace ::com::sun::star;
 
@@ -288,8 +289,7 @@ lcl_TypeToPropertyMap_Index(const TOXTypes eType)
     }
 }
 
-class SwXDocumentIndex::Impl
-    : public SvtListener
+class SwXDocumentIndex::Impl final: public SvtListener
 {
 private:
     ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
@@ -1489,8 +1489,7 @@ lcl_TypeToPropertyMap_Mark(const TOXTypes eType)
     }
 }
 
-class SwXDocumentIndexMark::Impl
-    : public SwClient
+class SwXDocumentIndexMark::Impl final: public SvtListener
 {
 private:
     ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
@@ -1504,7 +1503,6 @@ public:
     const TOXTypes m_eTOXType;
     ::comphelper::OInterfaceContainerHelper2 m_EventListeners;
     bool m_bIsDescriptor;
-    sw::WriterMultiListener m_aListener;
     const SwTOXType* m_pTOXType;
     const SwTOXMark* m_pTOXMark;
     SwDoc* m_pDoc;
@@ -1524,24 +1522,28 @@ public:
     Impl(SwXDocumentIndexMark& rThis,
             SwDoc* const pDoc,
             const enum TOXTypes eType,
-            SwTOXType* const pType, SwTOXMark const*const pMark)
-        : SwClient()
-        , m_rThis(rThis)
+            SwTOXType* const pType,
+            SwTOXMark const*const pMark)
+        : m_rThis(rThis)
         , m_bInReplaceMark(false)
         , m_rPropSet(
             *aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Mark(eType)))
         , m_eTOXType(eType)
         , m_EventListeners(m_Mutex)
         , m_bIsDescriptor(nullptr == pMark)
-        , m_aListener(*this)
         , m_pTOXType(pType)
         , m_pTOXMark(pMark)
         , m_pDoc(pDoc)
         , m_bMainEntry(false)
         , m_nLevel(0)
     {
-        m_aListener.StartListening(const_cast<SwTOXMark*>(pMark));
-        m_aListener.StartListening(pType);
+        auto pMarkNonConst = const_cast<SwTOXMark*>(m_pTOXMark);
+        auto pTypeNonConst = const_cast<SwTOXType*>(m_pTOXType);
+
+        if(pMarkNonConst)
+            StartListening(pMarkNonConst->GetNotifier());
+        if(pTypeNonConst)
+            StartListening(pTypeNonConst->GetNotifier());
     }
 
     SwTOXType* GetTOXType() const {
@@ -1550,7 +1552,8 @@ public:
 
     void DeleteTOXMark()
     {
-        m_pDoc->DeleteTOXMark(m_pTOXMark); // calls Invalidate() via Notify
+        m_pDoc->DeleteTOXMark(m_pTOXMark);
+        Invalidate();
     }
 
     void InsertTOXMark(SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam,
@@ -1573,9 +1576,7 @@ public:
     }
 
     void    Invalidate();
-protected:
-    // SwClient
-    virtual void SwClientNotify(const SwModify&, const SfxHint& ) override;
+    virtual void Notify(const SfxHint&) override;
 };
 
 void SwXDocumentIndexMark::Impl::Invalidate()
@@ -1590,21 +1591,21 @@ void SwXDocumentIndexMark::Impl::Invalidate()
             m_EventListeners.disposeAndClear(ev);
         }
     }
-    m_aListener.EndListeningAll();
+    EndListeningAll();
     m_pDoc = nullptr;
     m_pTOXMark = nullptr;
     m_pTOXType = nullptr;
 }
 
-void SwXDocumentIndexMark::Impl::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
+void SwXDocumentIndexMark::Impl::Notify(const SfxHint& rHint)
 {
-    assert(!GetRegisteredIn()); // we should only listen with the WriterMultiListener from now on
     if(auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint))
     {
-        if(pModifyChangedHint->m_pNew == nullptr || &rModify == m_pTOXMark)
+        if(auto pNewType = dynamic_cast<const SwTOXType*>(pModifyChangedHint->m_pNew))
+            m_pTOXType = pNewType;
+
+        else
             Invalidate();
-        else if(&rModify == m_pTOXType)
-            m_pTOXType = dynamic_cast<const SwTOXType*>(pModifyChangedHint->m_pNew);
     }
 }
 
@@ -1941,9 +1942,9 @@ void SwXDocumentIndexMark::Impl::InsertTOXMark(
     m_pDoc = pDoc;
     m_pTOXMark = &pNewTextAttr->GetTOXMark();
     m_pTOXType = &rTOXType;
-    m_aListener.EndListeningAll();
-    m_aListener.StartListening(const_cast<SwTOXMark*>(m_pTOXMark));
-    m_aListener.StartListening(const_cast<SwTOXType*>(m_pTOXType));
+    EndListeningAll();
+    StartListening(const_cast<SwTOXMark*>(m_pTOXMark)->GetNotifier());
+    StartListening(const_cast<SwTOXType*>(m_pTOXType)->GetNotifier());
 }
 
 uno::Reference< text::XTextRange > SAL_CALL


More information about the Libreoffice-commits mailing list