Merge branch 'grid-refresh-block'

Avoid asserts due to passing invalid coordinates to RefreshBlock() when
the grid didn't have any rows or columns.

Closes https://github.com/wxWidgets/wxWidgets/pull/1725

Closes #18659, #18660.
This commit is contained in:
Vadim Zeitlin
2020-02-05 03:32:46 +01:00
2 changed files with 44 additions and 2 deletions

View File

@@ -257,7 +257,7 @@ void wxGridSelection::SelectRow(int row, const wxKeyboardState& kbd)
} }
// Update View: // Update View:
if ( !m_grid->GetBatchCount() ) if ( !m_grid->GetBatchCount() && m_grid->GetNumberCols() != 0 )
{ {
m_grid->RefreshBlock(row, 0, row, m_grid->GetNumberCols() - 1); m_grid->RefreshBlock(row, 0, row, m_grid->GetNumberCols() - 1);
} }
@@ -349,7 +349,7 @@ void wxGridSelection::SelectCol(int col, const wxKeyboardState& kbd)
} }
// Update View: // Update View:
if ( !m_grid->GetBatchCount() ) if ( !m_grid->GetBatchCount() && m_grid->GetNumberRows() != 0 )
{ {
m_grid->RefreshBlock(0, col, m_grid->GetNumberRows() - 1, col); m_grid->RefreshBlock(0, col, m_grid->GetNumberRows() - 1, col);
} }

View File

@@ -73,6 +73,7 @@ private:
WXUISIM_TEST( RangeSelect ); WXUISIM_TEST( RangeSelect );
CPPUNIT_TEST( Cursor ); CPPUNIT_TEST( Cursor );
CPPUNIT_TEST( Selection ); CPPUNIT_TEST( Selection );
CPPUNIT_TEST( SelectEmptyGrid );
CPPUNIT_TEST( ScrollWhenSelect ); CPPUNIT_TEST( ScrollWhenSelect );
WXUISIM_TEST( MoveGridCursorUsingEndKey ); WXUISIM_TEST( MoveGridCursorUsingEndKey );
WXUISIM_TEST( SelectUsingEndKey ); WXUISIM_TEST( SelectUsingEndKey );
@@ -117,6 +118,7 @@ private:
void RangeSelect(); void RangeSelect();
void Cursor(); void Cursor();
void Selection(); void Selection();
void SelectEmptyGrid();
void ScrollWhenSelect(); void ScrollWhenSelect();
void MoveGridCursorUsingEndKey(); void MoveGridCursorUsingEndKey();
void SelectUsingEndKey(); void SelectUsingEndKey();
@@ -600,6 +602,46 @@ void GridTestCase::Selection()
CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0)); 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() void GridTestCase::ScrollWhenSelect()
{ {
m_grid->AppendCols(10); m_grid->AppendCols(10);