2004-10-25 04:36:39 +00:00
|
|
|
/* testimage.c
|
|
|
|
* Copyright (C) 2004 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2004-10-25 04:36:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2008-05-29 14:33:49 +00:00
|
|
|
#include <gio/gio.h>
|
2004-10-25 04:36:39 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
drag_begin (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *image = GTK_WIDGET (data);
|
2018-03-16 03:29:42 +00:00
|
|
|
GdkPaintable *paintable;
|
2004-10-25 04:36:39 +00:00
|
|
|
|
2018-03-16 03:29:42 +00:00
|
|
|
paintable = gtk_image_get_paintable (GTK_IMAGE (image));
|
|
|
|
gtk_drag_set_icon_paintable (context, paintable, -2, -2);
|
2004-10-25 04:36:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
drag_data_get (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint time,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *image = GTK_WIDGET (data);
|
2018-03-16 03:29:42 +00:00
|
|
|
GdkPaintable *paintable;
|
2004-10-25 04:36:39 +00:00
|
|
|
|
2018-03-16 03:29:42 +00:00
|
|
|
paintable = gtk_image_get_paintable (GTK_IMAGE (image));
|
|
|
|
if (GDK_IS_TEXTURE (paintable))
|
|
|
|
gtk_selection_data_set_texture (selection_data, GDK_TEXTURE (paintable));
|
2004-10-25 04:36:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_data_received (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint32 time,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *image = GTK_WIDGET (data);
|
2018-03-15 01:59:03 +00:00
|
|
|
GdkTexture *texture;
|
2004-10-25 04:36:39 +00:00
|
|
|
|
2010-12-15 23:47:45 +00:00
|
|
|
if (gtk_selection_data_get_length (selection_data) < 0)
|
2004-10-25 04:36:39 +00:00
|
|
|
return;
|
|
|
|
|
2018-03-15 01:59:03 +00:00
|
|
|
texture = gtk_selection_data_get_texture (selection_data);
|
2018-03-16 03:29:42 +00:00
|
|
|
gtk_image_set_from_paintable (GTK_IMAGE (image), GDK_PAINTABLE (texture));
|
2004-10-25 04:36:39 +00:00
|
|
|
|
2018-03-15 01:59:03 +00:00
|
|
|
g_object_unref (texture);
|
2004-10-25 04:36:39 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 14:40:41 +00:00
|
|
|
static gboolean
|
|
|
|
idle_func (gpointer data)
|
|
|
|
{
|
|
|
|
g_print ("keep me busy\n");
|
|
|
|
|
2012-01-31 00:12:27 +00:00
|
|
|
return G_SOURCE_CONTINUE;
|
2005-11-16 14:40:41 +00:00
|
|
|
}
|
|
|
|
|
2004-10-25 04:36:39 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2011-09-27 18:24:13 +00:00
|
|
|
GtkWidget *window, *grid;
|
2017-08-01 22:49:42 +00:00
|
|
|
GtkWidget *label, *image;
|
2004-10-25 04:36:39 +00:00
|
|
|
GtkIconTheme *theme;
|
2018-03-15 01:59:03 +00:00
|
|
|
GdkTexture *texture;
|
2017-10-23 03:41:29 +00:00
|
|
|
gchar *icon_name = "help-browser";
|
2005-11-16 14:40:41 +00:00
|
|
|
gchar *anim_filename = NULL;
|
2018-03-15 01:59:03 +00:00
|
|
|
GtkIconInfo *icon_info;
|
2008-05-29 14:33:49 +00:00
|
|
|
GIcon *icon;
|
|
|
|
GFile *file;
|
2005-11-16 14:40:41 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2004-10-25 04:36:39 +00:00
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
icon_name = argv[1];
|
|
|
|
|
2005-11-16 14:40:41 +00:00
|
|
|
if (argc > 2)
|
|
|
|
anim_filename = argv[2];
|
|
|
|
|
2004-10-25 04:36:39 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2014-03-14 17:45:47 +00:00
|
|
|
|
2011-09-27 18:24:13 +00:00
|
|
|
grid = gtk_grid_new ();
|
2017-10-23 03:41:29 +00:00
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 10);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 10);
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), grid);
|
2004-10-25 04:36:39 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("symbolic size");
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
|
2004-10-25 04:36:39 +00:00
|
|
|
label = gtk_label_new ("fixed size");
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 2, 0, 1, 1);
|
2004-10-25 04:36:39 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("GTK_IMAGE_PIXBUF");
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
|
2004-10-25 04:36:39 +00:00
|
|
|
|
|
|
|
theme = gtk_icon_theme_get_default ();
|
2018-03-15 01:59:03 +00:00
|
|
|
icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, icon_name, 48, gtk_widget_get_scale_factor (window), GTK_ICON_LOOKUP_GENERIC_FALLBACK);
|
|
|
|
texture = gtk_icon_info_load_texture (icon_info);
|
|
|
|
g_object_unref (icon_info);
|
2018-03-16 03:29:42 +00:00
|
|
|
image = gtk_image_new_from_paintable (GDK_PAINTABLE (texture));
|
2018-03-15 01:59:03 +00:00
|
|
|
g_object_unref (texture);
|
2017-08-01 22:49:42 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), image, 2, 1, 1, 1);
|
2004-10-25 04:36:39 +00:00
|
|
|
|
2017-08-01 22:49:42 +00:00
|
|
|
gtk_drag_source_set (image, GDK_BUTTON1_MASK,
|
2017-11-14 21:32:23 +00:00
|
|
|
NULL,
|
2004-10-25 04:36:39 +00:00
|
|
|
GDK_ACTION_COPY);
|
2017-08-01 22:49:42 +00:00
|
|
|
gtk_drag_source_add_image_targets (image);
|
|
|
|
g_signal_connect (image, "drag_begin", G_CALLBACK (drag_begin), image);
|
|
|
|
g_signal_connect (image, "drag_data_get", G_CALLBACK (drag_data_get), image);
|
2004-10-25 04:36:39 +00:00
|
|
|
|
2017-08-01 22:49:42 +00:00
|
|
|
gtk_drag_dest_set (image,
|
2004-10-25 04:36:39 +00:00
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
2017-11-14 21:32:23 +00:00
|
|
|
NULL, GDK_ACTION_COPY);
|
2017-08-01 22:49:42 +00:00
|
|
|
gtk_drag_dest_add_image_targets (image);
|
|
|
|
g_signal_connect (image, "drag_data_received",
|
2004-10-25 04:36:39 +00:00
|
|
|
G_CALLBACK (drag_data_received), image);
|
|
|
|
|
|
|
|
label = gtk_label_new ("GTK_IMAGE_ICON_NAME");
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 4, 1, 1);
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name (icon_name);
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), image, 1, 4, 1, 1);
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name (icon_name);
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
2004-10-25 04:36:39 +00:00
|
|
|
gtk_image_set_pixel_size (GTK_IMAGE (image), 30);
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), image, 2, 4, 1, 1);
|
2005-11-16 14:40:41 +00:00
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
label = gtk_label_new ("GTK_IMAGE_GICON");
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 5, 1, 1);
|
2008-05-29 14:33:49 +00:00
|
|
|
icon = g_themed_icon_new_with_default_fallbacks ("folder-remote");
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_gicon (icon);
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
2008-05-29 14:33:49 +00:00
|
|
|
g_object_unref (icon);
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), image, 1, 5, 1, 1);
|
2008-05-29 14:33:49 +00:00
|
|
|
file = g_file_new_for_path ("apple-red.png");
|
|
|
|
icon = g_file_icon_new (file);
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_gicon (icon);
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
2008-05-29 14:33:49 +00:00
|
|
|
g_object_unref (icon);
|
|
|
|
gtk_image_set_pixel_size (GTK_IMAGE (image), 30);
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), image, 2, 5, 1, 1);
|
2008-05-29 14:33:49 +00:00
|
|
|
|
2005-11-16 14:40:41 +00:00
|
|
|
if (anim_filename)
|
|
|
|
{
|
|
|
|
label = gtk_label_new ("GTK_IMAGE_ANIMATION (from file)");
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 6, 1, 1);
|
2005-11-16 14:40:41 +00:00
|
|
|
image = gtk_image_new_from_file (anim_filename);
|
|
|
|
gtk_image_set_pixel_size (GTK_IMAGE (image), 30);
|
2011-09-27 18:24:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), image, 2, 6, 1, 1);
|
2005-11-16 14:40:41 +00:00
|
|
|
|
|
|
|
/* produce high load */
|
2016-11-18 06:15:12 +00:00
|
|
|
g_idle_add_full (G_PRIORITY_DEFAULT,
|
|
|
|
idle_func, NULL, NULL);
|
2005-11-16 14:40:41 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2004-10-25 04:36:39 +00:00
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|