From d929eddf3a3dbb04f37624d255f4e24e07595ca1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 24 Apr 2013 09:01:57 +0000 Subject: [PATCH] Fix showing back hidden columns and rows in wxGrid. While we don't support auto-sizing of the hidden columns and rows, we need to still show them back when SetColSize() or SetRowSize() is called with -1 (a.k.a. wxGRID_AUTOSIZE) argument. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73848 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/grid.cpp | 20 ++++++++------------ tests/controls/gridtest.cpp | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 6bd231ea0b..771f35032e 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -8163,12 +8163,9 @@ void wxGrid::SetRowSize( int row, int height ) return; // The value of -1 is special and means to fit the height to the row label. - if ( height == -1 ) + // As with the columns, ignore attempts to auto-size the hidden rows. + if ( height == -1 && GetRowHeight(row) != 0 ) { - // As with the columns, ignore attempts to auto-size the hidden rows. - if ( GetRowHeight(row) == 0 ) - return; - long w, h; wxArrayString lines; wxClientDC dc(m_rowLabelWin); @@ -8239,14 +8236,13 @@ void wxGrid::SetColSize( int col, int width ) return; // The value of -1 is special and means to fit the width to the column label. - if ( width == -1 ) + // + // Notice that we currently don't support auto-sizing hidden columns (we + // could, but it's not clear whether this is really needed and it would + // make the code more complex), and for them passing -1 simply means to + // show the column back using its old size. + if ( width == -1 && GetColWidth(col) != 0 ) { - // We currently don't support auto-sizing hidden columns. We could, but - // it's not clear whether this is really needed and it would make the - // code more complex. - if ( GetColWidth(col) == 0 ) - return; - long w, h; wxArrayString lines; wxClientDC dc(m_colWindow); diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 3e94e92c4b..8012b51429 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -59,6 +59,7 @@ private: CPPUNIT_TEST( Selection ); CPPUNIT_TEST( AddRowCol ); CPPUNIT_TEST( ColumnOrder ); + CPPUNIT_TEST( ColumnVisibility ); CPPUNIT_TEST( LineFormatting ); CPPUNIT_TEST( SortSupport ); CPPUNIT_TEST( Labels ); @@ -87,6 +88,7 @@ private: void Selection(); void AddRowCol(); void ColumnOrder(); + void ColumnVisibility(); void LineFormatting(); void SortSupport(); void Labels(); @@ -526,6 +528,19 @@ void GridTestCase::ColumnOrder() CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColPos(3)); } +void GridTestCase::ColumnVisibility() +{ + m_grid->AppendCols(3); + CPPUNIT_ASSERT( m_grid->IsColShown(1) ); + + m_grid->HideCol(1); + CPPUNIT_ASSERT( !m_grid->IsColShown(1) ); + CPPUNIT_ASSERT( m_grid->IsColShown(2) ); + + m_grid->ShowCol(1); + CPPUNIT_ASSERT( m_grid->IsColShown(1) ); +} + void GridTestCase::LineFormatting() { CPPUNIT_ASSERT(m_grid->GridLinesEnabled());