From 624f89c2d7efce8d5370fe1871dcd0744dca2270 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Oct 2007 14:55:50 +0000 Subject: [PATCH] don't update the tree unnecessarily in Expand/CollapseAllChildren() (patch 1809520) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49262 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/common/treebase.cpp | 4 ++++ src/generic/treectlg.cpp | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 74998a35ca..a5ce357535 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -205,6 +205,7 @@ All (GUI): behaviour of GetNextSibling() consistent between wxMSW and generic versions. - Merged wxRichTextAttr and wxTextAttrEx into wxTextAttr, and added a font table to wxRichTextBuffer to reduce wxFont consumption and increase performance. +- Optimize wxGenericTreeCtrl::Collapse/ExpandAllChildren() (Szczepan Holyszewski) wxGTK: diff --git a/src/common/treebase.cpp b/src/common/treebase.cpp index eb37c0dbdb..4bd01ace53 100644 --- a/src/common/treebase.cpp +++ b/src/common/treebase.cpp @@ -191,6 +191,7 @@ void wxTreeCtrlBase::ExpandAll() void wxTreeCtrlBase::ExpandAllChildren(const wxTreeItemId& item) { + Freeze(); // expand this item first, this might result in its children being added on // the fly if ( item != GetRootItem() || !HasFlag(wxTR_HIDE_ROOT) ) @@ -205,6 +206,7 @@ void wxTreeCtrlBase::ExpandAllChildren(const wxTreeItemId& item) { ExpandAllChildren(idCurr); } + Thaw(); } void wxTreeCtrlBase::CollapseAll() @@ -217,6 +219,7 @@ void wxTreeCtrlBase::CollapseAll() void wxTreeCtrlBase::CollapseAllChildren(const wxTreeItemId& item) { + Freeze(); // first (recursively) collapse all the children wxTreeItemIdValue cookie; for ( wxTreeItemId idCurr = GetFirstChild(item, cookie); @@ -228,6 +231,7 @@ void wxTreeCtrlBase::CollapseAllChildren(const wxTreeItemId& item) // then collapse this element too Collapse(item); + Thaw(); } bool wxTreeCtrlBase::IsEmpty() const diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 87a01089a1..d30b80d4f0 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -1646,9 +1646,16 @@ void wxGenericTreeCtrl::Expand(const wxTreeItemId& itemId) } item->Expand(); - CalculatePositions(); + if ( !m_freezeCount ) + { + CalculatePositions(); - RefreshSubtree(item); + RefreshSubtree(item); + } + else // frozen + { + m_dirty = true; + } event.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED); GetEventHandler()->ProcessEvent( event ); @@ -3582,7 +3589,10 @@ void wxGenericTreeCtrl::Thaw() if ( --m_freezeCount == 0 ) { - Refresh(); + if ( m_dirty ) + DoDirtyProcessing(); + else + Refresh(); } } -- 2.47.2