Merge branch 'grid-autosize-native-header'

Fix auto-sizing column labels when using native header in wxGrid.

See https://github.com/wxWidgets/wxWidgets/pull/1559
This commit is contained in:
Vadim Zeitlin
2019-09-18 14:32:02 +02:00
4 changed files with 39 additions and 13 deletions

View File

@@ -159,6 +159,12 @@ public:
// compute column title width // compute column title width
int GetColumnTitleWidth(const wxHeaderColumn& col); int GetColumnTitleWidth(const wxHeaderColumn& col);
// compute column title width for the column with the given index
int GetColumnTitleWidth(unsigned int idx)
{
return GetColumnTitleWidth(GetColumn(idx));
}
// implementation only from now on // implementation only from now on
// ------------------------------- // -------------------------------

View File

@@ -404,6 +404,16 @@ public:
*/ */
int GetColumnTitleWidth(const wxHeaderColumn& col); int GetColumnTitleWidth(const wxHeaderColumn& col);
/**
Returns width needed for the column with the given index.
This is just a convenient wrapper for the overload taking
wxHeaderColumn.
@since 3.1.3
*/
int GetColumnTitleWidth(unsigned int idx);
protected: protected:
/** /**
Method to be implemented by the derived classes to return the Method to be implemented by the derived classes to return the

View File

@@ -9383,14 +9383,31 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
dc.SetFont( GetLabelFont() ); dc.SetFont( GetLabelFont() );
if ( column ) if ( column )
{
if ( m_useNativeHeader )
{
w = GetGridColHeader()->GetColumnTitleWidth(colOrRow);
h = 0;
}
else
{ {
dc.GetMultiLineTextExtent( GetColLabelValue(colOrRow), &w, &h ); dc.GetMultiLineTextExtent( GetColLabelValue(colOrRow), &w, &h );
if ( GetColLabelTextOrientation() == wxVERTICAL ) if ( GetColLabelTextOrientation() == wxVERTICAL )
w = h; w = h;
// leave some space around text
if ( w )
w += 10;
}
} }
else else
{
dc.GetMultiLineTextExtent( GetRowLabelValue(colOrRow), &w, &h ); dc.GetMultiLineTextExtent( GetRowLabelValue(colOrRow), &w, &h );
if ( h )
h += 6;
}
extent = column ? w : h; extent = column ? w : h;
if ( extent > extentMax ) if ( extent > extentMax )
extentMax = extent; extentMax = extent;
@@ -9401,14 +9418,6 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
// than default extent but != 0, it's OK) // than default extent but != 0, it's OK)
extentMax = column ? m_defaultColWidth : m_defaultRowHeight; extentMax = column ? m_defaultColWidth : m_defaultRowHeight;
} }
else
{
if ( column )
// leave some space around text
extentMax += 10;
else
extentMax += 6;
}
if ( column ) if ( column )
{ {

View File

@@ -590,9 +590,10 @@ int wxRendererMSW::GetHeaderButtonHeight(wxWindow * win)
return Header_Layout(hwndHeader, &hdl) ? wp.cy : DEFAULT_HEIGHT; return Header_Layout(hwndHeader, &hdl) ? wp.cy : DEFAULT_HEIGHT;
} }
int wxRendererMSW::GetHeaderButtonMargin(wxWindow *WXUNUSED(win)) int wxRendererMSW::GetHeaderButtonMargin(wxWindow *win)
{ {
return 10; // The native control seems to use 3*SM_CXEDGE margins on each size.
return 6*wxGetSystemMetrics(SM_CXEDGE, win);
} }
// ============================================================================ // ============================================================================