[clutter] drag-action: Remove the drag handle on destruction



commit a6a57d79677b8a498622c83c915c981779963460
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Fri Jun 17 16:53:22 2011 +0100

    drag-action: Remove the drag handle on destruction
    
    When the drag handle actor is destroyed we should unset the field inside
    the DragAction, to avoid having stale pointers lying around.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=652842

 clutter/clutter-drag-action.c |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/clutter/clutter-drag-action.c b/clutter/clutter-drag-action.c
index e207c2f..05a6e03 100644
--- a/clutter/clutter-drag-action.c
+++ b/clutter/clutter-drag-action.c
@@ -516,6 +516,8 @@ clutter_drag_action_dispose (GObject *gobject)
       priv->button_press_id = 0;
     }
 
+  clutter_drag_action_set_drag_handle (CLUTTER_DRAG_ACTION (gobject), NULL);
+
   G_OBJECT_CLASS (clutter_drag_action_parent_class)->dispose (gobject);
 }
 
@@ -837,12 +839,19 @@ clutter_drag_action_get_drag_threshold (ClutterDragAction *action,
     *y_threshold = y_res;
 }
 
+static void
+on_drag_handle_destroy (ClutterActor      *actor,
+                        ClutterDragAction *action)
+{
+  action->priv->drag_handle = NULL;
+}
+
 /**
  * clutter_drag_action_set_drag_handle:
  * @action: a #ClutterDragAction
- * @handle: a #ClutterActor
+ * @handle: (allow-none): a #ClutterActor, or %NULL to unset
  *
- * Sets the actor to be used as the drag handle
+ * Sets the actor to be used as the drag handle.
  *
  * Since: 1.4
  */
@@ -853,15 +862,25 @@ clutter_drag_action_set_drag_handle (ClutterDragAction *action,
   ClutterDragActionPrivate *priv;
 
   g_return_if_fail (CLUTTER_IS_DRAG_ACTION (action));
-  g_return_if_fail (CLUTTER_IS_ACTOR (handle));
+  g_return_if_fail (handle == NULL || CLUTTER_IS_ACTOR (handle));
 
   priv = action->priv;
 
   if (priv->drag_handle == handle)
     return;
 
+  if (priv->drag_handle != NULL)
+    g_signal_handlers_disconnect_by_func (priv->drag_handle,
+                                          G_CALLBACK (on_drag_handle_destroy),
+                                          action);
+
   priv->drag_handle = handle;
 
+  if (priv->drag_handle != NULL)
+    g_signal_connect (priv->drag_handle, "destroy",
+                      G_CALLBACK (on_drag_handle_destroy),
+                      action);
+
   g_object_notify_by_pspec (G_OBJECT (action), drag_props[PROP_DRAG_HANDLE]);
 }
 



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