diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-09 10:14:29 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-05-11 14:55:28 +0200 |
commit | cfba9f6802b66ae0bb7dd21b9e25b38c0c735f88 (patch) | |
tree | 55ca52fc010fc9ecde8c4df6fe434f02ec571769 /xmloff/source/text | |
parent | f440e1ab725c14c6acac4f7275ca9d9192c6af2a (diff) |
sw content controls, drop-down: add ODT filter
Map each list item to a dedicated XML element:
<loext:list-item loext:display-text="..." loext:value="...">
And do the opposite on import.
(cherry picked from commit c3f4c43694f0f9aec35193ccf40f0e7c8476fdc3)
Change-Id: I59a536a8317a3bb24919107b4449f858d5f6de96
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134145
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmloff/source/text')
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 26 | ||||
-rw-r--r-- | xmloff/source/text/xmlcontentcontrolcontext.cxx | 60 | ||||
-rw-r--r-- | xmloff/source/text/xmlcontentcontrolcontext.hxx | 19 |
3 files changed, 104 insertions, 1 deletions
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 85890612b96b..4ffb14ad528b 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -110,6 +110,7 @@ #include <iterator> #include <officecfg/Office/Common.hxx> #include <o3tl/safeint.hxx> +#include <comphelper/sequenceashashmap.hxx> using namespace ::std; using namespace ::com::sun::star; @@ -3862,9 +3863,9 @@ void XMLTextParagraphExport::ExportContentControl( uno::Reference<container::XEnumerationAccess> xEA(xTextContent, uno::UNO_QUERY_THROW); uno::Reference<container::XEnumeration> xTextEnum = xEA->createEnumeration(); + uno::Reference<beans::XPropertySet> xPropertySet(xTextContent, uno::UNO_QUERY_THROW); if (bExport) { - uno::Reference<beans::XPropertySet> xPropertySet(xTextContent, uno::UNO_QUERY_THROW); bool bShowingPlaceHolder = false; xPropertySet->getPropertyValue("ShowingPlaceHolder") >>= bShowingPlaceHolder; if (bShowingPlaceHolder) @@ -3911,6 +3912,29 @@ void XMLTextParagraphExport::ExportContentControl( SvXMLElementExport aElem(GetExport(), bExport, XML_NAMESPACE_LO_EXT, XML_CONTENT_CONTROL, false, false); + // Export list items of dropdowns. + uno::Sequence<beans::PropertyValues> aListItems; + xPropertySet->getPropertyValue("ListItems") >>= aListItems; + for (const auto& rListItem : aListItems) + { + comphelper::SequenceAsHashMap aMap(rListItem); + auto it = aMap.find("DisplayText"); + OUString aValue; + if (it != aMap.end() && (it->second >>= aValue)) + { + GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DISPLAY_TEXT, aValue); + } + + it = aMap.find("Value"); + if (it != aMap.end() && (it->second >>= aValue)) + { + GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_VALUE, aValue); + } + + SvXMLElementExport aItem(GetExport(), bExport, XML_NAMESPACE_LO_EXT, XML_LIST_ITEM, false, + false); + } + // Recurse to export content. exportTextRangeEnumeration(xTextEnum, bAutoStyles, isProgress, rPrevCharIsSpace); } diff --git a/xmloff/source/text/xmlcontentcontrolcontext.cxx b/xmloff/source/text/xmlcontentcontrolcontext.cxx index 61fa609e0185..eb3a384d6b98 100644 --- a/xmloff/source/text/xmlcontentcontrolcontext.cxx +++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx @@ -25,6 +25,8 @@ #include <xmloff/xmlimp.hxx> #include <xmloff/xmlnamespace.hxx> #include <xmloff/xmltoken.hxx> +#include <comphelper/propertyvalue.hxx> +#include <comphelper/sequence.hxx> #include "XMLTextMarkImportContext.hxx" #include "txtparai.hxx" @@ -142,12 +144,26 @@ void XMLContentControlContext::endFastElement(sal_Int32) { xPropertySet->setPropertyValue("UncheckedState", uno::makeAny(m_aUncheckedState)); } + if (!m_aListItems.empty()) + { + xPropertySet->setPropertyValue("ListItems", + uno::Any(comphelper::containerToSequence(m_aListItems))); + } } css::uno::Reference<css::xml::sax::XFastContextHandler> XMLContentControlContext::createFastChildContext( sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList) { + switch (nElement) + { + case XML_ELEMENT(LO_EXT, XML_LIST_ITEM): + return new XMLListItemContext(GetImport(), *this); + break; + default: + break; + } + return XMLImpSpanContext_Impl::CreateSpanContext(GetImport(), nElement, xAttrList, m_rHints, m_rIgnoreLeadingSpace); } @@ -157,4 +173,48 @@ void XMLContentControlContext::characters(const OUString& rChars) GetImport().GetTextImport()->InsertString(rChars, m_rIgnoreLeadingSpace); } +void XMLContentControlContext::AppendListItem(const css::beans::PropertyValues& rListItem) +{ + m_aListItems.push_back(rListItem); +} + +XMLListItemContext::XMLListItemContext(SvXMLImport& rImport, + XMLContentControlContext& rContentControl) + : SvXMLImportContext(rImport) + , m_rContentControl(rContentControl) +{ +} + +void XMLListItemContext::startFastElement( + sal_Int32 /*nElement*/, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList) +{ + OUString aDisplayText; + OUString aValue; + + for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList)) + { + switch (rIter.getToken()) + { + case XML_ELEMENT(LO_EXT, XML_DISPLAY_TEXT): + { + aDisplayText = rIter.toString(); + break; + } + case XML_ELEMENT(LO_EXT, XML_VALUE): + { + aValue = rIter.toString(); + break; + } + default: + XMLOFF_WARN_UNKNOWN("xmloff", rIter); + } + } + + uno::Sequence<beans::PropertyValue> aListItem = { + comphelper::makePropertyValue("DisplayText", uno::Any(aDisplayText)), + comphelper::makePropertyValue("Value", uno::Any(aValue)), + }; + m_rContentControl.AppendListItem(aListItem); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx b/xmloff/source/text/xmlcontentcontrolcontext.hxx index 3d3e44d76445..20c39ad44d2c 100644 --- a/xmloff/source/text/xmlcontentcontrolcontext.hxx +++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx @@ -20,7 +20,10 @@ #include <xmloff/xmlictxt.hxx> +#include <vector> + #include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/beans/PropertyValues.hpp> class XMLHints_Impl; @@ -39,6 +42,7 @@ class XMLContentControlContext : public SvXMLImportContext bool m_bChecked = false; OUString m_aCheckedState; OUString m_aUncheckedState; + std::vector<css::beans::PropertyValues> m_aListItems; public: XMLContentControlContext(SvXMLImport& rImport, sal_Int32 nElement, XMLHints_Impl& rHints, @@ -55,6 +59,21 @@ public: const css::uno::Reference<css::xml::sax::XFastAttributeList>& rAttrList) override; void SAL_CALL characters(const OUString& rChars) override; + + void AppendListItem(const css::beans::PropertyValues& rListItem); +}; + +/// Imports <loext:list-item> inside <loext:content-control>. +class XMLListItemContext : public SvXMLImportContext +{ + XMLContentControlContext& m_rContentControl; + +public: + XMLListItemContext(SvXMLImport& rImport, XMLContentControlContext& rContentControl); + + void SAL_CALL startFastElement( + sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) override; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |