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:
@@ -92,29 +92,8 @@ class WXDLLEXPORT wxTreeTextCtrl: public wxTextCtrl
|
|||||||
public:
|
public:
|
||||||
wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item);
|
wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item);
|
||||||
|
|
||||||
void EndEdit(bool discardChanges = false)
|
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);
|
|
||||||
}
|
|
||||||
const wxGenericTreeItem* item() const { return m_itemEdited; }
|
const wxGenericTreeItem* item() const { return m_itemEdited; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -123,13 +102,12 @@ protected:
|
|||||||
void OnKillFocus( wxFocusEvent &event );
|
void OnKillFocus( wxFocusEvent &event );
|
||||||
|
|
||||||
bool AcceptChanges();
|
bool AcceptChanges();
|
||||||
void Finish();
|
void Finish( bool setfocus = true );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxGenericTreeCtrl *m_owner;
|
wxGenericTreeCtrl *m_owner;
|
||||||
wxGenericTreeItem *m_itemEdited;
|
wxGenericTreeItem *m_itemEdited;
|
||||||
wxString m_startValue;
|
wxString m_startValue;
|
||||||
bool m_finished;
|
|
||||||
bool m_aboutToFinish;
|
bool m_aboutToFinish;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
@@ -363,7 +341,6 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner,
|
|||||||
: m_itemEdited(item), m_startValue(item->GetText())
|
: m_itemEdited(item), m_startValue(item->GetText())
|
||||||
{
|
{
|
||||||
m_owner = owner;
|
m_owner = owner;
|
||||||
m_finished = false;
|
|
||||||
m_aboutToFinish = false;
|
m_aboutToFinish = false;
|
||||||
|
|
||||||
int w = m_itemEdited->GetWidth(),
|
int w = m_itemEdited->GetWidth(),
|
||||||
@@ -407,6 +384,26 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner,
|
|||||||
wxPoint(x - 4, y - 4), wxSize(w + 11, h + 8));
|
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()
|
bool wxTreeTextCtrl::AcceptChanges()
|
||||||
{
|
{
|
||||||
const wxString value = GetValue();
|
const wxString value = GetValue();
|
||||||
@@ -435,30 +432,26 @@ bool wxTreeTextCtrl::AcceptChanges()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTreeTextCtrl::Finish()
|
void wxTreeTextCtrl::Finish( bool setfocus )
|
||||||
{
|
|
||||||
if ( !m_finished )
|
|
||||||
{
|
{
|
||||||
m_owner->ResetTextControl();
|
m_owner->ResetTextControl();
|
||||||
|
|
||||||
wxPendingDelete.Append(this);
|
wxPendingDelete.Append(this);
|
||||||
|
|
||||||
m_finished = true;
|
if (setfocus)
|
||||||
|
|
||||||
m_owner->SetFocus();
|
m_owner->SetFocus();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
|
void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
|
||||||
{
|
{
|
||||||
switch ( event.m_keyCode )
|
switch ( event.m_keyCode )
|
||||||
{
|
{
|
||||||
case WXK_RETURN:
|
case WXK_RETURN:
|
||||||
EndEdit();
|
EndEdit( false );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WXK_ESCAPE:
|
case WXK_ESCAPE:
|
||||||
StopEditing();
|
EndEdit( true );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -468,7 +461,7 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
|
|||||||
|
|
||||||
void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event )
|
void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event )
|
||||||
{
|
{
|
||||||
if ( !m_finished )
|
if ( !m_aboutToFinish )
|
||||||
{
|
{
|
||||||
// auto-grow the textctrl:
|
// auto-grow the textctrl:
|
||||||
wxSize parentSize = m_owner->GetSize();
|
wxSize parentSize = m_owner->GetSize();
|
||||||
@@ -488,18 +481,15 @@ void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event )
|
|||||||
|
|
||||||
void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &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() )
|
if ( !AcceptChanges() )
|
||||||
m_owner->OnRenameCancelled( m_itemEdited );
|
m_owner->OnRenameCancelled( m_itemEdited );
|
||||||
|
|
||||||
|
Finish( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
// We must let the native text control handle focus, too, otherwise
|
// We should let the native text control handle focus, too.
|
||||||
// it could have problems with the cursor (e.g., in wxGTK).
|
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1523,7 +1513,7 @@ void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
|
|||||||
void wxGenericTreeCtrl::ChildrenClosing(wxGenericTreeItem* item)
|
void wxGenericTreeCtrl::ChildrenClosing(wxGenericTreeItem* item)
|
||||||
{
|
{
|
||||||
if (m_textCtrl != NULL && item != m_textCtrl->item() && IsDescendantOf(item, m_textCtrl->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)) {
|
if (item != m_key_current && IsDescendantOf(item, m_key_current)) {
|
||||||
m_key_current = NULL;
|
m_key_current = NULL;
|
||||||
@@ -1557,7 +1547,7 @@ void wxGenericTreeCtrl::Delete(const wxTreeItemId& itemId)
|
|||||||
if (m_textCtrl != NULL && IsDescendantOf(item, m_textCtrl->item()))
|
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();
|
m_textCtrl->EndEdit( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGenericTreeItem *parent = item->GetParent();
|
wxGenericTreeItem *parent = item->GetParent();
|
||||||
|
Reference in New Issue
Block a user