diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 5a18e39a9a..6a8c9c228e 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -431,7 +431,7 @@ void MyFrame::OnIdle(wxIdleEvent& event) wxString status; if (idRoot.IsOk()) { - wxTreeItemId idLast = m_treeCtrl->GetLastChild(idRoot); + wxTreeItemId idLast = m_treeCtrl->GetLastTreeITem(); status = wxString::Format( wxT("Root/last item is %svisible/%svisible"), m_treeCtrl->IsVisible(idRoot) ? wxT("") : wxT("not "), @@ -759,7 +759,7 @@ void MyFrame::OnCollapseAndReset(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnEnsureVisible(wxCommandEvent& WXUNUSED(event)) { const wxTreeItemId - idLast = m_treeCtrl->GetLastChild(m_treeCtrl->GetRootItem()); + idLast = m_treeCtrl->GetLastTreeITem(); if ( idLast.IsOk() ) m_treeCtrl->EnsureVisible(idLast); else @@ -907,16 +907,7 @@ void MyFrame::OnScrollTo(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSelectLast(wxCommandEvent& WXUNUSED(event)) { - // select the very last item of the tree - wxTreeItemId item = m_treeCtrl->GetRootItem(); - for ( ;; ) - { - wxTreeItemId itemChild = m_treeCtrl->GetLastChild(item); - if ( !itemChild.IsOk() ) - break; - - item = itemChild; - } + wxTreeItemId item = m_treeCtrl->GetLastTreeITem(); CHECK_ITEM( item ); @@ -1210,6 +1201,21 @@ void MyTreeCtrl::AddTestItemsToTree(size_t numChildren, } } +wxTreeItemId MyTreeCtrl::GetLastTreeITem() const +{ + wxTreeItemId item = GetRootItem(); + for ( ;; ) + { + wxTreeItemId itemChild = GetLastChild(item); + if ( !itemChild.IsOk() ) + break; + + item = itemChild; + } + + return item; +} + void MyTreeCtrl::GetItemsRecursively(const wxTreeItemId& idParent, wxTreeItemIdValue cookie) { diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 325a82c54a..61fac9dacf 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -94,6 +94,7 @@ public: void OnRMouseUp(wxMouseEvent& event); void OnRMouseDClick(wxMouseEvent& event); + wxTreeItemId GetLastTreeITem() const; void GetItemsRecursively(const wxTreeItemId& idParent, wxTreeItemIdValue cookie = 0); @@ -137,6 +138,7 @@ protected: } private: + // Find the very last item in the tree. void AddItemsRecursively(const wxTreeItemId& idParent, size_t nChildren, size_t depth,