From 0c5a056a84a18861acab62ea97a4b1414ce2f4a5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 10 Mar 2013 01:09:41 +0000 Subject: [PATCH] Disable sorting of generic wxDataViewCtrl while it is frozen. Don't sort the contents of wxDataViewCtrl while it is frozen and resort it only when it is thawed. This dramatically speeds up adding items to the control when sorting is used as we only sort it once now instead of doing it after adding every item. Closes #14073. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73635 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/datavgen.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 94ff9da24e..def4fb5877 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -85,6 +85,9 @@ static wxDataViewModel* g_model; // of the special values in this enum: enum { + // Sort when we're thawed later. + SortColumn_OnThaw = -3, + // Don't sort at all. SortColumn_None = -2, @@ -593,9 +596,32 @@ public: UpdateDisplay(); } + // Override the base class method to resort if needed, i.e. if + // SortPrepare() was called -- and ignored -- while we were frozen. + virtual void DoThaw() + { + if ( g_column == SortColumn_OnThaw ) + { + Resort(); + g_column = SortColumn_None; + } + + wxWindow::DoThaw(); + } + void SortPrepare() { g_model = GetModel(); + + // Avoid sorting while the window is frozen, this allows to quickly add + // many items without resorting after each addition and only resort + // them all at once when the window is finally thawed, see above. + if ( IsFrozen() ) + { + g_column = SortColumn_OnThaw; + return; + } + wxDataViewColumn* col = GetOwner()->GetSortingColumn(); if( !col ) {