Simplified code and applied [ 1867939 ] fixes for wxTreeCtrl crashes when exiting from label editing

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51149 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2008-01-10 14:35:30 +00:00
parent 82b6efd2c2
commit d0e2c75cfa

View File

@ -92,29 +92,8 @@ class WXDLLEXPORT wxTreeTextCtrl: public wxTextCtrl
public:
wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item);
void EndEdit(bool discardChanges = false)
{
if ( discardChanges )
{
StopEditing();
}
else
{
m_aboutToFinish = true;
// Notify the owner about the changes
AcceptChanges();
// Even if vetoed, close the control (consistent with MSW)
Finish();
}
}
void StopEditing()
{
Finish();
m_owner->OnRenameCancelled(m_itemEdited);
}
void EndEdit(bool discardChanges = false);
const wxGenericTreeItem* item() const { return m_itemEdited; }
protected:
@ -123,13 +102,12 @@ protected:
void OnKillFocus( wxFocusEvent &event );
bool AcceptChanges();
void Finish();
void Finish( bool setfocus = true );
private:
wxGenericTreeCtrl *m_owner;
wxGenericTreeItem *m_itemEdited;
wxString m_startValue;
bool m_finished;
bool m_aboutToFinish;
DECLARE_EVENT_TABLE()
@ -363,7 +341,6 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner,
: m_itemEdited(item), m_startValue(item->GetText())
{
m_owner = owner;
m_finished = false;
m_aboutToFinish = false;
int w = m_itemEdited->GetWidth(),
@ -407,6 +384,26 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner,
wxPoint(x - 4, y - 4), wxSize(w + 11, h + 8));
}
void wxTreeTextCtrl::EndEdit(bool discardChanges)
{
m_aboutToFinish = true;
if ( discardChanges )
{
m_owner->OnRenameCancelled(m_itemEdited);
Finish();
}
else
{
// Notify the owner about the changes
AcceptChanges();
// Even if vetoed, close the control (consistent with MSW)
Finish();
}
}
bool wxTreeTextCtrl::AcceptChanges()
{
const wxString value = GetValue();
@ -435,18 +432,14 @@ bool wxTreeTextCtrl::AcceptChanges()
return true;
}
void wxTreeTextCtrl::Finish()
void wxTreeTextCtrl::Finish( bool setfocus )
{
if ( !m_finished )
{
m_owner->ResetTextControl();
m_owner->ResetTextControl();
wxPendingDelete.Append(this);
m_finished = true;
wxPendingDelete.Append(this);
if (setfocus)
m_owner->SetFocus();
}
}
void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
@ -454,11 +447,11 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
switch ( event.m_keyCode )
{
case WXK_RETURN:
EndEdit();
EndEdit( false );
break;
case WXK_ESCAPE:
StopEditing();
EndEdit( true );
break;
default:
@ -468,7 +461,7 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event )
{
if ( !m_finished )
if ( !m_aboutToFinish )
{
// auto-grow the textctrl:
wxSize parentSize = m_owner->GetSize();
@ -488,18 +481,15 @@ void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event )
void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &event )
{
if ( !m_finished && !m_aboutToFinish )
if ( !m_aboutToFinish )
{
// We must finish regardless of success, otherwise we'll get
// focus problems:
Finish();
if ( !AcceptChanges() )
m_owner->OnRenameCancelled( m_itemEdited );
Finish( false );
}
// We must let the native text control handle focus, too, otherwise
// it could have problems with the cursor (e.g., in wxGTK).
// We should let the native text control handle focus, too.
event.Skip();
}
@ -1523,7 +1513,7 @@ void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
void wxGenericTreeCtrl::ChildrenClosing(wxGenericTreeItem* item)
{
if (m_textCtrl != NULL && item != m_textCtrl->item() && IsDescendantOf(item, m_textCtrl->item())) {
m_textCtrl->StopEditing();
m_textCtrl->EndEdit( true );
}
if (item != m_key_current && IsDescendantOf(item, m_key_current)) {
m_key_current = NULL;
@ -1557,7 +1547,7 @@ void wxGenericTreeCtrl::Delete(const wxTreeItemId& itemId)
if (m_textCtrl != NULL && IsDescendantOf(item, m_textCtrl->item()))
{
// can't delete the item being edited, cancel editing it first
m_textCtrl->StopEditing();
m_textCtrl->EndEdit( true );
}
wxGenericTreeItem *parent = item->GetParent();