Also avoid updating wxHeaderCtrl column when resizing in wxGrid

This is another attempt to get rid of the flicker when using the native
header control with wxGrid under MSW and avoid calling UpdateColumn(),
which is currently implemented in a very inefficient way in wxHeaderCtrl
under MSW, during interactive resizing.

See #18794.
This commit is contained in:
Vadim Zeitlin
2020-06-21 23:46:59 +02:00
parent bf266ca348
commit f8a0438385
2 changed files with 34 additions and 1 deletions

View File

@@ -152,6 +152,14 @@ public:
(owner->CanHideColumns() ? wxHD_ALLOW_HIDE : 0) | (owner->CanHideColumns() ? wxHD_ALLOW_HIDE : 0) |
(owner->CanDragColMove() ? wxHD_ALLOW_REORDER : 0)) (owner->CanDragColMove() ? wxHD_ALLOW_REORDER : 0))
{ {
m_inResizing = 0;
}
// Special method to call from wxGrid::DoSetColSize(), see comments there.
void UpdateIfNotResizing(unsigned int idx)
{
if ( !m_inResizing )
UpdateColumn(idx);
} }
protected: protected:
@@ -259,7 +267,20 @@ private:
void OnResizing(wxHeaderCtrlEvent& event) void OnResizing(wxHeaderCtrlEvent& event)
{ {
// Calling wxGrid method results in a call to our own UpdateColumn()
// because it ends up in wxGrid::SetColSize() which must indeed update
// the column when it's called by the program -- but in the case where
// the size change comes from the column itself, it is useless and, in
// fact, harmful, as it results in extra flicker due to the inefficient
// implementation of UpdateColumn() in wxMSW wxHeaderCtrl, so skip
// calling it from our overridden version by setting this flag for the
// duration of this function execution and checking it in our
// UpdateIfNotResizing().
m_inResizing++;
GetOwner()->DoHeaderDragResizeCol(event.GetWidth()); GetOwner()->DoHeaderDragResizeCol(event.GetWidth());
m_inResizing--;
} }
void OnEndResize(wxHeaderCtrlEvent& event) void OnEndResize(wxHeaderCtrlEvent& event)
@@ -281,6 +302,9 @@ private:
wxVector<wxGridHeaderColumn> m_columns; wxVector<wxGridHeaderColumn> m_columns;
// The count of OnResizing() call nesting, 0 if not inside it.
int m_inResizing;
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
wxDECLARE_NO_COPY_CLASS(wxGridHeaderCtrl); wxDECLARE_NO_COPY_CLASS(wxGridHeaderCtrl);
}; };

View File

@@ -9765,7 +9765,16 @@ void wxGrid::DoSetColSize( int col, int width )
return; return;
if ( m_useNativeHeader ) if ( m_useNativeHeader )
GetGridColHeader()->UpdateColumn(col); {
// We have to update the native control if we're called from the
// program (directly or indirectly, e.g. via AutoSizeColumn()), but we
// want to avoid doing it when the column is being resized
// interactively, as this is unnecessary and results in very visible
// flicker, so take care to call the special method of our header
// control checking for whether it's being resized interactively
// instead of the usual UpdateColumn().
static_cast<wxGridHeaderCtrl*>(m_colLabelWin)->UpdateIfNotResizing(col);
}
//else: will be refreshed when the header is redrawn //else: will be refreshed when the header is redrawn
for ( int colPos = GetColPos(col); colPos < m_numCols; colPos++ ) for ( int colPos = GetColPos(col); colPos < m_numCols; colPos++ )