X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/16f32ee7652c15bdbe46a85cdc0ecf036bd4003e..bd2e08d06528b2014a4acf878e91fee4696d0666:/src/common/treebase.cpp diff --git a/src/common/treebase.cpp b/src/common/treebase.cpp index 08220fa503..4bd01ace53 100644 --- a/src/common/treebase.cpp +++ b/src/common/treebase.cpp @@ -183,14 +183,20 @@ wxSize wxTreeCtrlBase::DoGetBestSize() const void wxTreeCtrlBase::ExpandAll() { + if ( IsEmpty() ) + return; + ExpandAllChildren(GetRootItem()); } void wxTreeCtrlBase::ExpandAllChildren(const wxTreeItemId& item) { + Freeze(); // expand this item first, this might result in its children being added on // the fly - Expand(item); + if ( item != GetRootItem() || !HasFlag(wxTR_HIDE_ROOT) ) + Expand(item); + //else: expanding hidden root item is unsupported and unnecessary // then (recursively) expand all the children wxTreeItemIdValue cookie; @@ -200,6 +206,37 @@ void wxTreeCtrlBase::ExpandAllChildren(const wxTreeItemId& item) { ExpandAllChildren(idCurr); } + Thaw(); +} + +void wxTreeCtrlBase::CollapseAll() +{ + if ( IsEmpty() ) + return; + + CollapseAllChildren(GetRootItem()); +} + +void wxTreeCtrlBase::CollapseAllChildren(const wxTreeItemId& item) +{ + Freeze(); + // first (recursively) collapse all the children + wxTreeItemIdValue cookie; + for ( wxTreeItemId idCurr = GetFirstChild(item, cookie); + idCurr.IsOk(); + idCurr = GetNextChild(item, cookie) ) + { + CollapseAllChildren(idCurr); + } + + // then collapse this element too + Collapse(item); + Thaw(); +} + +bool wxTreeCtrlBase::IsEmpty() const +{ + return !GetRootItem().IsOk(); } #endif // wxUSE_TREECTRL