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

Bjoern Michaelsen (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 2 22:30:27 UTC 2020


 sw/inc/tox.hxx                      |   16 +++++++++++-----
 sw/source/core/doc/doctxm.cxx       |    2 +-
 sw/source/core/edit/edtox.cxx       |    2 +-
 sw/source/core/tox/tox.cxx          |   27 ++++++++++-----------------
 sw/source/core/unocore/unoidx.cxx   |    2 +-
 sw/source/uibase/utlui/unotools.cxx |    2 +-
 6 files changed, 25 insertions(+), 26 deletions(-)

New commits:
commit 7dc3a20cab712ee987ea25a8f5728529521485b7
Author:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Wed Jul 1 22:51:58 2020 +0200
Commit:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Fri Jul 3 00:29:48 2020 +0200

    SwTOXMark::InsertTOXMarks: SwIterator no more ...
    
    - remove manual SwIterator usage
    - moved SwTOXMark from ::Modify to ::SwClientNotify
    - replaced static InsertTOXMarks() with SwTOXType::CollectTextMarks()
      where it belongs
    
    Change-Id: Ib8289c07882a61278dedb1bc1fadc1a9237fea4b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97663
    Tested-by: Jenkins
    Reviewed-by: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>

diff --git a/sw/inc/tox.hxx b/sw/inc/tox.hxx
index 67dc6bae169b..8dca84897b47 100644
--- a/sw/inc/tox.hxx
+++ b/sw/inc/tox.hxx
@@ -44,13 +44,20 @@ class SwRootFrame;
 
 typedef std::vector<SwTOXMark*> SwTOXMarks;
 
+namespace sw {
+    struct CollectTextMarksHint final : SfxHint {
+        SwTOXMarks& m_rMarks;
+        CollectTextMarksHint(SwTOXMarks& rMarks) : m_rMarks(rMarks) {}
+    };
+}
+
 // Entry of content index, alphabetical index or user defined index
 
 extern const sal_Unicode C_NUM_REPL;
 extern const sal_Unicode C_END_PAGE_NUM;
 extern const OUString S_PAGE_DELI;
 
-class SW_DLLPUBLIC SwTOXMark
+class SW_DLLPUBLIC SwTOXMark final
     : public SfxPoolItem
     , public sw::BroadcastingModify
 {
@@ -78,9 +85,7 @@ class SW_DLLPUBLIC SwTOXMark
 
     SwTOXMark();                    // to create the default attribute in InitCore
 
-protected:
-    // SwClient
-    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) override;
+    virtual void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) override;
 
 public:
 
@@ -141,7 +146,6 @@ public:
     SAL_DLLPRIVATE void SetXTOXMark(css::uno::Reference<css::text::XDocumentIndexMark> const& xMark)
             { m_wXDocumentIndexMark = xMark; }
     void RegisterToTOXType( SwTOXType& rMark );
-    static void InsertTOXMarks( SwTOXMarks& aMarks, const SwTOXType& rType );
 };
 
 // index types
@@ -155,6 +159,8 @@ public:
 
     inline const OUString&  GetTypeName() const;
     inline TOXTypes         GetType() const;
+    void CollectTextMarks(SwTOXMarks& rMarks) const
+            { const_cast<SwTOXType*>(this)->GetNotifier().Broadcast(sw::CollectTextMarksHint(rMarks)); }
 
 private:
     OUString        m_aName;
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index be5f84233f6f..bea433019820 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -245,7 +245,7 @@ const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark,
 
     const SwTOXType* pType = rCurTOXMark.GetTOXType();
     SwTOXMarks aMarks;
-    SwTOXMark::InsertTOXMarks( aMarks, *pType );
+    pType->CollectTextMarks(aMarks);
 
     for(SwTOXMark* pTOXMark : aMarks)
     {
diff --git a/sw/source/core/edit/edtox.cxx b/sw/source/core/edit/edtox.cxx
index 343aa697d86f..20cc2df50eea 100644
--- a/sw/source/core/edit/edtox.cxx
+++ b/sw/source/core/edit/edtox.cxx
@@ -279,7 +279,7 @@ void SwEditShell::ApplyAutoMark()
         const SwTOXType* pTOXType = GetTOXType(TOX_INDEX, 0);
 
         SwTOXMarks aMarks;
-        SwTOXMark::InsertTOXMarks( aMarks, *pTOXType );
+        pTOXType->CollectTextMarks(aMarks);
         for( SwTOXMark* pMark : aMarks )
         {
             if(pMark->IsAutoGenerated() && pMark->GetTextTOXMark())
diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx
index 10d42cc89a60..9e7919a3ca1b 100644
--- a/sw/source/core/tox/tox.cxx
+++ b/sw/source/core/tox/tox.cxx
@@ -146,12 +146,17 @@ SwTOXMark* SwTOXMark::Clone( SfxItemPool* ) const
     return new SwTOXMark( *this );
 }
 
-void SwTOXMark::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew)
+void SwTOXMark::SwClientNotify(const SwModify&, const SfxHint& rHint)
 {
-    NotifyClients(pOld, pNew);
-    if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
-    {   // invalidate cached uno object
-        SetXTOXMark(css::uno::Reference<css::text::XDocumentIndexMark>(nullptr));
+    if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
+    {
+        NotifyClients(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
+        if (pLegacyHint->m_pOld && (RES_REMOVE_UNO_OBJECT == pLegacyHint->m_pOld->Which()))
+            SetXTOXMark(css::uno::Reference<css::text::XDocumentIndexMark>(nullptr));
+    } else if (auto pCollectHint = dynamic_cast<const sw::CollectTextMarksHint*>(&rHint))
+    {
+        if(GetTextTOXMark())
+            pCollectHint->m_rMarks.push_back(this);
     }
 }
 
@@ -181,18 +186,6 @@ OUString SwTOXMark::GetText(SwRootFrame const*const pLayout) const
     return OUString();
 }
 
-void SwTOXMark::InsertTOXMarks( SwTOXMarks& aMarks, const SwTOXType& rType )
-{
-    SwIterator<SwTOXMark,SwTOXType> aIter(rType);
-    SwTOXMark* pMark = aIter.First();
-    while( pMark )
-    {
-        if(pMark->GetTextTOXMark())
-            aMarks.push_back(pMark);
-        pMark = aIter.Next();
-    }
-}
-
 // Manage types of TOX
 SwTOXType::SwTOXType(TOXTypes eTyp, const OUString& rName)
     : m_aName(rName)
diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx
index 5121d1d9c104..dd83c7440155 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -1164,7 +1164,7 @@ SwXDocumentIndex::getPropertyValue(const OUString& rPropertyName)
             {
                 SwTOXMarks aMarks;
                 const SwTOXType* pType = pTOXBase->GetTOXType();
-                SwTOXMark::InsertTOXMarks( aMarks, *pType );
+                pType->CollectTextMarks(aMarks);
                 uno::Sequence< uno::Reference<text::XDocumentIndexMark> > aXMarks(aMarks.size());
                 uno::Reference<text::XDocumentIndexMark>* pxMarks = aXMarks.getArray();
                 for(size_t i = 0; i < aMarks.size(); ++i)
diff --git a/sw/source/uibase/utlui/unotools.cxx b/sw/source/uibase/utlui/unotools.cxx
index 15e2bbba05a9..c7f46d63982c 100644
--- a/sw/source/uibase/utlui/unotools.cxx
+++ b/sw/source/uibase/utlui/unotools.cxx
@@ -340,7 +340,7 @@ IMPL_LINK( SwOneExampleFrame, TimeoutHdl, Timer*, pTimer, void )
             {
                 const SwTOXType* pTOXType = pDoc->GetTOXType(eType, 0);
                 SwTOXMarks aMarks;
-                SwTOXMark::InsertTOXMarks(aMarks, *pTOXType);
+                pTOXType->CollectTextMarks(aMarks);
                 for (auto pMark : aMarks)
                 {
                     if (pMark->GetAlternativeText() == "Chapter")


More information about the Libreoffice-commits mailing list