sw/qa/extras/ooxmlexport/data/tdf157136_TwoContentControls.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx                      |   55 
++++++++++
 writerfilter/source/dmapper/SdtHelper.cxx                       |    5 
 3 files changed, 59 insertions(+), 1 deletion(-)

New commits:
commit da8e60218adac676e33b0031c70859027ec5f328
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Sep 7 19:32:54 2023 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Sep 11 08:33:55 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>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156729
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@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/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index ad18b6afc246..36b492c5d294 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -268,6 +268,61 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf150966_regularInset)
     assertXPathAttrs(pXmlDoc, "//wps:bodyPr", { { "tIns", "179640" }, { 
"bIns", "360000" } });
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf157136)
+{
+    // Given a document with two content controls - one block, one inline
+    load(DATA_DIRECTORY, "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
+    reload("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 99fd0de0de9d..8a75679ef73a 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -288,8 +288,11 @@ void SdtHelper::createPlainTextControl()
 
     xPropertySet->setPropertyValue("Content", uno::makeAny(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,

Reply via email to