sw/qa/extras/uiwriter/uiwriter6.cxx | 52 +++++++++++++++++++++++++++++++++++ sw/source/uibase/dochdl/swdtflvr.cxx | 8 ++++- 2 files changed, 59 insertions(+), 1 deletion(-)
New commits: commit 2da73834efd635213821c40b84067b751b2d8e61 Author: László Németh <nem...@numbertext.org> AuthorDate: Fri Apr 7 18:26:04 2023 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Sat Apr 8 21:09:58 2023 +0200 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 <nem...@numbertext.org> (cherry picked from commit 491e84eb7c6d92c44ab7fa62912452f7789bb8c8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150145 diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx b/sw/qa/extras/uiwriter/uiwriter6.cxx index 881f6ba231b4..eeae8a5387d4 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> @@ -940,6 +941,57 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf147181_TrackedMovingOfMultipleTable CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable2b->getRows()->getCount()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf154599_MovingColumn) +{ + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + 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) { createSwDoc(); diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index d9a6db5c1bb5..57615aa40a7e 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -4104,13 +4104,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; + } } } }