#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"
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 );
+ delete this;
+ }
+};
+
bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
{
m_item = item; // remember for later
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 );
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()
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;
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() );
switch ( event.m_keyCode )
{
case WXK_RETURN:
- wxPrintf( "OnChar RETURN\n" );
m_finished = true;
m_owner->FinishEditing();
break;
{
if (!m_finished)
{
- wxPrintf( "OnKillFocus\n" );
m_finished = true;
m_owner->FinishEditing();
}