dnd: Add gtk_drag_set_icon_definition()

... and use it for entry icons.

As a side effect, icons dragged from entries will now resize to DND
size.
This commit is contained in:
Benjamin Otte 2015-12-01 17:42:09 +01:00
parent 4a42aa5229
commit 7a154d9acd
4 changed files with 57 additions and 8 deletions

View File

@ -1453,6 +1453,43 @@ set_icon_stock_pixbuf (GdkDragContext *context,
cairo_surface_destroy (surface);
}
void
gtk_drag_set_icon_definition (GdkDragContext *context,
GtkImageDefinition *def,
gint hot_x,
gint hot_y)
{
switch (gtk_image_definition_get_storage_type (def))
{
case GTK_IMAGE_EMPTY:
gtk_drag_set_icon_default (context);
break;
case GTK_IMAGE_PIXBUF:
gtk_drag_set_icon_pixbuf (context,
gtk_image_definition_get_pixbuf (def),
hot_x, hot_y);
break;
case GTK_IMAGE_STOCK:
gtk_drag_set_icon_stock (context,
gtk_image_definition_get_stock (def),
hot_x, hot_y);
break;
case GTK_IMAGE_ICON_NAME:
gtk_drag_set_icon_name (context,
gtk_image_definition_get_icon_name (def),
hot_x, hot_y);
break;
default:
g_warning ("FIXME: setting drag icon of type %u not implemented, using default.", gtk_image_definition_get_storage_type (def));
gtk_drag_set_icon_default (context);
break;
}
}
/**
* gtk_drag_set_icon_pixbuf:
* @context: the context for a drag. (This must be called

View File

@ -2853,6 +2853,18 @@ set_icon_helper (GdkDragContext *context,
}
}
void
gtk_drag_set_icon_definition (GdkDragContext *context,
GtkImageDefinition *def,
gint hot_x,
gint hot_y)
{
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (def != NULL);
set_icon_helper (context, def, hot_x, hot_y, FALSE);
}
/**
* gtk_drag_set_icon_pixbuf: (method)
* @context: the context for a drag (This must be called

View File

@ -35,6 +35,10 @@ GdkDragContext * gtk_drag_begin_internal (GtkWidget
const GdkEvent *event,
int x,
int y);
void gtk_drag_set_icon_definition (GdkDragContext *context,
GtkImageDefinition *def,
gint hot_x,
gint hot_y);
void _gtk_drag_source_handle_event (GtkWidget *widget,
GdkEvent *event);
void _gtk_drag_dest_handle_event (GtkWidget *toplevel,

View File

@ -36,6 +36,7 @@
#include "gtkclipboard.h"
#include "gtkdebug.h"
#include "gtkdnd.h"
#include "gtkdndprivate.h"
#include "gtkentry.h"
#include "gtkentrybuffer.h"
#include "gtkiconhelperprivate.h"
@ -10054,14 +10055,9 @@ gtk_entry_drag_begin (GtkWidget *widget,
{
if (icon_info->in_drag)
{
GdkPixbuf *pix;
pix = _gtk_icon_helper_ensure_pixbuf
(icon_info->icon_helper,
gtk_widget_get_style_context (GTK_WIDGET (entry)));
gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
g_object_unref (pix);
gtk_drag_set_icon_definition (context,
gtk_icon_helper_get_definition (icon_info->icon_helper),
-2, -2);
return;
}
}