1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser 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.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include <pango/pango-utils.h> /* For pango_scan_* */
32 #include "gtkiconfactory.h"
33 #include "gtkiconcache.h"
35 #include "gtkicontheme.h"
36 #include "gtksettings.h"
38 #include "gtkwidget.h"
43 static GSList *all_icon_factories = NULL;
46 GTK_ICON_SOURCE_EMPTY,
47 GTK_ICON_SOURCE_ICON_NAME,
48 GTK_ICON_SOURCE_STATIC_ICON_NAME,
49 GTK_ICON_SOURCE_FILENAME,
50 GTK_ICON_SOURCE_PIXBUF
55 GtkIconSourceType type;
63 GdkPixbuf *filename_pixbuf;
65 GtkTextDirection direction;
69 /* If TRUE, then the parameter is wildcarded, and the above
70 * fields should be ignored. If FALSE, the parameter is
71 * specified, and the above fields should be valid.
73 guint any_direction : 1;
78 /* System codepage version of filename, for DLL ABI backward
79 * compatibility functions.
86 static void gtk_icon_factory_finalize (GObject *object);
87 static void get_default_icons (GtkIconFactory *icon_factory);
88 static void icon_source_clear (GtkIconSource *source);
90 static GtkIconSize icon_size_register_intern (const gchar *name,
94 #define GTK_ICON_SOURCE_INIT(any_direction, any_state, any_size) \
95 { GTK_ICON_SOURCE_EMPTY, { NULL }, NULL, \
97 any_direction, any_state, any_size }
99 G_DEFINE_TYPE (GtkIconFactory, gtk_icon_factory, G_TYPE_OBJECT)
102 gtk_icon_factory_init (GtkIconFactory *factory)
104 factory->icons = g_hash_table_new (g_str_hash, g_str_equal);
105 all_icon_factories = g_slist_prepend (all_icon_factories, factory);
109 gtk_icon_factory_class_init (GtkIconFactoryClass *klass)
111 GObjectClass *object_class = G_OBJECT_CLASS (klass);
113 object_class->finalize = gtk_icon_factory_finalize;
117 free_icon_set (gpointer key, gpointer value, gpointer data)
120 gtk_icon_set_unref (value);
124 gtk_icon_factory_finalize (GObject *object)
126 GtkIconFactory *factory = GTK_ICON_FACTORY (object);
128 all_icon_factories = g_slist_remove (all_icon_factories, factory);
130 g_hash_table_foreach (factory->icons, free_icon_set, NULL);
132 g_hash_table_destroy (factory->icons);
134 G_OBJECT_CLASS (gtk_icon_factory_parent_class)->finalize (object);
138 * gtk_icon_factory_new:
140 * Creates a new #GtkIconFactory. An icon factory manages a collection
141 * of #GtkIconSet<!-- -->s; a #GtkIconSet manages a set of variants of a
142 * particular icon (i.e. a #GtkIconSet contains variants for different
143 * sizes and widget states). Icons in an icon factory are named by a
144 * stock ID, which is a simple string identifying the icon. Each
145 * #GtkStyle has a list of #GtkIconFactory<!-- -->s derived from the current
146 * theme; those icon factories are consulted first when searching for
147 * an icon. If the theme doesn't set a particular icon, GTK+ looks for
148 * the icon in a list of default icon factories, maintained by
149 * gtk_icon_factory_add_default() and
150 * gtk_icon_factory_remove_default(). Applications with icons should
151 * add a default icon factory with their icons, which will allow
152 * themes to override the icons for the application.
154 * Return value: a new #GtkIconFactory
157 gtk_icon_factory_new (void)
159 return g_object_new (GTK_TYPE_ICON_FACTORY, NULL);
163 * gtk_icon_factory_add:
164 * @factory: a #GtkIconFactory
165 * @stock_id: icon name
166 * @icon_set: icon set
168 * Adds the given @icon_set to the icon factory, under the name
169 * @stock_id. @stock_id should be namespaced for your application,
170 * e.g. "myapp-whatever-icon". Normally applications create a
171 * #GtkIconFactory, then add it to the list of default factories with
172 * gtk_icon_factory_add_default(). Then they pass the @stock_id to
173 * widgets such as #GtkImage to display the icon. Themes can provide
174 * an icon with the same name (such as "myapp-whatever-icon") to
175 * override your application's default icons. If an icon already
176 * existed in @factory for @stock_id, it is unreferenced and replaced
177 * with the new @icon_set.
181 gtk_icon_factory_add (GtkIconFactory *factory,
182 const gchar *stock_id,
183 GtkIconSet *icon_set)
185 gpointer old_key = NULL;
186 gpointer old_value = NULL;
188 g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
189 g_return_if_fail (stock_id != NULL);
190 g_return_if_fail (icon_set != NULL);
192 g_hash_table_lookup_extended (factory->icons, stock_id,
193 &old_key, &old_value);
195 if (old_value == icon_set)
198 gtk_icon_set_ref (icon_set);
200 /* GHashTable key memory management is so fantastically broken. */
202 g_hash_table_insert (factory->icons, old_key, icon_set);
204 g_hash_table_insert (factory->icons, g_strdup (stock_id), icon_set);
207 gtk_icon_set_unref (old_value);
211 * gtk_icon_factory_lookup:
212 * @factory: a #GtkIconFactory
213 * @stock_id: an icon name
215 * Looks up @stock_id in the icon factory, returning an icon set
216 * if found, otherwise %NULL. For display to the user, you should
217 * use gtk_style_lookup_icon_set() on the #GtkStyle for the
218 * widget that will display the icon, instead of using this
219 * function directly, so that themes are taken into account.
221 * Return value: icon set of @stock_id.
224 gtk_icon_factory_lookup (GtkIconFactory *factory,
225 const gchar *stock_id)
227 g_return_val_if_fail (GTK_IS_ICON_FACTORY (factory), NULL);
228 g_return_val_if_fail (stock_id != NULL, NULL);
230 return g_hash_table_lookup (factory->icons, stock_id);
233 static GtkIconFactory *gtk_default_icons = NULL;
234 static GSList *default_factories = NULL;
237 * gtk_icon_factory_add_default:
238 * @factory: a #GtkIconFactory
240 * Adds an icon factory to the list of icon factories searched by
241 * gtk_style_lookup_icon_set(). This means that, for example,
242 * gtk_image_new_from_stock() will be able to find icons in @factory.
243 * There will normally be an icon factory added for each library or
244 * application that comes with icons. The default icon factories
245 * can be overridden by themes.
249 gtk_icon_factory_add_default (GtkIconFactory *factory)
251 g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
253 g_object_ref (factory);
255 default_factories = g_slist_prepend (default_factories, factory);
259 * gtk_icon_factory_remove_default:
260 * @factory: a #GtkIconFactory previously added with gtk_icon_factory_add_default()
262 * Removes an icon factory from the list of default icon
263 * factories. Not normally used; you might use it for a library that
264 * can be unloaded or shut down.
268 gtk_icon_factory_remove_default (GtkIconFactory *factory)
270 g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
272 default_factories = g_slist_remove (default_factories, factory);
274 g_object_unref (factory);
278 _gtk_icon_factory_ensure_default_icons (void)
280 if (gtk_default_icons == NULL)
282 gtk_default_icons = gtk_icon_factory_new ();
284 get_default_icons (gtk_default_icons);
289 * gtk_icon_factory_lookup_default:
290 * @stock_id: an icon name
292 * Looks for an icon in the list of default icon factories. For
293 * display to the user, you should use gtk_style_lookup_icon_set() on
294 * the #GtkStyle for the widget that will display the icon, instead of
295 * using this function directly, so that themes are taken into
299 * Return value: a #GtkIconSet, or %NULL
302 gtk_icon_factory_lookup_default (const gchar *stock_id)
306 g_return_val_if_fail (stock_id != NULL, NULL);
308 tmp_list = default_factories;
309 while (tmp_list != NULL)
311 GtkIconSet *icon_set =
312 gtk_icon_factory_lookup (GTK_ICON_FACTORY (tmp_list->data),
318 tmp_list = g_slist_next (tmp_list);
321 _gtk_icon_factory_ensure_default_icons ();
323 return gtk_icon_factory_lookup (gtk_default_icons, stock_id);
327 register_stock_icon (GtkIconFactory *factory,
328 const gchar *stock_id)
330 GtkIconSet *set = gtk_icon_set_new ();
331 GtkIconSource source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
333 source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
334 source.source.icon_name = (gchar *)stock_id;
335 gtk_icon_set_add_source (set, &source);
337 gtk_icon_factory_add (factory, stock_id, set);
338 gtk_icon_set_unref (set);
342 register_bidi_stock_icon (GtkIconFactory *factory,
343 const gchar *stock_id,
344 const gchar *stock_id_ltr,
345 const gchar *stock_id_rtl)
347 GtkIconSet *set = gtk_icon_set_new ();
348 GtkIconSource source = GTK_ICON_SOURCE_INIT (FALSE, TRUE, TRUE);
350 source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
351 source.source.icon_name = (gchar *)stock_id_ltr;
352 source.direction = GTK_TEXT_DIR_LTR;
353 gtk_icon_set_add_source (set, &source);
355 source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
356 source.source.icon_name = (gchar *)stock_id_rtl;
357 source.direction = GTK_TEXT_DIR_RTL;
358 gtk_icon_set_add_source (set, &source);
360 gtk_icon_factory_add (factory, stock_id, set);
361 gtk_icon_set_unref (set);
365 get_default_icons (GtkIconFactory *factory)
367 /* KEEP IN SYNC with gtkstock.c */
369 register_stock_icon (factory, GTK_STOCK_DIALOG_AUTHENTICATION);
370 register_stock_icon (factory, GTK_STOCK_DIALOG_ERROR);
371 register_stock_icon (factory, GTK_STOCK_DIALOG_INFO);
372 register_stock_icon (factory, GTK_STOCK_DIALOG_QUESTION);
373 register_stock_icon (factory, GTK_STOCK_DIALOG_WARNING);
374 register_stock_icon (factory, GTK_STOCK_DND);
375 register_stock_icon (factory, GTK_STOCK_DND_MULTIPLE);
376 register_stock_icon (factory, GTK_STOCK_APPLY);
377 register_stock_icon (factory, GTK_STOCK_CANCEL);
378 register_stock_icon (factory, GTK_STOCK_NO);
379 register_stock_icon (factory, GTK_STOCK_OK);
380 register_stock_icon (factory, GTK_STOCK_YES);
381 register_stock_icon (factory, GTK_STOCK_CLOSE);
382 register_stock_icon (factory, GTK_STOCK_ADD);
383 register_stock_icon (factory, GTK_STOCK_JUSTIFY_CENTER);
384 register_stock_icon (factory, GTK_STOCK_JUSTIFY_FILL);
385 register_stock_icon (factory, GTK_STOCK_JUSTIFY_LEFT);
386 register_stock_icon (factory, GTK_STOCK_JUSTIFY_RIGHT);
387 register_stock_icon (factory, GTK_STOCK_GOTO_BOTTOM);
388 register_stock_icon (factory, GTK_STOCK_CDROM);
389 register_stock_icon (factory, GTK_STOCK_CONVERT);
390 register_stock_icon (factory, GTK_STOCK_COPY);
391 register_stock_icon (factory, GTK_STOCK_CUT);
392 register_stock_icon (factory, GTK_STOCK_GO_DOWN);
393 register_stock_icon (factory, GTK_STOCK_EXECUTE);
394 register_stock_icon (factory, GTK_STOCK_QUIT);
395 register_bidi_stock_icon (factory,
396 GTK_STOCK_GOTO_FIRST,
397 GTK_STOCK_GOTO_FIRST "-ltr",
398 GTK_STOCK_GOTO_FIRST "-rtl");
399 register_stock_icon (factory, GTK_STOCK_SELECT_FONT);
400 register_stock_icon (factory, GTK_STOCK_FULLSCREEN);
401 register_stock_icon (factory, GTK_STOCK_LEAVE_FULLSCREEN);
402 register_stock_icon (factory, GTK_STOCK_HARDDISK);
403 register_stock_icon (factory, GTK_STOCK_HELP);
404 register_stock_icon (factory, GTK_STOCK_HOME);
405 register_stock_icon (factory, GTK_STOCK_INFO);
406 register_bidi_stock_icon (factory,
408 GTK_STOCK_JUMP_TO "-ltr",
409 GTK_STOCK_JUMP_TO "-rtl");
410 register_bidi_stock_icon (factory,
412 GTK_STOCK_GOTO_LAST "-ltr",
413 GTK_STOCK_GOTO_LAST "-rtl");
414 register_bidi_stock_icon (factory,
416 GTK_STOCK_GO_BACK "-ltr",
417 GTK_STOCK_GO_BACK "-rtl");
418 register_stock_icon (factory, GTK_STOCK_MISSING_IMAGE);
419 register_stock_icon (factory, GTK_STOCK_NETWORK);
420 register_stock_icon (factory, GTK_STOCK_NEW);
421 register_stock_icon (factory, GTK_STOCK_OPEN);
422 register_stock_icon (factory, GTK_STOCK_ORIENTATION_PORTRAIT);
423 register_stock_icon (factory, GTK_STOCK_ORIENTATION_LANDSCAPE);
424 register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT);
425 register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE);
426 register_stock_icon (factory, GTK_STOCK_PASTE);
427 register_stock_icon (factory, GTK_STOCK_PREFERENCES);
428 register_stock_icon (factory, GTK_STOCK_PRINT);
429 register_stock_icon (factory, GTK_STOCK_PRINT_PREVIEW);
430 register_stock_icon (factory, GTK_STOCK_PROPERTIES);
431 register_bidi_stock_icon (factory,
433 GTK_STOCK_REDO "-ltr",
434 GTK_STOCK_REDO "-rtl");
435 register_stock_icon (factory, GTK_STOCK_REMOVE);
436 register_stock_icon (factory, GTK_STOCK_REFRESH);
437 register_bidi_stock_icon (factory,
438 GTK_STOCK_REVERT_TO_SAVED,
439 GTK_STOCK_REVERT_TO_SAVED "-ltr",
440 GTK_STOCK_REVERT_TO_SAVED "-rtl");
441 register_bidi_stock_icon (factory,
442 GTK_STOCK_GO_FORWARD,
443 GTK_STOCK_GO_FORWARD "-ltr",
444 GTK_STOCK_GO_FORWARD "-rtl");
445 register_stock_icon (factory, GTK_STOCK_SAVE);
446 register_stock_icon (factory, GTK_STOCK_FLOPPY);
447 register_stock_icon (factory, GTK_STOCK_SAVE_AS);
448 register_stock_icon (factory, GTK_STOCK_FIND);
449 register_stock_icon (factory, GTK_STOCK_FIND_AND_REPLACE);
450 register_stock_icon (factory, GTK_STOCK_SORT_DESCENDING);
451 register_stock_icon (factory, GTK_STOCK_SORT_ASCENDING);
452 register_stock_icon (factory, GTK_STOCK_SPELL_CHECK);
453 register_stock_icon (factory, GTK_STOCK_STOP);
454 register_stock_icon (factory, GTK_STOCK_BOLD);
455 register_stock_icon (factory, GTK_STOCK_ITALIC);
456 register_stock_icon (factory, GTK_STOCK_STRIKETHROUGH);
457 register_stock_icon (factory, GTK_STOCK_UNDERLINE);
458 register_bidi_stock_icon (factory,
460 GTK_STOCK_INDENT "-ltr",
461 GTK_STOCK_INDENT "-rtl");
462 register_bidi_stock_icon (factory,
464 GTK_STOCK_UNINDENT "-ltr",
465 GTK_STOCK_UNINDENT "-rtl");
466 register_stock_icon (factory, GTK_STOCK_GOTO_TOP);
467 register_stock_icon (factory, GTK_STOCK_DELETE);
468 register_bidi_stock_icon (factory,
470 GTK_STOCK_UNDELETE "-ltr",
471 GTK_STOCK_UNDELETE "-rtl");
472 register_bidi_stock_icon (factory,
474 GTK_STOCK_UNDO "-ltr",
475 GTK_STOCK_UNDO "-rtl");
476 register_stock_icon (factory, GTK_STOCK_GO_UP);
477 register_stock_icon (factory, GTK_STOCK_FILE);
478 register_stock_icon (factory, GTK_STOCK_DIRECTORY);
479 register_stock_icon (factory, GTK_STOCK_ABOUT);
480 register_stock_icon (factory, GTK_STOCK_CONNECT);
481 register_stock_icon (factory, GTK_STOCK_DISCONNECT);
482 register_stock_icon (factory, GTK_STOCK_EDIT);
483 register_bidi_stock_icon (factory,
484 GTK_STOCK_MEDIA_FORWARD,
485 GTK_STOCK_MEDIA_FORWARD "-ltr",
486 GTK_STOCK_MEDIA_FORWARD "-rtl");
487 register_bidi_stock_icon (factory,
488 GTK_STOCK_MEDIA_NEXT,
489 GTK_STOCK_MEDIA_NEXT "-ltr",
490 GTK_STOCK_MEDIA_NEXT "-rtl");
491 register_stock_icon (factory, GTK_STOCK_MEDIA_PAUSE);
492 register_bidi_stock_icon (factory,
493 GTK_STOCK_MEDIA_PLAY,
494 GTK_STOCK_MEDIA_PLAY "-ltr",
495 GTK_STOCK_MEDIA_PLAY "-rtl");
496 register_bidi_stock_icon (factory,
497 GTK_STOCK_MEDIA_PREVIOUS,
498 GTK_STOCK_MEDIA_PREVIOUS "-ltr",
499 GTK_STOCK_MEDIA_PREVIOUS "-rtl");
500 register_stock_icon (factory, GTK_STOCK_MEDIA_RECORD);
501 register_bidi_stock_icon (factory,
502 GTK_STOCK_MEDIA_REWIND,
503 GTK_STOCK_MEDIA_REWIND "-ltr",
504 GTK_STOCK_MEDIA_REWIND "-rtl");
505 register_stock_icon (factory, GTK_STOCK_MEDIA_STOP);
506 register_stock_icon (factory, GTK_STOCK_INDEX);
507 register_stock_icon (factory, GTK_STOCK_ZOOM_100);
508 register_stock_icon (factory, GTK_STOCK_ZOOM_IN);
509 register_stock_icon (factory, GTK_STOCK_ZOOM_OUT);
510 register_stock_icon (factory, GTK_STOCK_ZOOM_FIT);
511 register_stock_icon (factory, GTK_STOCK_SELECT_ALL);
512 register_stock_icon (factory, GTK_STOCK_CLEAR);
513 register_stock_icon (factory, GTK_STOCK_SELECT_COLOR);
514 register_stock_icon (factory, GTK_STOCK_COLOR_PICKER);
517 /************************************************************
518 * Icon size handling *
519 ************************************************************/
521 typedef struct _IconSize IconSize;
532 typedef struct _IconAlias IconAlias;
540 typedef struct _SettingsIconSize SettingsIconSize;
542 struct _SettingsIconSize
548 static GHashTable *icon_aliases = NULL;
549 static IconSize *icon_sizes = NULL;
550 static gint icon_sizes_allocated = 0;
551 static gint icon_sizes_used = 0;
554 init_icon_sizes (void)
556 if (icon_sizes == NULL)
558 #define NUM_BUILTIN_SIZES 7
561 icon_aliases = g_hash_table_new (g_str_hash, g_str_equal);
563 icon_sizes = g_new (IconSize, NUM_BUILTIN_SIZES);
564 icon_sizes_allocated = NUM_BUILTIN_SIZES;
565 icon_sizes_used = NUM_BUILTIN_SIZES;
567 icon_sizes[GTK_ICON_SIZE_INVALID].size = 0;
568 icon_sizes[GTK_ICON_SIZE_INVALID].name = NULL;
569 icon_sizes[GTK_ICON_SIZE_INVALID].width = 0;
570 icon_sizes[GTK_ICON_SIZE_INVALID].height = 0;
572 /* the name strings aren't copied since we don't ever remove
573 * icon sizes, so we don't need to know whether they're static.
574 * Even if we did I suppose removing the builtin sizes would be
578 icon_sizes[GTK_ICON_SIZE_MENU].size = GTK_ICON_SIZE_MENU;
579 icon_sizes[GTK_ICON_SIZE_MENU].name = "gtk-menu";
580 icon_sizes[GTK_ICON_SIZE_MENU].width = 16;
581 icon_sizes[GTK_ICON_SIZE_MENU].height = 16;
583 icon_sizes[GTK_ICON_SIZE_BUTTON].size = GTK_ICON_SIZE_BUTTON;
584 icon_sizes[GTK_ICON_SIZE_BUTTON].name = "gtk-button";
585 icon_sizes[GTK_ICON_SIZE_BUTTON].width = 20;
586 icon_sizes[GTK_ICON_SIZE_BUTTON].height = 20;
588 icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].size = GTK_ICON_SIZE_SMALL_TOOLBAR;
589 icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].name = "gtk-small-toolbar";
590 icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].width = 18;
591 icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].height = 18;
593 icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].size = GTK_ICON_SIZE_LARGE_TOOLBAR;
594 icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].name = "gtk-large-toolbar";
595 icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].width = 24;
596 icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].height = 24;
598 icon_sizes[GTK_ICON_SIZE_DND].size = GTK_ICON_SIZE_DND;
599 icon_sizes[GTK_ICON_SIZE_DND].name = "gtk-dnd";
600 icon_sizes[GTK_ICON_SIZE_DND].width = 32;
601 icon_sizes[GTK_ICON_SIZE_DND].height = 32;
603 icon_sizes[GTK_ICON_SIZE_DIALOG].size = GTK_ICON_SIZE_DIALOG;
604 icon_sizes[GTK_ICON_SIZE_DIALOG].name = "gtk-dialog";
605 icon_sizes[GTK_ICON_SIZE_DIALOG].width = 48;
606 icon_sizes[GTK_ICON_SIZE_DIALOG].height = 48;
608 g_assert ((GTK_ICON_SIZE_DIALOG + 1) == NUM_BUILTIN_SIZES);
610 /* Alias everything to itself. */
611 i = 1; /* skip invalid size */
612 while (i < NUM_BUILTIN_SIZES)
614 gtk_icon_size_register_alias (icon_sizes[i].name, icon_sizes[i].size);
619 #undef NUM_BUILTIN_SIZES
624 free_settings_sizes (gpointer data)
626 g_array_free (data, TRUE);
630 get_settings_sizes (GtkSettings *settings,
633 GArray *settings_sizes;
634 static GQuark sizes_quark = 0;
637 sizes_quark = g_quark_from_static_string ("gtk-icon-sizes");
639 settings_sizes = g_object_get_qdata (G_OBJECT (settings), sizes_quark);
642 settings_sizes = g_array_new (FALSE, FALSE, sizeof (SettingsIconSize));
643 g_object_set_qdata_full (G_OBJECT (settings), sizes_quark,
644 settings_sizes, free_settings_sizes);
649 return settings_sizes;
653 icon_size_set_for_settings (GtkSettings *settings,
654 const gchar *size_name,
659 GArray *settings_sizes;
660 SettingsIconSize *settings_size;
662 g_return_if_fail (size_name != NULL);
664 size = gtk_icon_size_from_name (size_name);
665 if (size == GTK_ICON_SIZE_INVALID)
666 /* Reserve a place */
667 size = icon_size_register_intern (size_name, -1, -1);
669 settings_sizes = get_settings_sizes (settings, NULL);
670 if (size >= settings_sizes->len)
672 SettingsIconSize unset = { -1, -1 };
675 for (i = settings_sizes->len; i <= size; i++)
676 g_array_append_val (settings_sizes, unset);
679 settings_size = &g_array_index (settings_sizes, SettingsIconSize, size);
681 settings_size->width = width;
682 settings_size->height = height;
685 /* Like pango_parse_word, but accept - as well
688 scan_icon_size_name (const char **pos, GString *out)
690 const char *p = *pos;
692 while (g_ascii_isspace (*p))
695 if (!((*p >= 'A' && *p <= 'Z') ||
696 (*p >= 'a' && *p <= 'z') ||
697 *p == '_' || *p == '-'))
700 g_string_truncate (out, 0);
701 g_string_append_c (out, *p);
704 while ((*p >= 'A' && *p <= 'Z') ||
705 (*p >= 'a' && *p <= 'z') ||
706 (*p >= '0' && *p <= '9') ||
707 *p == '_' || *p == '-')
709 g_string_append_c (out, *p);
719 icon_size_setting_parse (GtkSettings *settings,
720 const gchar *icon_size_string)
722 GString *name_buf = g_string_new (NULL);
723 const gchar *p = icon_size_string;
725 while (pango_skip_space (&p))
729 if (!scan_icon_size_name (&p, name_buf))
732 if (!pango_skip_space (&p))
740 if (!pango_scan_int (&p, &width))
743 if (!pango_skip_space (&p))
751 if (!pango_scan_int (&p, &height))
754 if (width > 0 && height > 0)
756 icon_size_set_for_settings (settings, name_buf->str,
761 g_warning ("Invalid size in gtk-icon-sizes: %d,%d\n", width, height);
764 pango_skip_space (&p);
773 g_string_free (name_buf, TRUE);
777 g_warning ("Error parsing gtk-icon-sizes string:\n\t'%s'", icon_size_string);
778 g_string_free (name_buf, TRUE);
782 icon_size_set_all_from_settings (GtkSettings *settings)
784 GArray *settings_sizes;
785 gchar *icon_size_string;
787 /* Reset old settings */
788 settings_sizes = get_settings_sizes (settings, NULL);
789 g_array_set_size (settings_sizes, 0);
791 g_object_get (settings,
792 "gtk-icon-sizes", &icon_size_string,
795 if (icon_size_string)
797 icon_size_setting_parse (settings, icon_size_string);
798 g_free (icon_size_string);
803 icon_size_settings_changed (GtkSettings *settings,
806 icon_size_set_all_from_settings (settings);
808 gtk_rc_reset_styles (settings);
812 icon_sizes_init_for_settings (GtkSettings *settings)
814 g_signal_connect (settings,
815 "notify::gtk-icon-sizes",
816 G_CALLBACK (icon_size_settings_changed),
819 icon_size_set_all_from_settings (settings);
823 icon_size_lookup_intern (GtkSettings *settings,
828 GArray *settings_sizes;
829 gint width_for_settings = -1;
830 gint height_for_settings = -1;
834 if (size == (GtkIconSize)-1)
837 if (size >= icon_sizes_used)
840 if (size == GTK_ICON_SIZE_INVALID)
845 gboolean initial = FALSE;
847 settings_sizes = get_settings_sizes (settings, &initial);
849 icon_sizes_init_for_settings (settings);
851 if (size < settings_sizes->len)
853 SettingsIconSize *settings_size;
855 settings_size = &g_array_index (settings_sizes, SettingsIconSize, size);
857 width_for_settings = settings_size->width;
858 height_for_settings = settings_size->height;
863 *widthp = width_for_settings >= 0 ? width_for_settings : icon_sizes[size].width;
866 *heightp = height_for_settings >= 0 ? height_for_settings : icon_sizes[size].height;
872 * gtk_icon_size_lookup_for_settings:
873 * @settings: a #GtkSettings object, used to determine
874 * which set of user preferences to used.
875 * @size: an icon size
876 * @width: location to store icon width
877 * @height: location to store icon height
879 * Obtains the pixel size of a semantic icon size, possibly
880 * modified by user preferences for a particular
881 * #GtkSettings. Normally @size would be
882 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc. This function
883 * isn't normally needed, gtk_widget_render_icon() is the usual
884 * way to get an icon for rendering, then just look at the size of
885 * the rendered pixbuf. The rendered pixbuf may not even correspond to
886 * the width/height returned by gtk_icon_size_lookup(), because themes
887 * are free to render the pixbuf however they like, including changing
890 * Return value: %TRUE if @size was a valid size
895 gtk_icon_size_lookup_for_settings (GtkSettings *settings,
900 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
902 return icon_size_lookup_intern (settings, size, width, height);
906 * gtk_icon_size_lookup:
907 * @size: an icon size
908 * @width: location to store icon width
909 * @height: location to store icon height
911 * Obtains the pixel size of a semantic icon size, possibly
912 * modified by user preferences for the default #GtkSettings.
913 * (See gtk_icon_size_lookup_for_settings().)
914 * Normally @size would be
915 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc. This function
916 * isn't normally needed, gtk_widget_render_icon() is the usual
917 * way to get an icon for rendering, then just look at the size of
918 * the rendered pixbuf. The rendered pixbuf may not even correspond to
919 * the width/height returned by gtk_icon_size_lookup(), because themes
920 * are free to render the pixbuf however they like, including changing
923 * Return value: %TRUE if @size was a valid size
926 gtk_icon_size_lookup (GtkIconSize size,
931 g_warning ("gtk_icon_size_lookup ()) is not multihead safe"));
933 return gtk_icon_size_lookup_for_settings (gtk_settings_get_default (),
934 size, widthp, heightp);
938 icon_size_register_intern (const gchar *name,
942 IconAlias *old_alias;
947 old_alias = g_hash_table_lookup (icon_aliases, name);
948 if (old_alias && icon_sizes[old_alias->target].width > 0)
950 g_warning ("Icon size name '%s' already exists", name);
951 return GTK_ICON_SIZE_INVALID;
956 size = old_alias->target;
960 if (icon_sizes_used == icon_sizes_allocated)
962 icon_sizes_allocated *= 2;
963 icon_sizes = g_renew (IconSize, icon_sizes, icon_sizes_allocated);
966 size = icon_sizes_used++;
969 gtk_icon_size_register_alias (name, size);
971 icon_sizes[size].size = size;
972 icon_sizes[size].name = g_strdup (name);
975 icon_sizes[size].width = width;
976 icon_sizes[size].height = height;
982 * gtk_icon_size_register:
983 * @name: name of the icon size
984 * @width: the icon width
985 * @height: the icon height
987 * Registers a new icon size, along the same lines as #GTK_ICON_SIZE_MENU,
988 * etc. Returns the integer value for the size.
990 * Returns: integer value representing the size
994 gtk_icon_size_register (const gchar *name,
998 g_return_val_if_fail (name != NULL, 0);
999 g_return_val_if_fail (width > 0, 0);
1000 g_return_val_if_fail (height > 0, 0);
1002 return icon_size_register_intern (name, width, height);
1006 * gtk_icon_size_register_alias:
1007 * @alias: an alias for @target
1008 * @target: an existing icon size
1010 * Registers @alias as another name for @target.
1011 * So calling gtk_icon_size_from_name() with @alias as argument
1012 * will return @target.
1016 gtk_icon_size_register_alias (const gchar *alias,
1021 g_return_if_fail (alias != NULL);
1025 if (!icon_size_lookup_intern (NULL, target, NULL, NULL))
1026 g_warning ("gtk_icon_size_register_alias: Icon size %u does not exist", target);
1028 ia = g_hash_table_lookup (icon_aliases, alias);
1031 if (icon_sizes[ia->target].width > 0)
1033 g_warning ("gtk_icon_size_register_alias: Icon size name '%s' already exists", alias);
1037 ia->target = target;
1042 ia = g_new (IconAlias, 1);
1043 ia->name = g_strdup (alias);
1044 ia->target = target;
1046 g_hash_table_insert (icon_aliases, ia->name, ia);
1051 * gtk_icon_size_from_name:
1052 * @name: the name to look up.
1053 * @returns: the icon size with the given name.
1055 * Looks up the icon size associated with @name.
1058 gtk_icon_size_from_name (const gchar *name)
1064 ia = g_hash_table_lookup (icon_aliases, name);
1066 if (ia && icon_sizes[ia->target].width > 0)
1069 return GTK_ICON_SIZE_INVALID;
1073 * gtk_icon_size_get_name:
1074 * @size: a #GtkIconSize.
1075 * @returns: the name of the given icon size.
1077 * Gets the canonical name of the given icon size. The returned string
1078 * is statically allocated and should not be freed.
1080 G_CONST_RETURN gchar*
1081 gtk_icon_size_get_name (GtkIconSize size)
1083 if (size >= icon_sizes_used)
1086 return icon_sizes[size].name;
1089 /************************************************************/
1094 static GdkPixbuf *find_in_cache (GtkIconSet *icon_set,
1096 GtkTextDirection direction,
1099 static void add_to_cache (GtkIconSet *icon_set,
1101 GtkTextDirection direction,
1105 /* Clear icon set contents, drop references to all contained
1106 * GdkPixbuf objects and forget all GtkIconSources. Used to
1107 * recycle an icon set.
1109 static void clear_cache (GtkIconSet *icon_set,
1110 gboolean style_detach);
1111 static GSList* copy_cache (GtkIconSet *icon_set,
1112 GtkIconSet *copy_recipient);
1113 static void attach_to_style (GtkIconSet *icon_set,
1115 static void detach_from_style (GtkIconSet *icon_set,
1117 static void style_dnotify (gpointer data);
1125 /* Cache of the last few rendered versions of the icon. */
1133 static guint cache_serial = 0;
1138 * Creates a new #GtkIconSet. A #GtkIconSet represents a single icon
1139 * in various sizes and widget states. It can provide a #GdkPixbuf
1140 * for a given size and state on request, and automatically caches
1141 * some of the rendered #GdkPixbuf objects.
1143 * Normally you would use gtk_widget_render_icon() instead of
1144 * using #GtkIconSet directly. The one case where you'd use
1145 * #GtkIconSet is to create application-specific icon sets to place in
1146 * a #GtkIconFactory.
1148 * Return value: a new #GtkIconSet
1151 gtk_icon_set_new (void)
1153 GtkIconSet *icon_set;
1155 icon_set = g_new (GtkIconSet, 1);
1157 icon_set->ref_count = 1;
1158 icon_set->sources = NULL;
1159 icon_set->cache = NULL;
1160 icon_set->cache_size = 0;
1161 icon_set->cache_serial = cache_serial;
1167 * gtk_icon_set_new_from_pixbuf:
1168 * @pixbuf: a #GdkPixbuf
1170 * Creates a new #GtkIconSet with @pixbuf as the default/fallback
1171 * source image. If you don't add any additional #GtkIconSource to the
1172 * icon set, all variants of the icon will be created from @pixbuf,
1173 * using scaling, pixelation, etc. as required to adjust the icon size
1174 * or make the icon look insensitive/prelighted.
1176 * Return value: a new #GtkIconSet
1179 gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf)
1183 GtkIconSource source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
1185 g_return_val_if_fail (pixbuf != NULL, NULL);
1187 set = gtk_icon_set_new ();
1189 gtk_icon_source_set_pixbuf (&source, pixbuf);
1190 gtk_icon_set_add_source (set, &source);
1191 gtk_icon_source_set_pixbuf (&source, NULL);
1199 * @icon_set: a #GtkIconSet.
1201 * Increments the reference count on @icon_set.
1203 * Return value: @icon_set.
1206 gtk_icon_set_ref (GtkIconSet *icon_set)
1208 g_return_val_if_fail (icon_set != NULL, NULL);
1209 g_return_val_if_fail (icon_set->ref_count > 0, NULL);
1211 icon_set->ref_count += 1;
1217 * gtk_icon_set_unref:
1218 * @icon_set: a #GtkIconSet
1220 * Decrements the reference count on @icon_set, and frees memory
1221 * if the reference count reaches 0.
1224 gtk_icon_set_unref (GtkIconSet *icon_set)
1226 g_return_if_fail (icon_set != NULL);
1227 g_return_if_fail (icon_set->ref_count > 0);
1229 icon_set->ref_count -= 1;
1231 if (icon_set->ref_count == 0)
1233 GSList *tmp_list = icon_set->sources;
1234 while (tmp_list != NULL)
1236 gtk_icon_source_free (tmp_list->data);
1238 tmp_list = g_slist_next (tmp_list);
1240 g_slist_free (icon_set->sources);
1242 clear_cache (icon_set, TRUE);
1249 gtk_icon_set_get_type (void)
1251 static GType our_type = 0;
1254 our_type = g_boxed_type_register_static (I_("GtkIconSet"),
1255 (GBoxedCopyFunc) gtk_icon_set_ref,
1256 (GBoxedFreeFunc) gtk_icon_set_unref);
1262 * gtk_icon_set_copy:
1263 * @icon_set: a #GtkIconSet
1265 * Copies @icon_set by value.
1267 * Return value: a new #GtkIconSet identical to the first.
1270 gtk_icon_set_copy (GtkIconSet *icon_set)
1275 copy = gtk_icon_set_new ();
1277 tmp_list = icon_set->sources;
1278 while (tmp_list != NULL)
1280 copy->sources = g_slist_prepend (copy->sources,
1281 gtk_icon_source_copy (tmp_list->data));
1283 tmp_list = g_slist_next (tmp_list);
1286 copy->sources = g_slist_reverse (copy->sources);
1288 copy->cache = copy_cache (icon_set, copy);
1289 copy->cache_size = icon_set->cache_size;
1290 copy->cache_serial = icon_set->cache_serial;
1296 sizes_equivalent (GtkIconSize lhs,
1299 /* We used to consider sizes equivalent if they were
1300 * the same pixel size, but we don't have the GtkSettings
1301 * here, so we can't do that. Plus, it's not clear that
1302 * it is right... it was just a workaround for the fact
1303 * that we register icons by logical size, not pixel size.
1309 gint r_w, r_h, l_w, l_h;
1311 icon_size_lookup_intern (NULL, rhs, &r_w, &r_h);
1312 icon_size_lookup_intern (NULL, lhs, &l_w, &l_h);
1314 return r_w == l_w && r_h == l_h;
1318 static GtkIconSource *
1319 find_best_matching_source (GtkIconSet *icon_set,
1320 GtkTextDirection direction,
1325 GtkIconSource *source;
1328 /* We need to find the best icon source. Direction matters more
1329 * than state, state matters more than size. icon_set->sources
1330 * is sorted according to wildness, so if we take the first
1331 * match we find it will be the least-wild match (if there are
1332 * multiple matches for a given "wildness" then the RC file contained
1333 * dumb stuff, and we end up with an arbitrary matching source)
1337 tmp_list = icon_set->sources;
1338 while (tmp_list != NULL)
1340 GtkIconSource *s = tmp_list->data;
1342 if ((s->any_direction || (s->direction == direction)) &&
1343 (s->any_state || (s->state == state)) &&
1344 (s->any_size || size == (GtkIconSize)-1 || (sizes_equivalent (size, s->size))))
1346 if (!g_slist_find (failed, s))
1353 tmp_list = g_slist_next (tmp_list);
1360 ensure_filename_pixbuf (GtkIconSet *icon_set,
1361 GtkIconSource *source)
1363 if (source->filename_pixbuf == NULL)
1365 GError *error = NULL;
1367 source->filename_pixbuf = gdk_pixbuf_new_from_file (source->source.filename, &error);
1369 if (source->filename_pixbuf == NULL)
1371 /* Remove this icon source so we don't keep trying to
1374 g_warning (_("Error loading icon: %s"), error->message);
1375 g_error_free (error);
1377 icon_set->sources = g_slist_remove (icon_set->sources, source);
1379 gtk_icon_source_free (source);
1389 render_icon_name_pixbuf (GtkIconSource *icon_source,
1391 GtkTextDirection direction,
1398 GdkPixbuf *tmp_pixbuf;
1399 GtkIconSource tmp_source;
1401 GtkIconTheme *icon_theme;
1402 GtkSettings *settings;
1403 gint width, height, pixel_size;
1404 gint *sizes, *s, dist;
1405 GError *error = NULL;
1407 if (widget && gtk_widget_has_screen (widget))
1408 screen = gtk_widget_get_screen (widget);
1409 else if (style && style->colormap)
1410 screen = gdk_colormap_get_screen (style->colormap);
1413 screen = gdk_screen_get_default ();
1414 GTK_NOTE (MULTIHEAD,
1415 g_warning ("Using the default screen for gtk_icon_source_render_icon()"));
1418 icon_theme = gtk_icon_theme_get_for_screen (screen);
1419 settings = gtk_settings_get_for_screen (screen);
1421 if (!gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
1423 if (size == (GtkIconSize)-1)
1425 /* Find an available size close to 48
1427 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, icon_source->source.icon_name);
1429 width = height = 48;
1430 for (s = sizes; *s; s++)
1434 width = height = 48;
1441 width = height = *s;
1449 width = height = *s;
1459 g_warning ("Invalid icon size %u\n", size);
1460 width = height = 24;
1464 pixel_size = MIN (width, height);
1466 tmp_pixbuf = gtk_icon_theme_load_icon (icon_theme,
1467 icon_source->source.icon_name,
1473 g_warning ("Error loading theme icon '%s' for stock: %s",
1474 icon_source->source.icon_name, error->message);
1475 g_error_free (error);
1479 tmp_source = *icon_source;
1480 tmp_source.type = GTK_ICON_SOURCE_PIXBUF;
1481 tmp_source.source.pixbuf = tmp_pixbuf;
1483 pixbuf = gtk_style_render_icon (style, &tmp_source,
1484 direction, state, -1,
1488 g_warning ("Failed to render icon");
1490 g_object_unref (tmp_pixbuf);
1496 find_and_render_icon_source (GtkIconSet *icon_set,
1498 GtkTextDirection direction,
1504 GSList *failed = NULL;
1505 GdkPixbuf *pixbuf = NULL;
1507 /* We treat failure in two different ways:
1509 * A) If loading a source that specifies a filename fails,
1510 * we treat that as permanent, and remove the source
1511 * from the GtkIconSet. (in ensure_filename_pixbuf ()
1512 * B) If loading a themed icon fails, or scaling an icon
1513 * fails, we treat that as transient and will try
1514 * again next time the icon falls out of the cache
1515 * and we need to recreate it.
1517 while (pixbuf == NULL)
1519 GtkIconSource *source = find_best_matching_source (icon_set, direction, state, size, failed);
1524 switch (source->type)
1526 case GTK_ICON_SOURCE_FILENAME:
1527 if (!ensure_filename_pixbuf (icon_set, source))
1530 case GTK_ICON_SOURCE_PIXBUF:
1531 pixbuf = gtk_style_render_icon (style, source,
1532 direction, state, size,
1536 g_warning ("Failed to render icon");
1537 failed = g_slist_prepend (failed, source);
1540 case GTK_ICON_SOURCE_ICON_NAME:
1541 case GTK_ICON_SOURCE_STATIC_ICON_NAME:
1542 pixbuf = render_icon_name_pixbuf (source, style,
1543 direction, state, size,
1546 failed = g_slist_prepend (failed, source);
1548 case GTK_ICON_SOURCE_EMPTY:
1549 g_assert_not_reached ();
1553 g_slist_free (failed);
1558 extern GtkIconCache *_builtin_cache;
1561 render_fallback_image (GtkStyle *style,
1562 GtkTextDirection direction,
1568 /* This icon can be used for any direction/state/size */
1569 static GtkIconSource fallback_source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
1571 if (fallback_source.type == GTK_ICON_SOURCE_EMPTY)
1575 _gtk_icon_theme_ensure_builtin_cache ();
1577 pixbuf = _gtk_icon_cache_get_icon (_builtin_cache,
1578 GTK_STOCK_MISSING_IMAGE,
1580 gtk_icon_source_set_pixbuf (&fallback_source, pixbuf);
1581 g_object_unref (pixbuf);
1584 return gtk_style_render_icon (style,
1594 * gtk_icon_set_render_icon:
1595 * @icon_set: a #GtkIconSet
1596 * @style: a #GtkStyle associated with @widget, or %NULL
1597 * @direction: text direction
1598 * @state: widget state
1599 * @size: icon size. A size of (GtkIconSize)-1
1600 * means render at the size of the source and don't scale.
1601 * @widget: widget that will display the icon, or %NULL.
1602 * The only use that is typically made of this
1603 * is to determine the appropriate #GdkScreen.
1604 * @detail: detail to pass to the theme engine, or %NULL.
1605 * Note that passing a detail of anything but %NULL
1606 * will disable caching.
1608 * Renders an icon using gtk_style_render_icon(). In most cases,
1609 * gtk_widget_render_icon() is better, since it automatically provides
1610 * most of the arguments from the current widget settings. This
1611 * function never returns %NULL; if the icon can't be rendered
1612 * (perhaps because an image file fails to load), a default "missing
1613 * image" icon will be returned instead.
1615 * Return value: a #GdkPixbuf to be displayed
1618 gtk_icon_set_render_icon (GtkIconSet *icon_set,
1620 GtkTextDirection direction,
1628 g_return_val_if_fail (icon_set != NULL, NULL);
1629 g_return_val_if_fail (style == NULL || GTK_IS_STYLE (style), NULL);
1631 if (icon_set->sources == NULL)
1632 return render_fallback_image (style, direction, state, size, widget, detail);
1636 icon = find_in_cache (icon_set, style, direction,
1641 g_object_ref (icon);
1647 icon = find_and_render_icon_source (icon_set, style, direction, state, size,
1651 icon = render_fallback_image (style, direction, state, size, widget, detail);
1654 add_to_cache (icon_set, style, direction, state, size, icon);
1659 /* Order sources by their "wildness", so that "wilder" sources are
1660 * greater than "specific" sources; for determining ordering,
1661 * direction beats state beats size.
1665 icon_source_compare (gconstpointer ap, gconstpointer bp)
1667 const GtkIconSource *a = ap;
1668 const GtkIconSource *b = bp;
1670 if (!a->any_direction && b->any_direction)
1672 else if (a->any_direction && !b->any_direction)
1674 else if (!a->any_state && b->any_state)
1676 else if (a->any_state && !b->any_state)
1678 else if (!a->any_size && b->any_size)
1680 else if (a->any_size && !b->any_size)
1687 * gtk_icon_set_add_source:
1688 * @icon_set: a #GtkIconSet
1689 * @source: a #GtkIconSource
1691 * Icon sets have a list of #GtkIconSource, which they use as base
1692 * icons for rendering icons in different states and sizes. Icons are
1693 * scaled, made to look insensitive, etc. in
1694 * gtk_icon_set_render_icon(), but #GtkIconSet needs base images to
1695 * work with. The base images and when to use them are described by
1698 * This function copies @source, so you can reuse the same source immediately
1699 * without affecting the icon set.
1701 * An example of when you'd use this function: a web browser's "Back
1702 * to Previous Page" icon might point in a different direction in
1703 * Hebrew and in English; it might look different when insensitive;
1704 * and it might change size depending on toolbar mode (small/large
1705 * icons). So a single icon set would contain all those variants of
1706 * the icon, and you might add a separate source for each one.
1708 * You should nearly always add a "default" icon source with all
1709 * fields wildcarded, which will be used as a fallback if no more
1710 * specific source matches. #GtkIconSet always prefers more specific
1711 * icon sources to more generic icon sources. The order in which you
1712 * add the sources to the icon set does not matter.
1714 * gtk_icon_set_new_from_pixbuf() creates a new icon set with a
1715 * default icon source based on the given pixbuf.
1719 gtk_icon_set_add_source (GtkIconSet *icon_set,
1720 const GtkIconSource *source)
1722 g_return_if_fail (icon_set != NULL);
1723 g_return_if_fail (source != NULL);
1725 if (source->type == GTK_ICON_SOURCE_EMPTY)
1727 g_warning ("Useless empty GtkIconSource");
1731 icon_set->sources = g_slist_insert_sorted (icon_set->sources,
1732 gtk_icon_source_copy (source),
1733 icon_source_compare);
1737 * gtk_icon_set_get_sizes:
1738 * @icon_set: a #GtkIconSet
1739 * @sizes: return location for array of sizes
1740 * @n_sizes: location to store number of elements in returned array
1742 * Obtains a list of icon sizes this icon set can render. The returned
1743 * array must be freed with g_free().
1747 gtk_icon_set_get_sizes (GtkIconSet *icon_set,
1748 GtkIconSize **sizes,
1752 gboolean all_sizes = FALSE;
1753 GSList *specifics = NULL;
1755 g_return_if_fail (icon_set != NULL);
1756 g_return_if_fail (sizes != NULL);
1757 g_return_if_fail (n_sizes != NULL);
1759 tmp_list = icon_set->sources;
1760 while (tmp_list != NULL)
1762 GtkIconSource *source;
1764 source = tmp_list->data;
1766 if (source->any_size)
1772 specifics = g_slist_prepend (specifics, GINT_TO_POINTER (source->size));
1774 tmp_list = g_slist_next (tmp_list);
1779 /* Need to find out what sizes exist */
1784 *sizes = g_new (GtkIconSize, icon_sizes_used);
1785 *n_sizes = icon_sizes_used - 1;
1788 while (i < icon_sizes_used)
1790 (*sizes)[i - 1] = icon_sizes[i].size;
1798 *n_sizes = g_slist_length (specifics);
1799 *sizes = g_new (GtkIconSize, *n_sizes);
1802 tmp_list = specifics;
1803 while (tmp_list != NULL)
1805 (*sizes)[i] = GPOINTER_TO_INT (tmp_list->data);
1808 tmp_list = g_slist_next (tmp_list);
1812 g_slist_free (specifics);
1817 * gtk_icon_source_new:
1819 * Creates a new #GtkIconSource. A #GtkIconSource contains a #GdkPixbuf (or
1820 * image filename) that serves as the base image for one or more of the
1821 * icons in a #GtkIconSet, along with a specification for which icons in the
1822 * icon set will be based on that pixbuf or image file. An icon set contains
1823 * a set of icons that represent "the same" logical concept in different states,
1824 * different global text directions, and different sizes.
1826 * So for example a web browser's "Back to Previous Page" icon might
1827 * point in a different direction in Hebrew and in English; it might
1828 * look different when insensitive; and it might change size depending
1829 * on toolbar mode (small/large icons). So a single icon set would
1830 * contain all those variants of the icon. #GtkIconSet contains a list
1831 * of #GtkIconSource from which it can derive specific icon variants in
1834 * In the simplest case, #GtkIconSet contains one source pixbuf from
1835 * which it derives all variants. The convenience function
1836 * gtk_icon_set_new_from_pixbuf() handles this case; if you only have
1837 * one source pixbuf, just use that function.
1839 * If you want to use a different base pixbuf for different icon
1840 * variants, you create multiple icon sources, mark which variants
1841 * they'll be used to create, and add them to the icon set with
1842 * gtk_icon_set_add_source().
1844 * By default, the icon source has all parameters wildcarded. That is,
1845 * the icon source will be used as the base icon for any desired text
1846 * direction, widget state, or icon size.
1848 * Return value: a new #GtkIconSource
1851 gtk_icon_source_new (void)
1855 src = g_new0 (GtkIconSource, 1);
1857 src->direction = GTK_TEXT_DIR_NONE;
1858 src->size = GTK_ICON_SIZE_INVALID;
1859 src->state = GTK_STATE_NORMAL;
1861 src->any_direction = TRUE;
1862 src->any_state = TRUE;
1863 src->any_size = TRUE;
1869 * gtk_icon_source_copy:
1870 * @source: a #GtkIconSource
1872 * Creates a copy of @source; mostly useful for language bindings.
1874 * Return value: a new #GtkIconSource
1877 gtk_icon_source_copy (const GtkIconSource *source)
1879 GtkIconSource *copy;
1881 g_return_val_if_fail (source != NULL, NULL);
1883 copy = g_new (GtkIconSource, 1);
1889 case GTK_ICON_SOURCE_EMPTY:
1890 case GTK_ICON_SOURCE_STATIC_ICON_NAME:
1892 case GTK_ICON_SOURCE_ICON_NAME:
1893 copy->source.icon_name = g_strdup (copy->source.icon_name);
1895 case GTK_ICON_SOURCE_FILENAME:
1896 copy->source.filename = g_strdup (copy->source.filename);
1898 copy->cp_filename = g_strdup (copy->cp_filename);
1900 if (copy->filename_pixbuf)
1901 g_object_ref (copy->filename_pixbuf);
1903 case GTK_ICON_SOURCE_PIXBUF:
1904 g_object_ref (copy->source.pixbuf);
1907 g_assert_not_reached();
1914 * gtk_icon_source_free:
1915 * @source: a #GtkIconSource
1917 * Frees a dynamically-allocated icon source, along with its
1918 * filename, size, and pixbuf fields if those are not %NULL.
1921 gtk_icon_source_free (GtkIconSource *source)
1923 g_return_if_fail (source != NULL);
1925 icon_source_clear (source);
1930 gtk_icon_source_get_type (void)
1932 static GType our_type = 0;
1935 our_type = g_boxed_type_register_static (I_("GtkIconSource"),
1936 (GBoxedCopyFunc) gtk_icon_source_copy,
1937 (GBoxedFreeFunc) gtk_icon_source_free);
1943 icon_source_clear (GtkIconSource *source)
1945 switch (source->type)
1947 case GTK_ICON_SOURCE_EMPTY:
1949 case GTK_ICON_SOURCE_ICON_NAME:
1950 g_free (source->source.icon_name);
1952 case GTK_ICON_SOURCE_STATIC_ICON_NAME:
1953 source->source.icon_name = NULL;
1955 case GTK_ICON_SOURCE_FILENAME:
1956 g_free (source->source.filename);
1957 source->source.filename = NULL;
1959 g_free (source->cp_filename);
1960 source->cp_filename = NULL;
1962 if (source->filename_pixbuf)
1963 g_object_unref (source->filename_pixbuf);
1964 source->filename_pixbuf = NULL;
1966 case GTK_ICON_SOURCE_PIXBUF:
1967 g_object_unref (source->source.pixbuf);
1968 source->source.pixbuf = NULL;
1971 g_assert_not_reached();
1974 source->type = GTK_ICON_SOURCE_EMPTY;
1978 * gtk_icon_source_set_filename:
1979 * @source: a #GtkIconSource
1980 * @filename: image file to use
1982 * Sets the name of an image file to use as a base image when creating
1983 * icon variants for #GtkIconSet. The filename must be absolute.
1986 gtk_icon_source_set_filename (GtkIconSource *source,
1987 const gchar *filename)
1989 g_return_if_fail (source != NULL);
1990 g_return_if_fail (filename == NULL || g_path_is_absolute (filename));
1992 if (source->type == GTK_ICON_SOURCE_FILENAME &&
1993 source->source.filename == filename)
1996 icon_source_clear (source);
1998 if (filename != NULL)
2000 source->type = GTK_ICON_SOURCE_FILENAME;
2001 source->source.filename = g_strdup (filename);
2003 source->cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
2009 * gtk_icon_source_set_icon_name
2010 * @source: a #GtkIconSource
2011 * @icon_name: name of icon to use
2013 * Sets the name of an icon to look up in the current icon theme
2014 * to use as a base image when creating icon variants for #GtkIconSet.
2017 gtk_icon_source_set_icon_name (GtkIconSource *source,
2018 const gchar *icon_name)
2020 g_return_if_fail (source != NULL);
2022 if (source->type == GTK_ICON_SOURCE_ICON_NAME &&
2023 source->source.icon_name == icon_name)
2026 icon_source_clear (source);
2028 if (icon_name != NULL)
2030 source->type = GTK_ICON_SOURCE_ICON_NAME;
2031 source->source.icon_name = g_strdup (icon_name);
2036 * gtk_icon_source_set_pixbuf:
2037 * @source: a #GtkIconSource
2038 * @pixbuf: pixbuf to use as a source
2040 * Sets a pixbuf to use as a base image when creating icon variants
2044 gtk_icon_source_set_pixbuf (GtkIconSource *source,
2047 g_return_if_fail (source != NULL);
2048 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2050 if (source->type == GTK_ICON_SOURCE_PIXBUF &&
2051 source->source.pixbuf == pixbuf)
2054 icon_source_clear (source);
2058 source->type = GTK_ICON_SOURCE_PIXBUF;
2059 source->source.pixbuf = g_object_ref (pixbuf);
2064 * gtk_icon_source_get_filename:
2065 * @source: a #GtkIconSource
2067 * Retrieves the source filename, or %NULL if none is set. The
2068 * filename is not a copy, and should not be modified or expected to
2069 * persist beyond the lifetime of the icon source.
2071 * Return value: image filename. This string must not be modified
2074 G_CONST_RETURN gchar*
2075 gtk_icon_source_get_filename (const GtkIconSource *source)
2077 g_return_val_if_fail (source != NULL, NULL);
2079 if (source->type == GTK_ICON_SOURCE_FILENAME)
2080 return source->source.filename;
2086 * gtk_icon_source_get_icon_name:
2087 * @source: a #GtkIconSource
2089 * Retrieves the source icon name, or %NULL if none is set. The
2090 * icon_name is not a copy, and should not be modified or expected to
2091 * persist beyond the lifetime of the icon source.
2093 * Return value: icon name. This string must not be modified or freed.
2095 G_CONST_RETURN gchar*
2096 gtk_icon_source_get_icon_name (const GtkIconSource *source)
2098 g_return_val_if_fail (source != NULL, NULL);
2100 if (source->type == GTK_ICON_SOURCE_ICON_NAME ||
2101 source->type == GTK_ICON_SOURCE_STATIC_ICON_NAME)
2102 return source->source.icon_name;
2108 * gtk_icon_source_get_pixbuf:
2109 * @source: a #GtkIconSource
2111 * Retrieves the source pixbuf, or %NULL if none is set.
2112 * In addition, if a filename source is in use, this
2113 * function in some cases will return the pixbuf from
2114 * loaded from the filename. This is, for example, true
2115 * for the GtkIconSource passed to the GtkStyle::render_icon()
2116 * virtual function. The reference count on the pixbuf is
2119 * Return value: source pixbuf
2122 gtk_icon_source_get_pixbuf (const GtkIconSource *source)
2124 g_return_val_if_fail (source != NULL, NULL);
2126 if (source->type == GTK_ICON_SOURCE_PIXBUF)
2127 return source->source.pixbuf;
2128 else if (source->type == GTK_ICON_SOURCE_FILENAME)
2129 return source->filename_pixbuf;
2135 * gtk_icon_source_set_direction_wildcarded:
2136 * @source: a #GtkIconSource
2137 * @setting: %TRUE to wildcard the text direction
2139 * If the text direction is wildcarded, this source can be used
2140 * as the base image for an icon in any #GtkTextDirection.
2141 * If the text direction is not wildcarded, then the
2142 * text direction the icon source applies to should be set
2143 * with gtk_icon_source_set_direction(), and the icon source
2144 * will only be used with that text direction.
2146 * #GtkIconSet prefers non-wildcarded sources (exact matches) over
2147 * wildcarded sources, and will use an exact match when possible.
2151 gtk_icon_source_set_direction_wildcarded (GtkIconSource *source,
2154 g_return_if_fail (source != NULL);
2156 source->any_direction = setting != FALSE;
2160 * gtk_icon_source_set_state_wildcarded:
2161 * @source: a #GtkIconSource
2162 * @setting: %TRUE to wildcard the widget state
2164 * If the widget state is wildcarded, this source can be used as the
2165 * base image for an icon in any #GtkStateType. If the widget state
2166 * is not wildcarded, then the state the source applies to should be
2167 * set with gtk_icon_source_set_state() and the icon source will
2168 * only be used with that specific state.
2170 * #GtkIconSet prefers non-wildcarded sources (exact matches) over
2171 * wildcarded sources, and will use an exact match when possible.
2173 * #GtkIconSet will normally transform wildcarded source images to
2174 * produce an appropriate icon for a given state, for example
2175 * lightening an image on prelight, but will not modify source images
2176 * that match exactly.
2179 gtk_icon_source_set_state_wildcarded (GtkIconSource *source,
2182 g_return_if_fail (source != NULL);
2184 source->any_state = setting != FALSE;
2189 * gtk_icon_source_set_size_wildcarded:
2190 * @source: a #GtkIconSource
2191 * @setting: %TRUE to wildcard the widget state
2193 * If the icon size is wildcarded, this source can be used as the base
2194 * image for an icon of any size. If the size is not wildcarded, then
2195 * the size the source applies to should be set with
2196 * gtk_icon_source_set_size() and the icon source will only be used
2197 * with that specific size.
2199 * #GtkIconSet prefers non-wildcarded sources (exact matches) over
2200 * wildcarded sources, and will use an exact match when possible.
2202 * #GtkIconSet will normally scale wildcarded source images to produce
2203 * an appropriate icon at a given size, but will not change the size
2204 * of source images that match exactly.
2207 gtk_icon_source_set_size_wildcarded (GtkIconSource *source,
2210 g_return_if_fail (source != NULL);
2212 source->any_size = setting != FALSE;
2216 * gtk_icon_source_get_size_wildcarded:
2217 * @source: a #GtkIconSource
2219 * Gets the value set by gtk_icon_source_set_size_wildcarded().
2221 * Return value: %TRUE if this icon source is a base for any icon size variant
2224 gtk_icon_source_get_size_wildcarded (const GtkIconSource *source)
2226 g_return_val_if_fail (source != NULL, TRUE);
2228 return source->any_size;
2232 * gtk_icon_source_get_state_wildcarded:
2233 * @source: a #GtkIconSource
2235 * Gets the value set by gtk_icon_source_set_state_wildcarded().
2237 * Return value: %TRUE if this icon source is a base for any widget state variant
2240 gtk_icon_source_get_state_wildcarded (const GtkIconSource *source)
2242 g_return_val_if_fail (source != NULL, TRUE);
2244 return source->any_state;
2248 * gtk_icon_source_get_direction_wildcarded:
2249 * @source: a #GtkIconSource
2251 * Gets the value set by gtk_icon_source_set_direction_wildcarded().
2253 * Return value: %TRUE if this icon source is a base for any text direction variant
2256 gtk_icon_source_get_direction_wildcarded (const GtkIconSource *source)
2258 g_return_val_if_fail (source != NULL, TRUE);
2260 return source->any_direction;
2264 * gtk_icon_source_set_direction:
2265 * @source: a #GtkIconSource
2266 * @direction: text direction this source applies to
2268 * Sets the text direction this icon source is intended to be used
2271 * Setting the text direction on an icon source makes no difference
2272 * if the text direction is wildcarded. Therefore, you should usually
2273 * call gtk_icon_source_set_direction_wildcarded() to un-wildcard it
2274 * in addition to calling this function.
2278 gtk_icon_source_set_direction (GtkIconSource *source,
2279 GtkTextDirection direction)
2281 g_return_if_fail (source != NULL);
2283 source->direction = direction;
2287 * gtk_icon_source_set_state:
2288 * @source: a #GtkIconSource
2289 * @state: widget state this source applies to
2291 * Sets the widget state this icon source is intended to be used
2294 * Setting the widget state on an icon source makes no difference
2295 * if the state is wildcarded. Therefore, you should usually
2296 * call gtk_icon_source_set_state_wildcarded() to un-wildcard it
2297 * in addition to calling this function.
2301 gtk_icon_source_set_state (GtkIconSource *source,
2304 g_return_if_fail (source != NULL);
2306 source->state = state;
2310 * gtk_icon_source_set_size:
2311 * @source: a #GtkIconSource
2312 * @size: icon size this source applies to
2314 * Sets the icon size this icon source is intended to be used
2317 * Setting the icon size on an icon source makes no difference
2318 * if the size is wildcarded. Therefore, you should usually
2319 * call gtk_icon_source_set_size_wildcarded() to un-wildcard it
2320 * in addition to calling this function.
2324 gtk_icon_source_set_size (GtkIconSource *source,
2327 g_return_if_fail (source != NULL);
2329 source->size = size;
2333 * gtk_icon_source_get_direction:
2334 * @source: a #GtkIconSource
2336 * Obtains the text direction this icon source applies to. The return
2337 * value is only useful/meaningful if the text direction is <emphasis>not</emphasis>
2340 * Return value: text direction this source matches
2343 gtk_icon_source_get_direction (const GtkIconSource *source)
2345 g_return_val_if_fail (source != NULL, 0);
2347 return source->direction;
2351 * gtk_icon_source_get_state:
2352 * @source: a #GtkIconSource
2354 * Obtains the widget state this icon source applies to. The return
2355 * value is only useful/meaningful if the widget state is <emphasis>not</emphasis>
2358 * Return value: widget state this source matches
2361 gtk_icon_source_get_state (const GtkIconSource *source)
2363 g_return_val_if_fail (source != NULL, 0);
2365 return source->state;
2369 * gtk_icon_source_get_size:
2370 * @source: a #GtkIconSource
2372 * Obtains the icon size this source applies to. The return value
2373 * is only useful/meaningful if the icon size is <emphasis>not</emphasis> wildcarded.
2375 * Return value: icon size this source matches.
2378 gtk_icon_source_get_size (const GtkIconSource *source)
2380 g_return_val_if_fail (source != NULL, 0);
2382 return source->size;
2385 #define NUM_CACHED_ICONS 8
2387 typedef struct _CachedIcon CachedIcon;
2391 /* These must all match to use the cached pixbuf.
2392 * If any don't match, we must re-render the pixbuf.
2395 GtkTextDirection direction;
2403 ensure_cache_up_to_date (GtkIconSet *icon_set)
2405 if (icon_set->cache_serial != cache_serial)
2407 clear_cache (icon_set, TRUE);
2408 icon_set->cache_serial = cache_serial;
2413 cached_icon_free (CachedIcon *icon)
2415 g_object_unref (icon->pixbuf);
2418 g_object_unref (icon->style);
2424 find_in_cache (GtkIconSet *icon_set,
2426 GtkTextDirection direction,
2433 ensure_cache_up_to_date (icon_set);
2436 tmp_list = icon_set->cache;
2437 while (tmp_list != NULL)
2439 CachedIcon *icon = tmp_list->data;
2441 if (icon->style == style &&
2442 icon->direction == direction &&
2443 icon->state == state &&
2444 (size == (GtkIconSize)-1 || icon->size == size))
2448 /* Move this icon to the front of the list. */
2449 prev->next = tmp_list->next;
2450 tmp_list->next = icon_set->cache;
2451 icon_set->cache = tmp_list;
2454 return icon->pixbuf;
2458 tmp_list = g_slist_next (tmp_list);
2465 add_to_cache (GtkIconSet *icon_set,
2467 GtkTextDirection direction,
2474 ensure_cache_up_to_date (icon_set);
2476 g_object_ref (pixbuf);
2478 /* We have to ref the style, since if the style was finalized
2479 * its address could be reused by another style, creating a
2484 g_object_ref (style);
2486 icon = g_new (CachedIcon, 1);
2487 icon_set->cache = g_slist_prepend (icon_set->cache, icon);
2488 icon_set->cache_size++;
2490 icon->style = style;
2491 icon->direction = direction;
2492 icon->state = state;
2494 icon->pixbuf = pixbuf;
2497 attach_to_style (icon_set, icon->style);
2499 if (icon_set->cache_size >= NUM_CACHED_ICONS)
2501 /* Remove oldest item in the cache */
2504 tmp_list = icon_set->cache;
2506 /* Find next-to-last link */
2507 g_assert (NUM_CACHED_ICONS > 2);
2508 while (tmp_list->next->next)
2509 tmp_list = tmp_list->next;
2511 g_assert (tmp_list != NULL);
2512 g_assert (tmp_list->next != NULL);
2513 g_assert (tmp_list->next->next == NULL);
2515 /* Free the last icon */
2516 icon = tmp_list->next->data;
2518 g_slist_free (tmp_list->next);
2519 tmp_list->next = NULL;
2521 cached_icon_free (icon);
2526 clear_cache (GtkIconSet *icon_set,
2527 gboolean style_detach)
2529 GSList *cache, *tmp_list;
2530 GtkStyle *last_style = NULL;
2532 cache = icon_set->cache;
2533 icon_set->cache = NULL;
2534 icon_set->cache_size = 0;
2536 while (tmp_list != NULL)
2538 CachedIcon *icon = tmp_list->data;
2542 /* simple optimization for the case where the cache
2543 * contains contiguous icons from the same style.
2544 * it's safe to call detach_from_style more than
2545 * once on the same style though.
2547 if (last_style != icon->style)
2549 detach_from_style (icon_set, icon->style);
2550 last_style = icon->style;
2554 cached_icon_free (icon);
2556 tmp_list = g_slist_next (tmp_list);
2559 g_slist_free (cache);
2563 copy_cache (GtkIconSet *icon_set,
2564 GtkIconSet *copy_recipient)
2567 GSList *copy = NULL;
2569 ensure_cache_up_to_date (icon_set);
2571 tmp_list = icon_set->cache;
2572 while (tmp_list != NULL)
2574 CachedIcon *icon = tmp_list->data;
2575 CachedIcon *icon_copy = g_new (CachedIcon, 1);
2579 if (icon_copy->style)
2581 attach_to_style (copy_recipient, icon_copy->style);
2582 g_object_ref (icon_copy->style);
2585 g_object_ref (icon_copy->pixbuf);
2587 icon_copy->size = icon->size;
2589 copy = g_slist_prepend (copy, icon_copy);
2591 tmp_list = g_slist_next (tmp_list);
2594 return g_slist_reverse (copy);
2598 attach_to_style (GtkIconSet *icon_set,
2603 table = g_object_get_qdata (G_OBJECT (style),
2604 g_quark_try_string ("gtk-style-icon-sets"));
2608 table = g_hash_table_new (NULL, NULL);
2609 g_object_set_qdata_full (G_OBJECT (style),
2610 g_quark_from_static_string ("gtk-style-icon-sets"),
2615 g_hash_table_insert (table, icon_set, icon_set);
2619 detach_from_style (GtkIconSet *icon_set,
2624 table = g_object_get_qdata (G_OBJECT (style),
2625 g_quark_try_string ("gtk-style-icon-sets"));
2628 g_hash_table_remove (table, icon_set);
2632 iconsets_foreach (gpointer key,
2636 GtkIconSet *icon_set = key;
2638 /* We only need to remove cache entries for the given style;
2639 * but that complicates things because in destroy notify
2640 * we don't know which style got destroyed, and 95% of the
2641 * time all cache entries will have the same style,
2642 * so this is faster anyway.
2645 clear_cache (icon_set, FALSE);
2649 style_dnotify (gpointer data)
2651 GHashTable *table = data;
2653 g_hash_table_foreach (table, iconsets_foreach, NULL);
2655 g_hash_table_destroy (table);
2658 /* This allows the icon set to detect that its cache is out of date. */
2660 _gtk_icon_set_invalidate_caches (void)
2666 * _gtk_icon_factory_list_ids:
2668 * Gets all known IDs stored in an existing icon factory.
2669 * The strings in the returned list aren't copied.
2670 * The list itself should be freed.
2672 * Return value: List of ids in icon factories
2675 _gtk_icon_factory_list_ids (void)
2682 _gtk_icon_factory_ensure_default_icons ();
2684 tmp_list = all_icon_factories;
2685 while (tmp_list != NULL)
2689 GtkIconFactory *factory = GTK_ICON_FACTORY (tmp_list->data);
2691 these_ids = g_hash_table_get_keys (factory->icons);
2693 ids = g_list_concat (ids, these_ids);
2695 tmp_list = g_slist_next (tmp_list);
2703 /* DLL ABI stability backward compatibility versions */
2705 #undef gtk_icon_source_set_filename
2708 gtk_icon_source_set_filename (GtkIconSource *source,
2709 const gchar *filename)
2711 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2713 gtk_icon_source_set_filename_utf8 (source, utf8_filename);
2715 g_free (utf8_filename);
2718 #undef gtk_icon_source_get_filename
2720 G_CONST_RETURN gchar*
2721 gtk_icon_source_get_filename (const GtkIconSource *source)
2723 g_return_val_if_fail (source != NULL, NULL);
2725 if (source->type == GTK_ICON_SOURCE_FILENAME)
2726 return source->cp_filename;
2733 #define __GTK_ICON_FACTORY_C__
2734 #include "gtkaliasdef.c"