From 9be1f86ca0fa99df5221f9884c9183807cdda0bf Mon Sep 17 00:00:00 2001 From: Scott Talbert Date: Thu, 13 Aug 2020 20:01:45 -0400 Subject: [PATCH 1/3] Fix regression in wxGrid::DeselectRow() and wxGrid::DeselectCol() --- src/generic/grid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 464f3d2c7e..6bdad3143c 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -10515,7 +10515,7 @@ void wxGrid::DeselectRow(int row) wxCHECK_RET( row >= 0 && row < m_numRows, wxT("invalid row index") ); if ( m_selection ) - m_selection->DeselectBlock(wxGridBlockCoords(row, 0, row, m_numRows - 1)); + m_selection->DeselectBlock(wxGridBlockCoords(row, 0, row, m_numCols - 1)); } void wxGrid::DeselectCol(int col) @@ -10523,7 +10523,7 @@ void wxGrid::DeselectCol(int col) wxCHECK_RET( col >= 0 && col < m_numCols, wxT("invalid column index") ); if ( m_selection ) - m_selection->DeselectBlock(wxGridBlockCoords(0, col, m_numCols - 1, col)); + m_selection->DeselectBlock(wxGridBlockCoords(0, col, m_numRows - 1, col)); } void wxGrid::DeselectCell( int row, int col ) From 4475df82644479563cb425a9a1587a9478031fd0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 14 Aug 2020 12:33:40 +0200 Subject: [PATCH 2/3] Add unit tests for wxGrid::Deselect{Row,Col}() These functions got broken by the changes of cdf3187fe5 (Improve rows, columns and cells deselection in wxGrid, 2020-03-26), but this went unnoticed because they were not covered by the unit tests, so add the tests for them to prevent this from happening again in the future. --- tests/controls/gridtest.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 9429a76ac8..8a862fb7ce 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -565,6 +565,13 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Selection", "[grid]") CHECK(m_grid->IsInSelection(4, 0)); CHECK(m_grid->IsInSelection(4, 1)); CHECK(!m_grid->IsInSelection(3, 0)); + + m_grid->DeselectRow(4); + CHECK(!m_grid->IsInSelection(4, 0)); + CHECK(!m_grid->IsInSelection(4, 1)); + + m_grid->DeselectCol(1); + CHECK(!m_grid->IsInSelection(0, 1)); } TEST_CASE_METHOD(GridTestCase, "Grid::SelectionRange", "[grid]") From bb93682a87eb8173f9219c7776a00e9bb2c478a2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 14 Aug 2020 12:41:10 +0200 Subject: [PATCH 3/3] Improve wxGrid selection test slightly Check that deselecting a row leaves the cells outside of this row selected. This requires passing "true" to the previous call of SelectRow() to prevent it from clearing the existing selection, as it does by default. --- tests/controls/gridtest.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 8a862fb7ce..e0a8ff4732 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -560,15 +560,18 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Selection", "[grid]") CHECK(m_grid->IsInSelection(9, 1)); CHECK(!m_grid->IsInSelection(3, 0)); - m_grid->SelectRow(4); + m_grid->SelectRow(4, true /* add to selection */); CHECK(m_grid->IsInSelection(4, 0)); CHECK(m_grid->IsInSelection(4, 1)); CHECK(!m_grid->IsInSelection(3, 0)); + // Check that deselecting a row does deselect the cells in it, but leaves + // the other ones selected. m_grid->DeselectRow(4); CHECK(!m_grid->IsInSelection(4, 0)); CHECK(!m_grid->IsInSelection(4, 1)); + CHECK(m_grid->IsInSelection(0, 1)); m_grid->DeselectCol(1); CHECK(!m_grid->IsInSelection(0, 1));