forked from AuroraMiddleware/gtk
tests: Convert dnd test to surface apis
Stop using gtk_drag_set_icon_pixbuf in testdnd2. This api is going away.
This commit is contained in:
parent
27e89c69cd
commit
a783470491
@ -1,26 +1,27 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static GdkPixbuf *
|
||||
get_image_pixbuf (GtkImage *image)
|
||||
static cairo_surface_t *
|
||||
get_image_surface (GtkImage *image,
|
||||
int *out_size)
|
||||
{
|
||||
const gchar *icon_name;
|
||||
GtkIconSize size;
|
||||
GtkIconTheme *icon_theme;
|
||||
int width;
|
||||
cairo_surface_t *surface;
|
||||
|
||||
switch (gtk_image_get_storage_type (image))
|
||||
{
|
||||
case GTK_IMAGE_PIXBUF:
|
||||
return g_object_ref (gtk_image_get_pixbuf (image));
|
||||
case GTK_IMAGE_SURFACE:
|
||||
surface = gtk_image_get_surface (image);
|
||||
*out_size = cairo_image_surface_get_width (surface);
|
||||
return cairo_surface_reference (surface);
|
||||
case GTK_IMAGE_ICON_NAME:
|
||||
gtk_image_get_icon_name (image, &icon_name, &size);
|
||||
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (image)));
|
||||
gtk_icon_size_lookup (size, &width, NULL);
|
||||
return gtk_icon_theme_load_icon (icon_theme,
|
||||
icon_name,
|
||||
width,
|
||||
GTK_ICON_LOOKUP_GENERIC_FALLBACK,
|
||||
NULL);
|
||||
*out_size = width;
|
||||
return gtk_icon_theme_load_surface (icon_theme, icon_name, width, 1, NULL, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
|
||||
default:
|
||||
g_warning ("Image storage type %d not handled",
|
||||
gtk_image_get_storage_type (image));
|
||||
@ -44,11 +45,12 @@ image_drag_begin (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
gpointer data)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
cairo_surface_t *surface;
|
||||
gint hotspot;
|
||||
gint hot_x, hot_y;
|
||||
gint size;
|
||||
|
||||
pixbuf = get_image_pixbuf (GTK_IMAGE (data));
|
||||
surface = get_image_surface (GTK_IMAGE (data), &size);
|
||||
hotspot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (data), "hotspot"));
|
||||
switch (hotspot)
|
||||
{
|
||||
@ -58,16 +60,17 @@ image_drag_begin (GtkWidget *widget,
|
||||
hot_y = 0;
|
||||
break;
|
||||
case CENTER:
|
||||
hot_x = gdk_pixbuf_get_width (pixbuf) / 2;
|
||||
hot_y = gdk_pixbuf_get_height (pixbuf) / 2;
|
||||
hot_x = size / 2;
|
||||
hot_y = size / 2;
|
||||
break;
|
||||
case BOTTOM_RIGHT:
|
||||
hot_x = gdk_pixbuf_get_width (pixbuf);
|
||||
hot_y = gdk_pixbuf_get_height (pixbuf);
|
||||
hot_x = size;
|
||||
hot_y = size;
|
||||
break;
|
||||
}
|
||||
gtk_drag_set_icon_pixbuf (context, pixbuf, hot_x, hot_y);
|
||||
g_object_unref (pixbuf);
|
||||
cairo_surface_set_device_offset (surface, hot_x, hot_y);
|
||||
gtk_drag_set_icon_surface (context, surface);
|
||||
cairo_surface_destroy (surface);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -94,9 +97,10 @@ window_drag_begin (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
gpointer data)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
cairo_surface_t *surface;
|
||||
GtkWidget *image;
|
||||
int hotspot;
|
||||
int size;
|
||||
|
||||
hotspot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (data), "hotspot"));
|
||||
|
||||
@ -104,9 +108,9 @@ window_drag_begin (GtkWidget *widget,
|
||||
if (image == NULL)
|
||||
{
|
||||
g_print ("creating new drag widget\n");
|
||||
pixbuf = get_image_pixbuf (GTK_IMAGE (data));
|
||||
image = gtk_image_new_from_pixbuf (pixbuf);
|
||||
g_object_unref (pixbuf);
|
||||
surface = get_image_surface (GTK_IMAGE (data), &size);
|
||||
image = gtk_image_new_from_surface (surface);
|
||||
cairo_surface_destroy (surface);
|
||||
g_object_ref (image);
|
||||
g_object_set_data (G_OBJECT (widget), "drag widget", image);
|
||||
g_signal_connect (image, "destroy", G_CALLBACK (drag_widget_destroyed), widget);
|
||||
@ -159,15 +163,15 @@ image_drag_data_get (GtkWidget *widget,
|
||||
guint time,
|
||||
gpointer data)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
cairo_surface_t *surface;
|
||||
const gchar *name;
|
||||
int size;
|
||||
|
||||
switch (info)
|
||||
{
|
||||
case TARGET_IMAGE:
|
||||
pixbuf = get_image_pixbuf (GTK_IMAGE (data));
|
||||
gtk_selection_data_set_pixbuf (selection_data, pixbuf);
|
||||
g_object_unref (pixbuf);
|
||||
surface = get_image_surface (GTK_IMAGE (data), &size);
|
||||
gtk_selection_data_set_surface (selection_data, surface);
|
||||
break;
|
||||
case TARGET_TEXT:
|
||||
if (gtk_image_get_storage_type (GTK_IMAGE (data)) == GTK_IMAGE_ICON_NAME)
|
||||
@ -191,7 +195,7 @@ image_drag_data_received (GtkWidget *widget,
|
||||
guint32 time,
|
||||
gpointer data)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
cairo_surface_t *surface;
|
||||
gchar *text;
|
||||
|
||||
if (gtk_selection_data_get_length (selection_data) == 0)
|
||||
@ -200,9 +204,9 @@ image_drag_data_received (GtkWidget *widget,
|
||||
switch (info)
|
||||
{
|
||||
case TARGET_IMAGE:
|
||||
pixbuf = gtk_selection_data_get_pixbuf (selection_data);
|
||||
gtk_image_set_from_pixbuf (GTK_IMAGE (data), pixbuf);
|
||||
g_object_unref (pixbuf);
|
||||
surface = gtk_selection_data_get_surface (selection_data);
|
||||
gtk_image_set_from_surface (GTK_IMAGE (data), surface);
|
||||
cairo_surface_destroy (surface);
|
||||
break;
|
||||
case TARGET_TEXT:
|
||||
text = (gchar *)gtk_selection_data_get_text (selection_data);
|
||||
|
Loading…
Reference in New Issue
Block a user