summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-04-25 10:57:49 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-04-25 09:52:54 +0000
commitcafc53f8b4c08443524b1da6f4918d49afd45bb5 (patch)
tree22fe5b1c721bb4a83504b89201e34e3ab77a3842 /sd
parent474eca1f9b42749665bbf69f6dc62c66ea4ad7fd (diff)
tdf#99452 svx: fix undo of table row edge drag
The problem as seen by the user: if you have a table of 2 rows and 1 column, and the separator line is dragged upwards by the mouse, then undo doesn't restore the original situation. Two items are created on the undo stack: sd::UndoGeoObject and sdr::table::TableRowUndo. Let's say the table height is 8000 mm100 and the two cell heights are 4000 and 4000. If the user resizes the first cell, so that its height is 2000, then the new table height will be 6000. The problem is that when undo is executed, first sd::UndoGeoObject resizes the table, distributing the newly available 2000 between the existing rows, and then sdr::table::TableRowUndo sets the row height of the first row: the height of the second cell will be larger than expected. Fix the problem by not doing a relayout during sd::UndoGeoObject, but doing a relayout after sdr::table::TableRowUndo in this case. This is done by: 1) Adding a new SdrDragStat::mbEndDragChangesLayout, so that SdrTableObj::applySpecialDrag() can inform SdrDragObjOwn::EndSdrDrag() that TableRowUndo will do the layout instead of UndoGeoObject. (This is done only in case a row edge is dragged, as otherwise it's not guaranteed that a TableRowUndo will follow the UndoGeoObject on the undo stack.) 2) Adding a new SdrUndoGeoObj::mbSkipChangeLayout, so that SdrTableObj::applySpecialDrag() can let SdrUndoGeoObj::Undo() not do the layout. 3) Adding a sdr::table::SdrTableObjImpl::mbSkipChangeLayout, so that SdrUndoGeoObj::Undo() can let SdrTableObj::NbcSetLogicRect() not do the layout. 4) Marking the table model as modified in TableRowUndo::setData(), so it does the layout at the end of the undo group. Change-Id: I8adde3cdad5741e6fcb420e333ce336e18c77cf1 Reviewed-on: https://gerrit.libreoffice.org/24363 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sd')
-rw-r--r--sd/qa/unit/tiledrendering/data/table.odpbin0 -> 10559 bytes
-rw-r--r--sd/qa/unit/tiledrendering/tiledrendering.cxx51
2 files changed, 51 insertions, 0 deletions
diff --git a/sd/qa/unit/tiledrendering/data/table.odp b/sd/qa/unit/tiledrendering/data/table.odp
new file mode 100644
index 000000000000..6d92898a00c6
--- /dev/null
+++ b/sd/qa/unit/tiledrendering/data/table.odp
Binary files differ
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 88b437f3286b..a47f99077267 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -25,6 +25,7 @@
#include <sfx2/viewfrm.hxx>
#include <svl/srchitem.hxx>
#include <comphelper/lok.hxx>
+#include <svx/svdotable.hxx>
#include <DrawDocShell.hxx>
#include <ViewShell.hxx>
@@ -61,6 +62,7 @@ public:
void testInsertDeletePage();
void testInsertTable();
void testPartHash();
+ void testResizeTable();
#endif
CPPUNIT_TEST_SUITE(SdTiledRenderingTest);
@@ -80,6 +82,7 @@ public:
CPPUNIT_TEST(testInsertDeletePage);
CPPUNIT_TEST(testInsertTable);
CPPUNIT_TEST(testPartHash);
+ CPPUNIT_TEST(testResizeTable);
#endif
CPPUNIT_TEST_SUITE_END();
@@ -678,6 +681,54 @@ void SdTiledRenderingTest::testPartHash()
comphelper::LibreOfficeKit::setActive(false);
}
+void SdTiledRenderingTest::testResizeTable()
+{
+ // Load the document.
+ comphelper::LibreOfficeKit::setActive();
+ SdXImpressDocument* pXImpressDocument = createDoc("table.odp");
+ sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+ SdPage* pActualPage = pViewShell->GetActualPage();
+ SdrObject* pObject = pActualPage->GetObj(0);
+ auto pTableObject = dynamic_cast<sdr::table::SdrTableObj*>(pObject);
+ CPPUNIT_ASSERT(pTableObject);
+
+ // Select the table by marking it + starting and ending text edit.
+ SdrView* pView = pViewShell->GetView();
+ pView->MarkObj(pObject, pView->GetSdrPageView());
+ pView->SdrBeginTextEdit(pObject);
+ pView->SdrEndTextEdit();
+
+ // Remember the original row heights.
+ uno::Reference<table::XColumnRowRange> xTable(pTableObject->getTable(), uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xRows(xTable->getRows(), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xRow1(xRows->getByIndex(0), uno::UNO_QUERY);
+ sal_Int32 nExpectedRow1 = xRow1->getPropertyValue("Size").get<sal_Int32>();
+ uno::Reference<beans::XPropertySet> xRow2(xRows->getByIndex(1), uno::UNO_QUERY);
+ sal_Int32 nExpectedRow2 = xRow2->getPropertyValue("Size").get<sal_Int32>();
+
+ // Resize the upper row, decrease its height by 1 cm.
+ Point aInnerRowEdge = pObject->GetSnapRect().Center();
+ pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_START, convertMm100ToTwip(aInnerRowEdge.getX()), convertMm100ToTwip(aInnerRowEdge.getY()));
+ pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_END, convertMm100ToTwip(aInnerRowEdge.getX()), convertMm100ToTwip(aInnerRowEdge.getY() - 1000));
+
+ // Remember the resized row heights.
+ sal_Int32 nResizedRow1 = xRow1->getPropertyValue("Size").get<sal_Int32>();
+ CPPUNIT_ASSERT(nResizedRow1 < nExpectedRow1);
+ sal_Int32 nResizedRow2 = xRow2->getPropertyValue("Size").get<sal_Int32>();
+ CPPUNIT_ASSERT_EQUAL(nExpectedRow2, nResizedRow2);
+
+ // Now undo the resize.
+ pXImpressDocument->GetDocShell()->GetUndoManager()->Undo();
+
+ // Check the undo result.
+ sal_Int32 nActualRow1 = xRow1->getPropertyValue("Size").get<sal_Int32>();
+ CPPUNIT_ASSERT_EQUAL(nExpectedRow1, nActualRow1);
+ sal_Int32 nActualRow2 = xRow2->getPropertyValue("Size").get<sal_Int32>();
+ // Expected was 4000, actual was 4572, i.e. the second row after undo was larger than expected.
+ CPPUNIT_ASSERT_EQUAL(nExpectedRow2, nActualRow2);
+ comphelper::LibreOfficeKit::setActive(false);
+}
+
#endif
CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest);