summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-11-09 15:50:01 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-11-09 17:00:00 +0100
commit56db6406b0b63a2d2d99024e7c311ebd874f3893 (patch)
treeb7096b526b5bfd5f5a474f467761f7065f8e81c2 /xmloff
parentcb8a05bfccf77d5217f4f2e20b5898d6a24f990d (diff)
sw content controls: allow no list items in a dropdown
- Replace SwContentControl::HasListItems(), which assumed that the type is dropdown if we have list items. This is not valid, it's OK to have a dropdown with no list items. Add a GetDropDown() instead to check for the type, explicitly. - UNO API sets the dropdown bit when list items are set and the type is not expilcitly combo box or drop down, to keep backwards compatibility with existing documents. - No change to the edit shell, SwDropDownContentControlButton already checked if items are empty and used STR_DROP_DOWN_EMPTY_LIST in that case, but that was dead code previously. - ODT & DOCX filters are now updated, ODF has a new <loext:content-control loext:dropdown="..."> attribute to specify that the type is a dropdown, explicitly. Change-Id: Id577ba9639151549a8f953aab31685a73a898504 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142491 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/qa/unit/data/content-control-dropdown.fodt2
-rw-r--r--xmloff/qa/unit/text.cxx2
-rw-r--r--xmloff/source/text/txtparae.cxx9
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.cxx13
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.hxx1
5 files changed, 26 insertions, 1 deletions
diff --git a/xmloff/qa/unit/data/content-control-dropdown.fodt b/xmloff/qa/unit/data/content-control-dropdown.fodt
index 97344d1e8bec..73007b2c7c26 100644
--- a/xmloff/qa/unit/data/content-control-dropdown.fodt
+++ b/xmloff/qa/unit/data/content-control-dropdown.fodt
@@ -2,7 +2,7 @@
<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: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>
+ <text:p><loext:content-control loext:dropdown="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 16f830aa43cf..9befd99fc600 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -473,6 +473,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDropdownContentControlExport)
xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
{
+ xContentControlProps->setPropertyValue("DropDown", uno::Any(true));
uno::Sequence<beans::PropertyValues> aListItems = {
{
comphelper::makePropertyValue("DisplayText", uno::Any(OUString("red"))),
@@ -496,6 +497,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDropdownContentControlExport)
// Then make sure the expected markup is used:
xmlDocUniquePtr pXmlDoc = parseExport("content.xml");
+ assertXPath(pXmlDoc, "//loext:content-control", "dropdown", "true");
// Without the accompanying fix in place, this failed with:
// - Expected: 1
// - Actual : 0
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index f2b10130f71b..b52a66249a1b 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -4037,6 +4037,15 @@ void XMLTextParagraphExport::ExportContentControl(
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_COMBOBOX, aBuffer.makeStringAndClear());
}
+ bool bDropDown = false;
+ xPropertySet->getPropertyValue("DropDown") >>= bDropDown;
+ if (bDropDown)
+ {
+ OUStringBuffer aBuffer;
+ sax::Converter::convertBool(aBuffer, bDropDown);
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DROPDOWN, aBuffer.makeStringAndClear());
+ }
+
OUString aAlias;
xPropertySet->getPropertyValue("Alias") >>= aAlias;
if (!aAlias.isEmpty())
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.cxx b/xmloff/source/text/xmlcontentcontrolcontext.cxx
index 379bbe309bd2..c069a6eba9c1 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.cxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx
@@ -133,6 +133,14 @@ void XMLContentControlContext::startFastElement(
}
break;
}
+ case XML_ELEMENT(LO_EXT, XML_DROPDOWN):
+ {
+ if (sax::Converter::convertBool(bTmp, rIter.toView()))
+ {
+ m_bDropDown = bTmp;
+ }
+ break;
+ }
case XML_ELEMENT(LO_EXT, XML_ALIAS):
{
m_aAlias = rIter.toString();
@@ -239,6 +247,11 @@ void XMLContentControlContext::endFastElement(sal_Int32)
xPropertySet->setPropertyValue("ComboBox", uno::Any(m_bComboBox));
}
+ if (m_bDropDown)
+ {
+ xPropertySet->setPropertyValue("DropDown", uno::Any(m_bDropDown));
+ }
+
if (!m_aAlias.isEmpty())
{
xPropertySet->setPropertyValue("Alias", uno::Any(m_aAlias));
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx b/xmloff/source/text/xmlcontentcontrolcontext.hxx
index 0bfca015ec68..936fc03c781b 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.hxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx
@@ -50,6 +50,7 @@ class XMLContentControlContext : public SvXMLImportContext
OUString m_aCurrentDate;
bool m_bPlainText = false;
bool m_bComboBox = false;
+ bool m_bDropDown = false;
OUString m_aAlias;
OUString m_aTag;