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 232014937271d3f78dee569685fb446c105b223c
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:08 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/+/156692
    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 83a2c079fb55..b2f02ce337bc 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -660,6 +660,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 73d2ec44afa7..871708bc37c9 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -349,8 +349,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,

Reply via email to