mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 14:30:15 +00:00
dragsource: Store an itemdefinition, not an iconhelper
The icon is never rendered, so there's no need for the extra iconhelper code.
This commit is contained in:
parent
e666106a43
commit
1c96b703a6
25
gtk/gtkdnd.c
25
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);
|
||||
|
@ -23,12 +23,12 @@
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include <gtk/gtkselection.h>
|
||||
|
||||
#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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <math.h>
|
||||
|
||||
#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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user