Merge branch 'grid-native-header-autosize'

Fixes for auto-sizing grid columns when using native header control.

Closes https://github.com/wxWidgets/wxWidgets/pull/1579
This commit is contained in:
Vadim Zeitlin
2019-10-07 22:26:02 +02:00
3 changed files with 34 additions and 21 deletions

View File

@@ -3874,13 +3874,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
}
else
{
// adjust column width depending on label text
//
// TODO: generate RESIZING event, see #10754
if ( !SendGridSizeEvent(wxEVT_GRID_COL_AUTO_SIZE, -1, colEdge, event) )
AutoSizeColLabelSize( colEdge );
SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event);
HandleColumnAutosize(colEdge, event);
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, colLabelWin);
m_dragLastPos = -1;
@@ -4023,6 +4017,17 @@ void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent& event )
}
}
void wxGrid::HandleColumnAutosize(int col, const wxMouseEvent& event)
{
// adjust column width depending on label text
//
// TODO: generate RESIZING event, see #10754
if ( !SendGridSizeEvent(wxEVT_GRID_COL_AUTO_SIZE, -1, col, event) )
AutoSizeColLabelSize(col);
SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, col, event);
}
void wxGrid::CancelMouseCapture()
{
// cancel operation currently in progress, whatever it is
@@ -9128,16 +9133,23 @@ void wxGrid::SetColSize( int col, int width )
// show the column back using its old size.
if ( width == -1 && GetColWidth(col) != 0 )
{
long w, h;
wxArrayString lines;
wxClientDC dc(m_colLabelWin);
dc.SetFont(GetLabelFont());
StringToLines(GetColLabelValue(col), lines);
if ( GetColLabelTextOrientation() == wxHORIZONTAL )
GetTextBoxSize( dc, lines, &w, &h );
if ( m_useNativeHeader )
{
width = GetGridColHeader()->GetColumnTitleWidth(col);
}
else
GetTextBoxSize( dc, lines, &h, &w );
width = w + 6;
{
long w, h;
wxArrayString lines;
wxClientDC dc(m_colLabelWin);
dc.SetFont(GetLabelFont());
StringToLines(GetColLabelValue(col), lines);
if ( GetColLabelTextOrientation() == wxHORIZONTAL )
GetTextBoxSize( dc, lines, &w, &h );
else
GetTextBoxSize( dc, lines, &h, &w );
width = w + 6;
}
// Check that it is not less than the minimal width and do use the
// possibly greater than minimal-acceptable-width minimal-width itself