[Libreoffice-commits] core.git: Branch 'libreoffice-7-0' - officecfg/registry sw/qa writerfilter/source

Serge Krot (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 23 12:23:35 UTC 2020


 officecfg/registry/schema/org/openoffice/Office/Writer.xcs |   12 ++
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx                   |   26 ++++-
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx                 |   29 ++++--
 sw/qa/extras/ooxmlexport/ooxmlexport4.cxx                  |   35 ++++++-
 sw/qa/extras/ooxmlexport/ooxmlexport8.cxx                  |   33 +++++--
 writerfilter/source/dmapper/SdtHelper.cxx                  |   60 +++++++++----
 6 files changed, 155 insertions(+), 40 deletions(-)

New commits:
commit f7606f0c7d9fc5961adec6a84ccedf0f4dbcdad9
Author:     Serge Krot <Serge.Krot at cib.de>
AuthorDate: Tue Jun 16 17:11:12 2020 +0200
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Tue Jun 23 14:23:01 2020 +0200

    tdf#134043 DOCX import: DropDown text field instead of ComboBox form control
    
    Change-Id: Ide9cedefde3b00fa0eeb37a6540e8d4a420b70c0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96471
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96729

diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
index 8b76534d540d..6beb18105b08 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
@@ -5899,6 +5899,18 @@
             <value>true</value>
           </prop>
         </group>
+        <group oor:name="DOCX">
+          <info>
+            <desc>Contains settings for importing DOCX.</desc>
+          </info>
+          <prop oor:name="ImportComboBoxAsDropDown" oor:type="xs:boolean" oor:nillable="false">
+            <info>
+              <desc>Specifies whether ComboBox form control should be imported as DropDown text field.</desc>
+              <label>Import ComboBox as DropDown</label>
+            </info>
+            <value>true</value>
+          </prop>
+        </group>
       </group>
     </group>
     <group oor:name="Numbering">
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 5ff581743ccd..133c2add7822 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -264,12 +264,26 @@ DECLARE_OOXMLEXPORT_TEST(testDropdownInCell, "dropdown-in-cell.docx")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
 
     // Second problem: dropdown shape wasn't anchored inside the B1 cell.
-    uno::Reference<text::XTextContent> xShape(getShape(1), uno::UNO_QUERY);
-    uno::Reference<text::XTextRange> xAnchor = xShape->getAnchor();
-    uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
-    uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY);
-    uno::Reference<text::XTextRangeCompare> xTextRangeCompare(xCell, uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(sal_Int16(0), xTextRangeCompare->compareRegionStarts(xAnchor, xCell));
+    if (getShapes() > 0)
+    {
+        uno::Reference<text::XTextContent> xShape(getShape(1), uno::UNO_QUERY);
+        uno::Reference<text::XTextRange> xAnchor = xShape->getAnchor();
+        uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
+        uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY);
+        uno::Reference<text::XTextRangeCompare> xTextRangeCompare(xCell, uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(0), xTextRangeCompare->compareRegionStarts(xAnchor, xCell));
+    }
+    else
+    {
+        // ComboBox was imported as DropDown text field
+        uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+        uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+        uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+        CPPUNIT_ASSERT(xFields->hasMoreElements());
+        uno::Any aField = xFields->nextElement();
+        uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown"));
+    }
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTableAlignment, "table-alignment.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 272daae72c78..430749768862 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -560,7 +560,7 @@ DECLARE_OOXMLEXPORT_TEST(testParaAdjustDistribute, "para-adjust-distribute.docx"
 DECLARE_OOXMLEXPORT_TEST(testInputListExport, "tdf122186_input_list.odt")
 {
     CPPUNIT_ASSERT_EQUAL(1, getPages());
-    if (!mbExported) // importing the ODT, an input field
+    if (!mbExported || getShapes() == 0) // importing the ODT, an input field
     {
         uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
         uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
@@ -1032,11 +1032,28 @@ DECLARE_OOXMLEXPORT_TEST(tdf127085, "tdf127085.docx")
 DECLARE_OOXMLEXPORT_TEST(tdf119809, "tdf119809.docx")
 {
     // Combobox without an item list lost during import
-    uno::Reference<drawing::XControlShape> xControlShape(getShape(1), uno::UNO_QUERY);
-    uno::Reference<beans::XPropertySet> xPropertySet(xControlShape->getControl(), uno::UNO_QUERY);
-    uno::Reference<lang::XServiceInfo> xServiceInfo(xPropertySet, uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo->supportsService("com.sun.star.form.component.ComboBox")));
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty< uno::Sequence<OUString> >(xPropertySet, "StringItemList").getLength());
+    if (getShapes() > 0)
+    {
+        uno::Reference<drawing::XControlShape> xControlShape(getShape(1), uno::UNO_QUERY);
+        uno::Reference<beans::XPropertySet> xPropertySet(xControlShape->getControl(), uno::UNO_QUERY);
+        uno::Reference<lang::XServiceInfo> xServiceInfo(xPropertySet, uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo->supportsService("com.sun.star.form.component.ComboBox")));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty< uno::Sequence<OUString> >(xPropertySet, "StringItemList").getLength());
+    }
+    else
+    {
+        // ComboBox was imported as DropDown text field
+        uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+        uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+        uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+        CPPUNIT_ASSERT(xFields->hasMoreElements());
+        uno::Any aField = xFields->nextElement();
+        uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown"));
+
+        uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> >(aField, "Items");
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aItems.getLength());
+    }
 }
 
 DECLARE_OOXMLEXPORT_TEST(tdf118169, "tdf118169.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index 4dd7062c6e17..5289dec3dfc5 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -717,17 +717,38 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testComboBoxControl, "combobox-control.docx"
     xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
     assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dropDownList/w:listItem[1]", "value", "manolo");
     assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dropDownList/w:listItem[2]", "value", "pepito");
-    assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", "Manolo");
+    assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", "manolo");
 
     // check imported control
-    uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY);
+    if (getShapes() > 0)
+    {
+        uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY);
 
-    CPPUNIT_ASSERT_EQUAL(OUString("Manolo"), getProperty<OUString>(xControl->getControl(), "Text"));
+        CPPUNIT_ASSERT_EQUAL(OUString("Manolo"), getProperty<OUString>(xControl->getControl(), "Text"));
 
-    uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> >(xControl->getControl(), "StringItemList");
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aItems.getLength());
-    CPPUNIT_ASSERT_EQUAL(OUString("manolo"), aItems[0]);
-    CPPUNIT_ASSERT_EQUAL(OUString("pepito"), aItems[1]);
+        uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> >(xControl->getControl(), "StringItemList");
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aItems.getLength());
+        CPPUNIT_ASSERT_EQUAL(OUString("manolo"), aItems[0]);
+        CPPUNIT_ASSERT_EQUAL(OUString("pepito"), aItems[1]);
+    }
+    else
+    {
+        // ComboBox was imported as DropDown text field
+        uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+        uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+        uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+        CPPUNIT_ASSERT(xFields->hasMoreElements());
+        uno::Any aField = xFields->nextElement();
+        uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown"));
+
+        CPPUNIT_ASSERT_EQUAL(OUString("manolo"), getProperty<OUString>(aField, "SelectedItem"));
+
+        uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> >(aField, "Items");
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aItems.getLength());
+        CPPUNIT_ASSERT_EQUAL(OUString("manolo"), aItems[0]);
+        CPPUNIT_ASSERT_EQUAL(OUString("pepito"), aItems[1]);
+    }
 }
 
 DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testCheckBoxControl, "checkbox-control.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
index 56e6e6b1079f..5f401b266bfc 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
@@ -926,13 +926,32 @@ DECLARE_OOXMLEXPORT_TEST(testN592908_Picture, "n592908-picture.docx")
 DECLARE_OOXMLEXPORT_TEST(testN779630, "n779630.docx")
 {
     // A combo box is imported
-    uno::Reference<drawing::XControlShape> xControlShape(getShape(1), uno::UNO_QUERY);
-    uno::Reference<beans::XPropertySet> xPropertySet(xControlShape->getControl(), uno::UNO_QUERY);
-    uno::Reference<lang::XServiceInfo> xServiceInfo(xPropertySet, uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo->supportsService("com.sun.star.form.component.ComboBox")));
-    CPPUNIT_ASSERT_EQUAL(OUString("dropdown default text"), getProperty<OUString>(xPropertySet, "DefaultText"));
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty< uno::Sequence<OUString> >(xPropertySet, "StringItemList").getLength());
-    CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xPropertySet, "Dropdown"));
+    if (getShapes() > 0)
+    {
+        uno::Reference<drawing::XControlShape> xControlShape(getShape(1), uno::UNO_QUERY);
+        uno::Reference<beans::XPropertySet> xPropertySet(xControlShape->getControl(), uno::UNO_QUERY);
+        uno::Reference<lang::XServiceInfo> xServiceInfo(xPropertySet, uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo->supportsService("com.sun.star.form.component.ComboBox")));
+        CPPUNIT_ASSERT_EQUAL(OUString("dropdown default text"), getProperty<OUString>(xPropertySet, "DefaultText"));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty< uno::Sequence<OUString> >(xPropertySet, "StringItemList").getLength());
+        CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xPropertySet, "Dropdown"));
+    }
+    else
+    {
+        // ComboBox was imported as DropDown text field
+        uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+        uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+        uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+        CPPUNIT_ASSERT(xFields->hasMoreElements());
+        uno::Any aField = xFields->nextElement();
+        uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown"));
+
+        uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> >(aField, "Items");
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aItems.getLength());
+        CPPUNIT_ASSERT_EQUAL(OUString("Yes"), aItems[0]);
+        CPPUNIT_ASSERT_EQUAL(OUString("No"), aItems[1]);
+    }
 }
 
 DECLARE_OOXMLEXPORT_TEST(testIndentation, "indentation.docx")
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index d31bfe4db00c..4e437ae0e562 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -16,9 +16,10 @@
 #include <vcl/outdev.hxx>
 #include <comphelper/sequence.hxx>
 #include <xmloff/odffields.hxx>
-
+#include <com/sun/star/text/XTextField.hpp>
 #include "DomainMapper_Impl.hxx"
 #include "StyleSheetTable.hxx"
+#include <officecfg/Office/Writer.hxx>
 
 namespace writerfilter::dmapper
 {
@@ -77,19 +78,50 @@ SdtHelper::~SdtHelper() = default;
 void SdtHelper::createDropDownControl()
 {
     assert(m_bInsideDropDownControl);
-    OUString aDefaultText = m_aSdtTexts.makeStringAndClear();
-    uno::Reference<awt::XControlModel> xControlModel(
-        m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.form.component.ComboBox"),
-        uno::UNO_QUERY);
-    uno::Reference<beans::XPropertySet> xPropertySet(xControlModel, uno::UNO_QUERY);
-    xPropertySet->setPropertyValue("DefaultText", uno::makeAny(aDefaultText));
-    xPropertySet->setPropertyValue("Dropdown", uno::makeAny(true));
-    xPropertySet->setPropertyValue("StringItemList",
-                                   uno::makeAny(comphelper::containerToSequence(m_aDropDownItems)));
-
-    createControlShape(
-        lcl_getOptimalWidth(m_rDM_Impl.GetStyleSheetTable(), aDefaultText, m_aDropDownItems),
-        xControlModel, uno::Sequence<beans::PropertyValue>());
+
+    const bool bDropDown
+        = officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown::get();
+    const OUString aDefaultText = m_aSdtTexts.makeStringAndClear();
+
+    if (bDropDown)
+    {
+        // create field
+        uno::Reference<css::text::XTextField> xControlModel(
+            m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.text.TextField.DropDown"),
+            uno::UNO_QUERY);
+
+        // set properties
+        uno::Reference<beans::XPropertySet> xPropertySet(xControlModel, uno::UNO_QUERY);
+        xPropertySet->setPropertyValue("SelectedItem", uno::makeAny(aDefaultText));
+        xPropertySet->setPropertyValue(
+            "Items", uno::makeAny(comphelper::containerToSequence(m_aDropDownItems)));
+
+        // add it into document
+        m_rDM_Impl.appendTextContent(xControlModel, uno::Sequence<beans::PropertyValue>());
+
+        m_bHasElements = true;
+    }
+    else
+    {
+        // create control
+        uno::Reference<awt::XControlModel> xControlModel(
+            m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.form.component.ComboBox"),
+            uno::UNO_QUERY);
+
+        // set properties
+        uno::Reference<beans::XPropertySet> xPropertySet(xControlModel, uno::UNO_QUERY);
+        xPropertySet->setPropertyValue("DefaultText", uno::makeAny(aDefaultText));
+        xPropertySet->setPropertyValue("Dropdown", uno::makeAny(true));
+        xPropertySet->setPropertyValue(
+            "StringItemList", uno::makeAny(comphelper::containerToSequence(m_aDropDownItems)));
+
+        // add it into document
+        createControlShape(
+            lcl_getOptimalWidth(m_rDM_Impl.GetStyleSheetTable(), aDefaultText, m_aDropDownItems),
+            xControlModel, uno::Sequence<beans::PropertyValue>());
+    }
+
+    // clean up
     m_aDropDownItems.clear();
     m_bInsideDropDownControl = false;
 }


More information about the Libreoffice-commits mailing list