]> git.saurik.com Git - wxWidgets.git/commitdiff
Add test for context menu, fixed mem leak, fixed focus problem when re-editing same...
authorRobert Roebling <robert@roebling.de>
Fri, 11 Apr 2008 10:40:58 +0000 (10:40 +0000)
committerRobert Roebling <robert@roebling.de>
Fri, 11 Apr 2008 10:40:58 +0000 (10:40 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53126 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataview.h
samples/dataview/dataview.cpp
src/common/datavcmn.cpp
src/gtk/dataview.cpp

index c2db8eef481b92cdb03a362f16c24ddabfe1b502..dca249147ad30565e2ee7f441d4a8bc5850a53b8 100644 (file)
@@ -23,6 +23,7 @@
 #include "wx/dynarray.h"
 #include "wx/icon.h"
 #include "wx/imaglist.h"
+#include "wx/weakref.h"
 
 class WXDLLIMPEXP_FWD_CORE wxDataFormat;
 
@@ -413,6 +414,7 @@ public:
     wxDataViewRendererBase( const wxString &varianttype,
                             wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
                             int alignment = wxDVR_DEFAULT_ALIGNMENT );
+    ~wxDataViewRendererBase();
 
     virtual bool Validate( wxVariant& WXUNUSED(value) )
         { return true; }
@@ -456,7 +458,7 @@ public:
 protected:
     wxString                m_variantType;
     wxDataViewColumn       *m_owner;
-    wxControl              *m_editorCtrl;
+    wxWeakRef<wxControl>    m_editorCtrl;
     wxDataViewItem          m_item; // for m_editorCtrl
 
     // internal utility:
index 8e216d8ea661c686bc3aec7b04d512635b1c7bbe..14d66161b27985381935f8f89099188e399a99bc 100644 (file)
@@ -27,9 +27,7 @@
 #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"
@@ -1039,6 +1037,14 @@ void MyFrame::OnContextMenu( wxDataViewEvent &event )
     
     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());
 }
 
index 645aa4ed0ebedae7bc6327a4bd3d3b73e791a71c..7f85194b9bc8065dff598ef1a550bd75f2378861 100644 (file)
 #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,29 @@ 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 );
+      delete this;
+   }
+};
+
 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
 {
     m_item = item; // remember for later
@@ -676,6 +691,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 +716,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 +727,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 +739,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 +786,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 +804,6 @@ void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
 {
     if (!m_finished)
     {
-        wxPrintf( "OnKillFocus\n" );
         m_finished = true;
         m_owner->FinishEditing();
     }
index 0ecca2c7f12ba81e73ca9308bb439ba9c804a0e6..518590545fe9d0ff91e7c8425f8a6646e0fbe641 100644 (file)
@@ -975,8 +975,14 @@ static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
 {
     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,