summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-12-01 17:42:09 +0100
committerBenjamin Otte <otte@redhat.com>2015-12-02 00:29:30 +0100
commit7a154d9acd7a4b496c12a925ddea1d24b8efffd9 (patch)
treed9bcc077c0e0d29eb7a20abd1a5d32f3a3ba26b0
parent4a42aa5229e0ba80cf4673c67575ef57d60ae6c5 (diff)
downloadgtk+-7a154d9acd7a4b496c12a925ddea1d24b8efffd9.tar.gz
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.
-rw-r--r--gtk/gtkdnd-quartz.c37
-rw-r--r--gtk/gtkdnd.c12
-rw-r--r--gtk/gtkdndprivate.h4
-rw-r--r--gtk/gtkentry.c12
4 files changed, 57 insertions, 8 deletions
diff --git a/gtk/gtkdnd-quartz.c b/gtk/gtkdnd-quartz.c
index eb5fa95dc7..7505482a63 100644
--- a/gtk/gtkdnd-quartz.c
+++ b/gtk/gtkdnd-quartz.c
@@ -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
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 81abab0dca..d29e2f6370 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -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
diff --git a/gtk/gtkdndprivate.h b/gtk/gtkdndprivate.h
index 43df858b86..016f2634dc 100644
--- a/gtk/gtkdndprivate.h
+++ b/gtk/gtkdndprivate.h
@@ -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,
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index ff608693c8..68704532e5 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -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;
}
}