diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-11 08:17:32 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-05-11 09:25:27 +0200 |
commit | 24417d8c3c9e1c619936e85fa7a20481a24e3530 (patch) | |
tree | 9ca8cb76620cb5221c940305a8c1d05ded273dd6 /sw | |
parent | 3322e500f48794d3569c27f73cc5f3bafb5f2397 (diff) |
sw content controls, drop-down: add DOCX import
- inline drop-down content controls were imported as an SwDropDownField
previously, but that has the drawback of not being able to store both
display texts and values of each list items
- adapt tests under sw/qa/ which asserted that the import result is a
field, and check content control properties instead
- change dmapper so that SdtControlType::dropDown is one more inline
SDT that gets mapped to SwContentControl
- remove the no longer needed grab-bagging in writerfilter/, otherwise
we would write the SDT markup twice on export
- improve DomainMapper_Impl::PopSdt() to actually map the collected
dropdown properties to properties on the to-be-inserted content
control
Change-Id: I7e88ec8cd1d73bc1c6c75154d6ab07352cbcec8b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134143
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 23 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 59 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport8.cxx | 43 |
3 files changed, 85 insertions, 40 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 1e5a00d25bfb..5cd096e737f5 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -295,7 +295,7 @@ DECLARE_OOXMLEXPORT_TEST(testDropdownInCell, "dropdown-in-cell.docx") uno::Reference<text::XTextRangeCompare> xTextRangeCompare(xCell, uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int16(0), xTextRangeCompare->compareRegionStarts(xAnchor, xCell)); } - else + else if (!mbExported) { // ComboBox was imported as DropDown text field uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); @@ -306,6 +306,27 @@ DECLARE_OOXMLEXPORT_TEST(testDropdownInCell, "dropdown-in-cell.docx") uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY); CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown")); } + else + { + // DropDown text field is exported as inline SDT, we import that back here. + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<table::XCell> xCell = xTable->getCellByName("B1"); + uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValues> aListItems; + xContentControlProps->getPropertyValue("ListItems") >>= aListItems; + CPPUNIT_ASSERT(aListItems.hasElements()); + } } DECLARE_OOXMLEXPORT_TEST(testTableAlignment, "table-alignment.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index ceece00a23f5..0435f4254f1b 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -599,8 +599,7 @@ DECLARE_OOXMLEXPORT_TEST(testParaAdjustDistribute, "para-adjust-distribute.docx" DECLARE_OOXMLEXPORT_TEST(testInputListExport, "tdf122186_input_list.odt") { - CPPUNIT_ASSERT_EQUAL(1, getPages()); - if (!mbExported || getShapes() == 0) // importing the ODT, an input field + if (!mbExported) // importing the ODT, an input field { uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); @@ -610,19 +609,28 @@ DECLARE_OOXMLEXPORT_TEST(testInputListExport, "tdf122186_input_list.odt") uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY); CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown")); } - else // importing the DOCX, a form control + else // importing the DOCX, a content control { - 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(xServiceInfo->supportsService("com.sun.star.form.component.ComboBox")); - CPPUNIT_ASSERT(getProperty<bool>(xPropertySet, "Dropdown")); - auto const items(getProperty<uno::Sequence<OUString>>(xPropertySet, "StringItemList")); - CPPUNIT_ASSERT_EQUAL(sal_Int32(3), items.getLength()); - CPPUNIT_ASSERT_EQUAL(OUString("1"), items[0]); - CPPUNIT_ASSERT_EQUAL(OUString("2"), items[1]); - CPPUNIT_ASSERT_EQUAL(OUString("3"), items[2]); - CPPUNIT_ASSERT_EQUAL(OUString("1"), getProperty<OUString>(xPropertySet, "DefaultText")); + uno::Reference<beans::XPropertySet> xTextPortion(getRun(getParagraph(1), 1), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValues> aListItems; + xContentControlProps->getPropertyValue("ListItems") >>= aListItems; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), aListItems.getLength()); + comphelper::SequenceAsHashMap aMap0(aListItems[0]); + CPPUNIT_ASSERT_EQUAL(OUString("1"), aMap0["Value"].get<OUString>()); + comphelper::SequenceAsHashMap aMap1(aListItems[1]); + CPPUNIT_ASSERT_EQUAL(OUString("2"), aMap1["Value"].get<OUString>()); + comphelper::SequenceAsHashMap aMap2(aListItems[2]); + CPPUNIT_ASSERT_EQUAL(OUString("3"), aMap2["Value"].get<OUString>()); + uno::Reference<container::XEnumerationAccess> xContentEnumAccess(xContentControl, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xContentEnum = xContentEnumAccess->createEnumeration(); + uno::Reference<text::XTextRange> xContent(xContentEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xContent->getString()); } } @@ -1119,17 +1127,18 @@ DECLARE_OOXMLEXPORT_TEST(tdf119809, "tdf119809.docx") } 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(1), aItems.getLength()); + // DropDown was imported as content control + // First run: bookmark + uno::Reference<beans::XPropertySet> xTextPortion(getRun(getParagraph(1), 2), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValues> aListItems; + xContentControlProps->getPropertyValue("ListItems") >>= aListItems; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aListItems.getLength()); } } diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx index c949f59b34ca..b52c25c01544 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx @@ -933,20 +933,35 @@ DECLARE_OOXMLEXPORT_TEST(testN779630, "n779630.docx") } 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(3), aItems.getLength()); - CPPUNIT_ASSERT_EQUAL(OUString("Yes"), aItems[0]); - CPPUNIT_ASSERT_EQUAL(OUString("No"), aItems[1]); - CPPUNIT_ASSERT_EQUAL(OUString("dropdown default text"), aItems[2]); + // Inline SDT: dropdown is imported as content control. + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<table::XCell> xCell = xTable->getCellByName("B1"); + uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + // Label: + xPortions->nextElement(); + // Space: + xPortions->nextElement(); + // Default text: + uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValues> aListItems; + xContentControlProps->getPropertyValue("ListItems") >>= aListItems; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aListItems.getLength()); + uno::Reference<container::XEnumerationAccess> xContentEnumAccess(xContentControl, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xContentEnum = xContentEnumAccess->createEnumeration(); + uno::Reference<text::XTextRange> xContent(xContentEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("dropdown default text"), xContent->getString()); } } |