summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-10-05 15:18:53 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-10-05 16:05:19 +0200
commit5262aab9d220675f616579720b4bb43ee03cccfb (patch)
tree453d6eed7a019cc4a46e91e41726c4181a6dce8b
parent1490923bea9c3ec763488a73912ff0a143329a24 (diff)
sw content controls: preserve tag
This is similar to <w15:color> to preserve <w:tag>. Resolves <https://gerrit.libreoffice.org/c/core/+/137399/2#message-a5ba9f1e0dc9e586034758ee7c0a94e1533e8922>. Change-Id: I4fdab44aaf13ca812502ae79f38f32ec9468db11 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140981 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--offapi/com/sun/star/text/ContentControl.idl6
-rw-r--r--sw/inc/formatcontentcontrol.hxx7
-rw-r--r--sw/inc/unoprnms.hxx1
-rw-r--r--sw/qa/core/unocore/unocore.cxx2
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport17.cxx2
-rw-r--r--sw/source/core/txtnode/attrcontentcontrol.cxx1
-rw-r--r--sw/source/core/unocore/unocontentcontrol.cxx28
-rw-r--r--sw/source/core/unocore/unomap1.cxx1
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx6
-rw-r--r--writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx4
-rw-r--r--writerfilter/qa/cppunittests/dmapper/data/sdt-run-rich-text.docxbin4369 -> 4376 bytes
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx15
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx6
-rw-r--r--writerfilter/source/dmapper/SdtHelper.cxx4
-rw-r--r--writerfilter/source/dmapper/SdtHelper.hxx6
15 files changed, 89 insertions, 0 deletions
diff --git a/offapi/com/sun/star/text/ContentControl.idl b/offapi/com/sun/star/text/ContentControl.idl
index d07dbfc49256..8f390665c2b3 100644
--- a/offapi/com/sun/star/text/ContentControl.idl
+++ b/offapi/com/sun/star/text/ContentControl.idl
@@ -105,6 +105,12 @@ service ContentControl
@since LibreOffice 7.5
*/
[optional, property] string Alias;
+
+ /** The tag: just remembered.
+
+ @since LibreOffice 7.5
+ */
+ [optional, property] string Tag;
};
diff --git a/sw/inc/formatcontentcontrol.hxx b/sw/inc/formatcontentcontrol.hxx
index 6462bf49cd06..8cfa71dd04ba 100644
--- a/sw/inc/formatcontentcontrol.hxx
+++ b/sw/inc/formatcontentcontrol.hxx
@@ -169,6 +169,9 @@ class SW_DLLPUBLIC SwContentControl : public sw::BroadcastingModify
/// The alias: just remembered.
OUString m_aAlias;
+ /// The tag: just remembered.
+ OUString m_aTag;
+
/// Stores a list item index, in case the doc model is not yet updated.
std::optional<size_t> m_oSelectedListItem;
@@ -329,6 +332,10 @@ public:
const OUString& GetAlias() const { return m_aAlias; }
+ void SetTag(const OUString& rTag) { m_aTag = rTag; }
+
+ const OUString& GetTag() const { return m_aTag; }
+
void SetReadWrite(bool bReadWrite) { m_bReadWrite = bReadWrite; }
bool GetReadWrite() const { return m_bReadWrite; }
diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx
index 850a789900df..0a21fd182690 100644
--- a/sw/inc/unoprnms.hxx
+++ b/sw/inc/unoprnms.hxx
@@ -891,6 +891,7 @@
#define UNO_NAME_DATA_BINDING_STORE_ITEM_ID "DataBindingStoreItemID"
#define UNO_NAME_COLOR "Color"
#define UNO_NAME_ALIAS "Alias"
+#define UNO_NAME_TAG "Tag"
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index 23811a497566..ee1592110157 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -625,6 +625,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlDate)
"DataBindingStoreItemID", uno::Any(OUString("{241A8A02-7FFD-488D-8827-63FBE74E8BC9}")));
xContentControlProps->setPropertyValue("Color", uno::Any(OUString("008000")));
xContentControlProps->setPropertyValue("Alias", uno::Any(OUString("myalias")));
+ xContentControlProps->setPropertyValue("Tag", uno::Any(OUString("mytag")));
xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
// Then make sure that the specified properties are set:
@@ -649,6 +650,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlDate)
pContentControl->GetDataBindingStoreItemID());
CPPUNIT_ASSERT_EQUAL(OUString("008000"), pContentControl->GetColor());
CPPUNIT_ASSERT_EQUAL(OUString("myalias"), pContentControl->GetAlias());
+ CPPUNIT_ASSERT_EQUAL(OUString("mytag"), pContentControl->GetTag());
}
CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testListIdState)
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 5246edc2a1e7..a487e86d3269 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -427,6 +427,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDateContentControlExport)
xContentControlProps->setPropertyValue("DataBindingStoreItemID", uno::Any(OUString("{241A8A02-7FFD-488D-8827-63FBE74E8BC9}")));
xContentControlProps->setPropertyValue("Color", uno::Any(OUString("008000")));
xContentControlProps->setPropertyValue("Alias", uno::Any(OUString("myalias")));
+ xContentControlProps->setPropertyValue("Tag", uno::Any(OUString("mytag")));
xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
// When exporting to DOCX:
@@ -449,6 +450,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDateContentControlExport)
assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:dataBinding", "storeItemID", "{241A8A02-7FFD-488D-8827-63FBE74E8BC9}");
assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w15:color", "val", "008000");
assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:alias", "val", "myalias");
+ assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:tag", "val", "mytag");
}
CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorder)
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx b/sw/source/core/txtnode/attrcontentcontrol.cxx
index 911cff5e7a58..587d2f53ed74 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -410,6 +410,7 @@ void SwContentControl::dumpAsXml(xmlTextWriterPtr pWriter) const
BAD_CAST(m_aColor.toUtf8().getStr()));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("alias"),
BAD_CAST(m_aAlias.toUtf8().getStr()));
+ (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("tag"), BAD_CAST(m_aTag.toUtf8().getStr()));
if (!m_aListItems.empty())
{
diff --git a/sw/source/core/unocore/unocontentcontrol.cxx b/sw/source/core/unocore/unocontentcontrol.cxx
index 7af0fd0638b2..a0d7d96099cc 100644
--- a/sw/source/core/unocore/unocontentcontrol.cxx
+++ b/sw/source/core/unocore/unocontentcontrol.cxx
@@ -175,6 +175,7 @@ public:
OUString m_aDataBindingStoreItemID;
OUString m_aColor;
OUString m_aAlias;
+ OUString m_aTag;
Impl(SwXContentControl& rThis, SwDoc& rDoc, SwContentControl* pContentControl,
uno::Reference<text::XText> xParentText, std::unique_ptr<const TextRangeList_t> pPortions)
@@ -484,6 +485,7 @@ void SwXContentControl::AttachImpl(const uno::Reference<text::XTextRange>& xText
pContentControl->SetDataBindingStoreItemID(m_pImpl->m_aDataBindingStoreItemID);
pContentControl->SetColor(m_pImpl->m_aColor);
pContentControl->SetAlias(m_pImpl->m_aAlias);
+ pContentControl->SetTag(m_pImpl->m_aTag);
SwFormatContentControl aContentControl(pContentControl, nWhich);
bool bSuccess
@@ -918,6 +920,21 @@ void SAL_CALL SwXContentControl::setPropertyValue(const OUString& rPropertyName,
}
}
}
+ else if (rPropertyName == UNO_NAME_TAG)
+ {
+ OUString aValue;
+ if (rValue >>= aValue)
+ {
+ if (m_pImpl->m_bIsDescriptor)
+ {
+ m_pImpl->m_aTag = aValue;
+ }
+ else
+ {
+ m_pImpl->m_pContentControl->SetTag(aValue);
+ }
+ }
+ }
else
{
throw beans::UnknownPropertyException();
@@ -1140,6 +1157,17 @@ uno::Any SAL_CALL SwXContentControl::getPropertyValue(const OUString& rPropertyN
aRet <<= m_pImpl->m_pContentControl->GetAlias();
}
}
+ else if (rPropertyName == UNO_NAME_TAG)
+ {
+ if (m_pImpl->m_bIsDescriptor)
+ {
+ aRet <<= m_pImpl->m_aTag;
+ }
+ else
+ {
+ aRet <<= m_pImpl->m_pContentControl->GetTag();
+ }
+ }
else
{
throw beans::UnknownPropertyException();
diff --git a/sw/source/core/unocore/unomap1.cxx b/sw/source/core/unocore/unomap1.cxx
index ae9a718a57ee..55c1d2731de9 100644
--- a/sw/source/core/unocore/unomap1.cxx
+++ b/sw/source/core/unocore/unomap1.cxx
@@ -1010,6 +1010,7 @@ o3tl::span<const SfxItemPropertyMapEntry> SwUnoPropertyMapProvider::GetContentCo
{ u"" UNO_NAME_DATA_BINDING_STORE_ITEM_ID, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
{ u"" UNO_NAME_COLOR, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
{ u"" UNO_NAME_ALIAS, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
+ { u"" UNO_NAME_TAG, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
};
return aContentControlMap_Impl;
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 7338bb697fc4..de0775305145 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2367,6 +2367,12 @@ void DocxAttributeOutput::WriteContentControlStart()
m_pContentControl->GetAlias());
}
+ if (!m_pContentControl->GetTag().isEmpty())
+ {
+ m_pSerializer->singleElementNS(XML_w, XML_tag, FSNS(XML_w, XML_val),
+ m_pContentControl->GetTag());
+ }
+
if (m_pContentControl->GetShowingPlaceHolder())
{
m_pSerializer->singleElementNS(XML_w, XML_showingPlcHdr);
diff --git a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
index f6f67327fad8..5b62fdf55122 100644
--- a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
@@ -91,6 +91,10 @@ CPPUNIT_TEST_FIXTURE(Test, testSdtRunRichText)
xContentControlProps->getPropertyValue("Alias") >>= aAlias;
// This was empty.
CPPUNIT_ASSERT_EQUAL(OUString("myalias"), aAlias);
+ OUString aTag;
+ xContentControlProps->getPropertyValue("Tag") >>= aTag;
+ // This was empty.
+ CPPUNIT_ASSERT_EQUAL(OUString("mytag"), aTag);
}
CPPUNIT_TEST_FIXTURE(Test, testSdtRunPlainText)
diff --git a/writerfilter/qa/cppunittests/dmapper/data/sdt-run-rich-text.docx b/writerfilter/qa/cppunittests/dmapper/data/sdt-run-rich-text.docx
index b3b25d8cc3ab..b7f291f776bf 100644
--- a/writerfilter/qa/cppunittests/dmapper/data/sdt-run-rich-text.docx
+++ b/writerfilter/qa/cppunittests/dmapper/data/sdt-run-rich-text.docx
Binary files differ
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 2682f78e1e91..94e273a0fdcd 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2814,6 +2814,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
case NS_ooxml::LN_CT_SdtPr_alias:
case NS_ooxml::LN_CT_SdtPlaceholder_docPart:
case NS_ooxml::LN_CT_SdtPr_color:
+ case NS_ooxml::LN_CT_SdtPr_tag:
{
if (!m_pImpl->GetSdtStarts().empty())
{
@@ -2833,6 +2834,12 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
break;
}
+ if (nSprmId == NS_ooxml::LN_CT_SdtPr_tag)
+ {
+ m_pImpl->m_pSdtHelper->SetTag(sStringValue);
+ break;
+ }
+
if (nSprmId == NS_ooxml::LN_CT_SdtPr_checkbox)
{
m_pImpl->m_pSdtHelper->setControlType(SdtControlType::checkBox);
@@ -2864,6 +2871,14 @@ 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;
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index d73b89a78de0..191b7fec353c 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -943,6 +943,12 @@ void DomainMapper_Impl::PopSdt()
uno::Any(m_pSdtHelper->GetAlias()));
}
+ if (!m_pSdtHelper->GetTag().isEmpty())
+ {
+ xContentControlProps->setPropertyValue("Tag",
+ uno::Any(m_pSdtHelper->GetTag()));
+ }
+
if (m_pSdtHelper->getControlType() == SdtControlType::checkBox)
{
xContentControlProps->setPropertyValue("Checkbox", uno::Any(true));
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index ebcea44ef863..d8f48ef7ffe2 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -515,6 +515,10 @@ void SdtHelper::SetAlias(const OUString& rAlias) { m_aAlias = rAlias; }
const OUString& SdtHelper::GetAlias() const { return m_aAlias; }
+void SdtHelper::SetTag(const OUString& rTag) { m_aTag = rTag; }
+
+const OUString& SdtHelper::GetTag() const { return m_aTag; }
+
} // namespace writerfilter::dmapper
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index bdb95f3d7e13..dc1a3172e364 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -129,6 +129,9 @@ class SdtHelper final : public virtual SvRefBase
/// <w:sdtPr>'s <w:alias w:val="...">.
OUString m_aAlias;
+ /// <w:sdtPr>'s <w:tag w:val="...">.
+ OUString m_aTag;
+
public:
explicit SdtHelper(DomainMapper_Impl& rDM_Impl,
css::uno::Reference<css::uno::XComponentContext> xContext);
@@ -211,6 +214,9 @@ public:
void SetAlias(const OUString& rAlias);
const OUString& GetAlias() const;
+ void SetTag(const OUString& rTag);
+ const OUString& GetTag() const;
+
std::optional<OUString> getValueFromDataBinding();
};