mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-16 15:14:17 +00:00
gtk-demo: Use surface apis in the clipboard demo
Stop using gtk_drag_set_icon_pixbuf. This api is going away.
This commit is contained in:
parent
a783470491
commit
ff6698cf5f
@ -64,8 +64,8 @@ paste_button_clicked (GtkWidget *button,
|
|||||||
paste_received, entry);
|
paste_received, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GdkPixbuf *
|
static cairo_surface_t *
|
||||||
get_image_pixbuf (GtkImage *image)
|
get_image_surface (GtkImage *image)
|
||||||
{
|
{
|
||||||
const gchar *icon_name;
|
const gchar *icon_name;
|
||||||
GtkIconSize size;
|
GtkIconSize size;
|
||||||
@ -74,17 +74,13 @@ get_image_pixbuf (GtkImage *image)
|
|||||||
|
|
||||||
switch (gtk_image_get_storage_type (image))
|
switch (gtk_image_get_storage_type (image))
|
||||||
{
|
{
|
||||||
case GTK_IMAGE_PIXBUF:
|
case GTK_IMAGE_SURFACE:
|
||||||
return g_object_ref (gtk_image_get_pixbuf (image));
|
return cairo_surface_reference (gtk_image_get_surface (image));
|
||||||
case GTK_IMAGE_ICON_NAME:
|
case GTK_IMAGE_ICON_NAME:
|
||||||
gtk_image_get_icon_name (image, &icon_name, &size);
|
gtk_image_get_icon_name (image, &icon_name, &size);
|
||||||
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (image)));
|
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (image)));
|
||||||
gtk_icon_size_lookup (size, &width, NULL);
|
gtk_icon_size_lookup (size, &width, NULL);
|
||||||
return gtk_icon_theme_load_icon (icon_theme,
|
return gtk_icon_theme_load_surface (icon_theme, icon_name, width, 1, NULL, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
|
||||||
icon_name,
|
|
||||||
width,
|
|
||||||
GTK_ICON_LOOKUP_GENERIC_FALLBACK,
|
|
||||||
NULL);
|
|
||||||
default:
|
default:
|
||||||
g_warning ("Image storage type %d not handled",
|
g_warning ("Image storage type %d not handled",
|
||||||
gtk_image_get_storage_type (image));
|
gtk_image_get_storage_type (image));
|
||||||
@ -97,11 +93,14 @@ drag_begin (GtkWidget *widget,
|
|||||||
GdkDragContext *context,
|
GdkDragContext *context,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
cairo_surface_t *surface;
|
||||||
|
|
||||||
pixbuf = get_image_pixbuf (GTK_IMAGE (data));
|
surface = get_image_surface (GTK_IMAGE (widget));
|
||||||
gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
|
if (surface)
|
||||||
g_object_unref (pixbuf);
|
{
|
||||||
|
cairo_surface_set_device_offset (surface, -2, -2);
|
||||||
|
gtk_drag_set_icon_surface (context, surface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -112,11 +111,11 @@ drag_data_get (GtkWidget *widget,
|
|||||||
guint time,
|
guint time,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
cairo_surface_t *surface;
|
||||||
|
|
||||||
pixbuf = get_image_pixbuf (GTK_IMAGE (data));
|
surface = get_image_surface (GTK_IMAGE (data));
|
||||||
gtk_selection_data_set_pixbuf (selection_data, pixbuf);
|
if (surface)
|
||||||
g_object_unref (pixbuf);
|
gtk_selection_data_set_surface (selection_data, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -129,13 +128,13 @@ drag_data_received (GtkWidget *widget,
|
|||||||
guint32 time,
|
guint32 time,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
|
||||||
|
|
||||||
if (gtk_selection_data_get_length (selection_data) > 0)
|
if (gtk_selection_data_get_length (selection_data) > 0)
|
||||||
{
|
{
|
||||||
pixbuf = gtk_selection_data_get_pixbuf (selection_data);
|
cairo_surface_t *surface;
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,13 +143,16 @@ copy_image (GtkMenuItem *item,
|
|||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GtkClipboard *clipboard;
|
GtkClipboard *clipboard;
|
||||||
GdkPixbuf *pixbuf;
|
cairo_surface_t *surface;
|
||||||
|
|
||||||
clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
|
clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
|
||||||
pixbuf = get_image_pixbuf (GTK_IMAGE (data));
|
surface = get_image_surface (GTK_IMAGE (data));
|
||||||
|
|
||||||
gtk_clipboard_set_image (clipboard, pixbuf);
|
if (surface)
|
||||||
g_object_unref (pixbuf);
|
{
|
||||||
|
gtk_clipboard_set_surface (clipboard, surface);
|
||||||
|
cairo_surface_destroy (surface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -158,15 +160,15 @@ paste_image (GtkMenuItem *item,
|
|||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GtkClipboard *clipboard;
|
GtkClipboard *clipboard;
|
||||||
GdkPixbuf *pixbuf;
|
cairo_surface_t *surface;
|
||||||
|
|
||||||
clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
|
clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
|
||||||
pixbuf = gtk_clipboard_wait_for_image (clipboard);
|
surface = gtk_clipboard_wait_for_surface (clipboard);
|
||||||
|
|
||||||
if (pixbuf)
|
if (surface)
|
||||||
{
|
{
|
||||||
gtk_image_set_from_pixbuf (GTK_IMAGE (data), pixbuf);
|
gtk_image_set_from_surface (GTK_IMAGE (data), surface);
|
||||||
g_object_unref (pixbuf);
|
cairo_surface_destroy (surface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user