summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2023-04-07 18:26:04 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-04-10 18:52:20 +0200
commit6e6398764945045876176262f54dac6785890385 (patch)
tree2f2456daa7d3903aa5590765212fa8e6e30d2786
parent4300ea07cfa664a1de9509cb9cd83c7ae46afe87 (diff)
tdf#154599 sw: fix crash at drag & drop table columns
New code path for (tracked) row deletion resulted broken column deletion, by deleting more columns at their drag & drop, than needed. Regression from commit 5e8aa259e48d5602b932353bb146ebb523982cf2 "tdf#146967 sw table: fix freezing in Hide Changes mode". Change-Id: Ib649f5b534a588d192d27757e30c8f81087beb0a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150132 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit 491e84eb7c6d92c44ab7fa62912452f7789bb8c8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150146 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--sw/qa/extras/uiwriter/uiwriter6.cxx52
-rw-r--r--sw/source/uibase/dochdl/swdtflvr.cxx8
2 files changed, 59 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx b/sw/qa/extras/uiwriter/uiwriter6.cxx
index 1e1b31ac7ed8..f12f8b57e087 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -26,6 +26,7 @@
#include <txatbase.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentRedlineAccess.hxx>
+#include <IDocumentLayoutAccess.hxx>
#include <UndoManager.hxx>
#include <unotools/syslocaleoptions.hxx>
@@ -899,6 +900,57 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf147181_TrackedMovingOfMultipleTable
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable2b->getRows()->getCount());
}
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf154599_MovingColumn)
+{
+ //create new writer document
+ SwDoc* pDoc = createSwDoc();
+ CPPUNIT_ASSERT(pDoc);
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ CPPUNIT_ASSERT(pWrtShell);
+
+ // Create a table with less columns, than row
+ SwInsertTableOptions TableOpt(SwInsertTableFlags::DefaultBorder, 0);
+ (void)&pWrtShell->InsertTable(TableOpt, 4, 3);
+
+ uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xTableNames = xTablesSupplier->getTextTables();
+ CPPUNIT_ASSERT(xTableNames->hasByName("Table1"));
+ uno::Reference<text::XTextTable> xTable1(xTableNames->getByName("Table1"), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable1->getRows()->getCount());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable1->getColumns()->getCount());
+
+ // without redlining
+ CPPUNIT_ASSERT_MESSAGE("redlining should be off",
+ !pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+
+ // Move first column of the table before the third column by drag & drop
+
+ SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+ SwFrame* pPage = pLayout->Lower();
+ SwFrame* pBody = pPage->GetLower();
+ SwFrame* pTable = pBody->GetLower();
+ SwFrame* pRow1 = pTable->GetLower();
+ SwFrame* pCellA1 = pRow1->GetLower();
+ SwFrame* pCellC1 = pCellA1->GetNext()->GetNext();
+ const SwRect& rCellA1Rect = pCellA1->getFrameArea();
+ const SwRect& rCellC1Rect = pCellC1->getFrameArea();
+ Point ptTo(rCellC1Rect.Left() + rCellC1Rect.Width() / 2,
+ rCellC1Rect.Top() + rCellC1Rect.Height() / 2);
+ // select first table column by using the middle point of the top border of column A
+ Point ptColumn(rCellA1Rect.Left() + rCellA1Rect.Width() / 2, rCellA1Rect.Top() - 5);
+ pWrtShell->SelectTableRowCol(ptColumn);
+
+ // This crashed here before the fix.
+ rtl::Reference<SwTransferable> xTransfer = new SwTransferable(*pWrtShell);
+
+ xTransfer->PrivateDrop(*pWrtShell, ptTo, /*bMove=*/true, /*bXSelection=*/true);
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable1->getRows()->getCount());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable1->getColumns()->getCount());
+}
+
CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf115132)
{
SwDoc* pDoc = createSwDoc();
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index dd9fc88fbe57..372019273ccd 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -4092,13 +4092,19 @@ bool SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt,
}
}
- // delete rows without track changes
+ // delete original rows/columns, except in track changes mode
+ // TODO remove all the columns, not only the first one
if ( !bNeedTrack )
{
for (sal_Int32 nDeleted = 0; nDeleted < nSelRows; ++nDeleted)
+ {
pDispatch->Execute(bTableCol
? FN_TABLE_DELETE_COL
: FN_TABLE_DELETE_ROW, SfxCallMode::SYNCHRON);
+
+ if ( bTableCol )
+ break;
+ }
}
}
}