git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16714
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
unselect_others = !(extended_select || (ctrlDown && is_multiple));
}
unselect_others = !(extended_select || (ctrlDown && is_multiple));
}
+// check if the given item is under another one
+static bool IsDescendantOf(wxGenericTreeItem *parent, wxGenericTreeItem *item)
+{
+ while ( item )
+ {
+ if ( item == parent )
+ {
+ // item is a descendant of parent
+ return TRUE;
+ }
+
+ item = item->GetParent();
+ }
+
+ return FALSE;
+}
+
// -----------------------------------------------------------------------------
// wxTreeRenameTimer (internal)
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// wxTreeRenameTimer (internal)
// -----------------------------------------------------------------------------
wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem;
wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem;
- // don't stay with invalid m_key_current or we will crash in
- // the next call to OnChar()
- bool changeKeyCurrent = FALSE;
- wxGenericTreeItem *itemKey = m_key_current;
- while ( itemKey )
+ wxGenericTreeItem *parent = item->GetParent();
+
+ // don't keep stale pointers around!
+ if ( IsDescendantOf(item, m_key_current) )
- if ( itemKey == item )
- {
- // m_key_current is a descendant of the item being deleted
- changeKeyCurrent = TRUE;
- break;
- }
- itemKey = itemKey->GetParent();
+ m_key_current = parent;
- wxGenericTreeItem *parent = item->GetParent();
+ if ( IsDescendantOf(item, m_current) )
+ {
+ m_current = parent;
+ }
+
+ // remove the item from the tree
if ( parent )
{
parent->GetChildren().Remove( item ); // remove by value
}
if ( parent )
{
parent->GetChildren().Remove( item ); // remove by value
}
-
- if ( changeKeyCurrent )
+ else // deleting the root
- // may be NULL or not
- m_key_current = parent;
+ // nothing will be left in the tree
+ m_anchor = NULL;
+ // and delete all of its children and the item itself now
item->DeleteChildren(this);
SendDeleteEvent(item);
delete item;
item->DeleteChildren(this);
SendDeleteEvent(item);
delete item;
- m_dirty = TRUE;
-
- m_anchor->DeleteChildren(this);
- delete m_anchor;
-
- m_anchor = NULL;