[Libreoffice-commits] core.git: Branch 'distro/lhm/libreoffice-6-1+backports' - include/test offapi/com sc/inc sc/qa sc/source test/source
Samuel Mehrbrodt (via logerrit)
logerrit at kemper.freedesktop.org
Thu Apr 4 22:04:19 UTC 2019
include/test/sheet/shape.hxx | 3 -
offapi/com/sun/star/sheet/Shape.idl | 8 +++
sc/inc/unonames.hxx | 1
sc/qa/extras/scshapeobj.cxx | 3 -
sc/source/ui/unoobj/shapeuno.cxx | 33 ++++++++++++
test/source/sheet/shape.cxx | 94 +++++++++++++++++++++---------------
6 files changed, 103 insertions(+), 39 deletions(-)
New commits:
commit de89c8169cfbaa68e42e6a53c5d64fb404bf6892
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Mon Apr 1 15:00:00 2019 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Apr 5 00:03:55 2019 +0200
tdf#124329 Add API to make cell anchored graphic resize with cell
Change-Id: Ib2335b1eb26e55fcfcfb964d0f3fe3dd267bdd0d
Reviewed-on: https://gerrit.libreoffice.org/70067
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack at redhat.com>
(cherry picked from commit 823c77a98ffbc1c819a81687ca7e13d91277bca5)
The following commits have been squased into this one:
Improve sc shape test
Actually test anchoring the shape to a cell and to a page again
Change-Id: I2d625b9a4f04aaf61dd8c1e8d10c639cbb4f0da5
Reviewed-on: https://gerrit.libreoffice.org/70110
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit 67c5fb957f585772e23678fdcc6e24734b9fbc48)
tdf#124329 Test setting ResizeWithCell via UNO API
Change-Id: Iab8733e5a5df2b189197df89c3e08cd3463f2ec7
Reviewed-on: https://gerrit.libreoffice.org/70111
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit 8603d7029b0d62032a5c9d2e039117799be9e798)
Split large test method in two
Change-Id: If1b915f721a5768b682c63dc9c08b708ba37a705
Reviewed-on: https://gerrit.libreoffice.org/70116
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit 8ecdaecfa8f8665b0c8c9e3e909f683a6c198797)
tdf#124329 Keep ResizeWithCell value when anchoring to a different cell
Change-Id: I62010b4882268aae135a406eb27634c3335d72cf
Reviewed-on: https://gerrit.libreoffice.org/70118
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit c8e1f2fb1e5576dd85a1172d064480734e21d96e)
Reviewed-on: https://gerrit.libreoffice.org/70264
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/include/test/sheet/shape.hxx b/include/test/sheet/shape.hxx
index 3d10fc31eb4f..ad2b7b7657ce 100644
--- a/include/test/sheet/shape.hxx
+++ b/include/test/sheet/shape.hxx
@@ -23,7 +23,8 @@ public:
virtual css::uno::Reference<css::uno::XInterface> init() = 0;
virtual css::uno::Reference<css::uno::XInterface> getXSheetDocument() = 0;
- void testShapeProperties();
+ void testShapePropertiesAnchor();
+ void testShapePropertiesPosition();
protected:
~Shape() {}
diff --git a/offapi/com/sun/star/sheet/Shape.idl b/offapi/com/sun/star/sheet/Shape.idl
index d23a004b074e..9904a49ef163 100644
--- a/offapi/com/sun/star/sheet/Shape.idl
+++ b/offapi/com/sun/star/sheet/Shape.idl
@@ -35,6 +35,14 @@ service Shape
<p> Possible objects are XSpreadsheet and XCell.</p>
*/
[property] com::sun::star::uno::XInterface Anchor;
+
+ /** If set, the shape will resize with the cell.
+ Only works when shape is anchored to a cell.
+
+ @since LibreOffice 6.3
+ */
+ [optional, property] boolean ResizeWithCell;
+
/** contains the horizontal position of the object (1/100 mm).
<p> The position is relative to the anchor object.</p>
<p> If the underlying table layout direction is left to right
diff --git a/sc/inc/unonames.hxx b/sc/inc/unonames.hxx
index a2a407ee5fdc..b7d1823d06f3 100644
--- a/sc/inc/unonames.hxx
+++ b/sc/inc/unonames.hxx
@@ -192,6 +192,7 @@
// drawing objects
#define SC_UNONAME_IMAGEMAP "ImageMap"
#define SC_UNONAME_ANCHOR "Anchor"
+#define SC_UNONAME_RESIZE_WITH_CELL "ResizeWithCell"
#define SC_UNONAME_HORIPOS "HoriOrientPosition"
#define SC_UNONAME_VERTPOS "VertOrientPosition"
// #i66550 HLINK_FOR_SHAPES
diff --git a/sc/qa/extras/scshapeobj.cxx b/sc/qa/extras/scshapeobj.cxx
index 4b8c6069302e..cf9b0789385d 100644
--- a/sc/qa/extras/scshapeobj.cxx
+++ b/sc/qa/extras/scshapeobj.cxx
@@ -43,7 +43,8 @@ public:
CPPUNIT_TEST_SUITE(ScShapeObj);
// Shape
- CPPUNIT_TEST(testShapeProperties);
+ CPPUNIT_TEST(testShapePropertiesAnchor);
+ CPPUNIT_TEST(testShapePropertiesPosition);
CPPUNIT_TEST_SUITE_END();
diff --git a/sc/source/ui/unoobj/shapeuno.cxx b/sc/source/ui/unoobj/shapeuno.cxx
index aed1d55e389a..b3f6c3dad4e5 100644
--- a/sc/source/ui/unoobj/shapeuno.cxx
+++ b/sc/source/ui/unoobj/shapeuno.cxx
@@ -53,6 +53,7 @@ static const SfxItemPropertyMapEntry* lcl_GetShapeMap()
static const SfxItemPropertyMapEntry aShapeMap_Impl[] =
{
{OUString(SC_UNONAME_ANCHOR), 0, cppu::UnoType<uno::XInterface>::get(), 0, 0 },
+ {OUString(SC_UNONAME_RESIZE_WITH_CELL), 0, cppu::UnoType<sal_Bool>::get(), 0, 0 },
{OUString(SC_UNONAME_HORIPOS), 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
{OUString(SC_UNONAME_IMAGEMAP), 0, cppu::UnoType<container::XIndexContainer>::get(), 0, 0 },
{OUString(SC_UNONAME_VERTPOS), 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
@@ -418,6 +419,9 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& aPropertyName, const
ScDrawObjData aAnchor;
aAnchor.maStart = ScAddress(aAddress.StartColumn, aAddress.StartRow, aAddress.Sheet);
aAnchor.maStartOffset = Point(aRelPoint.X, aRelPoint.Y);
+ ScDrawObjData* pDrawObjData = ScDrawLayer::GetObjData(pObj);
+ if (pDrawObjData)
+ aAnchor.mbResizeWithCell = pDrawObjData->mbResizeWithCell;
//Uno sets the Anchor in terms of the unrotated shape, not much we can do
//about that since uno also displays the shape geometry in terms of the unrotated
//shape. #TODO think about changing the anchoring behaviour here too
@@ -433,6 +437,24 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& aPropertyName, const
}
}
+ else if ( aPropertyName == SC_UNONAME_RESIZE_WITH_CELL )
+ {
+ SdrObject* pObj = GetSdrObject();
+ if (!pObj)
+ return;
+ ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType(*pObj);
+
+ // Nothing to do if anchored to page
+ if (aAnchorType == SCA_PAGE)
+ return;
+
+ ScDrawObjData* pDrawObjData = ScDrawLayer::GetObjData(pObj);
+ if (!pDrawObjData)
+ return;
+
+ aValue >>= pDrawObjData->mbResizeWithCell;
+ ScDrawLayer::SetCellAnchored(*pObj, *pDrawObjData);
+ }
else if ( aPropertyName == SC_UNONAME_IMAGEMAP )
{
SdrObject* pObj = GetSdrObject();
@@ -692,6 +714,17 @@ uno::Any SAL_CALL ScShapeObj::getPropertyValue( const OUString& aPropertyName )
}
}
}
+ else if (aPropertyName == SC_UNONAME_RESIZE_WITH_CELL)
+ {
+ bool bIsResizeWithCell = false;
+ SdrObject* pObj = GetSdrObject();
+ if (pObj)
+ {
+ ScAnchorType anchorType = ScDrawLayer::GetAnchorType(*pObj);
+ bIsResizeWithCell = (anchorType == SCA_CELL_RESIZE);
+ }
+ aAny <<= bIsResizeWithCell;
+ }
else if ( aPropertyName == SC_UNONAME_IMAGEMAP )
{
uno::Reference< uno::XInterface > xImageMap;
diff --git a/test/source/sheet/shape.cxx b/test/source/sheet/shape.cxx
index ffa7d8ab112b..4e1505bcf602 100644
--- a/test/source/sheet/shape.cxx
+++ b/test/source/sheet/shape.cxx
@@ -10,8 +10,8 @@
#include <test/sheet/shape.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
-#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
+#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XSpreadsheets.hpp>
#include <com/sun/star/table/XCell.hpp>
#include <com/sun/star/uno/Any.hxx>
@@ -25,68 +25,88 @@ using namespace com::sun::star::uno;
namespace apitest
{
-void Shape::testShapeProperties()
+void Shape::testShapePropertiesAnchor()
{
uno::Reference<beans::XPropertySet> xShape(init(), UNO_QUERY_THROW);
- OUString propName;
uno::Any aNewValue;
- propName = "Anchor";
uno::Reference<sheet::XSpreadsheetDocument> xDoc(getXSheetDocument(), UNO_QUERY_THROW);
uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_QUERY_THROW);
uno::Sequence<OUString> sheetNames = xSheets->getElementNames();
uno::Reference<sheet::XSpreadsheet> xSheet(xSheets->getByName(sheetNames[0]), UNO_QUERY_THROW);
uno::Reference<table::XCell> xCell(xSheet->getCellByPosition(0, 0), UNO_QUERY_THROW);
+ // Shape should be anchored to sheet by default
uno::Reference<sheet::XSpreadsheet> xSheetGet;
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Anchor (XSpreadsheet)",
+ xShape->getPropertyValue("Anchor") >>= xSheetGet);
+
+ // Anchor the shape to a cell
+ aNewValue <<= xCell;
+ xShape->setPropertyValue("Anchor", aNewValue);
uno::Reference<table::XCell> xCellGet;
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Anchor (XCell)",
+ xShape->getPropertyValue("Anchor") >>= xCellGet);
+
+ // Shape should not resize with cell by default
+ bool bIsResizeWithCell;
+ xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell;
+ CPPUNIT_ASSERT_MESSAGE("Shape should not resize with the cell", !bIsResizeWithCell);
+
+ xShape->setPropertyValue("ResizeWithCell", uno::Any(true));
+ xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell;
+ CPPUNIT_ASSERT_MESSAGE("Shape should resize with the cell", bIsResizeWithCell);
+
+ // Anchoring to a different cell should keep the "ResizeWithCell" attribute
+ uno::Reference<table::XCell> xCell2(xSheet->getCellByPosition(1, 2), UNO_QUERY_THROW);
+ aNewValue <<= xCell2;
+ xShape->setPropertyValue("Anchor", aNewValue);
+ xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell;
+ CPPUNIT_ASSERT_MESSAGE("ResizeWithCell should still be set", bIsResizeWithCell);
+
+ // Now anchor to sheet again
+ aNewValue <<= xSheet;
+ xShape->setPropertyValue("Anchor", aNewValue);
+ xShape->getPropertyValue("Anchor") >>= xSheetGet;
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Anchor (XSpreadsheet)",
+ xShape->getPropertyValue("Anchor") >>= xSheetGet);
+
+ // Setting ResizeWithCell while anchored to page should not have any effect
+ xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell;
+ CPPUNIT_ASSERT_MESSAGE("ResizeWithCell should be false for sheet anchored shapes",
+ !bIsResizeWithCell);
+ xShape->setPropertyValue("ResizeWithCell", uno::Any(true));
+ xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell;
+ CPPUNIT_ASSERT_MESSAGE("ResizeWithCell should be unchangeable for sheet anchored shapes",
+ !bIsResizeWithCell);
+}
+
+void Shape::testShapePropertiesPosition()
+{
+ uno::Reference<beans::XPropertySet> xShape(init(), UNO_QUERY_THROW);
+ uno::Any aNewValue;
- if (xShape->getPropertyValue(propName) >>= xSheetGet)
- {
- uno::Reference<sheet::XSpreadsheet> xSheetSet;
- CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Anchor (XSpreadsheet)",
- xShape->getPropertyValue(propName) >>= xSheetGet);
-
- aNewValue <<= xSheet;
- xShape->setPropertyValue(propName, aNewValue);
- CPPUNIT_ASSERT(xShape->getPropertyValue(propName) >>= xSheetSet);
- // TODO: Find a way to compare sheet::XSpreadsheet objects
- //CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Anchor (XSpreadsheet)",
- //xSheet.get(), xSheetSet.get());
- }
- else if (xShape->getPropertyValue(propName) >>= xCellGet)
- {
- uno::Reference<table::XCell> xCellSet;
- CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Anchor (XCell)",
- xShape->getPropertyValue(propName) >>= xCellGet);
-
- aNewValue <<= xCell;
- xShape->setPropertyValue(propName, aNewValue);
- CPPUNIT_ASSERT(xShape->getPropertyValue(propName) >>= xCellSet);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Anchor (XCell)", xCell, xCellSet);
- }
-
- propName = "HoriOrientPosition";
sal_Int32 nHoriOrientPositionGet = 0;
sal_Int32 nHoriOrientPositionSet = 0;
CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue HoriOrientPosition",
- xShape->getPropertyValue(propName) >>= nHoriOrientPositionGet);
+ xShape->getPropertyValue("HoriOrientPosition")
+ >>= nHoriOrientPositionGet);
aNewValue <<= nHoriOrientPositionGet + 42;
- xShape->setPropertyValue(propName, aNewValue);
- CPPUNIT_ASSERT(xShape->getPropertyValue(propName) >>= nHoriOrientPositionSet);
+ xShape->setPropertyValue("HoriOrientPosition", aNewValue);
+ CPPUNIT_ASSERT(xShape->getPropertyValue("HoriOrientPosition") >>= nHoriOrientPositionSet);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue HoriOrientPosition",
nHoriOrientPositionGet + 42, nHoriOrientPositionSet);
- propName = "VertOrientPosition";
sal_Int32 nVertOrientPositionGet = 0;
sal_Int32 nVertOrientPositionSet = 0;
CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue VertOrientPosition",
- xShape->getPropertyValue(propName) >>= nVertOrientPositionGet);
+ xShape->getPropertyValue("VertOrientPosition")
+ >>= nVertOrientPositionGet);
aNewValue <<= nVertOrientPositionGet + 42;
- xShape->setPropertyValue(propName, aNewValue);
- CPPUNIT_ASSERT(xShape->getPropertyValue(propName) >>= nVertOrientPositionSet);
+ xShape->setPropertyValue("VertOrientPosition", aNewValue);
+ CPPUNIT_ASSERT(xShape->getPropertyValue("VertOrientPosition") >>= nVertOrientPositionSet);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue VertOrientPosition",
nVertOrientPositionGet + 42, nVertOrientPositionSet);
}
More information about the Libreoffice-commits
mailing list