From 4565382ee6f8fec96f0df94c34a2567816291c2e Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Wed, 19 Jan 2022 12:15:01 +0100 Subject: sw: generalize ModelToViewHelper to handle all NonTextFieldmarks Rename getDropDownsFor() to getNoTextFieldmarksIn(). Move some code so that sw::mark::ExpandFieldmark can expand all fieldmarks that use CH_TXT_ATR_FORMELEMENT. Change-Id: I8a1e28fc0ad77df3a749d9e55c306cb45187a082 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128606 Tested-by: Jenkins Reviewed-by: Michael Stahl --- sw/inc/IDocumentMarkAccess.hxx | 2 +- sw/source/core/doc/docbm.cxx | 7 +++++-- sw/source/core/inc/MarkManager.hxx | 2 +- sw/source/core/text/itrform2.cxx | 10 ++++++++++ sw/source/core/txtnode/modeltoviewhelper.cxx | 6 +++--- sw/source/core/unocore/unobkm.cxx | 11 +---------- 6 files changed, 21 insertions(+), 17 deletions(-) (limited to 'sw') diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index 3a05a2053bbe..1d11734e46e9 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -328,7 +328,7 @@ class IDocumentMarkAccess virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& pos) const =0; virtual ::sw::mark::IFieldmark* getDropDownFor(const SwPosition& pos) const=0; - virtual std::vector< ::sw::mark::IFieldmark* > getDropDownsFor(const SwPaM &rPaM) const=0; + virtual std::vector<::sw::mark::IFieldmark*> getNoTextFieldmarksIn(const SwPaM &rPaM) const=0; virtual void deleteFieldmarkAt(const SwPosition& rPos) = 0; virtual ::sw::mark::IFieldmark* changeFormFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) = 0; diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index e9c0ce701eba..5ed676719622 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1569,7 +1569,7 @@ namespace sw::mark return pMark; } - std::vector MarkManager::getDropDownsFor(const SwPaM &rPaM) const + std::vector MarkManager::getNoTextFieldmarksIn(const SwPaM &rPaM) const { std::vector aRet; @@ -1582,8 +1582,11 @@ namespace sw::mark continue; IFieldmark *pMark = dynamic_cast(pI); - if (!pMark || pMark->GetFieldname() != ODF_FORMDROPDOWN) + if (!pMark || (pMark->GetFieldname() != ODF_FORMDROPDOWN + && pMark->GetFieldname() != ODF_FORMCHECKBOX)) + { continue; + } aRet.push_back(pMark); } diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index 0e2ffa97bf33..38c6870de628 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -94,7 +94,7 @@ namespace sw::mark { virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& rPos) const override; virtual ::sw::mark::IFieldmark* getDropDownFor(const SwPosition &rPos) const override; - virtual std::vector< ::sw::mark::IFieldmark* > getDropDownsFor(const SwPaM &rPaM) const override; + virtual std::vector<::sw::mark::IFieldmark*> getNoTextFieldmarksIn(const SwPaM &rPaM) const override; virtual void deleteFieldmarkAt(const SwPosition& rPos) override; virtual ::sw::mark::IFieldmark* changeFormFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) override; diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 1c52ea7992d9..6a91d3c37dfc 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -875,6 +875,16 @@ void SwMetaPortion::Paint( const SwTextPaintInfo &rInf ) const namespace sw::mark { OUString ExpandFieldmark(IFieldmark* pBM) { + if (pBM->GetFieldname() == ODF_FORMCHECKBOX) + { + ::sw::mark::ICheckboxFieldmark const*const pCheckboxFm( + dynamic_cast(pBM)); + assert(pCheckboxFm); + return pCheckboxFm->IsChecked() + ? OUString(u"\u2612") + : OUString(u"\u2610"); + } + assert(pBM->GetFieldname() == ODF_FORMDROPDOWN); const IFieldmark::parameter_map_t* const pParameters = pBM->GetParameters(); sal_Int32 nCurrentIdx = 0; const IFieldmark::parameter_map_t::const_iterator pResult = pParameters->find(OUString(ODF_FORMDROPDOWN_RESULT)); diff --git a/sw/source/core/txtnode/modeltoviewhelper.cxx b/sw/source/core/txtnode/modeltoviewhelper.cxx index a5ae25962862..846e4d1a51b1 100644 --- a/sw/source/core/txtnode/modeltoviewhelper.cxx +++ b/sw/source/core/txtnode/modeltoviewhelper.cxx @@ -281,10 +281,10 @@ ModelToViewHelper::ModelToViewHelper(const SwTextNode &rNode, //now get the dropdown formfields, get their position in the node and what the text they expand //to is SwPaM aPaM(rNode, 0, rNode, rNode.Len()); - std::vector aDropDowns = - rNode.GetDoc().getIDocumentMarkAccess()->getDropDownsFor(aPaM); + std::vector aNoTextFieldmarks = + rNode.GetDoc().getIDocumentMarkAccess()->getNoTextFieldmarksIn(aPaM); - for (sw::mark::IFieldmark *pMark : aDropDowns) + for (sw::mark::IFieldmark *const pMark : aNoTextFieldmarks) { const sal_Int32 nDummyCharPos = pMark->GetMarkPos().nContent.GetIndex()-1; if (aHiddenMulti.IsSelected(nDummyCharPos)) diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx index b5577df6ecde..81a7cf0ac793 100644 --- a/sw/source/core/unocore/unobkm.cxx +++ b/sw/source/core/unocore/unobkm.cxx @@ -848,16 +848,7 @@ SwXFieldmark::getPresentation(sal_Bool const bShowCommand) else { OUString const type(getFieldType()); - if (type == ODF_FORMCHECKBOX) - { - ::sw::mark::ICheckboxFieldmark const*const pCheckboxFm( - dynamic_cast(pMark)); - assert(pCheckboxFm); - return pCheckboxFm->IsChecked() - ? OUString(u"\u2612") - : OUString(u"\u2610"); - } - else if (type == ODF_FORMDROPDOWN) + if (type == ODF_FORMCHECKBOX || type == ODF_FORMDROPDOWN) { return sw::mark::ExpandFieldmark(const_cast(pMark)); } -- cgit