diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2019-09-24 18:07:44 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@cib.de> | 2019-10-04 12:11:31 +0200 |
commit | 7ade17fd46c986ad2a624982c5737d7c667b8c89 (patch) | |
tree | 314801aee1c1587088793d8f9a6ade65b625b878 | |
parent | c3f746281f6ba4cbff95509c4791e203f260ec3d (diff) |
sw: add IDocumentMarkAccess::getFieldmarkAt()
... and use it where the mark for a given CH_TXT_ATR_FIELD* is
retrieved.
Change-Id: Id58ac2967ab66be8a07586ef31cfe9e18a5f073d
Reviewed-on: https://gerrit.libreoffice.org/80050
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r-- | sw/inc/IDocumentMarkAccess.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/doc/docbm.cxx | 18 | ||||
-rw-r--r-- | sw/source/core/inc/MarkManager.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/text/portxt.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/unocore/unoportenum.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/writerhelper.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8nds.cxx | 6 |
8 files changed, 30 insertions, 11 deletions
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index 4d12a236a4f1..a8dacbcbd7e4 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -307,6 +307,8 @@ class IDocumentMarkAccess // Fieldmarks + /// get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos + virtual ::sw::mark::IFieldmark* getFieldmarkAt(const SwPosition& rPos) const =0; virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& pos) const =0; virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& pos) const =0; virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& pos) const =0; diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 6f2a38b0be5a..1d61f2ac65e7 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1255,6 +1255,22 @@ namespace sw { namespace mark CompareIMarkStartsAfter()); } + IFieldmark* MarkManager::getFieldmarkAt(const SwPosition& rPos) const + { + auto const pFieldmark = find_if( + m_vFieldmarks.begin(), + m_vFieldmarks.end(), + [&rPos] (::sw::mark::MarkBase const*const pMark) { + return pMark->GetMarkStart() == rPos + // end position includes the CH_TXT_ATR_FIELDEND + || (pMark->GetMarkEnd().nContent.GetIndex() == rPos.nContent.GetIndex() + 1 + && pMark->GetMarkEnd().nNode == rPos.nNode); + } ); + return (pFieldmark == m_vFieldmarks.end()) + ? nullptr + : dynamic_cast<IFieldmark*>(*pFieldmark); + } + IFieldmark* MarkManager::getFieldmarkFor(const SwPosition& rPos) const { auto const pFieldmark = find_if( @@ -1377,7 +1393,7 @@ namespace sw { namespace mark IFieldmark* MarkManager::getDropDownFor(const SwPosition& rPos) const { - IFieldmark *pMark = getFieldmarkFor(rPos); + IFieldmark *pMark = getFieldmarkAt(rPos); if (!pMark || pMark->GetFieldname() != ODF_FORMDROPDOWN) return nullptr; return pMark; diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index 512cd4de9d6d..a97f28c21b53 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -83,6 +83,7 @@ namespace sw { virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const override; // Fieldmarks + virtual ::sw::mark::IFieldmark* getFieldmarkAt(const SwPosition& rPos) const override; virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& rPos) const override; virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& rPos) const override; virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& rPos) const override; diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx index f9aed8c08c6c..0460cb343dd3 100644 --- a/sw/source/core/text/portxt.cxx +++ b/sw/source/core/text/portxt.cxx @@ -794,7 +794,7 @@ void SwFieldFormCheckboxPortion::Paint( const SwTextPaintInfo& rInf ) const { SwPosition const aPosition(rInf.GetTextFrame()->MapViewToModelPos(rInf.GetIdx())); - IFieldmark const*const pBM = rInf.GetTextFrame()->GetDoc().getIDocumentMarkAccess()->getFieldmarkFor( aPosition ); + IFieldmark const*const pBM = rInf.GetTextFrame()->GetDoc().getIDocumentMarkAccess()->getFieldmarkAt(aPosition); OSL_ENSURE(pBM && pBM->GetFieldname( ) == ODF_FORMCHECKBOX, "Where is my form field bookmark???"); @@ -810,7 +810,7 @@ void SwFieldFormCheckboxPortion::Paint( const SwTextPaintInfo& rInf ) const bool SwFieldFormCheckboxPortion::Format( SwTextFormatInfo & rInf ) { SwPosition const aPosition(rInf.GetTextFrame()->MapViewToModelPos(rInf.GetIdx())); - IFieldmark const*const pBM = rInf.GetTextFrame()->GetDoc().getIDocumentMarkAccess()->getFieldmarkFor( aPosition ); + IFieldmark const*const pBM = rInf.GetTextFrame()->GetDoc().getIDocumentMarkAccess()->getFieldmarkAt(aPosition); OSL_ENSURE(pBM && pBM->GetFieldname( ) == ODF_FORMCHECKBOX, "Where is my form field bookmark???"); if (pBM && pBM->GetFieldname( ) == ODF_FORMCHECKBOX) { diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index 26a00c334746..f7ad846313d4 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -432,7 +432,7 @@ lcl_ExportFieldMark( if (pDoc) { pFieldmark = pDoc->getIDocumentMarkAccess()-> - getFieldmarkFor(*pUnoCursor->GetMark()); + getFieldmarkAt(*pUnoCursor->GetMark()); } SwXTextPortion* pPortion = new SwXTextPortion( pUnoCursor, i_xParentText, PORTION_FIELD_START); @@ -449,7 +449,7 @@ lcl_ExportFieldMark( if (pDoc) { pFieldmark = pDoc->getIDocumentMarkAccess()-> - getFieldmarkFor(*pUnoCursor->GetMark()); + getFieldmarkAt(*pUnoCursor->GetMark()); } SwXTextPortion* pPortion = new SwXTextPortion( pUnoCursor, i_xParentText, PORTION_FIELD_END); @@ -465,7 +465,7 @@ lcl_ExportFieldMark( ::sw::mark::IFieldmark* pFieldmark = nullptr; if (pDoc) { - pFieldmark = pDoc->getIDocumentMarkAccess()->getFieldmarkFor(*pUnoCursor->GetMark()); + pFieldmark = pDoc->getIDocumentMarkAccess()->getFieldmarkAt(*pUnoCursor->GetMark()); } SwXTextPortion* pPortion = new SwXTextPortion( pUnoCursor, i_xParentText, PORTION_FIELD_START_END); diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index 7375f911d476..f86ab2004dc2 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -1171,7 +1171,7 @@ void SwHTMLWriter::OutPointFieldmarks( const SwPosition& rPos ) if (!pMarkAccess) return; - const sw::mark::IFieldmark* pMark = pMarkAccess->getFieldmarkFor(rPos); + const sw::mark::IFieldmark* pMark = pMarkAccess->getFieldmarkAt(rPos); if (!pMark) return; diff --git a/sw/source/filter/ww8/writerhelper.cxx b/sw/source/filter/ww8/writerhelper.cxx index 520283dc5fe1..fa56ce68878e 100644 --- a/sw/source/filter/ww8/writerhelper.cxx +++ b/sw/source/filter/ww8/writerhelper.cxx @@ -718,7 +718,7 @@ namespace sw SwPosition const end(*rPos.nNode.GetNode().GetTextNode(), nIndex - 1); sw::mark::IFieldmark *const pFieldMark( - rPos.GetDoc()->getIDocumentMarkAccess()->getFieldmarkFor(end)); + rPos.GetDoc()->getIDocumentMarkAccess()->getFieldmarkAt(end)); SAL_WARN_IF(!pFieldMark, "sw.ww8", "expected a field mark"); if (pFieldMark && pFieldMark->GetMarkPos().nNode.GetIndex() == (*aResult)->m_aMkPos.m_nNode.GetIndex()+1 && pFieldMark->GetMarkPos().nContent.GetIndex() < (*aResult)->m_aMkPos.m_nContent) diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index b722b22621d3..fd0f55dc7063 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -2314,7 +2314,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) if ( ch == CH_TXT_ATR_FIELDSTART ) { SwPosition aPosition( rNode, SwIndex( &rNode, nCurrentPos ) ); - ::sw::mark::IFieldmark const * const pFieldmark = pMarkAccess->getFieldmarkFor( aPosition ); + ::sw::mark::IFieldmark const*const pFieldmark = pMarkAccess->getFieldmarkAt(aPosition); OSL_ENSURE( pFieldmark, "Looks like this doc is broken...; where is the Fieldmark for the FIELDSTART??" ); // Date field is exported as content control, not as a simple field @@ -2381,7 +2381,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) else if ( ch == CH_TXT_ATR_FIELDEND ) { SwPosition aPosition( rNode, SwIndex( &rNode, nCurrentPos ) ); - ::sw::mark::IFieldmark const * const pFieldmark = pMarkAccess->getFieldmarkFor( aPosition ); + ::sw::mark::IFieldmark const*const pFieldmark = pMarkAccess->getFieldmarkAt(aPosition); OSL_ENSURE( pFieldmark, "Looks like this doc is broken...; where is the Fieldmark for the FIELDEND??" ); @@ -2418,7 +2418,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) else if ( ch == CH_TXT_ATR_FORMELEMENT ) { SwPosition aPosition( rNode, SwIndex( &rNode, nCurrentPos ) ); - ::sw::mark::IFieldmark const * const pFieldmark = pMarkAccess->getFieldmarkFor( aPosition ); + ::sw::mark::IFieldmark const*const pFieldmark = pMarkAccess->getFieldmarkAt(aPosition); bool isDropdownOrCheckbox = pFieldmark && (pFieldmark->GetFieldname( ) == ODF_FORMDROPDOWN || pFieldmark->GetFieldname( ) == ODF_FORMCHECKBOX ); |