]> git.saurik.com Git - wxWidgets.git/commitdiff
don't allow expanding/collapsing hidden root node
authorVáclav Slavík <vslavik@fastmail.fm>
Tue, 9 Apr 2002 22:43:14 +0000 (22:43 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Tue, 9 Apr 2002 22:43:14 +0000 (22:43 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15063 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/treectlg.cpp

index ce148cd3012e029e15cb4d491a1a3697faa89450..562d1a840e32b76a79a8189dcc5730ef796a946b 100644 (file)
@@ -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();