diff --git a/include/wx/generic/private/grid.h b/include/wx/generic/private/grid.h index 709cf0c167..8628824814 100644 --- a/include/wx/generic/private/grid.h +++ b/include/wx/generic/private/grid.h @@ -152,6 +152,14 @@ public: (owner->CanHideColumns() ? wxHD_ALLOW_HIDE : 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: @@ -259,7 +267,20 @@ private: 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()); + + m_inResizing--; } void OnEndResize(wxHeaderCtrlEvent& event) @@ -281,6 +302,9 @@ private: wxVector m_columns; + // The count of OnResizing() call nesting, 0 if not inside it. + int m_inResizing; + wxDECLARE_EVENT_TABLE(); wxDECLARE_NO_COPY_CLASS(wxGridHeaderCtrl); }; diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 50fc4c49e8..2cf6315d41 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -9765,7 +9765,16 @@ void wxGrid::DoSetColSize( int col, int width ) return; 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(m_colLabelWin)->UpdateIfNotResizing(col); + } //else: will be refreshed when the header is redrawn for ( int colPos = GetColPos(col); colPos < m_numCols; colPos++ )