From b01d1a5e97748f4d797abe06be0a3bcba8562829 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Feb 2014 17:26:54 +0000 Subject: [PATCH] Add a helper function to get the last tree item to the sample. This makes the behaviour of different menu commands working with the "last item" consistent as some of them used the last root child while others used the really last item (i.e. the last child of the last child). This should have been part of r75987. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76013 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/treectrl/treetest.cpp | 30 ++++++++++++++++++------------ samples/treectrl/treetest.h | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) 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,