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 >= icon_sizes_used)
837 if (size == GTK_ICON_SIZE_INVALID)
842 gboolean initial = FALSE;
844 settings_sizes = get_settings_sizes (settings, &initial);
846 icon_sizes_init_for_settings (settings);
848 if (size < settings_sizes->len)
850 SettingsIconSize *settings_size;
852 settings_size = &g_array_index (settings_sizes, SettingsIconSize, size);
854 width_for_settings = settings_size->width;
855 height_for_settings = settings_size->height;
860 *widthp = width_for_settings >= 0 ? width_for_settings : icon_sizes[size].width;
863 *heightp = height_for_settings >= 0 ? height_for_settings : icon_sizes[size].height;
869 * gtk_icon_size_lookup_for_settings:
870 * @settings: a #GtkSettings object, used to determine
871 * which set of user preferences to used.
872 * @size: an icon size
873 * @width: location to store icon width
874 * @height: location to store icon height
876 * Obtains the pixel size of a semantic icon size, possibly
877 * modified by user preferences for a particular
878 * #GtkSettings. Normally @size would be
879 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc. This function
880 * isn't normally needed, gtk_widget_render_icon() is the usual
881 * way to get an icon for rendering, then just look at the size of
882 * the rendered pixbuf. The rendered pixbuf may not even correspond to
883 * the width/height returned by gtk_icon_size_lookup(), because themes
884 * are free to render the pixbuf however they like, including changing
887 * Return value: %TRUE if @size was a valid size
892 gtk_icon_size_lookup_for_settings (GtkSettings *settings,
897 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
899 return icon_size_lookup_intern (settings, size, width, height);
903 * gtk_icon_size_lookup:
904 * @size: an icon size
905 * @width: location to store icon width
906 * @height: location to store icon height
908 * Obtains the pixel size of a semantic icon size, possibly
909 * modified by user preferences for the default #GtkSettings.
910 * (See gtk_icon_size_lookup_for_settings().)
911 * Normally @size would be
912 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc. This function
913 * isn't normally needed, gtk_widget_render_icon() is the usual
914 * way to get an icon for rendering, then just look at the size of
915 * the rendered pixbuf. The rendered pixbuf may not even correspond to
916 * the width/height returned by gtk_icon_size_lookup(), because themes
917 * are free to render the pixbuf however they like, including changing
920 * Return value: %TRUE if @size was a valid size
923 gtk_icon_size_lookup (GtkIconSize size,
928 g_warning ("gtk_icon_size_lookup ()) is not multihead safe"));
930 return gtk_icon_size_lookup_for_settings (gtk_settings_get_default (),
931 size, widthp, heightp);
935 icon_size_register_intern (const gchar *name,
939 IconAlias *old_alias;
944 old_alias = g_hash_table_lookup (icon_aliases, name);
945 if (old_alias && icon_sizes[old_alias->target].width > 0)
947 g_warning ("Icon size name '%s' already exists", name);
948 return GTK_ICON_SIZE_INVALID;
953 size = old_alias->target;
957 if (icon_sizes_used == icon_sizes_allocated)
959 icon_sizes_allocated *= 2;
960 icon_sizes = g_renew (IconSize, icon_sizes, icon_sizes_allocated);
963 size = icon_sizes_used++;
966 gtk_icon_size_register_alias (name, size);
968 icon_sizes[size].size = size;
969 icon_sizes[size].name = g_strdup (name);
972 icon_sizes[size].width = width;
973 icon_sizes[size].height = height;
979 * gtk_icon_size_register:
980 * @name: name of the icon size
981 * @width: the icon width
982 * @height: the icon height
984 * Registers a new icon size, along the same lines as #GTK_ICON_SIZE_MENU,
985 * etc. Returns the integer value for the size.
987 * Returns: integer value representing the size
991 gtk_icon_size_register (const gchar *name,
995 g_return_val_if_fail (name != NULL, 0);
996 g_return_val_if_fail (width > 0, 0);
997 g_return_val_if_fail (height > 0, 0);
999 return icon_size_register_intern (name, width, height);
1003 * gtk_icon_size_register_alias:
1004 * @alias: an alias for @target
1005 * @target: an existing icon size
1007 * Registers @alias as another name for @target.
1008 * So calling gtk_icon_size_from_name() with @alias as argument
1009 * will return @target.
1013 gtk_icon_size_register_alias (const gchar *alias,
1018 g_return_if_fail (alias != NULL);
1022 if (!icon_size_lookup_intern (NULL, target, NULL, NULL))
1023 g_warning ("gtk_icon_size_register_alias: Icon size %d does not exist", target);
1025 ia = g_hash_table_lookup (icon_aliases, alias);
1028 if (icon_sizes[ia->target].width > 0)
1030 g_warning ("gtk_icon_size_register_alias: Icon size name '%s' already exists", alias);
1034 ia->target = target;
1039 ia = g_new (IconAlias, 1);
1040 ia->name = g_strdup (alias);
1041 ia->target = target;
1043 g_hash_table_insert (icon_aliases, ia->name, ia);
1048 * gtk_icon_size_from_name:
1049 * @name: the name to look up.
1050 * @returns: the icon size with the given name.
1052 * Looks up the icon size associated with @name.
1055 gtk_icon_size_from_name (const gchar *name)
1061 ia = g_hash_table_lookup (icon_aliases, name);
1063 if (ia && icon_sizes[ia->target].width > 0)
1066 return GTK_ICON_SIZE_INVALID;
1070 * gtk_icon_size_get_name:
1071 * @size: a #GtkIconSize.
1072 * @returns: the name of the given icon size.
1074 * Gets the canonical name of the given icon size. The returned string
1075 * is statically allocated and should not be freed.
1077 G_CONST_RETURN gchar*
1078 gtk_icon_size_get_name (GtkIconSize size)
1080 if (size >= icon_sizes_used)
1083 return icon_sizes[size].name;
1086 /************************************************************/
1091 static GdkPixbuf *find_in_cache (GtkIconSet *icon_set,
1093 GtkTextDirection direction,
1096 static void add_to_cache (GtkIconSet *icon_set,
1098 GtkTextDirection direction,
1102 /* Clear icon set contents, drop references to all contained
1103 * GdkPixbuf objects and forget all GtkIconSources. Used to
1104 * recycle an icon set.
1106 static void clear_cache (GtkIconSet *icon_set,
1107 gboolean style_detach);
1108 static GSList* copy_cache (GtkIconSet *icon_set,
1109 GtkIconSet *copy_recipient);
1110 static void attach_to_style (GtkIconSet *icon_set,
1112 static void detach_from_style (GtkIconSet *icon_set,
1114 static void style_dnotify (gpointer data);
1122 /* Cache of the last few rendered versions of the icon. */
1130 static guint cache_serial = 0;
1135 * Creates a new #GtkIconSet. A #GtkIconSet represents a single icon
1136 * in various sizes and widget states. It can provide a #GdkPixbuf
1137 * for a given size and state on request, and automatically caches
1138 * some of the rendered #GdkPixbuf objects.
1140 * Normally you would use gtk_widget_render_icon() instead of
1141 * using #GtkIconSet directly. The one case where you'd use
1142 * #GtkIconSet is to create application-specific icon sets to place in
1143 * a #GtkIconFactory.
1145 * Return value: a new #GtkIconSet
1148 gtk_icon_set_new (void)
1150 GtkIconSet *icon_set;
1152 icon_set = g_new (GtkIconSet, 1);
1154 icon_set->ref_count = 1;
1155 icon_set->sources = NULL;
1156 icon_set->cache = NULL;
1157 icon_set->cache_size = 0;
1158 icon_set->cache_serial = cache_serial;
1164 * gtk_icon_set_new_from_pixbuf:
1165 * @pixbuf: a #GdkPixbuf
1167 * Creates a new #GtkIconSet with @pixbuf as the default/fallback
1168 * source image. If you don't add any additional #GtkIconSource to the
1169 * icon set, all variants of the icon will be created from @pixbuf,
1170 * using scaling, pixelation, etc. as required to adjust the icon size
1171 * or make the icon look insensitive/prelighted.
1173 * Return value: a new #GtkIconSet
1176 gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf)
1180 GtkIconSource source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
1182 g_return_val_if_fail (pixbuf != NULL, NULL);
1184 set = gtk_icon_set_new ();
1186 gtk_icon_source_set_pixbuf (&source, pixbuf);
1187 gtk_icon_set_add_source (set, &source);
1188 gtk_icon_source_set_pixbuf (&source, NULL);
1196 * @icon_set: a #GtkIconSet.
1198 * Increments the reference count on @icon_set.
1200 * Return value: @icon_set.
1203 gtk_icon_set_ref (GtkIconSet *icon_set)
1205 g_return_val_if_fail (icon_set != NULL, NULL);
1206 g_return_val_if_fail (icon_set->ref_count > 0, NULL);
1208 icon_set->ref_count += 1;
1214 * gtk_icon_set_unref:
1215 * @icon_set: a #GtkIconSet
1217 * Decrements the reference count on @icon_set, and frees memory
1218 * if the reference count reaches 0.
1221 gtk_icon_set_unref (GtkIconSet *icon_set)
1223 g_return_if_fail (icon_set != NULL);
1224 g_return_if_fail (icon_set->ref_count > 0);
1226 icon_set->ref_count -= 1;
1228 if (icon_set->ref_count == 0)
1230 GSList *tmp_list = icon_set->sources;
1231 while (tmp_list != NULL)
1233 gtk_icon_source_free (tmp_list->data);
1235 tmp_list = g_slist_next (tmp_list);
1237 g_slist_free (icon_set->sources);
1239 clear_cache (icon_set, TRUE);
1246 gtk_icon_set_get_type (void)
1248 static GType our_type = 0;
1251 our_type = g_boxed_type_register_static (I_("GtkIconSet"),
1252 (GBoxedCopyFunc) gtk_icon_set_ref,
1253 (GBoxedFreeFunc) gtk_icon_set_unref);
1259 * gtk_icon_set_copy:
1260 * @icon_set: a #GtkIconSet
1262 * Copies @icon_set by value.
1264 * Return value: a new #GtkIconSet identical to the first.
1267 gtk_icon_set_copy (GtkIconSet *icon_set)
1272 copy = gtk_icon_set_new ();
1274 tmp_list = icon_set->sources;
1275 while (tmp_list != NULL)
1277 copy->sources = g_slist_prepend (copy->sources,
1278 gtk_icon_source_copy (tmp_list->data));
1280 tmp_list = g_slist_next (tmp_list);
1283 copy->sources = g_slist_reverse (copy->sources);
1285 copy->cache = copy_cache (icon_set, copy);
1286 copy->cache_size = icon_set->cache_size;
1287 copy->cache_serial = icon_set->cache_serial;
1293 sizes_equivalent (GtkIconSize lhs,
1296 /* We used to consider sizes equivalent if they were
1297 * the same pixel size, but we don't have the GtkSettings
1298 * here, so we can't do that. Plus, it's not clear that
1299 * it is right... it was just a workaround for the fact
1300 * that we register icons by logical size, not pixel size.
1306 gint r_w, r_h, l_w, l_h;
1308 icon_size_lookup_intern (NULL, rhs, &r_w, &r_h);
1309 icon_size_lookup_intern (NULL, lhs, &l_w, &l_h);
1311 return r_w == l_w && r_h == l_h;
1315 static GtkIconSource *
1316 find_best_matching_source (GtkIconSet *icon_set,
1317 GtkTextDirection direction,
1322 GtkIconSource *source;
1325 /* We need to find the best icon source. Direction matters more
1326 * than state, state matters more than size. icon_set->sources
1327 * is sorted according to wildness, so if we take the first
1328 * match we find it will be the least-wild match (if there are
1329 * multiple matches for a given "wildness" then the RC file contained
1330 * dumb stuff, and we end up with an arbitrary matching source)
1334 tmp_list = icon_set->sources;
1335 while (tmp_list != NULL)
1337 GtkIconSource *s = tmp_list->data;
1339 if ((s->any_direction || (s->direction == direction)) &&
1340 (s->any_state || (s->state == state)) &&
1341 (s->any_size || (sizes_equivalent (size, s->size))))
1343 if (!g_slist_find (failed, s))
1350 tmp_list = g_slist_next (tmp_list);
1357 ensure_filename_pixbuf (GtkIconSet *icon_set,
1358 GtkIconSource *source)
1360 if (source->filename_pixbuf == NULL)
1362 GError *error = NULL;
1364 source->filename_pixbuf = gdk_pixbuf_new_from_file (source->source.filename, &error);
1366 if (source->filename_pixbuf == NULL)
1368 /* Remove this icon source so we don't keep trying to
1371 g_warning (_("Error loading icon: %s"), error->message);
1372 g_error_free (error);
1374 icon_set->sources = g_slist_remove (icon_set->sources, source);
1376 gtk_icon_source_free (source);
1386 render_icon_name_pixbuf (GtkIconSource *icon_source,
1388 GtkTextDirection direction,
1395 GdkPixbuf *tmp_pixbuf;
1396 GtkIconSource tmp_source;
1398 GtkIconTheme *icon_theme;
1399 GtkSettings *settings;
1400 gint width, height, pixel_size;
1401 gint *sizes, *s, dist;
1402 GError *error = NULL;
1404 if (widget && gtk_widget_has_screen (widget))
1405 screen = gtk_widget_get_screen (widget);
1406 else if (style && style->colormap)
1407 screen = gdk_colormap_get_screen (style->colormap);
1410 screen = gdk_screen_get_default ();
1411 GTK_NOTE (MULTIHEAD,
1412 g_warning ("Using the default screen for gtk_icon_source_render_icon()"));
1415 icon_theme = gtk_icon_theme_get_for_screen (screen);
1416 settings = gtk_settings_get_for_screen (screen);
1418 if (!gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
1422 /* Find an available size close to 48
1424 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, icon_source->source.icon_name);
1426 width = height = 48;
1427 for (s = sizes; *s; s++)
1431 width = height = 48;
1438 width = height = *s;
1446 width = height = *s;
1456 g_warning ("Invalid icon size %d\n", size);
1457 width = height = 24;
1461 pixel_size = MIN (width, height);
1463 tmp_pixbuf = gtk_icon_theme_load_icon (icon_theme,
1464 icon_source->source.icon_name,
1470 g_warning ("Error loading theme icon for stock: %s", error->message);
1471 g_error_free (error);
1475 tmp_source = *icon_source;
1476 tmp_source.type = GTK_ICON_SOURCE_PIXBUF;
1477 tmp_source.source.pixbuf = tmp_pixbuf;
1479 pixbuf = gtk_style_render_icon (style, &tmp_source,
1480 direction, state, -1,
1484 g_warning ("Failed to render icon");
1486 g_object_unref (tmp_pixbuf);
1492 find_and_render_icon_source (GtkIconSet *icon_set,
1494 GtkTextDirection direction,
1500 GSList *failed = NULL;
1501 GdkPixbuf *pixbuf = NULL;
1503 /* We treat failure in two different ways:
1505 * A) If loading a source that specifies a filename fails,
1506 * we treat that as permanent, and remove the source
1507 * from the GtkIconSet. (in ensure_filename_pixbuf ()
1508 * B) If loading a themed icon fails, or scaling an icon
1509 * fails, we treat that as transient and will try
1510 * again next time the icon falls out of the cache
1511 * and we need to recreate it.
1513 while (pixbuf == NULL)
1515 GtkIconSource *source = find_best_matching_source (icon_set, direction, state, size, failed);
1520 switch (source->type)
1522 case GTK_ICON_SOURCE_FILENAME:
1523 if (!ensure_filename_pixbuf (icon_set, source))
1526 case GTK_ICON_SOURCE_PIXBUF:
1527 pixbuf = gtk_style_render_icon (style, source,
1528 direction, state, size,
1532 g_warning ("Failed to render icon");
1533 failed = g_slist_prepend (failed, source);
1536 case GTK_ICON_SOURCE_ICON_NAME:
1537 case GTK_ICON_SOURCE_STATIC_ICON_NAME:
1538 pixbuf = render_icon_name_pixbuf (source, style,
1539 direction, state, size,
1542 failed = g_slist_prepend (failed, source);
1544 case GTK_ICON_SOURCE_EMPTY:
1545 g_assert_not_reached ();
1549 g_slist_free (failed);
1554 extern GtkIconCache *_builtin_cache;
1557 render_fallback_image (GtkStyle *style,
1558 GtkTextDirection direction,
1564 /* This icon can be used for any direction/state/size */
1565 static GtkIconSource fallback_source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
1567 if (fallback_source.type == GTK_ICON_SOURCE_EMPTY)
1571 _gtk_icon_theme_ensure_builtin_cache ();
1573 pixbuf = _gtk_icon_cache_get_icon (_builtin_cache,
1574 GTK_STOCK_MISSING_IMAGE,
1576 gtk_icon_source_set_pixbuf (&fallback_source, pixbuf);
1577 g_object_unref (pixbuf);
1580 return gtk_style_render_icon (style,
1590 * gtk_icon_set_render_icon:
1591 * @icon_set: a #GtkIconSet
1592 * @style: a #GtkStyle associated with @widget, or %NULL
1593 * @direction: text direction
1594 * @state: widget state
1595 * @size: icon size. A size of (GtkIconSize)-1
1596 * means render at the size of the source and don't scale.
1597 * @widget: widget that will display the icon, or %NULL.
1598 * The only use that is typically made of this
1599 * is to determine the appropriate #GdkScreen.
1600 * @detail: detail to pass to the theme engine, or %NULL.
1601 * Note that passing a detail of anything but %NULL
1602 * will disable caching.
1604 * Renders an icon using gtk_style_render_icon(). In most cases,
1605 * gtk_widget_render_icon() is better, since it automatically provides
1606 * most of the arguments from the current widget settings. This
1607 * function never returns %NULL; if the icon can't be rendered
1608 * (perhaps because an image file fails to load), a default "missing
1609 * image" icon will be returned instead.
1611 * Return value: a #GdkPixbuf to be displayed
1614 gtk_icon_set_render_icon (GtkIconSet *icon_set,
1616 GtkTextDirection direction,
1624 g_return_val_if_fail (icon_set != NULL, NULL);
1625 g_return_val_if_fail (style == NULL || GTK_IS_STYLE (style), NULL);
1627 if (icon_set->sources == NULL)
1628 return render_fallback_image (style, direction, state, size, widget, detail);
1632 icon = find_in_cache (icon_set, style, direction,
1637 g_object_ref (icon);
1643 icon = find_and_render_icon_source (icon_set, style, direction, state, size,
1647 icon = render_fallback_image (style, direction, state, size, widget, detail);
1650 add_to_cache (icon_set, style, direction, state, size, icon);
1655 /* Order sources by their "wildness", so that "wilder" sources are
1656 * greater than "specific" sources; for determining ordering,
1657 * direction beats state beats size.
1661 icon_source_compare (gconstpointer ap, gconstpointer bp)
1663 const GtkIconSource *a = ap;
1664 const GtkIconSource *b = bp;
1666 if (!a->any_direction && b->any_direction)
1668 else if (a->any_direction && !b->any_direction)
1670 else if (!a->any_state && b->any_state)
1672 else if (a->any_state && !b->any_state)
1674 else if (!a->any_size && b->any_size)
1676 else if (a->any_size && !b->any_size)
1683 * gtk_icon_set_add_source:
1684 * @icon_set: a #GtkIconSet
1685 * @source: a #GtkIconSource
1687 * Icon sets have a list of #GtkIconSource, which they use as base
1688 * icons for rendering icons in different states and sizes. Icons are
1689 * scaled, made to look insensitive, etc. in
1690 * gtk_icon_set_render_icon(), but #GtkIconSet needs base images to
1691 * work with. The base images and when to use them are described by
1694 * This function copies @source, so you can reuse the same source immediately
1695 * without affecting the icon set.
1697 * An example of when you'd use this function: a web browser's "Back
1698 * to Previous Page" icon might point in a different direction in
1699 * Hebrew and in English; it might look different when insensitive;
1700 * and it might change size depending on toolbar mode (small/large
1701 * icons). So a single icon set would contain all those variants of
1702 * the icon, and you might add a separate source for each one.
1704 * You should nearly always add a "default" icon source with all
1705 * fields wildcarded, which will be used as a fallback if no more
1706 * specific source matches. #GtkIconSet always prefers more specific
1707 * icon sources to more generic icon sources. The order in which you
1708 * add the sources to the icon set does not matter.
1710 * gtk_icon_set_new_from_pixbuf() creates a new icon set with a
1711 * default icon source based on the given pixbuf.
1715 gtk_icon_set_add_source (GtkIconSet *icon_set,
1716 const GtkIconSource *source)
1718 g_return_if_fail (icon_set != NULL);
1719 g_return_if_fail (source != NULL);
1721 if (source->type == GTK_ICON_SOURCE_EMPTY)
1723 g_warning ("Useless empty GtkIconSource");
1727 icon_set->sources = g_slist_insert_sorted (icon_set->sources,
1728 gtk_icon_source_copy (source),
1729 icon_source_compare);
1733 * gtk_icon_set_get_sizes:
1734 * @icon_set: a #GtkIconSet
1735 * @sizes: return location for array of sizes
1736 * @n_sizes: location to store number of elements in returned array
1738 * Obtains a list of icon sizes this icon set can render. The returned
1739 * array must be freed with g_free().
1743 gtk_icon_set_get_sizes (GtkIconSet *icon_set,
1744 GtkIconSize **sizes,
1748 gboolean all_sizes = FALSE;
1749 GSList *specifics = NULL;
1751 g_return_if_fail (icon_set != NULL);
1752 g_return_if_fail (sizes != NULL);
1753 g_return_if_fail (n_sizes != NULL);
1755 tmp_list = icon_set->sources;
1756 while (tmp_list != NULL)
1758 GtkIconSource *source;
1760 source = tmp_list->data;
1762 if (source->any_size)
1768 specifics = g_slist_prepend (specifics, GINT_TO_POINTER (source->size));
1770 tmp_list = g_slist_next (tmp_list);
1775 /* Need to find out what sizes exist */
1780 *sizes = g_new (GtkIconSize, icon_sizes_used);
1781 *n_sizes = icon_sizes_used - 1;
1784 while (i < icon_sizes_used)
1786 (*sizes)[i - 1] = icon_sizes[i].size;
1794 *n_sizes = g_slist_length (specifics);
1795 *sizes = g_new (GtkIconSize, *n_sizes);
1798 tmp_list = specifics;
1799 while (tmp_list != NULL)
1801 (*sizes)[i] = GPOINTER_TO_INT (tmp_list->data);
1804 tmp_list = g_slist_next (tmp_list);
1808 g_slist_free (specifics);
1813 * gtk_icon_source_new:
1815 * Creates a new #GtkIconSource. A #GtkIconSource contains a #GdkPixbuf (or
1816 * image filename) that serves as the base image for one or more of the
1817 * icons in a #GtkIconSet, along with a specification for which icons in the
1818 * icon set will be based on that pixbuf or image file. An icon set contains
1819 * a set of icons that represent "the same" logical concept in different states,
1820 * different global text directions, and different sizes.
1822 * So for example a web browser's "Back to Previous Page" icon might
1823 * point in a different direction in Hebrew and in English; it might
1824 * look different when insensitive; and it might change size depending
1825 * on toolbar mode (small/large icons). So a single icon set would
1826 * contain all those variants of the icon. #GtkIconSet contains a list
1827 * of #GtkIconSource from which it can derive specific icon variants in
1830 * In the simplest case, #GtkIconSet contains one source pixbuf from
1831 * which it derives all variants. The convenience function
1832 * gtk_icon_set_new_from_pixbuf() handles this case; if you only have
1833 * one source pixbuf, just use that function.
1835 * If you want to use a different base pixbuf for different icon
1836 * variants, you create multiple icon sources, mark which variants
1837 * they'll be used to create, and add them to the icon set with
1838 * gtk_icon_set_add_source().
1840 * By default, the icon source has all parameters wildcarded. That is,
1841 * the icon source will be used as the base icon for any desired text
1842 * direction, widget state, or icon size.
1844 * Return value: a new #GtkIconSource
1847 gtk_icon_source_new (void)
1851 src = g_new0 (GtkIconSource, 1);
1853 src->direction = GTK_TEXT_DIR_NONE;
1854 src->size = GTK_ICON_SIZE_INVALID;
1855 src->state = GTK_STATE_NORMAL;
1857 src->any_direction = TRUE;
1858 src->any_state = TRUE;
1859 src->any_size = TRUE;
1865 * gtk_icon_source_copy:
1866 * @source: a #GtkIconSource
1868 * Creates a copy of @source; mostly useful for language bindings.
1870 * Return value: a new #GtkIconSource
1873 gtk_icon_source_copy (const GtkIconSource *source)
1875 GtkIconSource *copy;
1877 g_return_val_if_fail (source != NULL, NULL);
1879 copy = g_new (GtkIconSource, 1);
1885 case GTK_ICON_SOURCE_EMPTY:
1886 case GTK_ICON_SOURCE_STATIC_ICON_NAME:
1888 case GTK_ICON_SOURCE_ICON_NAME:
1889 copy->source.icon_name = g_strdup (copy->source.icon_name);
1891 case GTK_ICON_SOURCE_FILENAME:
1892 copy->source.filename = g_strdup (copy->source.filename);
1894 copy->cp_filename = g_strdup (copy->cp_filename);
1896 if (copy->filename_pixbuf)
1897 g_object_ref (copy->filename_pixbuf);
1899 case GTK_ICON_SOURCE_PIXBUF:
1900 g_object_ref (copy->source.pixbuf);
1903 g_assert_not_reached();
1910 * gtk_icon_source_free:
1911 * @source: a #GtkIconSource
1913 * Frees a dynamically-allocated icon source, along with its
1914 * filename, size, and pixbuf fields if those are not %NULL.
1917 gtk_icon_source_free (GtkIconSource *source)
1919 g_return_if_fail (source != NULL);
1921 icon_source_clear (source);
1926 gtk_icon_source_get_type (void)
1928 static GType our_type = 0;
1931 our_type = g_boxed_type_register_static ("GtkIconSource",
1932 (GBoxedCopyFunc) gtk_icon_source_copy,
1933 (GBoxedFreeFunc) gtk_icon_source_free);
1939 icon_source_clear (GtkIconSource *source)
1941 switch (source->type)
1943 case GTK_ICON_SOURCE_EMPTY:
1945 case GTK_ICON_SOURCE_ICON_NAME:
1946 g_free (source->source.icon_name);
1948 case GTK_ICON_SOURCE_STATIC_ICON_NAME:
1949 source->source.icon_name = NULL;
1951 case GTK_ICON_SOURCE_FILENAME:
1952 g_free (source->source.filename);
1953 source->source.filename = NULL;
1955 g_free (source->cp_filename);
1956 source->cp_filename = NULL;
1958 if (source->filename_pixbuf)
1959 g_object_unref (source->filename_pixbuf);
1960 source->filename_pixbuf = NULL;
1962 case GTK_ICON_SOURCE_PIXBUF:
1963 g_object_unref (source->source.pixbuf);
1964 source->source.pixbuf = NULL;
1967 g_assert_not_reached();
1970 source->type = GTK_ICON_SOURCE_EMPTY;
1974 * gtk_icon_source_set_filename:
1975 * @source: a #GtkIconSource
1976 * @filename: image file to use
1978 * Sets the name of an image file to use as a base image when creating
1979 * icon variants for #GtkIconSet. The filename must be absolute.
1982 gtk_icon_source_set_filename (GtkIconSource *source,
1983 const gchar *filename)
1985 g_return_if_fail (source != NULL);
1986 g_return_if_fail (filename == NULL || g_path_is_absolute (filename));
1988 if (source->type == GTK_ICON_SOURCE_FILENAME &&
1989 source->source.filename == filename)
1992 icon_source_clear (source);
1994 if (filename != NULL)
1996 source->type = GTK_ICON_SOURCE_FILENAME;
1997 source->source.filename = g_strdup (filename);
1999 source->cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
2005 * gtk_icon_source_set_icon_name
2006 * @source: a #GtkIconSource
2007 * @icon_name: name of icon to use
2009 * Sets the name of an icon to look up in the current icon theme
2010 * to use as a base image when creating icon variants for #GtkIconSet.
2013 gtk_icon_source_set_icon_name (GtkIconSource *source,
2014 const gchar *icon_name)
2016 g_return_if_fail (source != NULL);
2018 if (source->type == GTK_ICON_SOURCE_ICON_NAME &&
2019 source->source.icon_name == icon_name)
2022 icon_source_clear (source);
2024 if (icon_name != NULL)
2026 source->type = GTK_ICON_SOURCE_ICON_NAME;
2027 source->source.icon_name = g_strdup (icon_name);
2032 * gtk_icon_source_set_pixbuf:
2033 * @source: a #GtkIconSource
2034 * @pixbuf: pixbuf to use as a source
2036 * Sets a pixbuf to use as a base image when creating icon variants
2040 gtk_icon_source_set_pixbuf (GtkIconSource *source,
2043 g_return_if_fail (source != NULL);
2044 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2046 if (source->type == GTK_ICON_SOURCE_PIXBUF &&
2047 source->source.pixbuf == pixbuf)
2050 icon_source_clear (source);
2054 source->type = GTK_ICON_SOURCE_PIXBUF;
2055 source->source.pixbuf = g_object_ref (pixbuf);
2060 * gtk_icon_source_get_filename:
2061 * @source: a #GtkIconSource
2063 * Retrieves the source filename, or %NULL if none is set. The
2064 * filename is not a copy, and should not be modified or expected to
2065 * persist beyond the lifetime of the icon source.
2067 * Return value: image filename. This string must not be modified
2070 G_CONST_RETURN gchar*
2071 gtk_icon_source_get_filename (const GtkIconSource *source)
2073 g_return_val_if_fail (source != NULL, NULL);
2075 if (source->type == GTK_ICON_SOURCE_FILENAME)
2076 return source->source.filename;
2082 * gtk_icon_source_get_icon_name:
2083 * @source: a #GtkIconSource
2085 * Retrieves the source icon name, or %NULL if none is set. The
2086 * icon_name is not a copy, and should not be modified or expected to
2087 * persist beyond the lifetime of the icon source.
2089 * Return value: icon name. This string must not be modified or freed.
2091 G_CONST_RETURN gchar*
2092 gtk_icon_source_get_icon_name (const GtkIconSource *source)
2094 g_return_val_if_fail (source != NULL, NULL);
2096 if (source->type == GTK_ICON_SOURCE_ICON_NAME ||
2097 source->type == GTK_ICON_SOURCE_STATIC_ICON_NAME)
2098 return source->source.icon_name;
2104 * gtk_icon_source_get_pixbuf:
2105 * @source: a #GtkIconSource
2107 * Retrieves the source pixbuf, or %NULL if none is set.
2108 * In addition, if a filename source is in use, this
2109 * function in some cases will return the pixbuf from
2110 * loaded from the filename. This is, for example, true
2111 * for the GtkIconSource passed to the GtkStyle::render_icon()
2112 * virtual function. The reference count on the pixbuf is
2115 * Return value: source pixbuf
2118 gtk_icon_source_get_pixbuf (const GtkIconSource *source)
2120 g_return_val_if_fail (source != NULL, NULL);
2122 if (source->type == GTK_ICON_SOURCE_PIXBUF)
2123 return source->source.pixbuf;
2124 else if (source->type == GTK_ICON_SOURCE_FILENAME)
2125 return source->filename_pixbuf;
2131 * gtk_icon_source_set_direction_wildcarded:
2132 * @source: a #GtkIconSource
2133 * @setting: %TRUE to wildcard the text direction
2135 * If the text direction is wildcarded, this source can be used
2136 * as the base image for an icon in any #GtkTextDirection.
2137 * If the text direction is not wildcarded, then the
2138 * text direction the icon source applies to should be set
2139 * with gtk_icon_source_set_direction(), and the icon source
2140 * will only be used with that text direction.
2142 * #GtkIconSet prefers non-wildcarded sources (exact matches) over
2143 * wildcarded sources, and will use an exact match when possible.
2147 gtk_icon_source_set_direction_wildcarded (GtkIconSource *source,
2150 g_return_if_fail (source != NULL);
2152 source->any_direction = setting != FALSE;
2156 * gtk_icon_source_set_state_wildcarded:
2157 * @source: a #GtkIconSource
2158 * @setting: %TRUE to wildcard the widget state
2160 * If the widget state is wildcarded, this source can be used as the
2161 * base image for an icon in any #GtkStateType. If the widget state
2162 * is not wildcarded, then the state the source applies to should be
2163 * set with gtk_icon_source_set_state() and the icon source will
2164 * only be used with that specific state.
2166 * #GtkIconSet prefers non-wildcarded sources (exact matches) over
2167 * wildcarded sources, and will use an exact match when possible.
2169 * #GtkIconSet will normally transform wildcarded source images to
2170 * produce an appropriate icon for a given state, for example
2171 * lightening an image on prelight, but will not modify source images
2172 * that match exactly.
2175 gtk_icon_source_set_state_wildcarded (GtkIconSource *source,
2178 g_return_if_fail (source != NULL);
2180 source->any_state = setting != FALSE;
2185 * gtk_icon_source_set_size_wildcarded:
2186 * @source: a #GtkIconSource
2187 * @setting: %TRUE to wildcard the widget state
2189 * If the icon size is wildcarded, this source can be used as the base
2190 * image for an icon of any size. If the size is not wildcarded, then
2191 * the size the source applies to should be set with
2192 * gtk_icon_source_set_size() and the icon source will only be used
2193 * with that specific size.
2195 * #GtkIconSet prefers non-wildcarded sources (exact matches) over
2196 * wildcarded sources, and will use an exact match when possible.
2198 * #GtkIconSet will normally scale wildcarded source images to produce
2199 * an appropriate icon at a given size, but will not change the size
2200 * of source images that match exactly.
2203 gtk_icon_source_set_size_wildcarded (GtkIconSource *source,
2206 g_return_if_fail (source != NULL);
2208 source->any_size = setting != FALSE;
2212 * gtk_icon_source_get_size_wildcarded:
2213 * @source: a #GtkIconSource
2215 * Gets the value set by gtk_icon_source_set_size_wildcarded().
2217 * Return value: %TRUE if this icon source is a base for any icon size variant
2220 gtk_icon_source_get_size_wildcarded (const GtkIconSource *source)
2222 g_return_val_if_fail (source != NULL, TRUE);
2224 return source->any_size;
2228 * gtk_icon_source_get_state_wildcarded:
2229 * @source: a #GtkIconSource
2231 * Gets the value set by gtk_icon_source_set_state_wildcarded().
2233 * Return value: %TRUE if this icon source is a base for any widget state variant
2236 gtk_icon_source_get_state_wildcarded (const GtkIconSource *source)
2238 g_return_val_if_fail (source != NULL, TRUE);
2240 return source->any_state;
2244 * gtk_icon_source_get_direction_wildcarded:
2245 * @source: a #GtkIconSource
2247 * Gets the value set by gtk_icon_source_set_direction_wildcarded().
2249 * Return value: %TRUE if this icon source is a base for any text direction variant
2252 gtk_icon_source_get_direction_wildcarded (const GtkIconSource *source)
2254 g_return_val_if_fail (source != NULL, TRUE);
2256 return source->any_direction;
2260 * gtk_icon_source_set_direction:
2261 * @source: a #GtkIconSource
2262 * @direction: text direction this source applies to
2264 * Sets the text direction this icon source is intended to be used
2267 * Setting the text direction on an icon source makes no difference
2268 * if the text direction is wildcarded. Therefore, you should usually
2269 * call gtk_icon_source_set_direction_wildcarded() to un-wildcard it
2270 * in addition to calling this function.
2274 gtk_icon_source_set_direction (GtkIconSource *source,
2275 GtkTextDirection direction)
2277 g_return_if_fail (source != NULL);
2279 source->direction = direction;
2283 * gtk_icon_source_set_state:
2284 * @source: a #GtkIconSource
2285 * @state: widget state this source applies to
2287 * Sets the widget state this icon source is intended to be used
2290 * Setting the widget state on an icon source makes no difference
2291 * if the state is wildcarded. Therefore, you should usually
2292 * call gtk_icon_source_set_state_wildcarded() to un-wildcard it
2293 * in addition to calling this function.
2297 gtk_icon_source_set_state (GtkIconSource *source,
2300 g_return_if_fail (source != NULL);
2302 source->state = state;
2306 * gtk_icon_source_set_size:
2307 * @source: a #GtkIconSource
2308 * @size: icon size this source applies to
2310 * Sets the icon size this icon source is intended to be used
2313 * Setting the icon size on an icon source makes no difference
2314 * if the size is wildcarded. Therefore, you should usually
2315 * call gtk_icon_source_set_size_wildcarded() to un-wildcard it
2316 * in addition to calling this function.
2320 gtk_icon_source_set_size (GtkIconSource *source,
2323 g_return_if_fail (source != NULL);
2325 source->size = size;
2329 * gtk_icon_source_get_direction:
2330 * @source: a #GtkIconSource
2332 * Obtains the text direction this icon source applies to. The return
2333 * value is only useful/meaningful if the text direction is <emphasis>not</emphasis>
2336 * Return value: text direction this source matches
2339 gtk_icon_source_get_direction (const GtkIconSource *source)
2341 g_return_val_if_fail (source != NULL, 0);
2343 return source->direction;
2347 * gtk_icon_source_get_state:
2348 * @source: a #GtkIconSource
2350 * Obtains the widget state this icon source applies to. The return
2351 * value is only useful/meaningful if the widget state is <emphasis>not</emphasis>
2354 * Return value: widget state this source matches
2357 gtk_icon_source_get_state (const GtkIconSource *source)
2359 g_return_val_if_fail (source != NULL, 0);
2361 return source->state;
2365 * gtk_icon_source_get_size:
2366 * @source: a #GtkIconSource
2368 * Obtains the icon size this source applies to. The return value
2369 * is only useful/meaningful if the icon size is <emphasis>not</emphasis> wildcarded.
2371 * Return value: icon size this source matches.
2374 gtk_icon_source_get_size (const GtkIconSource *source)
2376 g_return_val_if_fail (source != NULL, 0);
2378 return source->size;
2381 #define NUM_CACHED_ICONS 8
2383 typedef struct _CachedIcon CachedIcon;
2387 /* These must all match to use the cached pixbuf.
2388 * If any don't match, we must re-render the pixbuf.
2391 GtkTextDirection direction;
2399 ensure_cache_up_to_date (GtkIconSet *icon_set)
2401 if (icon_set->cache_serial != cache_serial)
2403 clear_cache (icon_set, TRUE);
2404 icon_set->cache_serial = cache_serial;
2409 cached_icon_free (CachedIcon *icon)
2411 g_object_unref (icon->pixbuf);
2414 g_object_unref (icon->style);
2420 find_in_cache (GtkIconSet *icon_set,
2422 GtkTextDirection direction,
2429 ensure_cache_up_to_date (icon_set);
2432 tmp_list = icon_set->cache;
2433 while (tmp_list != NULL)
2435 CachedIcon *icon = tmp_list->data;
2437 if (icon->style == style &&
2438 icon->direction == direction &&
2439 icon->state == state &&
2444 /* Move this icon to the front of the list. */
2445 prev->next = tmp_list->next;
2446 tmp_list->next = icon_set->cache;
2447 icon_set->cache = tmp_list;
2450 return icon->pixbuf;
2454 tmp_list = g_slist_next (tmp_list);
2461 add_to_cache (GtkIconSet *icon_set,
2463 GtkTextDirection direction,
2470 ensure_cache_up_to_date (icon_set);
2472 g_object_ref (pixbuf);
2474 /* We have to ref the style, since if the style was finalized
2475 * its address could be reused by another style, creating a
2480 g_object_ref (style);
2482 icon = g_new (CachedIcon, 1);
2483 icon_set->cache = g_slist_prepend (icon_set->cache, icon);
2484 icon_set->cache_size++;
2486 icon->style = style;
2487 icon->direction = direction;
2488 icon->state = state;
2490 icon->pixbuf = pixbuf;
2493 attach_to_style (icon_set, icon->style);
2495 if (icon_set->cache_size >= NUM_CACHED_ICONS)
2497 /* Remove oldest item in the cache */
2500 tmp_list = icon_set->cache;
2502 /* Find next-to-last link */
2503 g_assert (NUM_CACHED_ICONS > 2);
2504 while (tmp_list->next->next)
2505 tmp_list = tmp_list->next;
2507 g_assert (tmp_list != NULL);
2508 g_assert (tmp_list->next != NULL);
2509 g_assert (tmp_list->next->next == NULL);
2511 /* Free the last icon */
2512 icon = tmp_list->next->data;
2514 g_slist_free (tmp_list->next);
2515 tmp_list->next = NULL;
2517 cached_icon_free (icon);
2522 clear_cache (GtkIconSet *icon_set,
2523 gboolean style_detach)
2525 GSList *cache, *tmp_list;
2526 GtkStyle *last_style = NULL;
2528 cache = icon_set->cache;
2529 icon_set->cache = NULL;
2530 icon_set->cache_size = 0;
2532 while (tmp_list != NULL)
2534 CachedIcon *icon = tmp_list->data;
2538 /* simple optimization for the case where the cache
2539 * contains contiguous icons from the same style.
2540 * it's safe to call detach_from_style more than
2541 * once on the same style though.
2543 if (last_style != icon->style)
2545 detach_from_style (icon_set, icon->style);
2546 last_style = icon->style;
2550 cached_icon_free (icon);
2552 tmp_list = g_slist_next (tmp_list);
2555 g_slist_free (cache);
2559 copy_cache (GtkIconSet *icon_set,
2560 GtkIconSet *copy_recipient)
2563 GSList *copy = NULL;
2565 ensure_cache_up_to_date (icon_set);
2567 tmp_list = icon_set->cache;
2568 while (tmp_list != NULL)
2570 CachedIcon *icon = tmp_list->data;
2571 CachedIcon *icon_copy = g_new (CachedIcon, 1);
2575 if (icon_copy->style)
2577 attach_to_style (copy_recipient, icon_copy->style);
2578 g_object_ref (icon_copy->style);
2581 g_object_ref (icon_copy->pixbuf);
2583 icon_copy->size = icon->size;
2585 copy = g_slist_prepend (copy, icon_copy);
2587 tmp_list = g_slist_next (tmp_list);
2590 return g_slist_reverse (copy);
2594 attach_to_style (GtkIconSet *icon_set,
2599 table = g_object_get_qdata (G_OBJECT (style),
2600 g_quark_try_string ("gtk-style-icon-sets"));
2604 table = g_hash_table_new (NULL, NULL);
2605 g_object_set_qdata_full (G_OBJECT (style),
2606 g_quark_from_static_string ("gtk-style-icon-sets"),
2611 g_hash_table_insert (table, icon_set, icon_set);
2615 detach_from_style (GtkIconSet *icon_set,
2620 table = g_object_get_qdata (G_OBJECT (style),
2621 g_quark_try_string ("gtk-style-icon-sets"));
2624 g_hash_table_remove (table, icon_set);
2628 iconsets_foreach (gpointer key,
2632 GtkIconSet *icon_set = key;
2634 /* We only need to remove cache entries for the given style;
2635 * but that complicates things because in destroy notify
2636 * we don't know which style got destroyed, and 95% of the
2637 * time all cache entries will have the same style,
2638 * so this is faster anyway.
2641 clear_cache (icon_set, FALSE);
2645 style_dnotify (gpointer data)
2647 GHashTable *table = data;
2649 g_hash_table_foreach (table, iconsets_foreach, NULL);
2651 g_hash_table_destroy (table);
2654 /* This allows the icon set to detect that its cache is out of date. */
2656 _gtk_icon_set_invalidate_caches (void)
2662 listify_foreach (gpointer key, gpointer value, gpointer data)
2664 GSList **list = data;
2666 *list = g_slist_prepend (*list, key);
2670 g_hash_table_get_keys (GHashTable *table)
2672 GSList *list = NULL;
2674 g_hash_table_foreach (table, listify_foreach, &list);
2680 * _gtk_icon_factory_list_ids:
2682 * Gets all known IDs stored in an existing icon factory.
2683 * The strings in the returned list aren't copied.
2684 * The list itself should be freed.
2686 * Return value: List of ids in icon factories
2689 _gtk_icon_factory_list_ids (void)
2696 _gtk_icon_factory_ensure_default_icons ();
2698 tmp_list = all_icon_factories;
2699 while (tmp_list != NULL)
2703 GtkIconFactory *factory = GTK_ICON_FACTORY (tmp_list->data);
2705 these_ids = g_hash_table_get_keys (factory->icons);
2707 ids = g_slist_concat (ids, these_ids);
2709 tmp_list = g_slist_next (tmp_list);
2717 /* DLL ABI stability backward compatibility versions */
2719 #undef gtk_icon_source_set_filename
2722 gtk_icon_source_set_filename (GtkIconSource *source,
2723 const gchar *filename)
2725 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2727 gtk_icon_source_set_filename_utf8 (source, utf8_filename);
2729 g_free (utf8_filename);
2732 #undef gtk_icon_source_get_filename
2734 G_CONST_RETURN gchar*
2735 gtk_icon_source_get_filename (const GtkIconSource *source)
2737 g_return_val_if_fail (source != NULL, NULL);
2739 if (source->type == GTK_ICON_SOURCE_FILENAME)
2740 return source->cp_filename;
2747 #define __GTK_ICON_FACTORY_C__
2748 #include "gtkaliasdef.c"