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

Bjoern Michaelsen (via logerrit) logerrit at kemper.freedesktop.org
Sun Feb 16 21:42:41 UTC 2020


 sw/inc/fldbas.hxx                 |    2 +
 sw/inc/fmtfld.hxx                 |    6 ++++
 sw/source/core/fields/fldbas.cxx  |    5 +++
 sw/source/core/txtnode/atrfld.cxx |    7 +++++
 sw/source/filter/ww8/wrtw8nds.cxx |    2 -
 sw/source/filter/ww8/wrtww8.hxx   |    3 +-
 sw/source/filter/ww8/ww8atr.cxx   |   50 ++++++++++++--------------------------
 7 files changed, 40 insertions(+), 35 deletions(-)

New commits:
commit bcc942fc34aad7db9b96c0e3d395c7426822327b
Author:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Sun Feb 16 20:38:38 2020 +0100
Commit:     Björn Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Sun Feb 16 22:42:06 2020 +0100

    GatherRefFields for ww8
    
    Change-Id: Ic40c1241854bdbcdf7987ab592e0f07ecdd73f0c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88823
    Tested-by: Jenkins
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>

diff --git a/sw/inc/fldbas.hxx b/sw/inc/fldbas.hxx
index 8601dea443b8..92a94fb8a096 100644
--- a/sw/inc/fldbas.hxx
+++ b/sw/inc/fldbas.hxx
@@ -35,6 +35,7 @@ class SwFormatField;
 class SwRootFrame;
 class SvNumberFormatter;
 class IDocumentRedlineAccess;
+class SwGetRefField;
 namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } } } }
 namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }
 
@@ -277,6 +278,7 @@ public:
     void CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, bool HideRedlines);
     bool HasHiddenInformationNotes();
     void GatherNodeIndex(std::vector<sal_uLong>& rvNodeIndex);
+    void GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp);
 };
 
 inline void SwFieldType::UpdateFields() const
diff --git a/sw/inc/fmtfld.hxx b/sw/inc/fmtfld.hxx
index e68a9be41582..3ddce1977d96 100644
--- a/sw/inc/fmtfld.hxx
+++ b/sw/inc/fmtfld.hxx
@@ -27,6 +27,7 @@
 #include "swdllapi.h"
 #include "calbck.hxx"
 #include "ndindex.hxx"
+#include "reffld.hxx"
 
 class SwField;
 class SwTextField;
@@ -61,6 +62,11 @@ namespace sw {
         std::vector<sal_uLong>& m_rvNodeIndex;
         GatherNodeIndexHint(std::vector<sal_uLong>& rvNodeIndex) : m_rvNodeIndex(rvNodeIndex) {};
     };
+    struct GatherRefFieldsHint final : SfxHint {
+        std::vector<SwGetRefField*>& m_rvRFields;
+        const sal_uInt16 m_nType;
+        GatherRefFieldsHint(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nType) : m_rvRFields(rvRFields), m_nType(nType) {};
+    };
 }
 
 
diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx
index a56b2c81302b..921c69752935 100644
--- a/sw/source/core/fields/fldbas.cxx
+++ b/sw/source/core/fields/fldbas.cxx
@@ -185,6 +185,11 @@ void SwFieldType::GatherNodeIndex(std::vector<sal_uLong>& rvNodeIndex)
     CallSwClientNotify(sw::GatherNodeIndexHint(rvNodeIndex));
 }
 
+void SwFieldType::GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp)
+{
+    CallSwClientNotify(sw::GatherRefFieldsHint(rvRFields, nTyp));
+}
+
 void SwFieldTypes::dumpAsXml(xmlTextWriterPtr pWriter) const
 {
     xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldTypes"));
diff --git a/sw/source/core/txtnode/atrfld.cxx b/sw/source/core/txtnode/atrfld.cxx
index 88b67c451b94..99eb71787ec0 100644
--- a/sw/source/core/txtnode/atrfld.cxx
+++ b/sw/source/core/txtnode/atrfld.cxx
@@ -266,6 +266,13 @@ void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHin
     {
         if(auto pTextField = GetTextField())
             pGatherNodeIndexHint->m_rvNodeIndex.push_back(pTextField->GetTextNode().GetIndex());
+    } else if (const auto pGatherRefFieldsHint = dynamic_cast<const sw::GatherRefFieldsHint*>( &rHint ))
+    {
+        if(!GetTextField() || pGatherRefFieldsHint->m_nType != GetField()->GetSubType())
+            return;
+        SwTextNode* pNd = GetTextField()->GetpTextNode();
+        if(pNd && pNd->GetNodes().IsDocNodes())
+            pGatherRefFieldsHint->m_rvRFields.push_back(static_cast<SwGetRefField*>(GetField()));
     }
 }
 
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 70a855efc7ed..53b709bc0f21 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -1217,7 +1217,7 @@ OUString BookmarkToWriter(const OUString &rBookmark)
 
 void SwWW8AttrIter::OutSwFormatRefMark(const SwFormatRefMark& rAttr)
 {
-    if ( m_rExport.HasRefToObject( REF_SETREFATTR, &rAttr.GetRefName(), 0 ) )
+    if(m_rExport.HasRefToAttr(rAttr.GetRefName()))
         m_rExport.AppendBookmark( MSWordExportBase::GetBookmarkName( REF_SETREFATTR,
                                             &rAttr.GetRefName(), 0 ));
 }
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 6ca1eb7d8717..21df13a16f6c 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -634,7 +634,8 @@ public:
     }
 
     /// Find the reference.
-    bool HasRefToObject( sal_uInt16 nTyp, const OUString* pName, sal_uInt16 nSeqNo );
+    bool HasRefToAttr(const OUString& rName);
+    bool HasRefToFootOrEndnote(const bool isEndNote, const sal_uInt16 nSeqNo);
 
     /// Find the bookmark name.
     static OUString GetBookmarkName( sal_uInt16 nTyp, const OUString* pName, sal_uInt16 nSeqNo );
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 38181c2d69b8..059bca60c954 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -22,6 +22,8 @@
  * (nodes, attributes, formats and chars).
  */
 
+
+#include <algorithm>
 #include <hintids.hxx>
 
 #include <o3tl/safeint.hxx>
@@ -911,40 +913,22 @@ void MSWordExportBase::OutputFormat( const SwFormat& rFormat, bool bPapFormat, b
     m_pOutFormatNode = pOldMod;
 }
 
-bool MSWordExportBase::HasRefToObject( sal_uInt16 nTyp, const OUString* pName, sal_uInt16 nSeqNo )
+bool MSWordExportBase::HasRefToAttr(const OUString& rName)
 {
+    SwFieldType* pType = m_pDoc->getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::GetRef);
+    std::vector<SwGetRefField*> vpRFields;
+    pType->GatherRefFields(vpRFields, REF_SETREFATTR);
+    return std::any_of(vpRFields.begin(), vpRFields.end(),
+            [rName](SwGetRefField* pF) { return rName == pF->GetSetRefName(); });
+}
 
-    SwFieldType* pType = m_pDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef );
-    SwIterator<SwFormatField, SwFieldType> aFormatFields( *pType );
-    for ( SwFormatField* pFormatField = aFormatFields.First(); pFormatField; pFormatField = aFormatFields.Next() )
-    {
-        const SwTextNode* pNd;
-        if ( pFormatField->GetTextField() && nTyp == pFormatField->GetField()->GetSubType() &&
-             nullptr != ( pNd  = pFormatField->GetTextField()->GetpTextNode() ) &&
-             pNd->GetNodes().IsDocNodes() )
-        {
-            const SwGetRefField& rRField = *static_cast< SwGetRefField* >( pFormatField->GetField() );
-            switch ( nTyp )
-            {
-                case REF_BOOKMARK:
-                case REF_SETREFATTR:
-                    if ( pName && *pName == rRField.GetSetRefName() )
-                        return true;
-                    break;
-                case REF_FOOTNOTE:
-                case REF_ENDNOTE:
-                    if ( nSeqNo == rRField.GetSeqNo() )
-                        return true;
-                    break;
-                case REF_SEQUENCEFLD:
-                    break;      // ???
-                case REF_OUTLINE:
-                    break;      // ???
-            }
-        }
-    }
-
-    return false;
+bool MSWordExportBase::HasRefToFootOrEndnote(const bool isEndNote, const sal_uInt16 nSeqNo)
+{
+    SwFieldType* pType = m_pDoc->getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::GetRef);
+    std::vector<SwGetRefField*> vpRFields;
+    pType->GatherRefFields(vpRFields, isEndNote ? REF_ENDNOTE : REF_FOOTNOTE);
+    return std::any_of(vpRFields.begin(), vpRFields.end(),
+            [nSeqNo](SwGetRefField* pF) { return nSeqNo == pF->GetSeqNo(); });
 }
 
 OUString MSWordExportBase::GetBookmarkName( sal_uInt16 nTyp, const OUString* pName, sal_uInt16 nSeqNo )
@@ -3487,7 +3471,7 @@ void AttributeOutputBase::TextFootnote( const SwFormatFootnote& rFootnote )
     // if any reference to this footnote/endnote then insert an internal
     // Bookmark.
     OUString sBkmkNm;
-    if ( GetExport().HasRefToObject( nTyp, nullptr, rFootnote.GetTextFootnote()->GetSeqRefNo() ))
+    if ( GetExport().HasRefToFootOrEndnote( rFootnote.IsEndNote(), rFootnote.GetTextFootnote()->GetSeqRefNo()))
     {
         sBkmkNm = MSWordExportBase::GetBookmarkName( nTyp, nullptr,
                                     rFootnote.GetTextFootnote()->GetSeqRefNo() );


More information about the Libreoffice-commits mailing list