From 1c96b703a684b7545535491f1d795056382d9738 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 25 Nov 2015 15:59:44 +0100 Subject: [PATCH] dragsource: Store an itemdefinition, not an iconhelper The icon is never rendered, so there's no need for the extra iconhelper code. --- gtk/gtkdnd.c | 25 ++++++++++++------------- gtk/gtkdndprivate.h | 4 ++-- gtk/gtkdragsource.c | 22 +++++++++++++--------- gtk/gtkiconhelper.c | 11 ++++++++++- gtk/gtkiconhelperprivate.h | 4 ++++ 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index 6e106c56e3..88e9d41284 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -2337,14 +2337,14 @@ gtk_drag_dest_drop (GtkWidget *widget, * so that we can set the icon from the source site information */ GdkDragContext * -gtk_drag_begin_internal (GtkWidget *widget, - GtkIconHelper *icon_helper, - GtkTargetList *target_list, - GdkDragAction actions, - gint button, - const GdkEvent *event, - int x, - int y) +gtk_drag_begin_internal (GtkWidget *widget, + GtkImageDefinition *icon, + GtkTargetList *target_list, + GdkDragAction actions, + gint button, + const GdkEvent *event, + int x, + int y) { GtkDragSourceInfo *info; GList *targets = NULL; @@ -2484,12 +2484,11 @@ gtk_drag_begin_internal (GtkWidget *widget, */ if (!info->icon_window && !info->icon_helper) { - if (icon_helper) - info->icon_helper = g_object_ref (icon_helper); - else - info->icon_helper = _gtk_icon_helper_new (); + info->icon_helper = _gtk_icon_helper_new (); - if (_gtk_icon_helper_get_is_empty (info->icon_helper)) + if (icon) + _gtk_icon_helper_set_definition (info->icon_helper, icon); + else _gtk_icon_helper_set_icon_name (info->icon_helper, "text-x-generic", GTK_ICON_SIZE_DND); set_icon_helper (info->context, info->icon_helper, 0, 0, FALSE); diff --git a/gtk/gtkdndprivate.h b/gtk/gtkdndprivate.h index 8487aa4577..43df858b86 100644 --- a/gtk/gtkdndprivate.h +++ b/gtk/gtkdndprivate.h @@ -23,12 +23,12 @@ #include #include -#include "gtkiconhelperprivate.h" +#include "gtkimagedefinitionprivate.h" G_BEGIN_DECLS GdkDragContext * gtk_drag_begin_internal (GtkWidget *widget, - GtkIconHelper *icon_helper, + GtkImageDefinition *icon, GtkTargetList *target_list, GdkDragAction actions, gint button, diff --git a/gtk/gtkdragsource.c b/gtk/gtkdragsource.c index 16f81fdb3f..5a4602234e 100644 --- a/gtk/gtkdragsource.c +++ b/gtk/gtkdragsource.c @@ -29,7 +29,7 @@ #include "gtkdnd.h" #include "gtkdndprivate.h" #include "gtkgesturedrag.h" -#include "gtkiconhelperprivate.h" +#include "gtkimagedefinitionprivate.h" #include "gtkintl.h" @@ -41,7 +41,7 @@ struct _GtkDragSourceSite GtkTargetList *target_list; /* Targets for drag data */ GdkDragAction actions; /* Possible actions */ - GtkIconHelper *icon_helper; + GtkImageDefinition *image_def; GtkGesture *drag_gesture; }; @@ -92,7 +92,7 @@ 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->icon_helper, site->target_list, + gtk_drag_begin_internal (widget, site->image_def, site->target_list, site->actions, button, last_event, start_x, start_y); return TRUE; @@ -110,7 +110,7 @@ gtk_drag_source_site_destroy (gpointer data) if (site->target_list) gtk_target_list_unref (site->target_list); - g_clear_object (&site->icon_helper); + gtk_image_definition_unref (site->image_def); g_clear_object (&site->drag_gesture); g_slice_free (GtkDragSourceSite, site); } @@ -153,7 +153,7 @@ gtk_drag_source_set (GtkWidget *widget, else { site = g_slice_new0 (GtkDragSourceSite); - site->icon_helper = _gtk_icon_helper_new (); + site->image_def = gtk_image_definition_new_empty (); site->drag_gesture = gtk_gesture_drag_new (widget); gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (site->drag_gesture), GTK_PHASE_NONE); @@ -369,7 +369,8 @@ gtk_drag_source_set_icon_pixbuf (GtkWidget *widget, g_return_if_fail (site != NULL); g_object_ref (pixbuf); - _gtk_icon_helper_set_pixbuf (site->icon_helper, pixbuf); + g_clear_pointer (&site->image_def, gtk_image_definition_unref); + site->image_def = gtk_image_definition_new_pixbuf (pixbuf, 1); } /** @@ -394,7 +395,8 @@ gtk_drag_source_set_icon_stock (GtkWidget *widget, site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); g_return_if_fail (site != NULL); - _gtk_icon_helper_set_stock_id (site->icon_helper, stock_id, GTK_ICON_SIZE_DND); + gtk_image_definition_unref (site->image_def); + site->image_def = gtk_image_definition_new_stock (stock_id, GTK_ICON_SIZE_DND); } /** @@ -419,7 +421,8 @@ gtk_drag_source_set_icon_name (GtkWidget *widget, site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); g_return_if_fail (site != NULL); - _gtk_icon_helper_set_icon_name (site->icon_helper, icon_name, GTK_ICON_SIZE_DND); + gtk_image_definition_unref (site->image_def); + site->image_def = gtk_image_definition_new_icon_name (icon_name, GTK_ICON_SIZE_DND); } /** @@ -444,6 +447,7 @@ gtk_drag_source_set_icon_gicon (GtkWidget *widget, site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); g_return_if_fail (site != NULL); - _gtk_icon_helper_set_gicon (site->icon_helper, icon, GTK_ICON_SIZE_DND); + gtk_image_definition_unref (site->image_def); + site->image_def = gtk_image_definition_new_gicon (icon, GTK_ICON_SIZE_DND); } diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c index 8e54bfd8f3..f71c464df5 100644 --- a/gtk/gtkiconhelper.c +++ b/gtk/gtkiconhelper.c @@ -24,7 +24,6 @@ #include #include "gtkcssenumvalueprivate.h" -#include "gtkimagedefinitionprivate.h" #include "gtkrender.h" #include "gtkstylecontextprivate.h" #include "deprecated/gtkstock.h" @@ -912,6 +911,16 @@ _gtk_icon_helper_get_size (GtkIconHelper *self, *height_out = height; } +void +_gtk_icon_helper_set_definition (GtkIconHelper *self, + GtkImageDefinition *def) +{ + if (def) + gtk_icon_helper_take_definition (self, gtk_image_definition_ref (def)); + else + _gtk_icon_helper_clear (self); +} + void _gtk_icon_helper_set_gicon (GtkIconHelper *self, GIcon *gicon, diff --git a/gtk/gtkiconhelperprivate.h b/gtk/gtkiconhelperprivate.h index 7e01d7882a..1e98f29040 100644 --- a/gtk/gtkiconhelperprivate.h +++ b/gtk/gtkiconhelperprivate.h @@ -23,6 +23,8 @@ #include "gtk/gtkimage.h" #include "gtk/gtktypes.h" +#include "gtkimagedefinitionprivate.h" + G_BEGIN_DECLS #define GTK_TYPE_ICON_HELPER _gtk_icon_helper_get_type() @@ -74,6 +76,8 @@ void _gtk_icon_helper_set_window (GtkIconHelper *self, gboolean _gtk_icon_helper_get_is_empty (GtkIconHelper *self); +void _gtk_icon_helper_set_definition (GtkIconHelper *self, + GtkImageDefinition *def); void _gtk_icon_helper_set_gicon (GtkIconHelper *self, GIcon *gicon, GtkIconSize icon_size);