tdf#134355 custom shapes are never on layer 'controls' in Calc
Custom shapes were erroneously put on layer 'controls' when drag-
create them. But layer 'controls' is special to force form controls
to front in edit mode. Layer 'controls' is exclusively used for form
controls.
Change-Id: I2dd8a3b5ee6ac9bcc72f0446b17a49c037aa6731
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110763
Tested-by: Jenkins
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
diff --git a/sc/CppunitTest_sc_shapetest.mk b/sc/CppunitTest_sc_shapetest.mk
index 50891e1da..9a36083 100644
--- a/sc/CppunitTest_sc_shapetest.mk
+++ b/sc/CppunitTest_sc_shapetest.mk
@@ -32,6 +32,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_shapetest, \
tl \
unotest \
utl \
vcl \
))
$(eval $(call gb_CppunitTest_set_include,sc_shapetest,\
diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx
index 9923e5c..bf9f568 100644
--- a/sc/qa/unit/scshapetest.cxx
+++ b/sc/qa/unit/scshapetest.cxx
@@ -27,9 +27,12 @@
#include <docsh.hxx>
#include <drwlayer.hxx>
#include <fuconcustomshape.hxx>
#include <tabvwsh.hxx>
#include <userdat.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <sc.hrc> // defines of slot-IDs
using namespace css;
@@ -42,6 +45,7 @@ public:
ScShapeTest();
void saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent,
const OUString& rFilter);
void testTdf134355_DragCreateCustomShape();
void testTdf140252_LayerOfControl();
void testTdf137082_LTR_to_RTL();
void testTdf137082_RTL_cell_anchored();
@@ -66,6 +70,7 @@ public:
void testCustomShapeCellAnchoredRotatedShape();
CPPUNIT_TEST_SUITE(ScShapeTest);
CPPUNIT_TEST(testTdf134355_DragCreateCustomShape);
CPPUNIT_TEST(testTdf140252_LayerOfControl);
CPPUNIT_TEST(testTdf137082_LTR_to_RTL);
CPPUNIT_TEST(testTdf137082_RTL_cell_anchored);
@@ -196,6 +201,52 @@ static SdrObject* lcl_getSdrObjectWithAssert(ScDocument& rDoc, sal_uInt16 nObjNu
return pObj;
}
void ScShapeTest::testTdf134355_DragCreateCustomShape()
{
// Error was, that drag-created custom shapes were initially on layer "controls", although that
// layer is exclusively for form controls. Effect was, that other shapes cound not be brought in
// front of custom shapes.
// Load an empty document.
OUString aFileURL;
createFileURL(u"ManualColWidthRowHeight.ods", aFileURL);
uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
CPPUNIT_ASSERT(xComponent.is());
// Get ScTabView
ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
ScTabViewShell* pTabViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
ScTabView* pTabView = pTabViewShell->GetViewData().GetView();
// drag-create custom shape
uno::Sequence<beans::PropertyValue> aPropertyValues = {
comphelper::makePropertyValue("SymbolShapes", OUString("smiley")),
};
dispatchCommand(xComponent, ".uno:SymbolShapes", aPropertyValues);
// above includes creation of FuConstCustomShape and call of its Activate() method
FuConstCustomShape* pFuConstCS = static_cast<FuConstCustomShape*>(pTabView->GetDrawFuncPtr());
CPPUNIT_ASSERT(pFuConstCS);
// points are in pixel
MouseEvent aMouseEvent(Point(50, 100), 1, MouseEventModifiers::NONE, MOUSE_LEFT, 0);
pFuConstCS->MouseButtonDown(aMouseEvent);
aMouseEvent = MouseEvent(Point(200, 250), 1, MouseEventModifiers::DRAGMOVE, MOUSE_LEFT, 0);
pFuConstCS->MouseMove(aMouseEvent);
aMouseEvent = MouseEvent(Point(200, 250), 1, MouseEventModifiers::NONE, MOUSE_LEFT, 0);
pFuConstCS->MouseButtonUp(aMouseEvent);
pFuConstCS->Deactivate();
pTabViewShell->SetDrawShell(false);
// Get document and newly created custom shape.
ScDocument& rDoc = pDocSh->GetDocument();
SdrObjCustomShape* pObj = static_cast<SdrObjCustomShape*>(lcl_getSdrObjectWithAssert(rDoc, 0));
// Without the fix in place, the shape would be on layer SC_LAYER_CONTROLS (3)
sal_uInt8 nExpectedID = sal_uInt8(SC_LAYER_FRONT);
sal_uInt8 nActualID = pObj->GetLayer().get();
CPPUNIT_ASSERT_EQUAL(nExpectedID, nActualID);
pDocSh->DoClose();
}
void ScShapeTest::testTdf140252_LayerOfControl()
{
// Error was, that a newly inserted control shape was put on layer
diff --git a/sc/source/ui/drawfunc/fuconcustomshape.cxx b/sc/source/ui/drawfunc/fuconcustomshape.cxx
index e73c6d9..a3888f1 100644
--- a/sc/source/ui/drawfunc/fuconcustomshape.cxx
+++ b/sc/source/ui/drawfunc/fuconcustomshape.cxx
@@ -103,10 +103,6 @@ void FuConstCustomShape::Activate()
aOldPointer = pWindow->GetPointer();
rViewShell.SetActivePointer( aNewPointer );
SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
if (pLayer)
pView->SetActiveLayer( pLayer->GetName() );
FuConstruct::Activate();
}
@@ -114,10 +110,6 @@ void FuConstCustomShape::Deactivate()
{
FuConstruct::Deactivate();
SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
if (pLayer)
pView->SetActiveLayer( pLayer->GetName() );
rViewShell.SetActivePointer( aOldPointer );
}