fixed crash in OnChar() after m_key_current was deleted
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6698 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
624d1a4f31
commit
aaa2f29761
@ -1072,13 +1072,36 @@ void wxTreeCtrl::DeleteChildren(const wxTreeItemId& itemId)
|
||||
void wxTreeCtrl::Delete(const wxTreeItemId& itemId)
|
||||
{
|
||||
wxGenericTreeItem *item = itemId.m_pItem;
|
||||
wxGenericTreeItem *parent = item->GetParent();
|
||||
|
||||
// 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 && !changeKeyCurrent )
|
||||
{
|
||||
if ( itemKey == item )
|
||||
{
|
||||
// m_key_current is a descendant of the item being deleted
|
||||
changeKeyCurrent = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemKey = itemKey->GetParent();
|
||||
}
|
||||
}
|
||||
|
||||
wxGenericTreeItem *parent = item->GetParent();
|
||||
if ( parent )
|
||||
{
|
||||
parent->GetChildren().Remove( item ); // remove by value
|
||||
}
|
||||
|
||||
if ( changeKeyCurrent )
|
||||
{
|
||||
// may be NULL or not
|
||||
m_key_current = parent;
|
||||
}
|
||||
|
||||
item->DeleteChildren(this);
|
||||
SendDeleteEvent(item);
|
||||
delete item;
|
||||
@ -1331,7 +1354,12 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId,
|
||||
// shift press
|
||||
if (extended_select)
|
||||
{
|
||||
if (m_current == NULL) m_current=m_key_current=GetRootItem().m_pItem;
|
||||
if ( !m_current )
|
||||
{
|
||||
m_current =
|
||||
m_key_current = GetRootItem().m_pItem;
|
||||
}
|
||||
|
||||
// don't change the mark (m_current)
|
||||
SelectItemRange(m_current, item);
|
||||
}
|
||||
@ -1951,7 +1979,6 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
|
||||
else
|
||||
{
|
||||
wxTreeItemId next = GetNextSibling( m_key_current );
|
||||
// if (next == 0)
|
||||
if (!next)
|
||||
{
|
||||
wxTreeItemId current = m_key_current;
|
||||
@ -1961,7 +1988,6 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
|
||||
if (current) next = GetNextSibling( current );
|
||||
}
|
||||
}
|
||||
// if (next != 0)
|
||||
if (next)
|
||||
{
|
||||
SelectItem( next, unselect_others, extended_select );
|
||||
|
Loading…
Reference in New Issue
Block a user