]> git.saurik.com Git - wxWidgets.git/commitdiff
all delete functions now send delete notification event
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 17 Dec 1998 19:26:16 +0000 (19:26 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 17 Dec 1998 19:26:16 +0000 (19:26 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1225 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/treectrl.h
src/generic/treectrl.cpp

index 44b152b9703eb3db27284d65599437ff24114830..6903436ec3165ba659cfd248c252c8f58bf43250 100644 (file)
@@ -423,6 +423,7 @@ public:
     void SortChildren(const wxTreeItemId& item,
                       wxTreeItemCmpFunc *cmpFunction = NULL);
 
+    // callbacks
     void OnPaint( wxPaintEvent &event );
     void OnSetFocus( wxFocusEvent &event );
     void OnKillFocus( wxFocusEvent &event );
@@ -430,6 +431,9 @@ public:
     void OnMouse( wxMouseEvent &event );
     void OnIdle( wxIdleEvent &event );
 
+    // implementation
+    void SendDeleteEvent(wxGenericTreeItem *itemBeingDeleted);
+
 protected:
     wxGenericTreeItem   *m_anchor;
     wxGenericTreeItem   *m_current;
index fb50c25a1768cfbbaf559dd0a0b6d51994091ff0..7231ed7c68acbf6cf6452b9f4b9a2530f31d5b08 100644 (file)
@@ -81,7 +81,10 @@ public:
   wxGenericTreeItem *GetParent() const { return m_parent; }
 
   // operations
-  void DeleteChildren();
+    // deletes all children notifying the treectrl about it if !NULL pointer
+    // given
+  void DeleteChildren(wxTreeCtrl *tree = NULL);
+    // FIXME don't know what is it for
   void Reset();
 
   // get count of all children (and grand children if 'recursively')
@@ -183,14 +186,24 @@ wxGenericTreeItem::~wxGenericTreeItem()
 {
   delete m_data;
 
-  DeleteChildren();
+  wxASSERT_MSG( m_children.IsEmpty(),
+                "please call DeleteChildren() before deleting the item" );
 }
 
-void wxGenericTreeItem::DeleteChildren()
+void wxGenericTreeItem::DeleteChildren(wxTreeCtrl *tree)
 {
   size_t count = m_children.Count();
   for ( size_t n = 0; n < count; n++ )
-    delete m_children[n];
+  {
+    wxGenericTreeItem *child = m_children[n];
+    if ( tree )
+    {
+      tree->SendDeleteEvent(child);
+    }
+
+    child->DeleteChildren(tree);
+    delete child;
+  }
 
   m_children.Empty();
 }
@@ -356,7 +369,8 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id,
 wxTreeCtrl::~wxTreeCtrl()
 {
   wxDELETE( m_hilightBrush );
-  wxDELETE( m_anchor );
+
+  DeleteAllItems();
 }
 
 // -----------------------------------------------------------------------------
@@ -698,10 +712,18 @@ wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parentId,
                       image, selImage, data);
 }
 
+void wxTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
+{
+  wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, GetId() );
+  event.m_item = item;
+  event.SetEventObject( this );
+  ProcessEvent( event );
+}
+
 void wxTreeCtrl::DeleteChildren(const wxTreeItemId& itemId)
 {
     wxGenericTreeItem *item = itemId.m_pItem;
-    item->DeleteChildren();
+    item->DeleteChildren(this);
 
     m_dirty = TRUE;
 }
@@ -711,17 +733,13 @@ void wxTreeCtrl::Delete(const wxTreeItemId& itemId)
   wxGenericTreeItem *item = itemId.m_pItem;
   wxGenericTreeItem *parent = item->GetParent();
 
-  // notify the parent...
-  wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, GetId() );
-  event.m_item = item;
-  event.SetEventObject( this );
-  ProcessEvent( event );
-
   if ( parent )
   {
     parent->GetChildren().Remove(item);
   }
 
+  item->DeleteChildren(this);
+  SendDeleteEvent(item);
   delete item;
 
   m_dirty = TRUE;
@@ -731,7 +749,9 @@ void wxTreeCtrl::DeleteAllItems()
 {
   if ( m_anchor )
   {
+    m_anchor->DeleteChildren(this);
     delete m_anchor;
+
     m_anchor = NULL;
 
     m_dirty = TRUE;