EVT_MENU(TreeTest_Quit, MyFrame::OnQuit)
EVT_MENU(TreeTest_About, MyFrame::OnAbout)
EVT_MENU(TreeTest_Dump, MyFrame::OnDump)
+ EVT_MENU(TreeTest_Delete, MyFrame::OnDelete)
+ EVT_MENU(TreeTest_DeleteAll, MyFrame::OnDeleteAll)
+ EVT_MENU(TreeTest_Recreate, MyFrame::OnRecreate)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl)
// Make a menubar
wxMenu *file_menu = new wxMenu;
- file_menu->Append(TreeTest_Dump, "&Dump tree items");
+ file_menu->Append(TreeTest_Dump, "D&ump tree items");
+ file_menu->Append(TreeTest_Delete, "&Delete this item");
+ file_menu->Append(TreeTest_DeleteAll, "Delete &all items");
+ file_menu->Append(TreeTest_Recreate, "&Recreate the tree");
file_menu->AppendSeparator();
file_menu->Append(TreeTest_About, "&About...");
file_menu->AppendSeparator();
void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
{
- wxTreeItemId root=m_treeCtrl->GetSelection();
+ wxTreeItemId root = m_treeCtrl->GetSelection();
m_treeCtrl->GetItemsRecursively(root, -1);
}
+void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetSelection();
+ m_treeCtrl->Delete(item);
+}
+
+void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->DeleteAllItems();
+}
+
+void MyFrame::OnRecreate(wxCommandEvent& event)
+{
+ OnDeleteAll(event);
+ m_treeCtrl->AddTestItemsToTree(3, 2);
+}
+
// MyTreeCtrl implementation
MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
const wxPoint& pos, const wxSize& size,
void OnSelChanging(wxTreeEvent& event);
void OnKeyDown(wxTreeEvent& event);
- void GetItemsRecursively(const wxTreeItemId& idParent, long cookie);
+ void GetItemsRecursively(const wxTreeItemId& idParent, long cookie);
+
+ void AddTestItemsToTree(size_t numChildren,
+ size_t depth);
private:
void AddItemsRecursively(const wxTreeItemId& idParent,
size_t nChildren,
size_t depth,
- size_t folder);
-
- void AddTestItemsToTree(size_t numChildren,
- size_t depth);
+ size_t folder);
wxImageList *m_imageListNormal;
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnDump(wxCommandEvent& event);
+ void OnDelete(wxCommandEvent& event);
+ void OnDeleteAll(wxCommandEvent& event);
+ void OnRecreate(wxCommandEvent& event);
private:
MyTreeCtrl *m_treeCtrl;
TreeTest_Quit,
TreeTest_About,
TreeTest_Dump,
+ TreeTest_Delete,
+ TreeTest_DeleteAll,
+ TreeTest_Recreate,
TreeTest_Ctrl = 100
};