summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorAttila Szűcs <szucs.attila3@nisz.hu>2020-09-18 12:59:38 +0200
committerLászló Németh <nemeth@numbertext.org>2020-09-30 10:32:30 +0200
commit605b4ba57b2daa447af9d43d3759079e15df8148 (patch)
treefcd7e60decd33fc8b3d678a9a27a9d8c639ed08a /sc
parent1ed04c2029218619aab2f3422130c890f67f309c (diff)
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 <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/copy_paste_test.cxx32
-rw-r--r--sc/source/ui/view/viewdata.cxx21
2 files changed, 52 insertions, 1 deletions
diff --git a/sc/qa/unit/copy_paste_test.cxx b/sc/qa/unit/copy_paste_test.cxx
index 0cb2dac43145..caeb05263a9c 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 10aedf7eb3fc..b101997e81ca 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -1143,7 +1143,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 = mrDoc.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;
}