]> git.saurik.com Git - wxWidgets.git/commitdiff
wxTreeCtrl::Delete() bug corrected, sample expanded to test it
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Nov 1998 19:10:01 +0000 (19:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Nov 1998 19:10:01 +0000 (19:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1068 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/treectrl/treetest.cpp
samples/treectrl/treetest.h
src/generic/treectrl.cpp

index 068853eac05f2a74607cd5ac14b63f3de1e93a85..5085521447ce1a8c12bedcfb837ba8511a35fc38 100644 (file)
@@ -43,6 +43,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
   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)
@@ -93,7 +96,10 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
   // 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();
@@ -157,10 +163,27 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 
 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,
index 68a4583b0af3363f77c86b1334d788369bbe2c38..7d125f59822a0bfb9a74db779dab8f42fd776e82 100644 (file)
@@ -56,16 +56,16 @@ public:
   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;
 
@@ -84,6 +84,9 @@ public:
   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;
@@ -97,6 +100,9 @@ enum
   TreeTest_Quit,
   TreeTest_About,
   TreeTest_Dump,
+  TreeTest_Delete,
+  TreeTest_DeleteAll,
+  TreeTest_Recreate,
   TreeTest_Ctrl = 100
 };
 
index c214bbe26af1f6e4d1282923baded168fd83ec09..e6f33a02596a3fda2903f8e76c907b5221d5f9d8 100644 (file)
@@ -51,7 +51,7 @@ public:
                      int image, int selImage,
                      wxTreeItemData *data );
 
-  inline ~wxGenericTreeItem();
+  ~wxGenericTreeItem();
 
   // trivial accessors
   wxArrayTreeItems& GetChildren() { return m_children; }
@@ -688,6 +688,12 @@ wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parentId,
 void wxTreeCtrl::Delete(const wxTreeItemId& itemId)
 {
   wxGenericTreeItem *item = itemId.m_pItem;
+  wxGenericTreeItem *parent = item->GetParent();
+
+  if ( parent )
+  {
+    parent->GetChildren().Remove(item);
+  }
 
   delete item;