From 999723f31a8e89e3d61e2d141e16229f1fb33baa Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 9 Apr 2002 22:43:14 +0000 Subject: [PATCH] don't allow expanding/collapsing hidden root node git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15063 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/treectlg.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index ce148cd301..562d1a840e 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -1212,7 +1212,8 @@ wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text, // if root is hidden, make sure we can navigate // into children m_anchor->SetHasPlus(); - Expand(m_anchor); + m_anchor->Expand(); + CalculatePositions(); } if (!HasFlag(wxTR_MULTIPLE)) @@ -1356,6 +1357,8 @@ void wxGenericTreeCtrl::Expand(const wxTreeItemId& itemId) wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem; wxCHECK_RET( item, _T("invalid item in wxGenericTreeCtrl::Expand") ); + wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT) || itemId != GetRootItem(), + _T("can't expand hidden root") ); if ( !item->HasPlus() ) return; @@ -1400,6 +1403,9 @@ void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId& item) void wxGenericTreeCtrl::Collapse(const wxTreeItemId& itemId) { + wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT) || itemId != GetRootItem(), + _T("can't collapse hidden root") ); + wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem; if ( !item->IsExpanded() ) @@ -1680,10 +1686,22 @@ void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId& item) // first expand all parent branches wxGenericTreeItem *parent = gitem->GetParent(); - while ( parent ) + + if ( HasFlag(wxTR_HIDE_ROOT) ) { - Expand(parent); - parent = parent->GetParent(); + while ( parent != m_anchor ) + { + Expand(parent); + parent = parent->GetParent(); + } + } + else + { + while ( parent ) + { + Expand(parent); + parent = parent->GetParent(); + } } //if (parent) CalculatePositions(); -- 2.47.2