all delete functions now send delete notification event
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1225 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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;
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user