officecfg/registry/schema/org/openoffice/Office/Writer.xcs | 12 ++ sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 29 ++++-- sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 37 ++++++-- sw/qa/extras/ooxmlexport/ooxmlexport4.cxx | 36 ++++++- sw/qa/extras/ooxmlexport/ooxmlexport8.cxx | 36 ++++++- writerfilter/source/dmapper/SdtHelper.cxx | 60 +++++++++---- 6 files changed, 171 insertions(+), 39 deletions(-)
New commits: commit 029d239dd64a52ebb548f699c89e9109ae836fce Author: Serge Krot <serge.k...@cib.de> AuthorDate: Tue Jun 16 17:11:12 2020 +0200 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Tue Jun 30 23:29:51 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.behr...@cib.de> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96608 diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs index e76bbeef495b..6ba34c5338ff 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs @@ -5883,6 +5883,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>false</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 d4a453a27580..9a771a5f81b7 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -272,13 +272,30 @@ DECLARE_OOXMLEXPORT_TEST(testDropdownInCell, "dropdown-in-cell.docx") uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + // 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 (xDrawPage->getCount() > 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 e586a666dff4..3cd34365a2f2 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -505,7 +505,12 @@ DECLARE_OOXMLEXPORT_TEST(testParaAdjustDistribute, "para-adjust-distribute.docx" DECLARE_OOXMLEXPORT_TEST(testInputListExport, "tdf122186_input_list.odt") { - if (!mbExported) // importing the ODT, an input field + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + + if (!mbExported || xDrawPage->getCount() == 0) // importing the ODT, an input field { uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); @@ -859,12 +864,32 @@ DECLARE_OOXMLEXPORT_TEST(tdf127085, "tdf127085.docx") DECLARE_OOXMLEXPORT_TEST(tdf119809, "tdf119809.docx") { + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + // 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 (xDrawPage->getCount() > 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 29d4d54534f8..c80c8f6655bb 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx @@ -775,15 +775,39 @@ DECLARE_OOXMLEXPORT_TEST(testComboBoxControl, "combobox-control.docx") 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"); + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + // check imported control - uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY); + if (xDrawPage->getCount() > 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_TEST(testCheckBoxControl, "checkbox-control.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx index 88f8610cc0e5..0e1416b7ee00 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx @@ -933,14 +933,36 @@ DECLARE_OOXMLEXPORT_TEST(testN592908_Picture, "n592908-picture.docx") DECLARE_OOXMLEXPORT_TEST(testN779630, "n779630.docx") { + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + // 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 (xDrawPage->getCount() > 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 aef7ac1e5fbd..3685e92cf942 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 { @@ -80,19 +81,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; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits