2 * Copyright (C) 2004 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 drag_begin (GtkWidget *widget,
25 GdkDragContext *context,
28 GtkWidget *image = GTK_WIDGET (data);
30 GdkPixbuf *pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (image));
32 gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
36 drag_data_get (GtkWidget *widget,
37 GdkDragContext *context,
38 GtkSelectionData *selection_data,
43 GtkWidget *image = GTK_WIDGET (data);
45 GdkPixbuf *pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (image));
47 gtk_selection_data_set_pixbuf (selection_data, pixbuf);
51 drag_data_received (GtkWidget *widget,
52 GdkDragContext *context,
55 GtkSelectionData *selection_data,
60 GtkWidget *image = GTK_WIDGET (data);
64 if (gtk_selection_data_get_length (selection_data) < 0)
67 pixbuf = gtk_selection_data_get_pixbuf (selection_data);
69 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
73 idle_func (gpointer data)
75 g_print ("keep me busy\n");
81 anim_image_draw (GtkWidget *widget,
85 g_print ("start busyness\n");
87 g_signal_handlers_disconnect_by_func (widget, anim_image_draw, data);
89 /* produce high load */
90 g_idle_add_full (G_PRIORITY_DEFAULT,
91 idle_func, NULL, NULL);
97 main (int argc, char **argv)
99 GtkWidget *window, *grid;
100 GtkWidget *label, *image, *box;
104 GtkIconSource *iconsource;
105 gchar *icon_name = "gnome-terminal";
106 gchar *anim_filename = NULL;
110 gtk_init (&argc, &argv);
116 anim_filename = argv[2];
118 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
119 grid = gtk_grid_new ();
120 gtk_container_add (GTK_CONTAINER (window), grid);
122 label = gtk_label_new ("symbolic size");
123 gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
124 label = gtk_label_new ("fixed size");
125 gtk_grid_attach (GTK_GRID (grid), label, 2, 0, 1, 1);
127 label = gtk_label_new ("GTK_IMAGE_PIXBUF");
128 gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
130 theme = gtk_icon_theme_get_default ();
131 pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 48, 0, NULL);
132 image = gtk_image_new_from_pixbuf (pixbuf);
133 box = gtk_event_box_new ();
134 gtk_container_add (GTK_CONTAINER (box), image);
135 gtk_grid_attach (GTK_GRID (grid), box, 2, 1, 1, 1);
137 gtk_drag_source_set (box, GDK_BUTTON1_MASK,
140 gtk_drag_source_add_image_targets (box);
141 g_signal_connect (box, "drag_begin", G_CALLBACK (drag_begin), image);
142 g_signal_connect (box, "drag_data_get", G_CALLBACK (drag_data_get), image);
144 gtk_drag_dest_set (box,
145 GTK_DEST_DEFAULT_MOTION |
146 GTK_DEST_DEFAULT_HIGHLIGHT |
147 GTK_DEST_DEFAULT_DROP,
148 NULL, 0, GDK_ACTION_COPY);
149 gtk_drag_dest_add_image_targets (box);
150 g_signal_connect (box, "drag_data_received",
151 G_CALLBACK (drag_data_received), image);
153 label = gtk_label_new ("GTK_IMAGE_STOCK");
154 gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
156 image = gtk_image_new_from_stock (GTK_STOCK_REDO, GTK_ICON_SIZE_DIALOG);
157 gtk_grid_attach (GTK_GRID (grid), image, 1, 2, 1, 1);
159 label = gtk_label_new ("GTK_IMAGE_ICON_SET");
160 gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
162 iconsource = gtk_icon_source_new ();
163 gtk_icon_source_set_icon_name (iconsource, icon_name);
164 iconset = gtk_icon_set_new ();
165 gtk_icon_set_add_source (iconset, iconsource);
166 image = gtk_image_new_from_icon_set (iconset, GTK_ICON_SIZE_DIALOG);
167 gtk_grid_attach (GTK_GRID (grid), image, 1, 3, 1, 1);
169 label = gtk_label_new ("GTK_IMAGE_ICON_NAME");
170 gtk_grid_attach (GTK_GRID (grid), label, 0, 4, 1, 1);
171 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_DIALOG);
172 gtk_grid_attach (GTK_GRID (grid), image, 1, 4, 1, 1);
173 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_DIALOG);
174 gtk_image_set_pixel_size (GTK_IMAGE (image), 30);
175 gtk_grid_attach (GTK_GRID (grid), image, 2, 4, 1, 1);
177 label = gtk_label_new ("GTK_IMAGE_GICON");
178 gtk_grid_attach (GTK_GRID (grid), label, 0, 5, 1, 1);
179 icon = g_themed_icon_new_with_default_fallbacks ("folder-remote");
180 image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
181 g_object_unref (icon);
182 gtk_grid_attach (GTK_GRID (grid), image, 1, 5, 1, 1);
183 file = g_file_new_for_path ("apple-red.png");
184 icon = g_file_icon_new (file);
185 image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
186 g_object_unref (icon);
187 gtk_image_set_pixel_size (GTK_IMAGE (image), 30);
188 gtk_grid_attach (GTK_GRID (grid), image, 2, 5, 1, 1);
193 label = gtk_label_new ("GTK_IMAGE_ANIMATION (from file)");
194 gtk_grid_attach (GTK_GRID (grid), label, 0, 6, 1, 1);
195 image = gtk_image_new_from_file (anim_filename);
196 gtk_image_set_pixel_size (GTK_IMAGE (image), 30);
197 gtk_grid_attach (GTK_GRID (grid), image, 2, 6, 1, 1);
199 /* produce high load */
200 g_signal_connect_after (image, "draw",
201 G_CALLBACK (anim_image_draw),
205 gtk_widget_show_all (window);