From 5e3ba81bbf10c45e7eb881162e2c329b58f23b25 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 12 Oct 2019 16:08:24 +0200 Subject: [PATCH] Revert accidentally committed wxGrid changes These changes were included in 18e05aeeee0b782a7e6b139b85ccd7c324294a3a accidentally, revert them for now (they will be recommitted later with a proper commit message). See https://github.com/wxWidgets/wxWidgets/pull/1601 --- src/generic/grid.cpp | 42 +++++---------- tests/controls/gridtest.cpp | 105 ------------------------------------ 2 files changed, 12 insertions(+), 135 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index d62407a637..7ae8040aef 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -9400,65 +9400,47 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction) wxCoord w, h; dc.SetFont( GetLabelFont() ); - bool noContent = (extentMax == 0); bool addMargin = true; if ( column ) { if ( m_useNativeHeader ) { - wxHeaderCtrl* header = GetGridColHeader(); - w = header->GetColumnTitleWidth(colOrRow); + w = GetGridColHeader()->GetColumnTitleWidth(colOrRow); // GetColumnTitleWidth already adds margins internally. addMargin = false; h = 0; - - // GetColumnTitleWidth uses GetTextExtent and not - // GetMultiLineTextExtent so use the same funtion. - if ( header->GetTextExtent(GetColLabelValue(colOrRow)).x > 0 ) - noContent = false; } else { dc.GetMultiLineTextExtent( GetColLabelValue(colOrRow), &w, &h ); if ( GetColLabelTextOrientation() == wxVERTICAL ) w = h; - - noContent = noContent && (w == 0); } } else { dc.GetMultiLineTextExtent( GetRowLabelValue(colOrRow), &w, &h ); - noContent = noContent && (h == 0); } - if ( noContent ) + extent = column ? w : h; + if ( extent > extentMax ) + extentMax = extent; + + if ( !extentMax ) { // empty column - give default extent (notice that if extentMax is less // than default extent but != 0, it's OK) extentMax = column ? m_defaultColWidth : m_defaultRowHeight; } - else + else if ( addMargin ) { - const int margin = column ? 10 : 6; - - // The current extentMax is the max extent of columns/rows values - // so always add margin. - extentMax += margin; - - // The current extent is the extent of the column/row title. - extent = column ? w : h; - - // Add the margin to the current extent only if needed. - if ( addMargin ) - extent += margin; - - // Find out the final max extent when the margin affected to the max extent - // and the current extent. - if ( extent > extentMax ) - extentMax = extent; + // leave some space around text + if ( column ) + extentMax += 10; + else + extentMax += 6; } if ( column ) diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 5ee3fe180f..8d7f9fe671 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -16,11 +16,9 @@ #ifndef WX_PRECOMP #include "wx/app.h" - #include "wx/dcclient.h" #endif // WX_PRECOMP #include "wx/grid.h" -#include "wx/headerctrl.h" #include "testableframe.h" #include "asserthelper.h" #include "wx/uiaction.h" @@ -72,21 +70,18 @@ private: WXUISIM_TEST( ReadOnly ); WXUISIM_TEST( ResizeScrolledHeader ); WXUISIM_TEST( ColumnMinWidth ); - WXUISIM_TEST( AutoSizeColumn ); CPPUNIT_TEST( PseudoTest_NativeHeader ); NONGTK_TEST( LabelClick ); NONGTK_TEST( SortClick ); CPPUNIT_TEST( ColumnOrder ); WXUISIM_TEST( ResizeScrolledHeader ); WXUISIM_TEST( ColumnMinWidth ); - WXUISIM_TEST( AutoSizeColumn ); CPPUNIT_TEST( DeleteAndAddRowCol ); CPPUNIT_TEST( PseudoTest_NativeLabels ); NONGTK_TEST( LabelClick ); NONGTK_TEST( SortClick ); CPPUNIT_TEST( ColumnOrder ); WXUISIM_TEST( WindowAsEditorControl ); - WXUISIM_TEST( AutoSizeColumn ); CPPUNIT_TEST_SUITE_END(); void CellEdit(); @@ -113,23 +108,10 @@ private: void WindowAsEditorControl(); void ResizeScrolledHeader(); void ColumnMinWidth(); - void AutoSizeColumn(); void PseudoTest_NativeHeader() { ms_nativeheader = true; } void PseudoTest_NativeLabels() { ms_nativeheader = false; ms_nativelabels = true; } - // The helper function to determine the width of the column label depending - // on whether the native column is used. - int GetColumnLabelWidth(wxClientDC& dc, int col, int margin) const - { - if (ms_nativeheader) - return m_grid->GetGridColHeader()->GetColumnTitleWidth(col); - - int w, h; - dc.GetMultiLineTextExtent(m_grid->GetColLabelValue(col), &w, &h); - return w + margin; - } - static bool ms_nativeheader; static bool ms_nativelabels; @@ -968,91 +950,4 @@ void GridTestCase::ColumnMinWidth() #endif } -void GridTestCase::AutoSizeColumn() -{ - // Hardcoded margin for columns. - const int margin = 10; - int maxWidth; - - wxGridCellAttr *attr = m_grid->GetOrCreateCellAttr(0, 0); - wxGridCellRenderer *renderer = attr->GetRenderer(m_grid, 0, 0); - REQUIRE(renderer != NULL); - - wxClientDC dcCell(m_grid->GetGridWindow()); - - wxClientDC dcLabel(m_grid->GetGridWindow()); - dcLabel.SetFont(m_grid->GetLabelFont()); - - const wxString shortStr = "W"; - const wxString mediumStr = "WWWW"; - const wxString longStr = "WWWWWWWW"; - const wxString multilineStr = mediumStr + "\n" + longStr; - - SECTION("Empty column") - { - m_grid->SetColLabelValue(0, wxEmptyString); - maxWidth = m_grid->GetDefaultColSize(); - } - - SECTION("Autosize by the title") - { - m_grid->SetColLabelValue(0, mediumStr); - maxWidth = GetColumnLabelWidth(dcLabel, 0, margin); - } - - SECTION("Autosize by cells") - { - m_grid->SetColLabelValue(0, wxEmptyString); - m_grid->SetCellValue(0, 0, mediumStr); - m_grid->SetCellValue(1, 0, shortStr); - m_grid->SetCellValue(3, 0, longStr); - maxWidth = renderer->GetBestWidth(*m_grid, *attr, dcCell, 3, 0, - m_grid->GetRowHeight(3)) - + margin; - } - - SECTION("Autosize with the longest title") - { - m_grid->SetColLabelValue(0, multilineStr); - m_grid->SetCellValue(0, 0, mediumStr); - m_grid->SetCellValue(1, 0, shortStr); - maxWidth = GetColumnLabelWidth(dcLabel, 0, margin); - } - - SECTION("Autosize with the longest cell") - { - m_grid->SetColLabelValue(0, mediumStr); - m_grid->SetCellValue(0, 0, mediumStr); - m_grid->SetCellValue(1, 0, shortStr); - m_grid->SetCellValue(3, 0, multilineStr); - maxWidth = renderer->GetBestWidth(*m_grid, *attr, dcCell, 3, 0, - m_grid->GetRowHeight(3)) - + margin; - } - - SECTION("Autosize with the same values") - { - m_grid->SetColLabelValue(0, mediumStr); - m_grid->SetCellValue(0, 0, mediumStr); - m_grid->SetCellValue(1, 0, mediumStr); - m_grid->SetCellValue(3, 0, mediumStr); - - const int labelWidth = GetColumnLabelWidth(dcLabel, 0, margin); - - const int cellWidth = - renderer->GetBestWidth(*m_grid, *attr, dcCell, 3, 0, - m_grid->GetRowHeight(3)) - + margin; - - // We can't be sure which size will be greater because of different fonts - // so just calculate the maximum width. - maxWidth = wxMax(labelWidth, cellWidth); - } - - m_grid->AutoSizeColumn(0); - - wxYield(); - CHECK(m_grid->GetColSize(0) == maxWidth); -} - #endif //wxUSE_GRID