summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-03-08 21:06:10 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-03-09 08:37:07 +0100
commitd2a45762f1b5f1c7093469e34d9f56defa88e9e4 (patch)
treee1b8520b9408ebd3312b59b1aba78174ac219649 /sw
parent3186f98a29432400d0627eec992da926dd5852c6 (diff)
tdf#140292 sw: fix z-order of textbox on undo
Regression from commit 200cd2b99bee18962a970edc5d059286f6c3ea0e (tdf#138995 DOCX import: fix handling of textbox zorders, 2021-01-11), the problem was already fixed by Michael Stahl, this just adds a test for it. Change-Id: Id613224d5fab0c2d2a3bdfd58bff6d77a92dd374 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112181 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/core/draw/data/textbox-undo-ordnum.docxbin0 -> 21223 bytes
-rw-r--r--sw/qa/core/draw/draw.cxx53
2 files changed, 53 insertions, 0 deletions
diff --git a/sw/qa/core/draw/data/textbox-undo-ordnum.docx b/sw/qa/core/draw/data/textbox-undo-ordnum.docx
new file mode 100644
index 000000000000..96b00973289a
--- /dev/null
+++ b/sw/qa/core/draw/data/textbox-undo-ordnum.docx
Binary files differ
diff --git a/sw/qa/core/draw/draw.cxx b/sw/qa/core/draw/draw.cxx
index b8544022589a..c4654dde8127 100644
--- a/sw/qa/core/draw/draw.cxx
+++ b/sw/qa/core/draw/draw.cxx
@@ -10,11 +10,14 @@
#include <swmodeltestbase.hxx>
#include <svx/svdpage.hxx>
+#include <vcl/scheduler.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <docsh.hxx>
#include <drawdoc.hxx>
#include <wrtsh.hxx>
+#include <frameformats.hxx>
+#include <textboxhelper.hxx>
constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/draw/data/";
@@ -46,6 +49,56 @@ CPPUNIT_TEST_FIXTURE(SwCoreDrawTest, testTextboxDeleteAsChar)
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nActual);
}
+CPPUNIT_TEST_FIXTURE(SwCoreDrawTest, testTextboxUndoOrdNum)
+{
+ // Given a document with 5 frame formats:
+ // - picture
+ // - draw format + fly format and a picture in it
+ // - picture
+ SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "textbox-undo-ordnum.docx");
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ const SwFrameFormats& rFormats = *pDoc->GetSpzFrameFormats();
+ // Test the state before del + undo.
+ for (const auto& pFormat : rFormats)
+ {
+ const SwFrameFormat* pFlyFormat
+ = SwTextBoxHelper::getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT);
+ if (!pFlyFormat)
+ {
+ continue;
+ }
+
+ sal_Int32 nDrawOrdNum = pFormat->FindRealSdrObject()->GetOrdNum();
+ sal_Int32 nFlyOrdNum = pFlyFormat->FindRealSdrObject()->GetOrdNum();
+ CPPUNIT_ASSERT_EQUAL(nDrawOrdNum + 1, nFlyOrdNum);
+ }
+
+ // When selecting the first page, deleting the selection and undoing:
+ pWrtShell->Down(true, 3);
+ pWrtShell->DelLeft();
+ pWrtShell->Undo();
+
+ // Then the z-order of the fly format should be still the z-order of the draw format + 1, when
+ // the fly and draw formats form a textbox pair.
+ for (const auto& pFormat : rFormats)
+ {
+ const SwFrameFormat* pFlyFormat
+ = SwTextBoxHelper::getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT);
+ if (!pFlyFormat)
+ {
+ continue;
+ }
+
+ sal_Int32 nDrawOrdNum = pFormat->FindRealSdrObject()->GetOrdNum();
+ sal_Int32 nFlyOrdNum = pFlyFormat->FindRealSdrObject()->GetOrdNum();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 4
+ // - Actual : 2
+ // i.e. the fly format was behind the draw format, not visible.
+ CPPUNIT_ASSERT_EQUAL(nDrawOrdNum + 1, nFlyOrdNum);
+ }
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */