#include "wx/dynarray.h"
#include "wx/icon.h"
#include "wx/imaglist.h"
+#include "wx/weakref.h"
class WXDLLIMPEXP_FWD_CORE wxDataFormat;
wxDataViewRendererBase( const wxString &varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
+ ~wxDataViewRendererBase();
virtual bool Validate( wxVariant& WXUNUSED(value) )
{ return true; }
protected:
wxString m_variantType;
wxDataViewColumn *m_owner;
- wxControl *m_editorCtrl;
+ wxWeakRef<wxControl> m_editorCtrl;
wxDataViewItem m_item; // for m_editorCtrl
// internal utility:
#include "wx/numdlg.h"
#include "wx/dataview.h"
#include "wx/spinctrl.h"
-
-#include "wx/ptr_shrd.h"
-#include "wx/vector.h"
+#include "wx/menu.h"
#ifndef __WXMSW__
#include "../sample.xpm"
wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title.GetData());
+
+ wxMenu *menu = new wxMenu;
+ menu->Append( 1, wxT("entry 1") );
+ menu->Append( 2, wxT("entry 2") );
+ menu->Append( 3, wxT("entry 3") );
+
+ m_musicCtrl->PopupMenu( menu );
+
// wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s Value: %s"),title.GetData(), event.GetValue().GetString());
}
#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();
}
{
GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
wxDataViewCustomRenderer *cell = wxrenderer->cell;
+
+ // Renderer doesn't support in-place editing
if (!cell->HasEditorCtrl())
return NULL;
+
+ // An in-place editing control is still around
+ if (cell->GetEditorCtrl())
+ return NULL;
GdkRectangle rect;
gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,