summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2020-02-16 20:38:38 +0100
committerBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>2020-02-16 22:42:06 +0100
commitbcc942fc34aad7db9b96c0e3d395c7426822327b (patch)
treec6fda73a4b55a67069378a886896e12d496bbfcf /sw/source
parent1bc6f5868fd5e780e70f999144432f30d8f64149 (diff)
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@libreoffice.org>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/fields/fldbas.cxx5
-rw-r--r--sw/source/core/txtnode/atrfld.cxx7
-rw-r--r--sw/source/filter/ww8/wrtw8nds.cxx2
-rw-r--r--sw/source/filter/ww8/wrtww8.hxx3
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx50
5 files changed, 32 insertions, 35 deletions
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() );