From e95f081682e00b5250d5d6a1ce5618f3dc3931cd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Jun 2010 17:43:11 +0000 Subject: [PATCH] Add a test for selecting the last item in the tree control sample. This allows to test whether an item is brought into view by selecting it, see #11154. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64650 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/treectrl/treetest.cpp | 21 +++++++++++++++++++++ samples/treectrl/treetest.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 5ac4e9c5cb..70c37f8dd4 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -142,6 +142,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) MENU_LINK(ShowPrevSibling) MENU_LINK(ShowNextSibling) MENU_LINK(ScrollTo) + MENU_LINK(SelectLast) #undef MENU_LINK END_EVENT_TABLE() @@ -308,6 +309,8 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) item_menu->AppendSeparator(); item_menu->Append(TreeTest_ScrollTo, "Scroll &to item", "Scroll to the last by one top level child"); + item_menu->Append(TreeTest_SelectLast, "Select &last item", + "Select the last item"); #ifndef NO_MULTIPLE_SELECTION item_menu->AppendSeparator(); @@ -878,6 +881,24 @@ void MyFrame::OnScrollTo(wxCommandEvent& WXUNUSED(event)) m_treeCtrl->ScrollTo(item); } +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; + } + + CHECK_ITEM( item ); + + m_treeCtrl->SelectItem(item); +} + void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event)) { wxColour col = wxGetColourFromUser(this, m_treeCtrl->GetForegroundColour()); diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 645e0d0668..c105ad6fff 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -272,6 +272,7 @@ public: { DoShowRelativeItem(&wxTreeCtrl::GetNextSibling, "next sibling"); } void OnScrollTo(wxCommandEvent& event); + void OnSelectLast(wxCommandEvent& event); void OnIdle(wxIdleEvent& event); void OnSize(wxSizeEvent& event); @@ -368,5 +369,6 @@ enum TreeTest_ShowPrevSibling, TreeTest_ShowNextSibling, TreeTest_ScrollTo, + TreeTest_SelectLast, TreeTest_Ctrl = 1000 };