summaryrefslogtreecommitdiff
path: root/tests/testdnd2.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-03-15 02:59:03 +0100
committerBenjamin Otte <otte@redhat.com>2018-03-16 06:04:45 +0100
commit01f996447e15094f72d14addb1634623bebb61c1 (patch)
tree0a074d4a23ad4ce15065da52774997237c50fde7 /tests/testdnd2.c
parenta8608618a909e50309a400c9c857aadd2e1afa6d (diff)
downloadgtk+-01f996447e15094f72d14addb1634623bebb61c1.tar.gz
tests: Port from surface to texture
Diffstat (limited to 'tests/testdnd2.c')
-rw-r--r--tests/testdnd2.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/tests/testdnd2.c b/tests/testdnd2.c
index 17d6fee9cc..7fee35c7cc 100644
--- a/tests/testdnd2.c
+++ b/tests/testdnd2.c
@@ -1,25 +1,29 @@
#include <gtk/gtk.h>
-static cairo_surface_t *
-get_image_surface (GtkImage *image,
+static GdkTexture *
+get_image_texture (GtkImage *image,
int *out_size)
{
GtkIconTheme *icon_theme;
const char *icon_name;
int width = 48;
- cairo_surface_t *surface;
+ GdkTexture *texture;
+ GtkIconInfo *icon_info;
switch (gtk_image_get_storage_type (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_PAINTABLE:
+ paintable = gtk_image_get_paintable (image);
+ *out_size = gdk_paintable_get_intrinsic_width (paintable);
+ return g_object_ref (paintable);
case GTK_IMAGE_ICON_NAME:
icon_name = gtk_image_get_icon_name (image);
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image)));
*out_size = width;
- return gtk_icon_theme_load_surface (icon_theme, icon_name, width, 1, NULL, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, width, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
+ texture = gtk_icon_info_load_texture (icon_info);
+ g_object_unref (icon_info);
+ return texture;
default:
g_warning ("Image storage type %d not handled",
gtk_image_get_storage_type (image));
@@ -38,12 +42,12 @@ image_drag_begin (GtkWidget *widget,
GdkDragContext *context,
gpointer data)
{
- cairo_surface_t *surface;
+ GdkTexture *texture;
gint hotspot;
gint hot_x, hot_y;
gint size;
- surface = get_image_surface (GTK_IMAGE (data), &size);
+ texture = get_image_texture (GTK_IMAGE (data), &size);
hotspot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (data), "hotspot"));
switch (hotspot)
{
@@ -61,9 +65,8 @@ image_drag_begin (GtkWidget *widget,
hot_y = size;
break;
}
- cairo_surface_set_device_offset (surface, hot_x, hot_y);
- gtk_drag_set_icon_surface (context, surface);
- cairo_surface_destroy (surface);
+ gtk_drag_set_icon_paintable (context, GDK_PAINTABLE (texture), hot_x, hot_y);
+ g_object_unref (texture);
}
static void
@@ -90,7 +93,7 @@ window_drag_begin (GtkWidget *widget,
GdkDragContext *context,
gpointer data)
{
- cairo_surface_t *surface;
+ GdkTexture *texture;
GtkWidget *image;
int hotspot;
int size;
@@ -101,9 +104,9 @@ window_drag_begin (GtkWidget *widget,
if (image == NULL)
{
g_print ("creating new drag widget\n");
- surface = get_image_surface (GTK_IMAGE (data), &size);
- image = gtk_image_new_from_surface (surface);
- cairo_surface_destroy (surface);
+ texture = get_image_texture (GTK_IMAGE (data), &size);
+ image = gtk_image_new_from_texture (texture);
+ g_object_unref (texture);
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);
@@ -155,14 +158,15 @@ image_drag_data_get (GtkWidget *widget,
guint time,
gpointer data)
{
- cairo_surface_t *surface;
+ GdkTexture *texture;
const gchar *name;
int size;
if (gtk_selection_data_targets_include_image (selection_data, TRUE))
{
- surface = get_image_surface (GTK_IMAGE (data), &size);
- gtk_selection_data_set_surface (selection_data, surface);
+ texture = get_image_texture (GTK_IMAGE (data), &size);
+ gtk_selection_data_set_texture (selection_data, texture);
+ g_object_unref (texture);
}
else if (gtk_selection_data_targets_include_text (selection_data))
{
@@ -185,7 +189,6 @@ image_drag_data_received (GtkWidget *widget,
guint32 time,
gpointer data)
{
- cairo_surface_t *surface;
gchar *text;
if (gtk_selection_data_get_length (selection_data) == 0)
@@ -193,9 +196,12 @@ image_drag_data_received (GtkWidget *widget,
if (gtk_selection_data_targets_include_image (selection_data, FALSE))
{
- surface = gtk_selection_data_get_surface (selection_data);
- gtk_image_set_from_surface (GTK_IMAGE (data), surface);
- cairo_surface_destroy (surface);
+ GdkTexture *texture;
+
+ texture = gtk_selection_data_get_texture (selection_data);
+ gtk_image_set_from_texture (GTK_IMAGE (data), texture);
+
+ g_object_unref (texture);
}
else if (gtk_selection_data_targets_include_text (selection_data))
{