include/xmloff/xmltoken.hxx                                 |    2 
 schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng |   16 ++
 sw/inc/formatcontentcontrol.hxx                             |    2 
 sw/qa/extras/tiledrendering/tiledrendering.cxx              |   70 +++++++++++
 xmloff/qa/unit/data/content-control-date.fodt               |    8 +
 xmloff/qa/unit/text.cxx                                     |   75 ++++++++++++
 xmloff/source/core/xmltoken.cxx                             |    2 
 xmloff/source/text/txtparae.cxx                             |   23 +++
 xmloff/source/text/xmlcontentcontrolcontext.cxx             |   31 ++++
 xmloff/source/text/xmlcontentcontrolcontext.hxx             |    3 
 xmloff/source/token/tokens.txt                              |    2 
 11 files changed, 234 insertions(+)

New commits:
commit 553dce1708de1b7da29d3487198e4c6ce07cb916
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu May 26 14:49:22 2022 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon May 30 14:26:23 2022 +0200

    sw content controls, picture: add LOK API testcase
    
    Fails with commit 9a76be53dfb801b754bf55f9d4b8c5f82991a62f (sw content
    controls, picture: add LOK API, 2022-05-23) reverted.
    
    Change-Id: I6164e597099632a2212afee86ac9a4c7555e5c61
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135022
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit ce12103990f7a8623c6de8b668784dbd0ab4d1b7)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135118
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 3e0771d1c6d1..b852d8f91206 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -66,6 +66,8 @@
 #include <docsh.hxx>
 #include <txtfrm.hxx>
 #include <rootfrm.hxx>
+#include <fmtanchr.hxx>
+#include <textcontentcontrol.hxx>
 
 constexpr OUStringLiteral DATA_DIRECTORY = 
u"/sw/qa/extras/tiledrendering/data/";
 
@@ -169,6 +171,7 @@ public:
     void testRedlinePortions();
     void testContentControl();
     void testDropDownContentControl();
+    void testPictureContentControl();
 
     CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -258,6 +261,7 @@ public:
     CPPUNIT_TEST(testRedlinePortions);
     CPPUNIT_TEST(testContentControl);
     CPPUNIT_TEST(testDropDownContentControl);
+    CPPUNIT_TEST(testPictureContentControl);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3721,6 +3725,72 @@ void SwTiledRenderingTest::testDropDownContentControl()
     CPPUNIT_ASSERT_EQUAL(OUString("green"), 
pTextNode->GetExpandText(pWrtShell->GetLayout()));
 }
 
+void SwTiledRenderingTest::testPictureContentControl()
+{
+    // Given a document with a picture content control:
+    SwXTextDocument* pXTextDocument = createDoc();
+    SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+    setupLibreOfficeKitViewCallback(pWrtShell->GetSfxViewShell());
+    uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<text::XText> xText = xTextDocument->getText();
+    uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+    uno::Reference<beans::XPropertySet> xTextGraphic(
+        xMSF->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+    xTextGraphic->setPropertyValue("AnchorType",
+                                   
uno::Any(text::TextContentAnchorType_AS_CHARACTER));
+    uno::Reference<text::XTextContent> xTextContent(xTextGraphic, 
uno::UNO_QUERY);
+    xText->insertTextContent(xCursor, xTextContent, 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::Any(true));
+    xContentControlProps->setPropertyValue("Picture", uno::Any(true));
+    xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+    pWrtShell->SttEndDoc(/*bStt=*/true);
+    m_aContentControl.clear();
+
+    // When clicking on that content control:
+    pWrtShell->GotoObj(/*bNext=*/true, GotoObjFlags::Any);
+    pWrtShell->EnterSelFrameMode();
+    const SwFrameFormat* pFlyFormat = pWrtShell->GetFlyFrameFormat();
+    const SwFormatAnchor& rFormatAnchor = pFlyFormat->GetAnchor();
+    const SwPosition* pAnchorPos = rFormatAnchor.GetContentAnchor();
+    SwTextNode* pTextNode = pAnchorPos->nNode.GetNode().GetTextNode();
+    SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, 
RES_TXTATR_CONTENTCONTROL);
+    auto pTextContentControl = 
static_txtattr_cast<SwTextContentControl*>(pAttr);
+    auto& rFormatContentControl
+        = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr());
+    pWrtShell->GotoContentControl(rFormatContentControl);
+
+    // Then make sure that the callback is emitted:
+    // Without the accompanying fix in place, this test would have failed, no 
callback was emitted.
+    CPPUNIT_ASSERT(!m_aContentControl.isEmpty());
+    std::stringstream aStream(m_aContentControl.getStr());
+    boost::property_tree::ptree aTree;
+    boost::property_tree::read_json(aStream, aTree);
+    OString sAction = 
aTree.get_child("action").get_value<std::string>().c_str();
+    CPPUNIT_ASSERT_EQUAL(OString("change-picture"), sAction);
+
+    // And when replacing the image:
+    std::map<OUString, OUString> aArguments;
+    aArguments.emplace("type", "picture");
+    OUString aURL = 
m_directories.getURLFromSrc(u"sw/qa/extras/uiwriter/data/ole2.png");
+    aArguments.emplace("changed", aURL);
+    pXTextDocument->executeContentControlEvent(aArguments);
+
+    // Then make sure that the document is updated accordingly:
+    uno::Reference<drawing::XShape> xShape = getShape(1);
+    auto xGraphic = getProperty<uno::Reference<beans::XPropertySet>>(xShape, 
"Graphic");
+    // Without the accompanying fix in place, this test would have failed, 
xGraphic was empty after
+    // executeContentControlEvent().
+    CPPUNIT_ASSERT(xGraphic.is());
+    CPPUNIT_ASSERT_EQUAL(OUString("image/png"), 
getProperty<OUString>(xGraphic, "MimeType"));
+
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
commit c2bc478f217c5dd898321dfba19078ae1c32b0c4
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu May 26 08:25:50 2022 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon May 30 14:26:07 2022 +0200

    sw content controls, date: add ODT filter
    
    Map the Date, DateFormat and DateLanguage UNO properties to:
    
            <loext:content-control loext:date="..." loext:date-format="..." 
loext:date-rfc-language-tag="...">
    
    And do the opposite on import.
    
    (cherry picked from commit b3c6511659c58bcc75a9742e0ae0cc436b6f6825)
    
    Change-Id: I16d3f755d77ed20380d877ba65dfe6d063f2bec2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135117
    Tested-by: Miklos Vajna <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index 85619ab39550..b0e9003b0261 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -3474,6 +3474,8 @@ namespace xmloff::token {
         XML_UNCHECKED_STATE,
         XML_DISPLAY_TEXT,
         XML_PICTURE,
+        XML_DATE_FORMAT,
+        XML_DATE_RFC_LANGUAGE_TAG,
 
         XML_TOKEN_END
     };
diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng 
b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
index 32ab55fb9445..514a30c30307 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -2800,6 +2800,22 @@ 
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:date">
+          <rng:ref name="boolean"/>
+        </rng:attribute>
+      </rng:optional>
+      <rng:optional>
+        <rng:attribute name="loext:date-format">
+          <rng:ref name="string"/>
+        </rng:attribute>
+      </rng:optional>
+      <rng:optional>
+        <rng:attribute name="loext:date-rfc-language-tag">
+          <rng:ref name="language"/>
+        </rng:attribute>
+      </rng:optional>
       <rng:zeroOrMore>
         <rng:element name="loext:list-item">
           <rng:attribute name="loext:display-text">
diff --git a/sw/inc/formatcontentcontrol.hxx b/sw/inc/formatcontentcontrol.hxx
index 00e52fc3d649..1dba4bce03a6 100644
--- a/sw/inc/formatcontentcontrol.hxx
+++ b/sw/inc/formatcontentcontrol.hxx
@@ -129,8 +129,10 @@ class SW_DLLPUBLIC SwContentControl : public 
sw::BroadcastingModify
 
     bool m_bDate = false;
 
+    /// If m_bDate is true, the date format in a syntax accepted by 
SvNumberFormatter::PutEntry().
     OUString m_aDateFormat;
 
+    /// If m_bDate is true, the date's BCP 47 language tag.
     OUString m_aDateLanguage;
 
     /// Stores a list item index, in case the doc model is not yet updated.
diff --git a/xmloff/qa/unit/data/content-control-date.fodt 
b/xmloff/qa/unit/data/content-control-date.fodt
new file mode 100644
index 000000000000..dd3749a02e99
--- /dev/null
+++ b/xmloff/qa/unit/data/content-control-date.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:date="true" 
loext:date-format="YYYY-MM-DD" loext:date-rfc-language-tag="en-US">choose a 
date</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 e91f71d64cc7..4f32c23025de 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -648,6 +648,81 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, 
testPictureContentControlImport)
     CPPUNIT_ASSERT(bPicture);
 }
 
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDateContentControlExport)
+{
+    // Given a document with a date 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, "choose a date", /*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("Date", uno::Any(true));
+    xContentControlProps->setPropertyValue("DateFormat", 
uno::Any(OUString("YYYY-MM-DD")));
+    xContentControlProps->setPropertyValue("DateLanguage", 
uno::Any(OUString("en-US")));
+    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");
+    // Without the accompanying fix in place, this test would have failed with:
+    // - XPath '//loext:content-control' no attribute 'date' exist
+    xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get());
+    assertXPath(pXmlDoc, "//loext:content-control", "date", "true");
+    assertXPath(pXmlDoc, "//loext:content-control", "date-format", 
"YYYY-MM-DD");
+    assertXPath(pXmlDoc, "//loext:content-control", "date-rfc-language-tag", 
"en-US");
+}
+
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDateContentControlImport)
+{
+    // Given an ODF document with a date content control:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"content-control-date.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 bDate{};
+    xContentControlProps->getPropertyValue("Date") >>= bDate;
+    // Without the accompanying fix in place, this test would have failed, the 
content control was
+    // imported as a default rich text one.
+    CPPUNIT_ASSERT(bDate);
+    OUString aDateFormat;
+    xContentControlProps->getPropertyValue("DateFormat") >>= aDateFormat;
+    CPPUNIT_ASSERT_EQUAL(OUString("YYYY-MM-DD"), aDateFormat);
+    OUString aDateLanguage;
+    xContentControlProps->getPropertyValue("DateLanguage") >>= aDateLanguage;
+    CPPUNIT_ASSERT_EQUAL(OUString("en-US"), aDateLanguage);
+}
+
 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 f2a3386a532e..179bd5094245 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -3476,6 +3476,8 @@ namespace xmloff::token {
         TOKEN("unchecked-state", XML_UNCHECKED_STATE),
         TOKEN("display-text", XML_DISPLAY_TEXT),
         TOKEN("picture", XML_PICTURE),
+        TOKEN("date-format", XML_DATE_FORMAT),
+        TOKEN("date-rfc-language-tag", XML_DATE_RFC_LANGUAGE_TAG),
 
 
 #if OSL_DEBUG_LEVEL > 0
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index ef5471c5aeed..e2ec85cb8105 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3917,6 +3917,29 @@ void XMLTextParagraphExport::ExportContentControl(
             GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_PICTURE,
                                      aBuffer.makeStringAndClear());
         }
+
+        bool bDate = false;
+        xPropertySet->getPropertyValue("Date") >>= bDate;
+        if (bDate)
+        {
+            OUStringBuffer aBuffer;
+            sax::Converter::convertBool(aBuffer, bDate);
+            GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATE, 
aBuffer.makeStringAndClear());
+        }
+
+        OUString aDateFormat;
+        xPropertySet->getPropertyValue("DateFormat") >>= aDateFormat;
+        if (!aDateFormat.isEmpty())
+        {
+            GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATE_FORMAT, 
aDateFormat);
+        }
+
+        OUString aDateLanguage;
+        xPropertySet->getPropertyValue("DateLanguage") >>= aDateLanguage;
+        if (!aDateLanguage.isEmpty())
+        {
+            GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, 
XML_DATE_RFC_LANGUAGE_TAG, aDateLanguage);
+        }
     }
 
     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 c9f4b8a8b2b9..24b81e04a67c 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.cxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx
@@ -94,6 +94,24 @@ void XMLContentControlContext::startFastElement(
                 }
                 break;
             }
+            case XML_ELEMENT(LO_EXT, XML_DATE):
+            {
+                if (sax::Converter::convertBool(bTmp, rIter.toView()))
+                {
+                    m_bDate = bTmp;
+                }
+                break;
+            }
+            case XML_ELEMENT(LO_EXT, XML_DATE_FORMAT):
+            {
+                m_aDateFormat = rIter.toString();
+                break;
+            }
+            case XML_ELEMENT(LO_EXT, XML_DATE_RFC_LANGUAGE_TAG):
+            {
+                m_aDateLanguage = rIter.toString();
+                break;
+            }
             default:
                 XMLOFF_WARN_UNKNOWN("xmloff", rIter);
         }
@@ -162,6 +180,19 @@ void XMLContentControlContext::endFastElement(sal_Int32)
     {
         xPropertySet->setPropertyValue("Picture", uno::Any(m_bPicture));
     }
+
+    if (m_bDate)
+    {
+        xPropertySet->setPropertyValue("Date", uno::Any(m_bDate));
+    }
+    if (!m_aDateFormat.isEmpty())
+    {
+        xPropertySet->setPropertyValue("DateFormat", uno::Any(m_aDateFormat));
+    }
+    if (!m_aDateLanguage.isEmpty())
+    {
+        xPropertySet->setPropertyValue("DateLanguage", 
uno::Any(m_aDateLanguage));
+    }
 }
 
 css::uno::Reference<css::xml::sax::XFastContextHandler>
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx 
b/xmloff/source/text/xmlcontentcontrolcontext.hxx
index d3874d31257e..623ef97e8df3 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.hxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx
@@ -44,6 +44,9 @@ class XMLContentControlContext : public SvXMLImportContext
     OUString m_aUncheckedState;
     std::vector<css::beans::PropertyValues> m_aListItems;
     bool m_bPicture = false;
+    bool m_bDate = false;
+    OUString m_aDateFormat;
+    OUString m_aDateLanguage;
 
 public:
     XMLContentControlContext(SvXMLImport& rImport, sal_Int32 nElement, 
XMLHints_Impl& rHints,
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index ffd10a485dd0..6d74b224296d 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -3220,4 +3220,6 @@ checked-state
 unchecked-state
 display-text
 picture
+date-format
+date-rfc-language-tag
 TOKEN_END_DUMMY

Reply via email to