From a9be974d5bbb4f98cd3ce7a8e9797e5adb370469 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Mar 2016 19:51:06 +0100 Subject: [PATCH] Avoid unnecessarily refreshing last column in generic wxDataViewCtrl UpdateColumnSizes() was called whenever the control was modified in any way since 4156e1a5c94283cb037132518dfb80dbc1403e12 and it refreshed the entire last column even if absolutely nothing changed. Don't do this unless the last column width has really changed. --- include/wx/generic/dataview.h | 21 ++++++++++++++++----- src/generic/datavgen.cpp | 6 +++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 27bdf1dc90..fee9e14020 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -64,11 +64,10 @@ public: virtual void SetWidth(int width) wxOVERRIDE { - if ( width != m_width ) - { - m_width = width; - UpdateDisplay(); - } + // As a small optimization, use this method to avoid calling + // UpdateDisplay() if the width didn't really change, even if we don't + // care about its return value. + (void)WXUpdateWidth(width); } virtual int GetWidth() const wxOVERRIDE; @@ -122,6 +121,18 @@ public: UpdateDisplay(); } + // This method is specific to the generic implementation and is used only + // by wxWidgets itself. + bool WXUpdateWidth(int width) + { + if ( width == m_width ) + return false; + + m_width = width; + UpdateDisplay(); + + return true; + } private: // common part of all ctors diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 706efcb90f..3192e483e4 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -4577,7 +4577,11 @@ void wxDataViewMainWindow::UpdateColumnSizes() if ( lastColX < fullWinWidth ) { int desiredWidth = wxMax(fullWinWidth - lastColX, lastCol->GetMinWidth()); - lastCol->SetWidth(desiredWidth); + if ( !lastCol->WXUpdateWidth(desiredWidth) ) + { + // The column width didn't change, no need to do anything else. + return; + } // All columns fit on screen, so we don't need horizontal scrolling. // To prevent flickering scrollbar when resizing the window to be