[gtk+/gtk-3-14] dnd: Introduce a helper to manage the weak pointer
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-14] dnd: Introduce a helper to manage the weak pointer
- Date: Mon, 23 Mar 2015 03:33:29 +0000 (UTC)
commit 78605a6549203a4c3cc4a1a1f421b7c2f15500f3
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 22 11:13:08 2015 -0400
dnd: Introduce a helper to manage the weak pointer
Introduce a setter that takes care of updating the weak ref
whenever we assign info->widget. Just a cleanup of the previous patch.
gtk/gtkdnd.c | 39 +++++++++++++++++++++++----------------
1 files changed, 23 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 3d79e90..e4e2117 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -228,6 +228,8 @@ static gboolean gtk_drag_dest_drop (GtkWidget *widget,
gint x,
gint y,
guint time);
+static void gtk_drag_dest_set_widget (GtkDragDestInfo *info,
+ GtkWidget *widget);
static GtkDragDestInfo * gtk_drag_get_dest_info (GdkDragContext *context,
gboolean create);
@@ -1639,9 +1641,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
case GDK_DRAG_LEAVE:
if (info->widget)
{
- g_object_remove_weak_pointer (G_OBJECT (info->widget), (gpointer *) &info->widget);
gtk_drag_dest_leave (info->widget, context, event->dnd.time);
- info->widget = NULL;
+ gtk_drag_dest_set_widget (info, NULL);
}
break;
@@ -1660,9 +1661,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
*/
if (info->widget)
{
- g_object_remove_weak_pointer (G_OBJECT (info->widget), (gpointer *) &info->widget);
gtk_drag_dest_leave (info->widget, context, event->dnd.time);
- info->widget = NULL;
+ gtk_drag_dest_set_widget (info, NULL);
}
}
@@ -1693,9 +1693,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
if (info->widget && !found)
{
- g_object_remove_weak_pointer (G_OBJECT (info->widget), (gpointer *) &info->widget);
gtk_drag_dest_leave (info->widget, context, event->dnd.time);
- info->widget = NULL;
+ gtk_drag_dest_set_widget (info, NULL);
}
/* Send a reply.
@@ -1926,13 +1925,9 @@ gtk_drag_find_widget (GtkWidget *widget,
if (found && info->widget != widget)
{
if (info->widget)
- {
- g_object_remove_weak_pointer (G_OBJECT (info->widget), (gpointer *) &info->widget);
- gtk_drag_dest_leave (info->widget, context, time);
- }
+ gtk_drag_dest_leave (info->widget, context, time);
- info->widget = widget;
- g_object_add_weak_pointer (G_OBJECT (widget), (gpointer *) &info->widget);
+ gtk_drag_dest_set_widget (info, widget);
}
}
@@ -2015,13 +2010,25 @@ gtk_drag_proxy_begin (GtkWidget *widget,
}
static void
+gtk_drag_dest_set_widget (GtkDragDestInfo *info,
+ GtkWidget *widget)
+{
+ if (info->widget)
+ g_object_remove_weak_pointer (G_OBJECT (info->widget), (gpointer *) &info->widget);
+
+ info->widget = widget;
+
+ if (info->widget)
+ g_object_add_weak_pointer (G_OBJECT (info->widget), (gpointer *) &info->widget);
+}
+
+static void
gtk_drag_dest_info_destroy (gpointer data)
{
GtkDragDestInfo *info = (GtkDragDestInfo *)data;
- if (info->widget)
- {
- g_object_remove_weak_pointer (G_OBJECT (info->widget), (gpointer *) &info->widget);
- }
+
+ gtk_drag_dest_set_widget (info, NULL);
+
g_slice_free (GtkDragDestInfo, data);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]