[Libreoffice-commits] core.git: sc/qa sc/source

Regina Henschel (via logerrit) logerrit at kemper.freedesktop.org
Tue Feb 16 20:38:48 UTC 2021


 sc/qa/unit/scshapetest.cxx    |   55 +++++++++++++++++++++++++++++++++++++++++-
 sc/source/ui/inc/fuconstr.hxx |    4 ++-
 sc/source/ui/inc/fuconuno.hxx |   10 ++++---
 3 files changed, 63 insertions(+), 6 deletions(-)

New commits:
commit ae2e7a2a7f9fc56f0388b823a6e35111c4005619
Author:     Regina Henschel <rb.henschel at t-online.de>
AuthorDate: Mon Feb 15 22:07:41 2021 +0100
Commit:     Regina Henschel <rb.henschel at t-online.de>
CommitDate: Tue Feb 16 21:38:01 2021 +0100

    tdf#140252 unit test Controls in Calc are always on layer 'controls'
    
    This is the missing unit test for the case of drag-created controls in
    the fix in commit 1d53f3709de2956f14db31677b6c461f33843bd9.
    
    Change-Id: I3afce044588e6b5d850d948dd0cbc4df9185029d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110959
    Tested-by: Jenkins
    Reviewed-by: Regina Henschel <rb.henschel at t-online.de>

diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx
index 8d50feb0f02e..a6d591c006fd 100644
--- a/sc/qa/unit/scshapetest.cxx
+++ b/sc/qa/unit/scshapetest.cxx
@@ -19,15 +19,16 @@
 #include <svl/intitem.hxx>
 #include <svx/svdoashp.hxx>
 #include <svx/svdomeas.hxx>
-#include <svx/svdpage.hxx>
 #include <svx/svdorect.hxx>
 #include <svx/svdouno.hxx>
+#include <svx/svdpage.hxx>
 #include <unotools/tempfile.hxx>
 #include <vcl/keycodes.hxx>
 
 #include <docsh.hxx>
 #include <drwlayer.hxx>
 #include <fuconcustomshape.hxx>
+#include <fuconuno.hxx>
 #include <tabvwsh.hxx>
 #include <userdat.hxx>
 
@@ -45,6 +46,7 @@ public:
     ScShapeTest();
     void saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent,
                        const OUString& rFilter);
+    void testTdf140252_DragCreateFormControl();
     void testTdf134355_DragCreateCustomShape();
     void testTdf140252_LayerOfControl();
     void testTdf137082_LTR_to_RTL();
@@ -70,6 +72,7 @@ public:
     void testCustomShapeCellAnchoredRotatedShape();
 
     CPPUNIT_TEST_SUITE(ScShapeTest);
+    CPPUNIT_TEST(testTdf140252_DragCreateFormControl);
     CPPUNIT_TEST(testTdf134355_DragCreateCustomShape);
     CPPUNIT_TEST(testTdf140252_LayerOfControl);
     CPPUNIT_TEST(testTdf137082_LTR_to_RTL);
@@ -201,6 +204,56 @@ static SdrObject* lcl_getSdrObjectWithAssert(ScDocument& rDoc, sal_uInt16 nObjNu
     return pObj;
 }
 
+void ScShapeTest::testTdf140252_DragCreateFormControl()
+{
+    // Error was, that drag-created form controls were initially not on layer 'controls' and thus
+    // other shapes could be placed in front of form controls.
+    // Load an empty document.
+    OUString aFileURL;
+    createFileURL(u"ManualColWidthRowHeight.ods", aFileURL);
+    uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
+    CPPUNIT_ASSERT(xComponent.is());
+
+    // Get ScTabViewShell
+    ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
+    ScTabViewShell* pTabViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
+
+    // drag-create a push button as example of form control
+    SfxUInt16Item aIdentifierItem(SID_FM_CONTROL_IDENTIFIER, OBJ_FM_BUTTON);
+    SfxUInt32Item aInventorItem(SID_FM_CONTROL_INVENTOR, sal_uInt32(SdrInventor::FmForm));
+    const SfxPoolItem* pArgs[] = { &aIdentifierItem, &aInventorItem, nullptr };
+    pTabViewShell->GetViewData().GetDispatcher().Execute(SID_FM_CREATE_CONTROL,
+                                                         SfxCallMode::SYNCHRON, pArgs);
+    // above includes creation of FuConstUnoControl and call of its Activate() method
+
+    // get FuConstUnoControl
+    ScTabView* pTabView = pTabViewShell->GetViewData().GetView();
+    CPPUNIT_ASSERT(pTabView);
+    FuConstUnoControl* pFuConstUC = static_cast<FuConstUnoControl*>(pTabView->GetDrawFuncPtr());
+    CPPUNIT_ASSERT(pFuConstUC);
+
+    // drag-create shape, points are in pixel
+    MouseEvent aMouseEvent(Point(50, 100), 1, MouseEventModifiers::NONE, MOUSE_LEFT, 0);
+    pFuConstUC->MouseButtonDown(aMouseEvent);
+    aMouseEvent = MouseEvent(Point(200, 250), 1, MouseEventModifiers::DRAGMOVE, MOUSE_LEFT, 0);
+    pFuConstUC->MouseMove(aMouseEvent);
+    aMouseEvent = MouseEvent(Point(200, 250), 1, MouseEventModifiers::NONE, MOUSE_LEFT, 0);
+    pFuConstUC->MouseButtonUp(aMouseEvent);
+    pFuConstUC->Deactivate();
+    pTabViewShell->SetDrawShell(false);
+
+    // Get document and newly created push button.
+    ScDocument& rDoc = pDocSh->GetDocument();
+    SdrUnoObj* pObj = static_cast<SdrUnoObj*>(lcl_getSdrObjectWithAssert(rDoc, 0));
+
+    // Without the fix in place, the shape would be on layer SC_LAYER_FRONT (0)
+    sal_uInt8 nExpectedID = sal_uInt8(SC_LAYER_CONTROLS);
+    sal_uInt8 nActualID = pObj->GetLayer().get();
+    CPPUNIT_ASSERT_EQUAL(nExpectedID, nActualID);
+
+    pDocSh->DoClose();
+}
+
 void ScShapeTest::testTdf134355_DragCreateCustomShape()
 {
     // Error was, that drag-created custom shapes were initially on layer "controls", although that
diff --git a/sc/source/ui/inc/fuconstr.hxx b/sc/source/ui/inc/fuconstr.hxx
index e87a32092b26..7fa20b7c86d0 100644
--- a/sc/source/ui/inc/fuconstr.hxx
+++ b/sc/source/ui/inc/fuconstr.hxx
@@ -22,6 +22,8 @@
 
 #include "fudraw.hxx"
 
+#include <scdllapi.h> // SC_DLLPUBLIC is needed for unittest
+
 /** Draw rectangle */
 class FuConstruct : public FuDraw
 {
@@ -32,7 +34,7 @@ public:
     virtual ~FuConstruct() override;
                                        // Mouse- & Key-Events
     virtual bool KeyInput(const KeyEvent& rKEvt) override;
-    virtual bool MouseMove(const MouseEvent& rMEvt) override;
+    SC_DLLPUBLIC virtual bool MouseMove(const MouseEvent& rMEvt) override;
     virtual bool MouseButtonUp(const MouseEvent& rMEvt) override;
     virtual bool MouseButtonDown(const MouseEvent& rMEvt) override;
 
diff --git a/sc/source/ui/inc/fuconuno.hxx b/sc/source/ui/inc/fuconuno.hxx
index 4353243eef6c..332cdc350034 100644
--- a/sc/source/ui/inc/fuconuno.hxx
+++ b/sc/source/ui/inc/fuconuno.hxx
@@ -22,6 +22,8 @@
 
 #include "fuconstr.hxx"
 
+#include <scdllapi.h> // SC_DLLPUBLIC is needed for unittest
+
 enum class SdrInventor : sal_uInt32;
 
 /** Draw Control */
@@ -36,11 +38,11 @@ public:
 
     virtual ~FuConstUnoControl() override;
                                        // Mouse- & Key-Events
-    virtual bool MouseButtonUp(const MouseEvent& rMEvt) override;
-    virtual bool MouseButtonDown(const MouseEvent& rMEvt) override;
+    SC_DLLPUBLIC virtual bool MouseButtonUp(const MouseEvent& rMEvt) override;
+    SC_DLLPUBLIC virtual bool MouseButtonDown(const MouseEvent& rMEvt) override;
 
-    virtual void Activate() override;
-    virtual void Deactivate() override;
+    SC_DLLPUBLIC virtual void Activate() override;
+    SC_DLLPUBLIC virtual void Deactivate() override;
 
     // Create default drawing objects via keyboard
     virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle& rRectangle) override;


More information about the Libreoffice-commits mailing list