include/xmloff/xmltoken.hxx                                 |    1 
 schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng |    6 +
 sw/source/ui/misc/contentcontroldlg.cxx                     |   40 ++++++
 sw/source/uibase/inc/contentcontroldlg.hxx                  |    1 
 sw/uiconfig/swriter/ui/contentcontroldlg.ui                 |    4 
 xmloff/qa/unit/data/content-control-picture.fodt            |   13 ++
 xmloff/qa/unit/text.cxx                                     |   71 ++++++++++++
 xmloff/source/core/xmltoken.cxx                             |    1 
 xmloff/source/text/txtparae.cxx                             |   10 +
 xmloff/source/text/xmlcontentcontrolcontext.cxx             |   13 ++
 xmloff/source/text/xmlcontentcontrolcontext.hxx             |    1 
 xmloff/source/token/tokens.txt                              |    1 
 12 files changed, 162 insertions(+)

New commits:
commit 7111b64948bc6eb62397bc8a097b75a20e8a0d33
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu May 19 09:12:21 2022 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri May 20 14:27:57 2022 +0200

    sw content controls, picture: add ODT filter
    
    Map Picture UNO property on content controls to:
    
    <loext:content-control loext:picture="...">
    
    And do the opposite on import.
    
    (cherry picked from commit 81ce15c466cda946ae94f38904215f24555021ad)
    
    Change-Id: I47c3d04c505ba94da958d5d6b6b2c883236afc3d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134665
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index 1344e5a4b56f..85619ab39550 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -3473,6 +3473,7 @@ namespace xmloff::token {
         XML_CHECKED_STATE,
         XML_UNCHECKED_STATE,
         XML_DISPLAY_TEXT,
+        XML_PICTURE,
 
         XML_TOKEN_END
     };
diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng 
b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
index cc24f7a386a9..32ab55fb9445 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -2794,6 +2794,12 @@ 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.
         <rng:ref name="string"/>
         </rng:attribute>
       </rng:optional>
+      <rng:optional>
+        <!-- default value: false -->
+        <rng:attribute name="loext:picture">
+        <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-picture.fodt 
b/xmloff/qa/unit/data/content-control-picture.fodt
new file mode 100644
index 000000000000..ae47bfa0dfac
--- /dev/null
+++ b/xmloff/qa/unit/data/content-control-picture.fodt
@@ -0,0 +1,13 @@
+<?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" 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0">
+  <office:body>
+    <office:text>
+      <text:p><loext:content-control loext:showing-place-holder="true" 
loext:picture="true"><draw:frame text:anchor-type="as-char" svg:width="1cm" 
svg:height="1cm"><draw:image draw:mime-type="image/png">
+       
<office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAAEElEQVR4nGJgAQAAAP//AwAA
+        BgAFV7+r1AAAAABJRU5ErkJggg==
+       </office:binary-data>
+      </draw:image>
+     </draw:frame></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 d11c58a69ed0..e91f71d64cc7 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -17,6 +17,7 @@
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/text/XTextDocument.hpp>
 #include <com/sun/star/text/BibliographyDataType.hpp>
+#include <com/sun/star/text/TextContentAnchorType.hpp>
 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
 #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
 
@@ -577,6 +578,76 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, 
testDropdownContentControlImport)
     CPPUNIT_ASSERT_EQUAL(OUString("choose a color"), xContent->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPictureContentControlExport)
+{
+    // Given a document with a picture content control around an as-char image:
+    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();
+    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("Picture", 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 'picture' exist
+    assertXPath(pXmlDoc, "//loext:content-control", "picture", "true");
+}
+
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPictureContentControlImport)
+{
+    // Given an ODF document with a picture content control:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"content-control-picture.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 bPicture{};
+    xContentControlProps->getPropertyValue("Picture") >>= bPicture;
+    // Without the accompanying fix in place, this failed, as the picture 
attribute was ignored on
+    // import.
+    CPPUNIT_ASSERT(bPicture);
+}
+
 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 ffc2eddaf792..f2a3386a532e 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -3475,6 +3475,7 @@ namespace xmloff::token {
         TOKEN("checked-state", XML_CHECKED_STATE),
         TOKEN("unchecked-state", XML_UNCHECKED_STATE),
         TOKEN("display-text", XML_DISPLAY_TEXT),
+        TOKEN("picture", XML_PICTURE),
 
 
 #if OSL_DEBUG_LEVEL > 0
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 4665df3e2f1f..ef5471c5aeed 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3907,6 +3907,16 @@ void XMLTextParagraphExport::ExportContentControl(
         {
             GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, 
XML_UNCHECKED_STATE, aUncheckedState);
         }
+
+        bool bPicture = false;
+        xPropertySet->getPropertyValue("Picture") >>= bPicture;
+        if (bPicture)
+        {
+            OUStringBuffer aBuffer;
+            sax::Converter::convertBool(aBuffer, bPicture);
+            GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_PICTURE,
+                                     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 eb3a384d6b98..c9f4b8a8b2b9 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.cxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx
@@ -86,6 +86,14 @@ void XMLContentControlContext::startFastElement(
                 m_aUncheckedState = rIter.toString();
                 break;
             }
+            case XML_ELEMENT(LO_EXT, XML_PICTURE):
+            {
+                if (sax::Converter::convertBool(bTmp, rIter.toView()))
+                {
+                    m_bPicture = bTmp;
+                }
+                break;
+            }
             default:
                 XMLOFF_WARN_UNKNOWN("xmloff", rIter);
         }
@@ -149,6 +157,11 @@ void XMLContentControlContext::endFastElement(sal_Int32)
         xPropertySet->setPropertyValue("ListItems",
                                        
uno::Any(comphelper::containerToSequence(m_aListItems)));
     }
+
+    if (m_bPicture)
+    {
+        xPropertySet->setPropertyValue("Picture", uno::Any(m_bPicture));
+    }
 }
 
 css::uno::Reference<css::xml::sax::XFastContextHandler>
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx 
b/xmloff/source/text/xmlcontentcontrolcontext.hxx
index 20c39ad44d2c..d3874d31257e 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.hxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx
@@ -43,6 +43,7 @@ class XMLContentControlContext : public SvXMLImportContext
     OUString m_aCheckedState;
     OUString m_aUncheckedState;
     std::vector<css::beans::PropertyValues> m_aListItems;
+    bool m_bPicture = false;
 
 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 f0aadbea63f2..ffd10a485dd0 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -3219,4 +3219,5 @@ showing-place-holder
 checked-state
 unchecked-state
 display-text
+picture
 TOKEN_END_DUMMY
commit 18f8522f6d70315caa3d6626d1c7c96a333ab9a4
Author:     Miklos Vajna <[email protected]>
AuthorDate: Wed May 18 17:00:36 2022 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri May 20 14:27:41 2022 +0200

    sw content controls, dropdown: disable NOP buttons in the property dialog
    
    Rename, delete, move up & move down does nothing initially, disable the
    buttons when their event handler would just do an early return to make
    this less confusing.
    
    (cherry picked from commit e9bee595fdff989b78abb3ebf27efbe9af543eca)
    
    Change-Id: I4cfb9750d07b4686440c05901ef72e8ce4de961e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134664
    Tested-by: Miklos Vajna <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sw/source/ui/misc/contentcontroldlg.cxx 
b/sw/source/ui/misc/contentcontroldlg.cxx
index 9e5902149720..49157fdec606 100644
--- a/sw/source/ui/misc/contentcontroldlg.cxx
+++ b/sw/source/ui/misc/contentcontroldlg.cxx
@@ -44,6 +44,7 @@ SwContentControlDlg::SwContentControlDlg(weld::Window* 
pParent, SwWrtShell& rWrt
     , m_xMoveDownBtn(m_xBuilder->weld_button("movedown"))
     , m_xOk(m_xBuilder->weld_button("ok"))
 {
+    m_xListItems->connect_changed(LINK(this, SwContentControlDlg, 
SelectionChangedHdl));
     m_xOk->connect_clicked(LINK(this, SwContentControlDlg, OkHdl));
 
     // Only 2 items would be visible by default.
@@ -245,4 +246,43 @@ IMPL_LINK_NOARG(SwContentControlDlg, MoveDownHdl, 
weld::Button&, void)
     m_xListItems->select(nRow);
 }
 
+IMPL_LINK_NOARG(SwContentControlDlg, SelectionChangedHdl, weld::TreeView&, 
void)
+{
+    if (!m_xListItems->has_focus())
+    {
+        return;
+    }
+
+    int nRow = m_xListItems->get_selected_index();
+    if (nRow < 0)
+    {
+        m_xRenameBtn->set_sensitive(false);
+        m_xDeleteBtn->set_sensitive(false);
+    }
+    else
+    {
+        m_xRenameBtn->set_sensitive(true);
+        m_xDeleteBtn->set_sensitive(true);
+    }
+
+    if (nRow <= 0)
+    {
+        m_xMoveUpBtn->set_sensitive(false);
+    }
+    else
+    {
+        m_xMoveUpBtn->set_sensitive(true);
+    }
+
+    int nEndPos = m_xListItems->n_children() - 1;
+    if (nRow < 0 || nRow >= nEndPos)
+    {
+        m_xMoveDownBtn->set_sensitive(false);
+    }
+    else
+    {
+        m_xMoveDownBtn->set_sensitive(true);
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/contentcontroldlg.hxx 
b/sw/source/uibase/inc/contentcontroldlg.hxx
index 642c7d078fe5..b6a42860e073 100644
--- a/sw/source/uibase/inc/contentcontroldlg.hxx
+++ b/sw/source/uibase/inc/contentcontroldlg.hxx
@@ -52,6 +52,7 @@ class SwContentControlDlg final : public SfxDialogController
     DECL_LINK(DeleteHdl, weld::Button&, void);
     DECL_LINK(MoveUpHdl, weld::Button&, void);
     DECL_LINK(MoveDownHdl, weld::Button&, void);
+    DECL_LINK(SelectionChangedHdl, weld::TreeView&, void);
     DECL_LINK(OkHdl, weld::Button&, void);
 
 public:
diff --git a/sw/uiconfig/swriter/ui/contentcontroldlg.ui 
b/sw/uiconfig/swriter/ui/contentcontroldlg.ui
index 815d0f14ef35..8190317048ca 100644
--- a/sw/uiconfig/swriter/ui/contentcontroldlg.ui
+++ b/sw/uiconfig/swriter/ui/contentcontroldlg.ui
@@ -214,6 +214,7 @@
               <object class="GtkButton" id="modify">
                 <property name="label" translatable="yes" 
context="contentcontordlg|modify">Modify</property>
                 <property name="visible">True</property>
+                <property name="sensitive">False</property>
                 <property name="can-focus">True</property>
                 <property name="receives-default">True</property>
               </object>
@@ -228,6 +229,7 @@
               <object class="GtkButton" id="remove">
                 <property name="label" translatable="yes" 
context="contentcontordlg|remove">Remove</property>
                 <property name="visible">True</property>
+                <property name="sensitive">False</property>
                 <property name="can-focus">True</property>
                 <property name="receives-default">True</property>
               </object>
@@ -242,6 +244,7 @@
               <object class="GtkButton" id="moveup">
                 <property name="label" translatable="yes" 
context="contentcontordlg|moveup">Move Up</property>
                 <property name="visible">True</property>
+                <property name="sensitive">False</property>
                 <property name="can-focus">True</property>
                 <property name="receives-default">True</property>
               </object>
@@ -256,6 +259,7 @@
               <object class="GtkButton" id="movedown">
                 <property name="label" translatable="yes" 
context="contentcontordlg|movedown">Move Down</property>
                 <property name="visible">True</property>
+                <property name="sensitive">False</property>
                 <property name="can-focus">True</property>
                 <property name="receives-default">True</property>
               </object>

Reply via email to