sc/qa/unit/copy_paste_test.cxx | 32 ++++++++++++++++++++++++++++++++ sc/source/ui/view/viewdata.cxx | 21 ++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)
New commits: commit 5c2d2a4f3bdb03bb957178dce4df09e9914e3a44 Author: Attila Szűcs <szucs.atti...@nisz.hu> AuthorDate: Fri Sep 18 12:59:38 2020 +0200 Commit: Gabor Kelemen <kelemen.gab...@nisz.hu> CommitDate: Tue Feb 23 15:09:47 2021 +0100 tdf#43958 sc: fix fill by selecting merged cell wholly instead of only its top left corner, if there is no marked selection present. This fixes the selection rectangle during dragging by fill handle of selected merged cells, copying their attributes in other cells of the target area, too, fixing losing merged cell structure, e.g. incomplete grid and other problems. Follow-up of commit 1ed04c2029218619aab2f3422130c890f67f309c (tdf#40993 tdf#59585 sc fill: copy merged cell structure). Note: the selection is a bit different, if there is filtered (hidden) rows in the current cell area. Co-authored-by: Tibor Nagy (NISZ) Change-Id: I387feef640b7a89ab601c24e3641075934d3fc54 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103001 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit 605b4ba57b2daa447af9d43d3759079e15df8148) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111329 Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu> diff --git a/sc/qa/unit/copy_paste_test.cxx b/sc/qa/unit/copy_paste_test.cxx index 5580f8349de7..22c0f832e64a 100644 --- a/sc/qa/unit/copy_paste_test.cxx +++ b/sc/qa/unit/copy_paste_test.cxx @@ -41,6 +41,7 @@ public: void testTdf107394(); void testTdf53431_fillOnAutofilter(); void testTdf40993_fillMergedCells(); + void testTdf43958_clickSelectOnMergedCells(); CPPUNIT_TEST_SUITE(ScCopyPasteTest); CPPUNIT_TEST(testCopyPasteXLS); @@ -50,6 +51,7 @@ public: CPPUNIT_TEST(testTdf107394); CPPUNIT_TEST(testTdf53431_fillOnAutofilter); CPPUNIT_TEST(testTdf40993_fillMergedCells); + CPPUNIT_TEST(testTdf43958_clickSelectOnMergedCells); CPPUNIT_TEST_SUITE_END(); private: @@ -588,6 +590,36 @@ void ScCopyPasteTest::testTdf40993_fillMergedCells() CPPUNIT_ASSERT_EQUAL(lcl_getMergeSizeOfCell(rDoc, 3, 5, 0), ScAddress(2, 1, 0)); } +static void lcl_clickAndCheckCurrentArea(SCCOL nCol, SCROW nRow, SCCOL nCol2, SCROW nRow2) +{ + ScRange aRange; + ScDocShell::GetViewData()->SetCurX(nCol); + ScDocShell::GetViewData()->SetCurY(nRow); + ScDocShell::GetViewData()->GetSimpleArea(aRange); + CPPUNIT_ASSERT_EQUAL(aRange, ScRange(nCol, nRow, 0, nCol2, nRow2, 0)); +} + +void ScCopyPasteTest::testTdf43958_clickSelectOnMergedCells() +{ + loadDocAndSetupModelViewController("tdf40993_fillMergedCells.", FORMAT_ODS, true); + + // select cell (e.g. by clicking on it) and check what is selected [but not marked]: + // if it is the top left cell of a merged area, the selection is enlarged to the area + lcl_clickAndCheckCurrentArea(1, 5, 2, 8); // B6 -> B6:C9 + lcl_clickAndCheckCurrentArea(0, 5, 0, 6); // A6 -> A6:A7 + lcl_clickAndCheckCurrentArea(3, 5, 4, 5); // D6 -> D6:E6 + lcl_clickAndCheckCurrentArea(4, 6, 4, 7); // D7 -> D6:D7 + lcl_clickAndCheckCurrentArea(7, 10, 8, 10); // H11 -> H11:I11 + lcl_clickAndCheckCurrentArea(7, 13, 8, 13); // H14 -> H14:I14 + + // otherwise it remains the same + lcl_clickAndCheckCurrentArea(0, 7, 0, 7); // A8 + lcl_clickAndCheckCurrentArea(0, 8, 0, 8); // A9 + lcl_clickAndCheckCurrentArea(2, 6, 2, 6); // C7 + lcl_clickAndCheckCurrentArea(2, 7, 2, 7); // C8 + lcl_clickAndCheckCurrentArea(2, 8, 2, 8); // C9 +} + ScCopyPasteTest::ScCopyPasteTest() : ScBootstrapFixture( "sc/qa/unit/data" ) { diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index 0fddf7862b82..0b50f90a3bfa 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -1149,7 +1149,26 @@ ScMarkType ScViewData::GetSimpleArea( ScRange & rRange, ScMarkData & rNewMark ) { if (eMarkType == SC_MARK_NONE) eMarkType = SC_MARK_SIMPLE; - rRange = ScRange( GetCurX(), GetCurY(), GetTabNo() ); + const ScPatternAttr* pMarkPattern = pDoc->GetPattern(GetCurX(), GetCurY(), GetTabNo()); + if (pMarkPattern->GetItemSet().GetItemState(ATTR_MERGE, false) == SfxItemState::SET) + { + SCROW nRow = pMarkPattern->GetItem(ATTR_MERGE).GetRowMerge(); + SCCOL nCol = pMarkPattern->GetItem(ATTR_MERGE).GetColMerge(); + if ( nRow < 1 || nCol < 1 ) + { + // This kind of cells do exist. Not sure if that is intended or a bug. + rRange = ScRange(GetCurX(), GetCurY(), GetTabNo()); + } + else + { + rRange = ScRange(GetCurX(), GetCurY(), GetTabNo(), + GetCurX() + nCol - 1, GetCurY() + nRow - 1, GetTabNo()); + if ( ScViewUtil::HasFiltered(rRange, GetDocument()) ) + eMarkType = SC_MARK_SIMPLE_FILTERED; + } + } + else + rRange = ScRange(GetCurX(), GetCurY(), GetTabNo()); } return eMarkType; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits