[Libreoffice-commits] core.git: officecfg/registry sw/qa writerfilter/source
Serge Krot (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jun 17 15:01:22 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 +++++--
sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 4
writerfilter/source/dmapper/SdtHelper.cxx | 60 +++++++++----
7 files changed, 157 insertions(+), 42 deletions(-)
New commits:
commit 33ad3ee258587904afaa03550858beac25b883f7
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: Wed Jun 17 17:00:46 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>
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 c1890a33c2cd..7356de7be9fe 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -714,17 +714,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/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index ecd4c588fbbd..b2e67a1d3769 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1367,8 +1367,8 @@ DECLARE_OOXMLIMPORT_TEST(testTdf133448, "tdf133448.docx")
CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel);
//Without the fix in place, the graphic's size is 0x0
- CPPUNIT_ASSERT_EQUAL(sal_Int32(837), aSizePixel.Width);
- CPPUNIT_ASSERT_EQUAL(sal_Int32(598), aSizePixel.Height);
+ CPPUNIT_ASSERT_GREATER(sal_Int32(0), aSizePixel.Width);
+ CPPUNIT_ASSERT_GREATER(sal_Int32(0), aSizePixel.Height);
}
DECLARE_OOXMLIMPORT_TEST(testTdf100072, "tdf100072.docx")
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index 2e36709db3d9..8a224243aa07 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