Applied patch to stop crashing the tree control

when deleting a selected item. Also does something
   to the inplace edit control.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30751 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2004-11-24 15:03:28 +00:00
parent ad68ed32f7
commit 0cf3b5429a
2 changed files with 29 additions and 15 deletions

View File

@ -503,6 +503,7 @@ protected:
bool TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select); bool TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select);
bool TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select); bool TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select);
void UnselectAllChildren( wxGenericTreeItem *item ); void UnselectAllChildren( wxGenericTreeItem *item );
void ChildrenClosing(wxGenericTreeItem* item);
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()

View File

@ -88,25 +88,18 @@ class WXDLLEXPORT wxTreeTextCtrl: public wxTextCtrl
public: public:
wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item); wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item);
// wxGenericTreeCtrl can use this one to abandon editing the given item, void StopEditing()
// it's not an error to call it if this item is not being edited
void StopEditing(wxGenericTreeItem *item)
{ {
if ( item == m_itemEdited ) Finish();
DoStopEditing(); m_owner->OnRenameCancelled(m_itemEdited);
} }
const wxGenericTreeItem* item() const { return m_itemEdited; }
protected: protected:
void OnChar( wxKeyEvent &event ); void OnChar( wxKeyEvent &event );
void OnKeyUp( wxKeyEvent &event ); void OnKeyUp( wxKeyEvent &event );
void OnKillFocus( wxFocusEvent &event ); void OnKillFocus( wxFocusEvent &event );
void DoStopEditing()
{
Finish();
m_owner->OnRenameCancelled(m_itemEdited);
}
bool AcceptChanges(); bool AcceptChanges();
void Finish(); void Finish();
@ -302,7 +295,7 @@ static void EventFlagsToSelType(long style,
} }
// check if the given item is under another one // check if the given item is under another one
static bool IsDescendantOf(wxGenericTreeItem *parent, wxGenericTreeItem *item) static bool IsDescendantOf(const wxGenericTreeItem *parent, const wxGenericTreeItem *item)
{ {
while ( item ) while ( item )
{ {
@ -440,7 +433,7 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
break; break;
case WXK_ESCAPE: case WXK_ESCAPE:
DoStopEditing(); StopEditing();
break; break;
default: default:
@ -1505,11 +1498,30 @@ void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
ProcessEvent( event ); ProcessEvent( event );
} }
// Don't leave edit or selection on a child which is about to disappear
void wxGenericTreeCtrl::ChildrenClosing(wxGenericTreeItem* item)
{
if (m_textCtrl != NULL && item != m_textCtrl->item() && IsDescendantOf(item, m_textCtrl->item())) {
m_textCtrl->StopEditing();
}
if (item != m_key_current && IsDescendantOf(item, m_key_current)) {
m_key_current = NULL;
}
if (IsDescendantOf(item, m_select_me)) {
m_select_me = item;
}
if (item != m_current && IsDescendantOf(item, m_current)) {
m_current = NULL;
m_select_me = item;
}
}
void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId& itemId) void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId& itemId)
{ {
m_dirty = true; // do this first so stuff below doesn't cause flicker m_dirty = true; // do this first so stuff below doesn't cause flicker
wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem; wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem;
ChildrenClosing(item);
item->DeleteChildren(this); item->DeleteChildren(this);
} }
@ -1519,10 +1531,10 @@ void wxGenericTreeCtrl::Delete(const wxTreeItemId& itemId)
wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem; wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem;
if ( m_textCtrl ) if (m_textCtrl != NULL && IsDescendantOf(item, m_textCtrl->item()))
{ {
// can't delete the item being edited, cancel editing it first // can't delete the item being edited, cancel editing it first
m_textCtrl->StopEditing(item); m_textCtrl->StopEditing();
} }
wxGenericTreeItem *parent = item->GetParent(); wxGenericTreeItem *parent = item->GetParent();
@ -1656,6 +1668,7 @@ void wxGenericTreeCtrl::Collapse(const wxTreeItemId& itemId)
return; return;
} }
ChildrenClosing(item);
item->Collapse(); item->Collapse();
#if 0 // TODO why should items be collapsed recursively? #if 0 // TODO why should items be collapsed recursively?