From 692fab2b73dce6f599b8a88f50435855871c21d6 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 18 Feb 2019 17:19:00 +0100 Subject: [PATCH] WX_GRID::GetVisibleWidth(): fix column label height of our wxGrid, for multiline column labels --- common/widgets/wx_grid.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/common/widgets/wx_grid.cpp b/common/widgets/wx_grid.cpp index 13256480b3..6c5211c9e3 100644 --- a/common/widgets/wx_grid.cpp +++ b/common/widgets/wx_grid.cpp @@ -245,6 +245,25 @@ int WX_GRID::GetVisibleWidth( int aCol, bool aHeader, bool aContents, bool aKeep { // The 1.1 scale factor is due to the fact headers use a bold font, bigger than the normal font size = std::max( size, int( GetTextExtent( GetColLabelValue( aCol ) + "M" ).x * 1.1 ) ); + + // Headers can be multiline. Fix the Column Label Height to show the full header + // However GetTextExtent does not work on multiline strings, + // and do not return the full text height (only the height of one line) + int nl_count = 0; + + for( unsigned ii = 0; ii < GetColLabelValue( aCol ).size(); ii++ ) + if( GetColLabelValue( aCol )[ii] == '\n' ) + nl_count++; + + if( nl_count ) + { + // calculate a reasonable text height and its margin + int heigth = int( GetTextExtent( "Mj" ).y * 1.1 ) + 3; + + // Col Label height must be able to show nl_count+1 lines + if( GetColLabelSize() < heigth * (nl_count+1) ) + SetColLabelSize( GetColLabelSize() + heigth*nl_count ); + } } for( int row = 0; aContents && row < GetNumberRows(); row++ )