[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - oox/source sc/qa sc/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 8 06:39:39 UTC 2021


 oox/source/token/tokens.txt                   |    5 ++
 sc/qa/unit/data/xlsx/button-form-control.xlsx |binary
 sc/qa/unit/subsequent_export-test.cxx         |   25 ++++++++++
 sc/source/filter/excel/xeescher.cxx           |   63 +++++++++++++++++++++++++-
 sc/source/filter/xcl97/xcl97rec.cxx           |    1 
 5 files changed, 93 insertions(+), 1 deletion(-)

New commits:
commit dc6c9a37f367fd28a45e70e6de98cb0b24e50040
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Jul 1 12:34:52 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Jul 8 08:39:05 2021 +0200

    XLSX export: handle button form controls
    
    This builds on top of commit 94678a7b9c6b7e577c15adacc885e03551bcf17b
    (XLSX export: improve handling of checkbox (form controls), 2021-06-30),
    so now both checkboxes and buttons are handled during export.
    
    (cherry picked from commit 1e3263a677b61c718d0fd1be15c066b933f7de18)
    
    Conflicts:
            sc/qa/unit/subsequent_export-test2.cxx
    
    Change-Id: I278b4925414d29399401cc15ab3d944db88ee0c5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118546
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/oox/source/token/tokens.txt b/oox/source/token/tokens.txt
index 25f607cb5ae0..76dad54c8904 100644
--- a/oox/source/token/tokens.txt
+++ b/oox/source/token/tokens.txt
@@ -713,6 +713,7 @@ autoLoad
 autoNoTable
 autoPage
 autoPageBreaks
+autoPict
 autoRecover
 autoRedefine
 autoRepublish
@@ -1402,6 +1403,7 @@ contributors
 control
 control1
 control2
+controlPr
 controls
 convMailMergeEsc
 convex
@@ -2371,6 +2373,7 @@ forcedash
 foredepth
 forestGreen
 forgetLastTabAlignment
+formControlPr
 formFld
 formLetters
 formProt
@@ -3178,6 +3181,7 @@ location
 lock
 lockRevision
 lockStructure
+lockText
 lockWindows
 locked
 lockedCanvas
@@ -3660,6 +3664,7 @@ objOverTx
 objTx
 object
 objectDefaults
+objectType
 objects
 obliqueBottom
 obliqueBottomLeft
diff --git a/sc/qa/unit/data/xlsx/button-form-control.xlsx b/sc/qa/unit/data/xlsx/button-form-control.xlsx
new file mode 100644
index 000000000000..c5e9fe65a245
Binary files /dev/null and b/sc/qa/unit/data/xlsx/button-form-control.xlsx differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 4baebf766459..3b5e3903290a 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -282,6 +282,7 @@ public:
     void testTdf136721_paper_size();
     void testTdf139258_rotated_image();
     void testCheckboxFormControlXlsxExport();
+    void testButtonFormControlXlsxExport();
 
     CPPUNIT_TEST_SUITE(ScExportTest);
     CPPUNIT_TEST(test);
@@ -462,6 +463,7 @@ public:
     CPPUNIT_TEST(testTdf136721_paper_size);
     CPPUNIT_TEST(testTdf139258_rotated_image);
     CPPUNIT_TEST(testCheckboxFormControlXlsxExport);
+    CPPUNIT_TEST(testButtonFormControlXlsxExport);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -5869,6 +5871,29 @@ void ScExportTest::testCheckboxFormControlXlsxExport()
     assertXPathContent(pDoc, "/xml/v:shape/xx:ClientData/xx:Anchor", "1, 22, 3, 3, 3, 30, 6, 1");
 }
 
+void ScExportTest::testButtonFormControlXlsxExport()
+{
+    // Given a document that has a checkbox form control:
+    ScDocShellRef xShell = loadDoc(u"button-form-control.", FORMAT_XLSX);
+    CPPUNIT_ASSERT(xShell.is());
+
+    // When exporting to XLSX:
+    std::shared_ptr<utl::TempFile> pXPathFile
+        = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX);
+
+    // Then make sure its control markup is written and it has a correct position + size:
+    xmlDocUniquePtr pDoc
+        = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml");
+    CPPUNIT_ASSERT(pDoc);
+    // Without the fix in place, this test would have failed with:
+    // - XPath '//x:anchor/x:from/xdr:col' not found
+    // i.e. the control markup was missing, the button was lost on export.
+    assertXPathContent(pDoc, "//x:anchor/x:from/xdr:col", "1");
+    assertXPathContent(pDoc, "//x:anchor/x:from/xdr:row", "3");
+    assertXPathContent(pDoc, "//x:anchor/x:to/xdr:col", "3");
+    assertXPathContent(pDoc, "//x:anchor/x:to/xdr:row", "7");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
index 19fb63465a48..67b1e7807322 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -1153,6 +1153,9 @@ void VmlFormControlExporter::EndShape(sal_Int32 nShapeElement)
         case EXC_OBJTYPE_CHECKBOX:
             aObjectType = "Checkbox";
             break;
+        case EXC_OBJTYPE_BUTTON:
+            aObjectType = "Button";
+            break;
     }
     pVmlDrawing->startElement(FSNS(XML_x, XML_ClientData), XML_ObjectType, aObjectType);
     OString aAnchor = OString::number(m_aAreaFrom.Left());
@@ -1165,7 +1168,11 @@ void VmlFormControlExporter::EndShape(sal_Int32 nShapeElement)
     aAnchor += ", " + OString::number(m_aAreaTo.Bottom());
     XclXmlUtils::WriteElement(pVmlDrawing, FSNS(XML_x, XML_Anchor), aAnchor);
 
-    // XclExpOcxControlObj::WriteSubRecs() has the same fixed value.
+    // XclExpOcxControlObj::WriteSubRecs() has the same fixed values.
+    if (m_nObjType == EXC_OBJTYPE_BUTTON)
+    {
+        XclXmlUtils::WriteElement(pVmlDrawing, FSNS(XML_x, XML_TextHAlign), "Center");
+    }
     XclXmlUtils::WriteElement(pVmlDrawing, FSNS(XML_x, XML_TextVAlign), "Center");
 
     pVmlDrawing->endElement(FSNS(XML_x, XML_ClientData));
@@ -1393,6 +1400,21 @@ OUString XclExpTbxControlObj::SaveControlPropertiesXml(XclExpXmlStream& rStrm) c
 
             break;
         }
+        case EXC_OBJTYPE_BUTTON:
+        {
+            const sal_Int32 nDrawing = XclExpObjList::getNewDrawingUniqueId();
+            sax_fastparser::FSHelperPtr pFormControl = rStrm.CreateOutputStream(
+                XclXmlUtils::GetStreamName("xl/", "ctrlProps/ctrlProps", nDrawing),
+                XclXmlUtils::GetStreamName("../", "ctrlProps/ctrlProps", nDrawing),
+                rStrm.GetCurrentStream()->getOutputStream(),
+                "application/vnd.ms-excel.controlproperties+xml",
+                oox::getRelationship(Relationship::CTRLPROP), &sIdFormControlPr);
+
+            pFormControl->singleElement(XML_formControlPr, XML_xmlns,
+                                        rStrm.getNamespaceURL(OOX_NS(xls14Lst)), XML_objectType,
+                                        "Button", XML_lockText, "1");
+            break;
+        }
     }
 
     return sIdFormControlPr;
@@ -1450,6 +1472,45 @@ void XclExpTbxControlObj::SaveSheetXml(XclExpXmlStream& rStrm, const OUString& a
 
             break;
         }
+        case EXC_OBJTYPE_BUTTON:
+        {
+            sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
+
+            rWorksheet->startElement(FSNS(XML_mc, XML_AlternateContent), FSNS(XML_xmlns, XML_mc),
+                                     rStrm.getNamespaceURL(OOX_NS(mce)));
+            rWorksheet->startElement(FSNS(XML_mc, XML_Choice), XML_Requires, "x14");
+
+            rWorksheet->startElement(XML_control, XML_shapeId, OString::number(mnShapeId).getStr(),
+                                     FSNS(XML_r, XML_id), aIdFormControlPr, XML_name, msLabel);
+
+            rWorksheet->startElement(XML_controlPr, XML_defaultSize, "0", XML_print,
+                                     mbPrint ? "true" : "false", XML_autoFill, "0", XML_autoPict,
+                                     "0");
+
+            rWorksheet->startElement(XML_anchor, XML_moveWithCells, "true", XML_sizeWithCells,
+                                     "false");
+
+            SdrObject* pObj = SdrObject::getSdrObjectFromXShape(mxShape);
+            tools::Rectangle aAreaFrom;
+            tools::Rectangle aAreaTo;
+            lcl_GetFromTo(mrRoot, pObj->GetLogicRect(), GetTab(), aAreaFrom, aAreaTo,
+                          /*bInEMU=*/true);
+
+            rWorksheet->startElement(XML_from);
+            lcl_WriteAnchorVertex(rWorksheet, aAreaFrom);
+            rWorksheet->endElement(XML_from);
+            rWorksheet->startElement(XML_to);
+            lcl_WriteAnchorVertex(rWorksheet, aAreaTo);
+            rWorksheet->endElement(XML_to);
+            rWorksheet->endElement(XML_anchor);
+
+            rWorksheet->endElement(XML_controlPr);
+
+            rWorksheet->endElement(XML_control);
+            rWorksheet->endElement(FSNS(XML_mc, XML_Choice));
+            rWorksheet->endElement(FSNS(XML_mc, XML_AlternateContent));
+            break;
+        }
     }
 }
 
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index d786f09c040c..95bbf188e8dc 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -161,6 +161,7 @@ bool IsFormControlObject( const XclObj *rObj )
     switch( rObj->GetObjType() )
     {
         case EXC_OBJTYPE_CHECKBOX:
+        case EXC_OBJTYPE_BUTTON:
             return true;
         default:
             return false;


More information about the Libreoffice-commits mailing list