sw/qa/extras/ooxmlexport/data/tdf157136_TwoContentControls.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport19.cxx | 57 ++++++++++ writerfilter/source/dmapper/SdtHelper.cxx | 5 3 files changed, 61 insertions(+), 1 deletion(-)
New commits: commit b7a5c2502434d3da92d1fbcad528cabeb61a2719 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Thu Sep 7 19:32:54 2023 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Sep 7 21:15:45 2023 +0200 tdf#157136: apply top context properties to the text input field Change-Id: Ie3877811e482c1ec395a00ec6bf67155220b2b64 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156675 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/data/tdf157136_TwoContentControls.docx b/sw/qa/extras/ooxmlexport/data/tdf157136_TwoContentControls.docx new file mode 100644 index 000000000000..f4e898cb057f Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf157136_TwoContentControls.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx index 961bbdfb6def..275891d4f58b 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx @@ -17,6 +17,8 @@ #include <com/sun/star/view/XSelectionSupplier.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <com/sun/star/text/SizeType.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextField.hpp> #include <com/sun/star/text/XTextTable.hpp> #include <tools/UnitConversion.hxx> @@ -1096,6 +1098,61 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156548) } } +CPPUNIT_TEST_FIXTURE(Test, testTdf157136) +{ + // Given a document with two content controls - one block, one inline + createSwDoc("tdf157136_TwoContentControls.docx"); + + // Both of them must import with the correct character style + + { + // 1st paragraph - block content control + auto xRun = getRun(getParagraph(1), 1); + CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text.\r"), xRun->getString()); + // Without the fix in place, this would fail with + // - Expected: Placeholder Text + // - Actual : + CPPUNIT_ASSERT_EQUAL(OUString("Placeholder Text"), + getProperty<OUString>(xRun, "CharStyleName")); + } + + { + // 2nd paragraph - inline content control + auto xRun = getRun(getParagraph(2), 1); + auto xContentControl + = getProperty<css::uno::Reference<css::text::XTextRange>>(xRun, "ContentControl"); + CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text."), + xContentControl->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("Placeholder Text"), + getProperty<OUString>(xRun, "CharStyleName")); + } + + // Test the same after round-trip + saveAndReload("Office Open XML Text"); + + { + // 1st paragraph - becomes inline content control after roundtrip + auto xRun = getRun(getParagraph(1), 1); + auto xContentControl + = getProperty<css::uno::Reference<css::text::XTextRange>>(xRun, "ContentControl"); + CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text."), + xContentControl->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("Placeholder Text"), + getProperty<OUString>(xRun, "CharStyleName")); + } + + { + // 2nd paragraph - inline content control + auto xRun = getRun(getParagraph(2), 1); + auto xContentControl + = getProperty<css::uno::Reference<css::text::XTextRange>>(xRun, "ContentControl"); + CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text."), + xContentControl->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("Placeholder Text"), + getProperty<OUString>(xRun, "CharStyleName")); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx index 4f94c46f2f55..041802147605 100644 --- a/writerfilter/source/dmapper/SdtHelper.cxx +++ b/writerfilter/source/dmapper/SdtHelper.cxx @@ -350,8 +350,11 @@ void SdtHelper::createPlainTextControl() xPropertySet->setPropertyValue("Content", uno::Any(aDefaultText)); + PropertyMap aMap; + aMap.InsertProps(m_rDM_Impl.GetTopContext()); + // add it into document - m_rDM_Impl.appendTextContent(xControlModel, uno::Sequence<beans::PropertyValue>()); + m_rDM_Impl.appendTextContent(xControlModel, aMap.GetPropertyValues()); // Store all unused sdt parameters from grabbag xPropertySet->setPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG,