Fix assert with setting current cell in wxGrid::Redimension()

Avoid calling wxGrid::SetCurrentCell(0, 0) when the grid has no columns
or rows, as it doesn't have any cells then and doing this logically
fails the precondition assert in GetColPos().

Also refactor all 6 different snippets calling SetCurrentCell() in
Redimension() into a single function to simplify the code and make it
more maintainable.

Add a unit test verifying that this works as intended.

Closes https://github.com/wxWidgets/wxWidgets/pull/1546
This commit is contained in:
Ilya Sinitsyn
2019-09-13 00:06:37 +07:00
committed by Vadim Zeitlin
parent 41b444e011
commit dda6aa6bdc
3 changed files with 78 additions and 46 deletions

View File

@@ -58,6 +58,7 @@ private:
CPPUNIT_TEST( Cursor );
CPPUNIT_TEST( Selection );
CPPUNIT_TEST( AddRowCol );
CPPUNIT_TEST( DeleteAndAddRowCol );
CPPUNIT_TEST( ColumnOrder );
CPPUNIT_TEST( ColumnVisibility );
CPPUNIT_TEST( LineFormatting );
@@ -75,6 +76,7 @@ private:
CPPUNIT_TEST( ColumnOrder );
WXUISIM_TEST( ResizeScrolledHeader );
WXUISIM_TEST( ColumnMinWidth );
CPPUNIT_TEST( DeleteAndAddRowCol );
CPPUNIT_TEST( PseudoTest_NativeLabels );
NONGTK_TEST( LabelClick );
NONGTK_TEST( SortClick );
@@ -93,6 +95,7 @@ private:
void Cursor();
void Selection();
void AddRowCol();
void DeleteAndAddRowCol();
void ColumnOrder();
void ColumnVisibility();
void LineFormatting();
@@ -540,6 +543,35 @@ void GridTestCase::AddRowCol()
CPPUNIT_ASSERT_EQUAL(7, m_grid->GetNumberCols());
}
void GridTestCase::DeleteAndAddRowCol()
{
CPPUNIT_ASSERT_EQUAL(10, m_grid->GetNumberRows());
CPPUNIT_ASSERT_EQUAL(2, m_grid->GetNumberCols());
m_grid->DeleteRows(0, 10);
m_grid->DeleteCols(0, 2);
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetNumberRows());
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetNumberCols());
m_grid->AppendRows(5);
m_grid->AppendCols(3);
CPPUNIT_ASSERT_EQUAL(5, m_grid->GetNumberRows());
CPPUNIT_ASSERT_EQUAL(3, m_grid->GetNumberCols());
// The order of functions calls can be important
m_grid->DeleteCols(0, 3);
m_grid->DeleteRows(0, 5);
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetNumberRows());
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetNumberCols());
// Different functions calls order
m_grid->AppendCols(3);
m_grid->AppendRows(5);
}
void GridTestCase::ColumnOrder()
{
m_grid->AppendCols(2);