]> git.saurik.com Git - wxWidgets.git/commitdiff
test showing parent/sibling items too (#9903)
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 3 Sep 2008 20:16:56 +0000 (20:16 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 3 Sep 2008 20:16:56 +0000 (20:16 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55445 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/treectrl/treetest.cpp
samples/treectrl/treetest.h

index b3ba5a751ddd5b190476062a2fe1ab88b0a8d341..a6c3435ade908086f264cacfa836dacbee60fe5b 100644 (file)
@@ -128,6 +128,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 #endif // wxHAS_LAST_VISIBLE
     MENU_LINK(ShowNextVisible)
     MENU_LINK(ShowPrevVisible)
 #endif // wxHAS_LAST_VISIBLE
     MENU_LINK(ShowNextVisible)
     MENU_LINK(ShowPrevVisible)
+    MENU_LINK(ShowParent)
+    MENU_LINK(ShowPrevSibling)
+    MENU_LINK(ShowNextSibling)
 #undef MENU_LINK
 
 END_EVENT_TABLE()
 #undef MENU_LINK
 
 END_EVENT_TABLE()
@@ -282,6 +285,10 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
 #endif // wxHAS_LAST_VISIBLE
     item_menu->Append(TreeTest_ShowNextVisible, wxT("Show &next visible"));
     item_menu->Append(TreeTest_ShowPrevVisible, wxT("Show &previous visible"));
 #endif // wxHAS_LAST_VISIBLE
     item_menu->Append(TreeTest_ShowNextVisible, wxT("Show &next visible"));
     item_menu->Append(TreeTest_ShowPrevVisible, wxT("Show &previous visible"));
+    item_menu->AppendSeparator();
+    item_menu->Append(TreeTest_ShowParent, "Show pa&rent");
+    item_menu->Append(TreeTest_ShowPrevSibling, "Show &previous sibling");
+    item_menu->Append(TreeTest_ShowNextSibling, "Show &next sibling");
 
 #ifndef NO_MULTIPLE_SELECTION
     item_menu->AppendSeparator();
 
 #ifndef NO_MULTIPLE_SELECTION
     item_menu->AppendSeparator();
@@ -773,25 +780,27 @@ void MyFrame::DoShowFirstOrLast(TreeFunc0_t pfn, const wxString& label)
                      label, m_treeCtrl->GetItemText(item));
 }
 
                      label, m_treeCtrl->GetItemText(item));
 }
 
-void MyFrame::DoShowNextOrPrev(TreeFunc1_t pfn, const wxString& label)
+void MyFrame::DoShowRelativeItem(TreeFunc1_t pfn, const wxString& label)
 {
     wxTreeItemId item = m_treeCtrl->GetSelection();
 
     CHECK_ITEM( item );
 
 {
     wxTreeItemId item = m_treeCtrl->GetSelection();
 
     CHECK_ITEM( item );
 
-    if ( !m_treeCtrl->IsVisible(item) )
+    if ((pfn == (TreeFunc1_t) &wxTreeCtrl::GetPrevVisible
+         || pfn == (TreeFunc1_t) &wxTreeCtrl::GetNextVisible)
+        && !m_treeCtrl->IsVisible(item))
     {
         wxLogMessage("The selected item must be visible.");
         return;
     }
 
     {
         wxLogMessage("The selected item must be visible.");
         return;
     }
 
-    item = (m_treeCtrl->*pfn)(item);
+    wxTreeItemId new_item = (m_treeCtrl->*pfn)(item);
 
 
-    if ( !item.IsOk() )
+    if ( !new_item.IsOk() )
         wxLogMessage("There is no %s item", label);
     else
         wxLogMessage("The %s item is \"%s\"",
         wxLogMessage("There is no %s item", label);
     else
         wxLogMessage("The %s item is \"%s\"",
-                     label, m_treeCtrl->GetItemText(item));
+                     label, m_treeCtrl->GetItemText(new_item));
 }
 
 void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
 }
 
 void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
index e2908c0c449c60e0ec6f2da6b79aa67213871f4b..5b93a8113290e4ce11591c1aabe579e4eae9214c 100644 (file)
@@ -246,9 +246,16 @@ public:
 #endif // wxHAS_LAST_VISIBLE
 
     void OnShowNextVisible(wxCommandEvent& WXUNUSED(event))
 #endif // wxHAS_LAST_VISIBLE
 
     void OnShowNextVisible(wxCommandEvent& WXUNUSED(event))
-        { DoShowNextOrPrev(&wxTreeCtrl::GetNextVisible, "next visible"); }
+        { DoShowRelativeItem(&wxTreeCtrl::GetNextVisible, "next visible"); }
     void OnShowPrevVisible(wxCommandEvent& WXUNUSED(event))
     void OnShowPrevVisible(wxCommandEvent& WXUNUSED(event))
-        { DoShowNextOrPrev(&wxTreeCtrl::GetPrevVisible, "previous visible"); }
+        { DoShowRelativeItem(&wxTreeCtrl::GetPrevVisible, "previous visible"); }
+
+    void OnShowParent(wxCommandEvent& WXUNUSED(event))
+        { DoShowRelativeItem(&wxTreeCtrl::GetItemParent, "parent"); }
+    void OnShowPrevSibling(wxCommandEvent& WXUNUSED(event))
+        { DoShowRelativeItem(&wxTreeCtrl::GetPrevSibling, "previous sibling"); }
+    void OnShowNextSibling(wxCommandEvent& WXUNUSED(event))
+        { DoShowRelativeItem(&wxTreeCtrl::GetNextSibling, "next sibling"); }
 
     void OnIdle(wxIdleEvent& event);
     void OnSize(wxSizeEvent& event);
 
     void OnIdle(wxIdleEvent& event);
     void OnSize(wxSizeEvent& event);
@@ -268,7 +275,7 @@ private:
     void DoShowFirstOrLast(TreeFunc0_t pfn, const wxString& label);
 
     typedef wxTreeItemId (wxTreeCtrl::*TreeFunc1_t)(const wxTreeItemId&) const;
     void DoShowFirstOrLast(TreeFunc0_t pfn, const wxString& label);
 
     typedef wxTreeItemId (wxTreeCtrl::*TreeFunc1_t)(const wxTreeItemId&) const;
-    void DoShowNextOrPrev(TreeFunc1_t pfn, const wxString& label);
+    void DoShowRelativeItem(TreeFunc1_t pfn, const wxString& label);
 
 
     wxPanel *m_panel;
 
 
     wxPanel *m_panel;
@@ -337,5 +344,8 @@ enum
     TreeTest_ShowLastVisible,
     TreeTest_ShowNextVisible,
     TreeTest_ShowPrevVisible,
     TreeTest_ShowLastVisible,
     TreeTest_ShowNextVisible,
     TreeTest_ShowPrevVisible,
+    TreeTest_ShowParent,
+    TreeTest_ShowPrevSibling,
+    TreeTest_ShowNextSibling,
     TreeTest_Ctrl = 1000
 };
     TreeTest_Ctrl = 1000
 };