From 0c9a9dc126a4f7ce03bdce53ed2680aabd40d1c4 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Mon, 3 Feb 2020 18:09:47 +0700 Subject: [PATCH 1/2] Fix wrong wxGrid::RefreshBlock calling for an empty grid There is no cells to select if the grid is empty (no rows or no columns). So check for the columns count in SelectRow and check for the rows count in SelectCol and call RefreshBlock only if it necessary. Fix https://trac.wxwidgets.org/ticket/18659 Fix https://trac.wxwidgets.org/ticket/18660 --- src/generic/gridsel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index 8497a17af6..0bda0caa44 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -257,7 +257,7 @@ void wxGridSelection::SelectRow(int row, const wxKeyboardState& kbd) } // Update View: - if ( !m_grid->GetBatchCount() ) + if ( !m_grid->GetBatchCount() && m_grid->GetNumberCols() != 0 ) { m_grid->RefreshBlock(row, 0, row, m_grid->GetNumberCols() - 1); } @@ -349,7 +349,7 @@ void wxGridSelection::SelectCol(int col, const wxKeyboardState& kbd) } // Update View: - if ( !m_grid->GetBatchCount() ) + if ( !m_grid->GetBatchCount() && m_grid->GetNumberRows() != 0 ) { m_grid->RefreshBlock(0, col, m_grid->GetNumberRows() - 1, col); } From 217349d772ba4f047e1c603ce2feb08309b08434 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Mon, 3 Feb 2020 19:15:32 +0700 Subject: [PATCH 2/2] Test wxGrid RefreshBlock function when a grid is empty SelectCol and SelectRow should not fail an assertion if a grid has no rows or columns. --- tests/controls/gridtest.cpp | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 6d88a72d3c..f7eb5257df 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -73,6 +73,7 @@ private: WXUISIM_TEST( RangeSelect ); CPPUNIT_TEST( Cursor ); CPPUNIT_TEST( Selection ); + CPPUNIT_TEST( SelectEmptyGrid ); CPPUNIT_TEST( ScrollWhenSelect ); WXUISIM_TEST( MoveGridCursorUsingEndKey ); WXUISIM_TEST( SelectUsingEndKey ); @@ -117,6 +118,7 @@ private: void RangeSelect(); void Cursor(); void Selection(); + void SelectEmptyGrid(); void ScrollWhenSelect(); void MoveGridCursorUsingEndKey(); void SelectUsingEndKey(); @@ -600,6 +602,46 @@ void GridTestCase::Selection() CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0)); } +void GridTestCase::SelectEmptyGrid() +{ + SECTION("Delete rows/columns") + { + SECTION("No rows") + { + m_grid->DeleteRows(0, 10); + REQUIRE( m_grid->GetNumberRows() == 0 ); + } + SECTION("No columns") + { + m_grid->DeleteCols(0, 2); + REQUIRE( m_grid->GetNumberCols() == 0 ); + } + } + + SECTION("Select") + { + SECTION("Move right") + { + m_grid->MoveCursorRight(true); + } + SECTION("Move down") + { + m_grid->MoveCursorDown(true); + } + SECTION("Select row") + { + m_grid->SelectRow(1); + } + SECTION("Select column") + { + m_grid->SelectCol(1); + } + } + + CHECK( m_grid->GetSelectionBlockTopLeft().Count() == 0 ); + CHECK( m_grid->GetSelectionBlockBottomRight().Count() == 0 ); +} + void GridTestCase::ScrollWhenSelect() { m_grid->AppendCols(10);