]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/treectrl/treetest.cpp
Fix strings formatting in wxrc.
[wxWidgets.git] / samples / treectrl / treetest.cpp
index 0da06d9ea11f13d7a66b977a9d4e329ca30c3316..70c37f8dd40f121f3d20308d5255c8a1763c0f8f 100644 (file)
@@ -129,6 +129,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     MENU_LINK(ToggleIcon)
     MENU_LINK(ToggleState)
     MENU_LINK(SelectRoot)
+    MENU_LINK(SetFocusedRoot)
+    MENU_LINK(ClearFocused)
 
     MENU_LINK(ShowFirstVisible)
 #ifdef wxHAS_LAST_VISIBLE
@@ -140,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()
@@ -263,6 +266,9 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
     tree_menu->Append(TreeTest_DeleteChildren, wxT("Delete &children"));
     tree_menu->Append(TreeTest_DeleteAll, wxT("Delete &all items"));
     tree_menu->Append(TreeTest_SelectRoot, wxT("Select root item"));
+    tree_menu->AppendSeparator();
+    tree_menu->Append(TreeTest_SetFocusedRoot, wxT("Set focus to root item"));
+    tree_menu->Append(TreeTest_ClearFocused, wxT("Reset focus"));
 
     tree_menu->AppendSeparator();
     tree_menu->Append(TreeTest_Count, wxT("Count children of current item"));
@@ -303,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();
@@ -592,6 +600,17 @@ void MyFrame::OnSelectRoot(wxCommandEvent& WXUNUSED(event))
         m_treeCtrl->SelectItem(m_treeCtrl->GetRootItem());
 }
 
+void MyFrame::OnSetFocusedRoot(wxCommandEvent& WXUNUSED(event))
+{
+    if ( !m_treeCtrl->HasFlag(wxTR_HIDE_ROOT) )
+        m_treeCtrl->SetFocusedItem(m_treeCtrl->GetRootItem());
+}
+
+void MyFrame::OnClearFocused(wxCommandEvent& WXUNUSED(event))
+{
+    m_treeCtrl->ClearFocusedItem();
+}
+
 void MyFrame::OnUnselect(wxCommandEvent& WXUNUSED(event))
 {
     m_treeCtrl->UnselectAll();
@@ -862,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());