Merge branch 'win32-fix-dnd-info-disposal' into 'gtk-3-24'

Fix DND info disposal

See merge request GNOME/gtk!390
This commit is contained in:
Benjamin Otte
2018-10-16 19:41:03 +00:00
3 changed files with 38 additions and 29 deletions

View File

@@ -1699,18 +1699,20 @@ gtk_drag_is_managed (GtkWidget *source_widget)
FALSE;
}
/* Like gtk_drag_begin(), but also takes a GtkIconHelper
* so that we can set the icon from the source site information
/* Like gtk_drag_begin(), but also communicates the need to
* create an icon for the drag operation back to the caller.
* If the caller passes out_needs_icon == NULL, it means that
* the caller does not care.
*/
GdkDragContext *
gtk_drag_begin_internal (GtkWidget *widget,
GtkImageDefinition *icon,
GtkTargetList *target_list,
GdkDragAction actions,
gint button,
const GdkEvent *event,
int x,
int y)
gtk_drag_begin_internal (GtkWidget *widget,
gboolean *out_needs_icon,
GtkTargetList *target_list,
GdkDragAction actions,
gint button,
const GdkEvent *event,
int x,
int y)
{
GtkDragSourceInfo *info;
GList *targets = NULL;
@@ -1873,20 +1875,16 @@ gtk_drag_begin_internal (GtkWidget *widget,
* application may have set one in ::drag_begin, or it may
* not have set one.
*/
if (!info->icon_widget)
if (!info->icon_widget && out_needs_icon == NULL)
{
if (icon)
{
set_icon_helper (info->context, icon, 0, 0);
}
else
{
icon = gtk_image_definition_new_icon_name ("text-x-generic");
set_icon_helper (info->context, icon, 0, 0);
gtk_image_definition_unref (icon);
}
GtkImageDefinition *icon = gtk_image_definition_new_icon_name ("text-x-generic");
set_icon_helper (info->context, icon, 0, 0);
gtk_image_definition_unref (icon);
}
if (out_needs_icon != NULL)
*out_needs_icon = (info->icon_widget == NULL);
if (managed)
{
g_signal_connect (context, "drop-performed",
@@ -2768,6 +2766,9 @@ gtk_drag_source_info_free (GtkDragSourceInfo *info)
static void
gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
{
GdkDragContext *context;
GdkEvent *last_event;
g_signal_handlers_disconnect_by_func (info->context,
gtk_drag_context_drop_performed_cb,
info);
@@ -2820,12 +2821,15 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
/* keep the icon_window alive until the (possible) drag cancel animation is done */
g_object_set_data_full (G_OBJECT (info->context), "former-gtk-source-info", info, (GDestroyNotify)gtk_drag_source_info_free);
context = info->context;
last_event = info->last_event;
gtk_drag_clear_source_info (info->context);
g_object_unref (info->context);
gtk_drag_clear_source_info (context);
if (info->last_event)
gdk_event_free (info->last_event);
if (last_event)
gdk_event_free (last_event);
g_object_unref (context);
}
static gboolean

View File

@@ -43,7 +43,7 @@ struct _GtkDragDestSite
G_BEGIN_DECLS
GdkDragContext * gtk_drag_begin_internal (GtkWidget *widget,
GtkImageDefinition *icon,
gboolean *out_needs_icon,
GtkTargetList *target_list,
GdkDragAction actions,
gint button,

View File

@@ -88,6 +88,8 @@ gtk_drag_source_event_cb (GtkWidget *widget,
GdkEventSequence *sequence;
GdkEvent *last_event;
guint button;
gboolean needs_icon;
GdkDragContext *context;
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (site->drag_gesture));
last_event = gdk_event_copy (gtk_gesture_get_last_event (site->drag_gesture, sequence));
@@ -95,9 +97,12 @@ gtk_drag_source_event_cb (GtkWidget *widget,
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (site->drag_gesture));
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (site->drag_gesture));
gtk_drag_begin_internal (widget, site->image_def, site->target_list,
site->actions, button, last_event,
start_x, start_y);
context = gtk_drag_begin_internal (widget, &needs_icon, site->target_list,
site->actions, button, last_event,
start_x, start_y);
if (context != NULL && needs_icon)
gtk_drag_set_icon_definition (context, site->image_def, 0, 0);
gdk_event_free (last_event);