Commit 37774928 authored by Matthias Clasen's avatar Matthias Clasen

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.
parent e7eaca95
...@@ -228,6 +228,8 @@ static gboolean gtk_drag_dest_drop (GtkWidget *widget, ...@@ -228,6 +228,8 @@ static gboolean gtk_drag_dest_drop (GtkWidget *widget,
gint x, gint x,
gint y, gint y,
guint time); guint time);
static void gtk_drag_dest_set_widget (GtkDragDestInfo *info,
GtkWidget *widget);
static GtkDragDestInfo * gtk_drag_get_dest_info (GdkDragContext *context, static GtkDragDestInfo * gtk_drag_get_dest_info (GdkDragContext *context,
gboolean create); gboolean create);
...@@ -1637,9 +1639,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel, ...@@ -1637,9 +1639,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
case GDK_DRAG_LEAVE: case GDK_DRAG_LEAVE:
if (info->widget) 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); gtk_drag_dest_leave (info->widget, context, event->dnd.time);
info->widget = NULL; gtk_drag_dest_set_widget (info, NULL);
} }
break; break;
...@@ -1658,9 +1659,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel, ...@@ -1658,9 +1659,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
*/ */
if (info->widget) 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); gtk_drag_dest_leave (info->widget, context, event->dnd.time);
info->widget = NULL; gtk_drag_dest_set_widget (info, NULL);
} }
} }
...@@ -1691,9 +1691,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel, ...@@ -1691,9 +1691,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
if (info->widget && !found) 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); gtk_drag_dest_leave (info->widget, context, event->dnd.time);
info->widget = NULL; gtk_drag_dest_set_widget (info, NULL);
} }
/* Send a reply. /* Send a reply.
...@@ -1924,13 +1923,9 @@ gtk_drag_find_widget (GtkWidget *widget, ...@@ -1924,13 +1923,9 @@ gtk_drag_find_widget (GtkWidget *widget,
if (found && info->widget != widget) if (found && info->widget != widget)
{ {
if (info->widget) if (info->widget)
{ gtk_drag_dest_leave (info->widget, context, time);
g_object_remove_weak_pointer (G_OBJECT (info->widget), (gpointer *) &info->widget);
gtk_drag_dest_leave (info->widget, context, time);
}
info->widget = widget; gtk_drag_dest_set_widget (info, widget);
g_object_add_weak_pointer (G_OBJECT (widget), (gpointer *) &info->widget);
} }
} }
...@@ -2012,14 +2007,26 @@ gtk_drag_proxy_begin (GtkWidget *widget, ...@@ -2012,14 +2007,26 @@ gtk_drag_proxy_begin (GtkWidget *widget,
dest_info->proxy_source = source_info; dest_info->proxy_source = source_info;
} }
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 static void
gtk_drag_dest_info_destroy (gpointer data) gtk_drag_dest_info_destroy (gpointer data)
{ {
GtkDragDestInfo *info = (GtkDragDestInfo *)data; GtkDragDestInfo *info = (GtkDragDestInfo *)data;
if (info->widget)
{ gtk_drag_dest_set_widget (info, NULL);
g_object_remove_weak_pointer (G_OBJECT (info->widget), (gpointer *) &info->widget);
}
g_slice_free (GtkDragDestInfo, data); g_slice_free (GtkDragDestInfo, data);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment