Applied [ 1867939 ] fixes for wxTreeCtrl crashes when exiting from label editing to wxListCtrl as well and made code more similar to wxTreeCtrl' code doing the same
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51150 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -464,7 +464,7 @@ public:
|
|||||||
|
|
||||||
wxTextCtrl *GetText() const { return m_text; }
|
wxTextCtrl *GetText() const { return m_text; }
|
||||||
|
|
||||||
void AcceptChangesAndFinish();
|
void EndEdit( bool discardChanges );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnChar( wxKeyEvent &event );
|
void OnChar( wxKeyEvent &event );
|
||||||
@@ -472,14 +472,13 @@ protected:
|
|||||||
void OnKillFocus( wxFocusEvent &event );
|
void OnKillFocus( wxFocusEvent &event );
|
||||||
|
|
||||||
bool AcceptChanges();
|
bool AcceptChanges();
|
||||||
void Finish();
|
void Finish( bool setfocus );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxListMainWindow *m_owner;
|
wxListMainWindow *m_owner;
|
||||||
wxTextCtrl *m_text;
|
wxTextCtrl *m_text;
|
||||||
wxString m_startValue;
|
wxString m_startValue;
|
||||||
size_t m_itemEdited;
|
size_t m_itemEdited;
|
||||||
bool m_finished;
|
|
||||||
bool m_aboutToFinish;
|
bool m_aboutToFinish;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
@@ -593,11 +592,10 @@ public:
|
|||||||
return m_textctrlWrapper ? m_textctrlWrapper->GetText() : NULL;
|
return m_textctrlWrapper ? m_textctrlWrapper->GetText() : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinishEditing(wxTextCtrl *text)
|
void ResetTextControl(wxTextCtrl *text)
|
||||||
{
|
{
|
||||||
delete text;
|
delete text;
|
||||||
m_textctrlWrapper = NULL;
|
m_textctrlWrapper = NULL;
|
||||||
SetFocusIgnoringChildren();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we don't draw anything while we're frozen so we must refresh ourselves
|
// we don't draw anything while we're frozen so we must refresh ourselves
|
||||||
@@ -2120,7 +2118,6 @@ wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner,
|
|||||||
{
|
{
|
||||||
m_owner = owner;
|
m_owner = owner;
|
||||||
m_text = text;
|
m_text = text;
|
||||||
m_finished = false;
|
|
||||||
m_aboutToFinish = false;
|
m_aboutToFinish = false;
|
||||||
|
|
||||||
wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
|
wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
|
||||||
@@ -2136,17 +2133,35 @@ wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner,
|
|||||||
m_text->PushEventHandler(this);
|
m_text->PushEventHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListTextCtrlWrapper::Finish()
|
void wxListTextCtrlWrapper::EndEdit(bool discardChanges)
|
||||||
{
|
{
|
||||||
if ( !m_finished )
|
m_aboutToFinish = true;
|
||||||
{
|
|
||||||
m_finished = true;
|
|
||||||
|
|
||||||
|
if ( discardChanges )
|
||||||
|
{
|
||||||
|
m_owner->OnRenameCancelled(m_itemEdited);
|
||||||
|
|
||||||
|
Finish( true );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Notify the owner about the changes
|
||||||
|
AcceptChanges();
|
||||||
|
|
||||||
|
// Even if vetoed, close the control (consistent with MSW)
|
||||||
|
Finish( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxListTextCtrlWrapper::Finish( bool setfocus )
|
||||||
|
{
|
||||||
m_text->RemoveEventHandler(this);
|
m_text->RemoveEventHandler(this);
|
||||||
m_owner->FinishEditing(m_text);
|
m_owner->ResetTextControl( m_text );
|
||||||
|
|
||||||
wxPendingDelete.Append( this );
|
wxPendingDelete.Append( this );
|
||||||
}
|
|
||||||
|
if (setfocus)
|
||||||
|
m_owner->SetFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxListTextCtrlWrapper::AcceptChanges()
|
bool wxListTextCtrlWrapper::AcceptChanges()
|
||||||
@@ -2168,28 +2183,16 @@ bool wxListTextCtrlWrapper::AcceptChanges()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListTextCtrlWrapper::AcceptChangesAndFinish()
|
|
||||||
{
|
|
||||||
m_aboutToFinish = true;
|
|
||||||
|
|
||||||
// Notify the owner about the changes
|
|
||||||
AcceptChanges();
|
|
||||||
|
|
||||||
// Even if vetoed, close the control (consistent with MSW)
|
|
||||||
Finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxListTextCtrlWrapper::OnChar( wxKeyEvent &event )
|
void wxListTextCtrlWrapper::OnChar( wxKeyEvent &event )
|
||||||
{
|
{
|
||||||
switch ( event.m_keyCode )
|
switch ( event.m_keyCode )
|
||||||
{
|
{
|
||||||
case WXK_RETURN:
|
case WXK_RETURN:
|
||||||
AcceptChangesAndFinish();
|
EndEdit( false );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WXK_ESCAPE:
|
case WXK_ESCAPE:
|
||||||
m_owner->OnRenameCancelled( m_itemEdited );
|
EndEdit( true );
|
||||||
Finish();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -2199,12 +2202,8 @@ void wxListTextCtrlWrapper::OnChar( wxKeyEvent &event )
|
|||||||
|
|
||||||
void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent &event )
|
void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent &event )
|
||||||
{
|
{
|
||||||
if (m_finished)
|
if (m_aboutToFinish)
|
||||||
{
|
{
|
||||||
event.Skip();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// auto-grow the textctrl:
|
// auto-grow the textctrl:
|
||||||
wxSize parentSize = m_owner->GetSize();
|
wxSize parentSize = m_owner->GetSize();
|
||||||
wxPoint myPos = m_text->GetPosition();
|
wxPoint myPos = m_text->GetPosition();
|
||||||
@@ -2216,18 +2215,19 @@ void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent &event )
|
|||||||
if (mySize.x > sx)
|
if (mySize.x > sx)
|
||||||
sx = mySize.x;
|
sx = mySize.x;
|
||||||
m_text->SetSize(sx, wxDefaultCoord);
|
m_text->SetSize(sx, wxDefaultCoord);
|
||||||
|
}
|
||||||
|
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent &event )
|
void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent &event )
|
||||||
{
|
{
|
||||||
if ( !m_finished && !m_aboutToFinish )
|
if ( !m_aboutToFinish )
|
||||||
{
|
{
|
||||||
if ( !AcceptChanges() )
|
if ( !AcceptChanges() )
|
||||||
m_owner->OnRenameCancelled( m_itemEdited );
|
m_owner->OnRenameCancelled( m_itemEdited );
|
||||||
|
|
||||||
Finish();
|
Finish( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
// We must let the native text control handle focus
|
// We must let the native text control handle focus
|
||||||
@@ -2991,7 +2991,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
|
|||||||
// listctrl because the order of events is different (or something like
|
// listctrl because the order of events is different (or something like
|
||||||
// that), so explicitly end the edit if it is active.
|
// that), so explicitly end the edit if it is active.
|
||||||
if ( event.LeftDown() && m_textctrlWrapper )
|
if ( event.LeftDown() && m_textctrlWrapper )
|
||||||
m_textctrlWrapper->AcceptChangesAndFinish();
|
m_textctrlWrapper->EndEdit( false );
|
||||||
#endif // __WXMAC__
|
#endif // __WXMAC__
|
||||||
|
|
||||||
if ( event.LeftDown() )
|
if ( event.LeftDown() )
|
||||||
|
@@ -92,7 +92,7 @@ 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 );
|
||||||
|
|
||||||
const wxGenericTreeItem* item() const { return m_itemEdited; }
|
const wxGenericTreeItem* item() const { return m_itemEdited; }
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ protected:
|
|||||||
void OnKillFocus( wxFocusEvent &event );
|
void OnKillFocus( wxFocusEvent &event );
|
||||||
|
|
||||||
bool AcceptChanges();
|
bool AcceptChanges();
|
||||||
void Finish( bool setfocus = true );
|
void Finish( bool setfocus );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxGenericTreeCtrl *m_owner;
|
wxGenericTreeCtrl *m_owner;
|
||||||
@@ -392,7 +392,7 @@ void wxTreeTextCtrl::EndEdit(bool discardChanges)
|
|||||||
{
|
{
|
||||||
m_owner->OnRenameCancelled(m_itemEdited);
|
m_owner->OnRenameCancelled(m_itemEdited);
|
||||||
|
|
||||||
Finish();
|
Finish( true );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -400,7 +400,7 @@ void wxTreeTextCtrl::EndEdit(bool discardChanges)
|
|||||||
AcceptChanges();
|
AcceptChanges();
|
||||||
|
|
||||||
// Even if vetoed, close the control (consistent with MSW)
|
// Even if vetoed, close the control (consistent with MSW)
|
||||||
Finish();
|
Finish( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user