[gtkmm] Use g_object_weak_ref() instead of the destroy signal.



commit d8232f145f8a752c4a0d2223172a6d58b1f834f3
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Sep 28 16:49:20 2010 +0200

    Use g_object_weak_ref() instead of the destroy signal.
    
    * gtk/gtkmm/object.[h|cc]: _release_c_instance(): Use g_object_weak_ref()
      instead of connecting to the GtkWidget::destroy signal, which was removed
      from GTK+. We only ever used this for a short time anyway.

 ChangeLog           |    8 ++++++++
 gtk/gtkmm/object.cc |    8 +++++---
 gtk/gtkmm/object.h  |    2 +-
 3 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9eb4294..ba82644 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2010-09-28  Murray Cumming  <murrayc murrayc com>
 
+	Use g_object_weak_ref() instead of the destroy signal.
+
+	* gtk/gtkmm/object.[h|cc]: _release_c_instance(): Use g_object_weak_ref()
+  instead of connecting to the GtkWidget::"destroy" signal, which was removed
+  from GTK+. We only ever used this for a short time anyway.
+
+2010-09-28  Murray Cumming  <murrayc murrayc com>
+
 	Object: Use g_object_run_dispose() as a gtk_object_destroy() replacement.
 
 	* gtk/gtkmm/object.cc: This does the same thing so it should work as well.
diff --git a/gtk/gtkmm/object.cc b/gtk/gtkmm/object.cc
index fa398ad..1d02266 100644
--- a/gtk/gtkmm/object.cc
+++ b/gtk/gtkmm/object.cc
@@ -121,13 +121,13 @@ void Object::_release_c_instance()
         //TODO: The "destroy" signal had been removed. Use a GWeakRef instead?
         //Because we called disconnect_cpp_wrapper() our dispose callback will not be called, because the qdata has been removed.
         //So we'll connect a callback again, just so that gobject_disposed_ gets set for use later in this same method.
-        const gulong connection_id_destroy = g_signal_connect (object,  "destroy", G_CALLBACK (&callback_destroy_), this);
+        g_object_weak_ref (object, &Object::callback_weak_notify_, this);
 
         GLIBMM_DEBUG_UNREFERENCE(this, object);
         g_object_unref(object);
 
         if(!gobject_disposed_) //or if(g_signal_handler_is_connected(object, connection_id_destroy))
-          g_signal_handler_disconnect(object, connection_id_destroy);
+          g_object_weak_unref(object, &Object::callback_weak_notify_, this);
 
         //destroy_notify() should have been called after the final g_object_unref() or g_object_run_dispose(), so gobject_disposed_ could now be true.
 
@@ -298,7 +298,7 @@ void Object::set_manage()
   referenced_ = false;
 }
 
-void Object::callback_destroy_(GObject*, void* data) //static
+void Object::callback_weak_notify_(void* data, GObject* /* gobject */) //static
 {
   //This is only used for a short time, then disconnected.
 
@@ -307,6 +307,8 @@ void Object::callback_destroy_(GObject*, void* data) //static
   {
     cppObject->gobject_disposed_ = true;
   }
+
+  //TODO: Do we need to do this?: g_object_weak_unref(gobject, &Object::callback_weak_notify_, data);
 }
 
 bool Object::is_managed_() const
diff --git a/gtk/gtkmm/object.h b/gtk/gtkmm/object.h
index 24e2a67..c2c5fdf 100644
--- a/gtk/gtkmm/object.h
+++ b/gtk/gtkmm/object.h
@@ -123,7 +123,7 @@ protected:
   virtual void destroy_notify_(); //override.
   void disconnect_cpp_wrapper();
   void _release_c_instance();
-  static void callback_destroy_(GObject* gobject, void* data); //only connected for a short time.
+  static void callback_weak_notify_(void* data, GObject* gobject); //only connected for a short time.
 
   // set if flags used by derived classes.
   bool referenced_; // = not managed.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]