include/xmloff/txtparae.hxx | 4 include/xmloff/xmltoken.hxx | 4 schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng | 15 + xmloff/Library_xo.mk | 1 xmloff/qa/unit/data/content-control.fodt | 8 xmloff/qa/unit/text.cxx | 70 +++++++ xmloff/source/core/xmltoken.cxx | 3 xmloff/source/text/txtparae.cxx | 41 ++++ xmloff/source/text/txtparai.cxx | 42 ---- xmloff/source/text/txtparai.hxx | 40 ++++ xmloff/source/text/xmlcontentcontrolcontext.cxx | 117 ++++++++++++ xmloff/source/text/xmlcontentcontrolcontext.hxx | 55 +++++ xmloff/source/token/tokens.txt | 2 13 files changed, 365 insertions(+), 37 deletions(-)
New commits: commit 1790cc337fc1b72eab5e6254baf7030b51c6c875 Author: Miklos Vajna <[email protected]> AuthorDate: Mon Apr 11 11:27:13 2022 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Apr 22 14:58:44 2022 +0200 sw content controls: add ODT import Map <loext:content-control loext:showing-place-holder="..."> to com.sun.star.text.ContentControl and set its ShowingPlaceHolder property based on the XML attribute. This requires moving XMLImpSpanContext_Impl to txtparai.hxx, otherwise XMLContentControlContext would have to be in txtparai.cxx, which is already large. (cherry picked from commit d1649e5d38b51cd422302e566719a2c5aff42b2f) Change-Id: I9a915868160ebcc0e98ded61bfab72f32864bd76 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133316 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk index c76b2b2381c0..29eb22ef324a 100644 --- a/xmloff/Library_xo.mk +++ b/xmloff/Library_xo.mk @@ -357,6 +357,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\ xmloff/source/text/txtstyle \ xmloff/source/text/txtstyli \ xmloff/source/text/txtvfldi \ + xmloff/source/text/xmlcontentcontrolcontext \ xmloff/source/xforms/SchemaContext \ xmloff/source/xforms/SchemaRestrictionContext \ xmloff/source/xforms/SchemaSimpleTypeContext \ diff --git a/xmloff/qa/unit/data/content-control.fodt b/xmloff/qa/unit/data/content-control.fodt new file mode 100644 index 000000000000..97769c662b66 --- /dev/null +++ b/xmloff/qa/unit/data/content-control.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:showing-place-holder="true">test</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 5e5f24b64975..9ab19785028f 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -352,6 +352,40 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testContentControlExport) assertXPath(pXmlDoc, "//loext:content-control", "showing-place-holder", "true"); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testContentControlImport) +{ + // Given an ODF document with a content control: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control.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; + // Without the accompanying fix in place, this failed with: + // - Expected: ContentControl + // - Actual : Text + // i.e. the content control was lost on import. + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference<text::XTextRange> xContentControlRange(xContentControl, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xContentControlRange->getText(); + uno::Reference<container::XEnumerationAccess> xContentEnumAccess(xText, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xContentEnum = xContentEnumAccess->createEnumeration(); + uno::Reference<text::XTextRange> xContent(xContentEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("test"), xContent->getString()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx index d4c93642105b..be40c2c34ea6 100644 --- a/xmloff/source/text/txtparai.cxx +++ b/xmloff/source/text/txtparai.cxx @@ -60,6 +60,7 @@ #include "txtparaimphint.hxx" #include "xmllinebreakcontext.hxx" +#include "xmlcontentcontrolcontext.hxx" using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -288,43 +289,6 @@ XMLEndReferenceContext_Impl::XMLEndReferenceContext_Impl( namespace { -class XMLImpSpanContext_Impl : public SvXMLImportContext -{ - XMLHints_Impl& m_rHints; - XMLStyleHint_Impl *pHint; - - bool& rIgnoreLeadingSpace; - - sal_uInt8 nStarFontsConvFlags; - -public: - - - XMLImpSpanContext_Impl( - SvXMLImport& rImport, - sal_Int32 nElement, - const Reference< xml::sax::XFastAttributeList > & xAttrList, - XMLHints_Impl& rHints, - bool& rIgnLeadSpace, - sal_uInt8 nSFConvFlags - ); - - static css::uno::Reference< css::xml::sax::XFastContextHandler > CreateSpanContext( - SvXMLImport& rImport, - sal_Int32 nElement, - const Reference< xml::sax::XFastAttributeList > & xAttrList, - XMLHints_Impl& rHints, - bool& rIgnLeadSpace, - sal_uInt8 nStarFontsConvFlags = 0 - ); - - virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( - sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; - - virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override; - virtual void SAL_CALL characters( const OUString& rChars ) override; -}; - class XMLImpHyperlinkContext_Impl : public SvXMLImportContext { XMLHints_Impl& m_rHints; @@ -1564,6 +1528,10 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLImpSpanContext_Impl rHints, rIgnoreLeadingSpace ); break; + case XML_ELEMENT(LO_EXT, XML_CONTENT_CONTROL): + pContext = new XMLContentControlContext(rImport, nElement, rHints, rIgnoreLeadingSpace); + break; + default: // none of the above? then it's probably a text field! pContext = XMLTextFieldImportContext::CreateTextFieldImportContext( diff --git a/xmloff/source/text/txtparai.hxx b/xmloff/source/text/txtparai.hxx index 10a60bf162f3..66c64181c4ba 100644 --- a/xmloff/source/text/txtparai.hxx +++ b/xmloff/source/text/txtparai.hxx @@ -102,4 +102,44 @@ public: }; +class XMLHints_Impl; +class XMLStyleHint_Impl; + +class XMLImpSpanContext_Impl : public SvXMLImportContext +{ + XMLHints_Impl& m_rHints; + XMLStyleHint_Impl *pHint; + + bool& rIgnoreLeadingSpace; + + sal_uInt8 nStarFontsConvFlags; + +public: + + + XMLImpSpanContext_Impl( + SvXMLImport& rImport, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, + XMLHints_Impl& rHints, + bool& rIgnLeadSpace, + sal_uInt8 nSFConvFlags + ); + + static css::uno::Reference< css::xml::sax::XFastContextHandler > CreateSpanContext( + SvXMLImport& rImport, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, + XMLHints_Impl& rHints, + bool& rIgnLeadSpace, + sal_uInt8 nStarFontsConvFlags = 0 + ); + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + + virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override; + virtual void SAL_CALL characters( const OUString& rChars ) override; +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/xmlcontentcontrolcontext.cxx b/xmloff/source/text/xmlcontentcontrolcontext.cxx new file mode 100644 index 000000000000..fb7869b6e8a8 --- /dev/null +++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "xmlcontentcontrolcontext.hxx" + +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <sax/tools/converter.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlnamespace.hxx> +#include <xmloff/xmltoken.hxx> + +#include "XMLTextMarkImportContext.hxx" +#include "txtparai.hxx" + +using namespace com::sun::star; +using namespace xmloff::token; + +XMLContentControlContext::XMLContentControlContext(SvXMLImport& rImport, sal_Int32 /*nElement*/, + XMLHints_Impl& rHints, bool& rIgnoreLeadingSpace) + : SvXMLImportContext(rImport) + , m_rHints(rHints) + , m_rIgnoreLeadingSpace(rIgnoreLeadingSpace) + , m_xStart(GetImport().GetTextImport()->GetCursorAsRange()->getStart()) +{ +} + +void XMLContentControlContext::startFastElement( + sal_Int32 /*nElement*/, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList) +{ + for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList)) + { + bool bTmp = false; + + switch (rIter.getToken()) + { + case XML_ELEMENT(LO_EXT, XML_SHOWING_PLACE_HOLDER): + { + if (sax::Converter::convertBool(bTmp, rIter.toView())) + { + m_bShowingPlaceHolder = bTmp; + } + break; + } + default: + XMLOFF_WARN_UNKNOWN("xmloff", rIter); + } + } +} + +void XMLContentControlContext::endFastElement(sal_Int32) +{ + if (!m_xStart.is()) + { + SAL_WARN("xmloff.text", "XMLContentControlContext::endFastElement: no m_xStart"); + return; + } + + uno::Reference<text::XTextRange> xEndRange + = GetImport().GetTextImport()->GetCursorAsRange()->getStart(); + + // Create range for insertion. + uno::Reference<text::XTextCursor> xInsertionCursor + = GetImport().GetTextImport()->GetText()->createTextCursorByRange(xEndRange); + xInsertionCursor->gotoRange(m_xStart, /*bExpand=*/true); + + uno::Reference<text::XTextContent> xContentControl + = XMLTextMarkImportContext::CreateAndInsertMark( + GetImport(), "com.sun.star.text.ContentControl", OUString(), xInsertionCursor); + if (!xContentControl.is()) + { + SAL_WARN("xmloff.text", "cannot insert content control"); + return; + } + + uno::Reference<beans::XPropertySet> xPropertySet(xContentControl, uno::UNO_QUERY); + if (!xPropertySet.is()) + { + return; + } + + if (m_bShowingPlaceHolder) + { + xPropertySet->setPropertyValue("ShowingPlaceHolder", uno::makeAny(m_bShowingPlaceHolder)); + } +} + +css::uno::Reference<css::xml::sax::XFastContextHandler> +XMLContentControlContext::createFastChildContext( + sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList) +{ + return XMLImpSpanContext_Impl::CreateSpanContext(GetImport(), nElement, xAttrList, m_rHints, + m_rIgnoreLeadingSpace); +} + +void XMLContentControlContext::characters(const OUString& rChars) +{ + GetImport().GetTextImport()->InsertString(rChars, m_rIgnoreLeadingSpace); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx b/xmloff/source/text/xmlcontentcontrolcontext.hxx new file mode 100644 index 000000000000..2658fa76972b --- /dev/null +++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <xmloff/xmlictxt.hxx> + +#include <com/sun/star/text/XTextContent.hpp> + +class XMLHints_Impl; + +/// Imports <loext:content-control>. +class XMLContentControlContext : public SvXMLImportContext +{ + XMLHints_Impl& m_rHints; + + bool& m_rIgnoreLeadingSpace; + + css::uno::Reference<css::text::XTextRange> m_xStart; + + bool m_bShowingPlaceHolder = false; + +public: + XMLContentControlContext(SvXMLImport& rImport, sal_Int32 nElement, XMLHints_Impl& rHints, + bool& rIgnoreLeadingSpace); + + void SAL_CALL startFastElement( + sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) override; + + void SAL_CALL endFastElement(sal_Int32 nElement) override; + + css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList>& rAttrList) override; + + void SAL_CALL characters(const OUString& rChars) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 4e31fc026cdd841c8ab263a81cdb9a163f4db4d8 Author: Miklos Vajna <[email protected]> AuthorDate: Fri Apr 8 11:32:22 2022 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Apr 22 14:58:27 2022 +0200 sw content controls: add ODT export Wrap the text portions inside the content control in a <loext:content-control> XML element. Also map the (so far) single UNO property of it to <loext:content-control loext:showing-place-holder="...">. This is just initial export for inline text content controls, more properties are to be added in follow-up commits. (cherry picked from commit cf5bbe3fce4a250ab25998053965bdc604c6114e) Conflicts: include/xmloff/xmltoken.hxx xmloff/qa/unit/text.cxx xmloff/source/core/xmltoken.cxx xmloff/source/token/tokens.txt Change-Id: I5d928255b925ed7e08fb635ba39f546e9a4879de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133315 Tested-by: Miklos Vajna <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/include/xmloff/txtparae.hxx b/include/xmloff/txtparae.hxx index 70716c1f77a2..546bf2adca3c 100644 --- a/include/xmloff/txtparae.hxx +++ b/include/xmloff/txtparae.hxx @@ -368,6 +368,10 @@ protected: const css::uno::Reference< css::beans::XPropertySet> & i_xPortion, bool i_bAutoStyles, bool i_isProgress, bool & rPrevCharIsSpace); + /// Exports a <loext:content-control> element. + void ExportContentControl(const css::uno::Reference<css::beans::XPropertySet>& xPortion, + bool bAutoStyles, bool isProgress, bool& rPrevCharIsSpace); + bool isAutoStylesCollected() const { return mbCollected; } virtual void exportTableAutoStyles(); diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index 0cdd604e1ce7..f4378934fb8f 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -3467,6 +3467,10 @@ namespace xmloff::token { XML_LINKED_STYLE_NAME, + + XML_CONTENT_CONTROL, + XML_SHOWING_PLACE_HOLDER, + XML_TOKEN_END }; diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng index 5190957e93e7..ab895a066d32 100644 --- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng +++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng @@ -2763,6 +2763,21 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. </rng:element> </rng:define> + <!-- TODO(vmiklos) no proposal --> + <rng:define name="paragraph-content" combine="choice"> + <rng:element name="loext:content-control"> + <rng:optional> + <!-- default value: false --> + <rng:attribute name="loext:showing-place-holder"> + <rng:ref name="boolean"/> + </rng:attribute> + </rng:optional> + <rng:zeroOrMore> + <rng:ref name="paragraph-content-or-hyperlink"/> + </rng:zeroOrMore> + </rng:element> + </rng:define> + <!-- TODO no proposal --> <rng:define name="animation-element" combine="choice"> <rng:choice> diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index a386df28acbd..5e5f24b64975 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -316,6 +316,42 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testClearingBreakImport) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(3), eClear); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testContentControlExport) +{ + // Given a document with a content control around one or more text portions: + 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("ShowingPlaceHolder", uno::makeAny(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::makeAny(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 failed with: + // - XPath '//loext:content-control' number of nodes is incorrect + // i.e. the content control was lost on export. + assertXPath(pXmlDoc, "//loext:content-control", "showing-place-holder", "true"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index c1646dfb0701..ebde9b9f34b7 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3470,6 +3470,9 @@ namespace xmloff::token { TOKEN("linked-style-name", XML_LINKED_STYLE_NAME ), + TOKEN("content-control", XML_CONTENT_CONTROL ), + TOKEN("showing-place-holder", XML_SHOWING_PLACE_HOLDER ), + #if OSL_DEBUG_LEVEL > 0 { 0, nullptr, std::nullopt, XML_TOKEN_END } diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 5f0247bc32c7..109015c9fe98 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -2212,6 +2212,10 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( { exportMeta(xPropSet, bAutoStyles, bIsProgress, rPrevCharIsSpace); } + else if (sType == "ContentControl") + { + ExportContentControl(xPropSet, bAutoStyles, bIsProgress, rPrevCharIsSpace); + } else if (sType == gsTextFieldStart) { Reference< css::text::XFormField > xFormField(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY); @@ -3842,6 +3846,43 @@ void XMLTextParagraphExport::exportMeta( exportTextRangeEnumeration(xTextEnum, i_bAutoStyles, i_isProgress, rPrevCharIsSpace); } +void XMLTextParagraphExport::ExportContentControl( + const uno::Reference<beans::XPropertySet>& xPortion, bool bAutoStyles, bool isProgress, + bool& rPrevCharIsSpace) +{ + // Do not export the element in the autostyle case. + bool bExport = !bAutoStyles; + if (!(GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)) + { + bExport = false; + } + + uno::Reference<text::XTextContent> xTextContent(xPortion->getPropertyValue("ContentControl"), + uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xTextContent, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumeration> xTextEnum = xEA->createEnumeration(); + + if (bExport) + { + uno::Reference<beans::XPropertySet> xPropertySet(xTextContent, uno::UNO_QUERY_THROW); + bool bShowingPlaceHolder = false; + xPropertySet->getPropertyValue("ShowingPlaceHolder") >>= bShowingPlaceHolder; + if (bShowingPlaceHolder) + { + OUStringBuffer aBuffer; + sax::Converter::convertBool(aBuffer, bShowingPlaceHolder); + GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_SHOWING_PLACE_HOLDER, + aBuffer.makeStringAndClear()); + } + } + + SvXMLElementExport aElem(GetExport(), bExport, XML_NAMESPACE_LO_EXT, XML_CONTENT_CONTROL, false, + false); + + // Recurse to export content. + exportTextRangeEnumeration(xTextEnum, bAutoStyles, isProgress, rPrevCharIsSpace); +} + void XMLTextParagraphExport::PreventExportOfControlsInMuteSections( const Reference<XIndexAccess> & rShapes, const rtl::Reference<xmloff::OFormLayerXMLExport>& xFormExport ) diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 2547fbd58c66..b202beb7a319 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -3214,4 +3214,6 @@ rspace rtl symmetric linked-style-name +content-control +showing-place-holder TOKEN_END_DUMMY
