X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f2b7492a88eef36f26668cefff8d3f8b91e5f50e..d75a69e8329cecf6f07c667ffc015186c230a2b5:/src/common/datavcmn.cpp?ds=sidebyside diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 645aa4ed0e..6e67dbaa40 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -18,9 +18,10 @@ #if wxUSE_DATAVIEWCTRL #include "wx/dataview.h" - #include "wx/spinctrl.h" +#include "wx/weakref.h" + #ifndef WX_PRECOMP #include "wx/dc.h" #include "wx/settings.h" @@ -658,15 +659,30 @@ wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, int WXUNUSED(align) ) { m_variantType = varianttype; - m_editorCtrl = NULL; m_owner = NULL; } +wxDataViewRendererBase::~wxDataViewRendererBase() +{ +} + const wxDataViewCtrl* wxDataViewRendererBase::GetView() const { return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner(); } +class wxKillRef: public wxWindowRef +{ +public: + wxKillRef( wxWindow *win ) : wxWindowRef( win ) { } + virtual void OnObjectDestroy() + { + get()->PopEventHandler( true ); + m_pobj = NULL; + delete this; + } +}; + bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect ) { m_item = item; // remember for later @@ -676,6 +692,7 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col ); m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value ); + (void) new wxKillRef( m_editorCtrl.get() ); wxDataViewEditorCtrlEvtHandler *handler = new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this ); @@ -700,11 +717,10 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la void wxDataViewRendererBase::CancelEditing() { - wxPendingDelete.Append( m_editorCtrl ); - GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); - - // m_editorCtrl->PopEventHandler( true ); + + m_editorCtrl->Hide(); + wxPendingDelete.Append( m_editorCtrl ); } bool wxDataViewRendererBase::FinishEditing() @@ -712,10 +728,11 @@ bool wxDataViewRendererBase::FinishEditing() wxVariant value; GetValueFromEditorCtrl( m_editorCtrl, value ); - wxPendingDelete.Append( m_editorCtrl ); - GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); + m_editorCtrl->Hide(); + wxPendingDelete.Append( m_editorCtrl ); + if (!Validate(value)) return false; @@ -723,8 +740,6 @@ bool wxDataViewRendererBase::FinishEditing() GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col ); GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col ); - // m_editorCtrl->PopEventHandler( true ); - // Now we should send Editing Done event wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() ); event.SetDataViewColumn( GetOwner() ); @@ -772,7 +787,6 @@ void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event ) switch ( event.m_keyCode ) { case WXK_RETURN: - wxPrintf( "OnChar RETURN\n" ); m_finished = true; m_owner->FinishEditing(); break; @@ -791,7 +805,6 @@ void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event ) { if (!m_finished) { - wxPrintf( "OnKillFocus\n" ); m_finished = true; m_owner->FinishEditing(); }