summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-09-22 08:36:51 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-09-22 09:34:38 +0200
commit21d93d8d2ffd9c5d5cfe9064590b35e0727295c9 (patch)
treeb26051aa82044f21a5440e20c1662cd0b7c61e11
parentddc5a7bb10c6229018dbdb3192740b6d893fa08b (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. Change-Id: I33c162ace15025c8031eb678ba5a43ac085c4b6c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140364 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng6
-rw-r--r--xmloff/qa/unit/data/content-control-combo-box.fodt8
-rw-r--r--xmloff/qa/unit/text.cxx66
-rw-r--r--xmloff/source/text/txtparae.cxx9
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.cxx13
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.hxx1
6 files changed, 103 insertions, 0 deletions
diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
index cd0c8fb04244..a26e920aa687 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -2986,6 +2986,12 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.
<rng:ref name="boolean"/>
</rng:attribute>
</rng:optional>
+ <rng:optional>
+ <!-- default value: false -->
+ <rng:attribute name="loext:combobox">
+ <rng:ref name="boolean"/>
+ </rng:attribute>
+ </rng:optional>
<rng:zeroOrMore>
<rng:element name="loext:list-item">
<rng:attribute name="loext:display-text">
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 8ad3ea6f941b..72b0e49ecbd0 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -899,6 +899,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
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index fdb3de666389..bbbf5f26b931 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -4027,6 +4027,15 @@ void XMLTextParagraphExport::ExportContentControl(
sax::Converter::convertBool(aBuffer, bPlainText);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_PLAIN_TEXT, aBuffer.makeStringAndClear());
}
+
+ bool bComboBox = false;
+ xPropertySet->getPropertyValue("ComboBox") >>= bComboBox;
+ if (bComboBox)
+ {
+ OUStringBuffer aBuffer;
+ sax::Converter::convertBool(aBuffer, bComboBox);
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_COMBOBOX, aBuffer.makeStringAndClear());
+ }
}
SvXMLElementExport aElem(GetExport(), bExport, XML_NAMESPACE_LO_EXT, XML_CONTENT_CONTROL, false,
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.cxx b/xmloff/source/text/xmlcontentcontrolcontext.cxx
index ea3b90299664..0df8d79e9f84 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.cxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx
@@ -125,6 +125,14 @@ void XMLContentControlContext::startFastElement(
}
break;
}
+ case XML_ELEMENT(LO_EXT, XML_COMBOBOX):
+ {
+ if (sax::Converter::convertBool(bTmp, rIter.toView()))
+ {
+ m_bComboBox = bTmp;
+ }
+ break;
+ }
default:
XMLOFF_WARN_UNKNOWN("xmloff", rIter);
}
@@ -215,6 +223,11 @@ void XMLContentControlContext::endFastElement(sal_Int32)
{
xPropertySet->setPropertyValue("PlainText", uno::Any(m_bPlainText));
}
+
+ if (m_bComboBox)
+ {
+ xPropertySet->setPropertyValue("ComboBox", uno::Any(m_bComboBox));
+ }
}
css::uno::Reference<css::xml::sax::XFastContextHandler>
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx b/xmloff/source/text/xmlcontentcontrolcontext.hxx
index 59c852419b6c..e507b02e85cd 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.hxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx
@@ -49,6 +49,7 @@ class XMLContentControlContext : public SvXMLImportContext
OUString m_aDateLanguage;
OUString m_aCurrentDate;
bool m_bPlainText = false;
+ bool m_bComboBox = false;
public:
XMLContentControlContext(SvXMLImport& rImport, sal_Int32 nElement, XMLHints_Impl& rHints,