From a5098b222c9406af858fd6d94d0ceb2c3c2066a8 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Thu, 8 Dec 2022 11:45:05 -0500 Subject: tdf#151548 sw content controls: preserve tag for block SDTs The tag is critical for VBA access. Although we do not yet import blockSdts as content controls, losing this would break any VBA macros for MS Word. So make sure it round-trips. I can't imagine why it wasn't treated the same as alias. I guess because Alias is seen, while tag appears to have no valuable function (until VBA, where it becomes the most likely ID field.) Change-Id: I05a04faa9d2314c7b37c5b86f107bd1a16019509 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143830 Tested-by: Jenkins Reviewed-by: Justin Luth Reviewed-by: Miklos Vajna --- sw/qa/extras/ooxmlexport/ooxmlexport16.cxx | 6 ++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 10 ++++++++++ sw/source/filter/ww8/docxattributeoutput.hxx | 1 + writerfilter/source/dmapper/DomainMapper.cxx | 11 ++--------- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx index d631c783b1a9..f5230adb643a 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx @@ -490,6 +490,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf148671, "tdf148671.docx") { // Don't assert with 'pFieldMark' failed when document is opened CPPUNIT_ASSERT_EQUAL(1, getPages()); + + if (!isExported()) + return; + // Preserve tag on SDT blocks. (Before the fix, these were all lost) + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:tag", 3); } DECLARE_OOXMLEXPORT_TEST(testTdf140668, "tdf140668.docx") diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index dcafe422a0e8..95f137ec771f 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -615,6 +615,8 @@ void SdtBlockHelper::DeleteAndResetTheLists() m_pTextAttrs.clear(); if (!m_aAlias.isEmpty()) m_aAlias.clear(); + if (!m_aTag.isEmpty()) + m_aTag.clear(); if (!m_aPlaceHolderDocPart.isEmpty()) m_aPlaceHolderDocPart.clear(); if (!m_aColor.isEmpty()) @@ -719,6 +721,9 @@ void SdtBlockHelper::WriteExtraParams(const ::sax_fastparser::FSHelperPtr& pSeri if (!m_aAlias.isEmpty()) pSerializer->singleElementNS(XML_w, XML_alias, FSNS(XML_w, XML_val), m_aAlias); + + if (!m_aTag.isEmpty()) + pSerializer->singleElementNS(XML_w, XML_tag, FSNS(XML_w, XML_val), m_aTag); } void SdtBlockHelper::EndSdtBlock(const ::sax_fastparser::FSHelperPtr& pSerializer) @@ -828,6 +833,11 @@ void SdtBlockHelper::GetSdtParamsFromGrabBag(const uno::Sequence>= m_aAlias)) SAL_WARN("sw.ww8", "DocxAttributeOutput::GrabBag: unexpected sdt alias value"); } + else if (aPropertyValue.Name == "ooxml:CT_SdtPr_tag" && m_aTag.isEmpty()) + { + if (!(aPropertyValue.Value >>= m_aTag)) + SAL_WARN("sw.ww8", "DocxAttributeOutput::GrabBag: unexpected sdt tag value"); + } else if (aPropertyValue.Name == "ooxml:CT_SdtPr_id") m_bHasId = true; else if (aPropertyValue.Name == "ooxml:CT_SdtPr_citation") diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 6e029cc9dfc4..f8da5a4bd32d 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -144,6 +144,7 @@ public: OUString m_aPlaceHolderDocPart; bool m_bShowingPlaceHolder; OUString m_aAlias; + OUString m_aTag; sal_Int32 m_nSdtPrToken; void DeleteAndResetTheLists(); diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 4683ff445458..a3a4407a5971 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -2910,14 +2910,6 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) break; } } - else - { - if (nSprmId == NS_ooxml::LN_CT_SdtPr_tag) - { - // Tag is only handled here in case of inline SDT. - break; - } - } // this is an unsupported SDT property, create a grab bag for it OUString sName; @@ -2933,6 +2925,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) case NS_ooxml::LN_CT_SdtPr_group: sName = "ooxml:CT_SdtPr_group"; break; case NS_ooxml::LN_CT_SdtPr_id: sName = "ooxml:CT_SdtPr_id"; break; case NS_ooxml::LN_CT_SdtPr_alias: sName = "ooxml:CT_SdtPr_alias"; break; + case NS_ooxml::LN_CT_SdtPr_tag: sName = "ooxml:CT_SdtPr_tag"; break; case NS_ooxml::LN_CT_SdtPlaceholder_docPart: sName = "ooxml:CT_SdtPlaceholder_docPart"; break; case NS_ooxml::LN_CT_SdtPr_showingPlcHdr: sName = "ooxml:CT_SdtPr_showingPlcHdr"; break; case NS_ooxml::LN_CT_SdtPr_color: sName = "ooxml:CT_SdtPr_color"; break; @@ -2954,7 +2947,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) if (pProperties) pProperties->resolve(*this); - if (nSprmId == NS_ooxml::LN_CT_SdtPr_alias) + if (nSprmId == NS_ooxml::LN_CT_SdtPr_alias || nSprmId == NS_ooxml::LN_CT_SdtPr_tag) { beans::PropertyValue aValue; aValue.Name = sName; -- cgit