diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-09-22 08:36:51 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-09-23 08:53:50 +0200 |
commit | ae40ecb0a78c8a77afce27cd2036ef780acc6e58 (patch) | |
tree | bf98df3a70c6cbf43acb20ed900736dc8ed654c1 /xmloff/qa/unit | |
parent | d818fbc65db108ee74d695b4a6cd1bce190a0cfe (diff) |
sw content controls, combo box: add ODT filter
Map the ComboBox UNO property to:
<loext:content-control loext:combbobox="...">
on export, and do the opposite on import.
(cherry picked from commit 21d93d8d2ffd9c5d5cfe9064590b35e0727295c9)
Change-Id: I33c162ace15025c8031eb678ba5a43ac085c4b6c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140430
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmloff/qa/unit')
-rw-r--r-- | xmloff/qa/unit/data/content-control-combo-box.fodt | 8 | ||||
-rw-r--r-- | xmloff/qa/unit/text.cxx | 66 |
2 files changed, 74 insertions, 0 deletions
diff --git a/xmloff/qa/unit/data/content-control-combo-box.fodt b/xmloff/qa/unit/data/content-control-combo-box.fodt new file mode 100644 index 000000000000..03f6911fb7dd --- /dev/null +++ b/xmloff/qa/unit/data/content-control-combo-box.fodt @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <text:p><loext:content-control loext:combobox="true"><loext:list-item loext:display-text="red" loext:value="R"/><loext:list-item loext:display-text="green" loext:value="G"/><loext:list-item loext:display-text="blue" loext:value="B"/>choose a color</loext:content-control></text:p> + </office:text> + </office:body> +</office:document> diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index 94d7da5e30a9..388106702217 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -795,6 +795,72 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPlainTextContentControlImport) CPPUNIT_ASSERT(bPlainText); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testComboBoxContentControlExport) +{ + // Given a document with a combo box content control around a text portion: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference<lang::XMultiServiceFactory> xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("ComboBox", uno::Any(true)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to ODT: + uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + validate(aTempFile.GetFileName(), test::ODF); + + // Then make sure the expected markup is used: + std::unique_ptr<SvStream> pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//loext:content-control' no attribute 'combobox' exist + // i.e. the combo box content control was turned into a drop-down one on export. + assertXPath(pXmlDoc, "//loext:content-control", "combobox", "true"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testComboBoxContentControlImport) +{ + // Given an ODF document with a plain-text content control: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control-combo-box.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the content control is not lost on import: + uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xTextDocument->getText(), + 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); + bool bComboBox{}; + xContentControlProps->getPropertyValue("ComboBox") >>= bComboBox; + // Without the accompanying fix in place, this test would have failed, the import result was a + // drop-down content control (not a combo box one). + CPPUNIT_ASSERT(bComboBox); +} + CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDropdownContentControlAutostyleExport) { // Given a document with a dropdown content control, and formatting that forms an autostyle in |