1 /* GtkIconTheme - a loader for icon themes
2 * gtk-icon-theme.c Copyright (C) 2002, 2003 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.
22 #include <sys/types.h>
30 #include <glib/gstdio.h>
34 #define S_ISDIR(mode) ((mode)&_S_IFDIR)
36 #endif /* G_OS_WIN32 */
38 #include "gtkicontheme.h"
39 #include "gtkiconfactory.h"
40 #include "gtkiconcache.h"
42 #include "gtksettings.h"
43 #include "gtkprivate.h"
47 #define DEFAULT_THEME_NAME "hicolor"
52 ICON_THEME_DIR_SCALABLE,
53 ICON_THEME_DIR_THRESHOLD,
54 ICON_THEME_DIR_UNTHEMED
57 /* In reverse search order: */
61 ICON_SUFFIX_XPM = 1 << 0,
62 ICON_SUFFIX_SVG = 1 << 1,
63 ICON_SUFFIX_PNG = 1 << 2,
64 HAS_ICON_FILE = 1 << 3
68 struct _GtkIconThemePrivate
70 guint custom_theme : 1;
71 guint is_screen_singleton : 1;
72 guint pixbuf_supports_svg : 1;
78 gboolean themes_valid;
79 /* A list of all the themes needed to look up icons.
80 * In search order, without duplicates
83 GHashTable *unthemed_icons;
85 /* Note: The keys of this hashtable are owned by the
86 * themedir and unthemed hashtables.
88 GHashTable *all_icons;
90 /* GdkScreen for the icon theme (may be NULL)
94 /* time when we last stat:ed for theme changes */
98 gulong reset_styles_idle;
100 gboolean check_reload;
105 /* Information about the source
109 /* System codepage version of filename, for DLL ABI backward
110 * compatibility functions.
114 GdkPixbuf *builtin_pixbuf;
116 /* Cache pixbuf (if there is any) */
117 GdkPixbuf *cache_pixbuf;
121 /* Information about the directory where
122 * the source was found
124 IconThemeDirType dir_type;
128 /* Parameters influencing the scaled icon
131 gboolean raw_coordinates;
133 /* Cached information if we go ahead and try to load
148 /* In search order */
154 IconThemeDirType type;
168 GHashTable *icon_data;
174 char *no_svg_filename;
186 time_t mtime; /* 0 == not existing or not a dir */
191 static void gtk_icon_theme_class_init (GtkIconThemeClass *klass);
192 static void gtk_icon_theme_init (GtkIconTheme *icon_theme);
193 static void gtk_icon_theme_finalize (GObject *object);
194 static void theme_dir_destroy (IconThemeDir *dir);
196 static void theme_destroy (IconTheme *theme);
197 static GtkIconInfo *theme_lookup_icon (IconTheme *theme,
198 const char *icon_name,
201 gboolean use_default_icons);
202 static void theme_list_icons (IconTheme *theme,
205 static void theme_subdir_load (GtkIconTheme *icon_theme,
207 GKeyFile *theme_file,
209 static void do_theme_change (GtkIconTheme *icon_theme);
211 static void blow_themes (GtkIconTheme *icon_themes);
213 static void icon_data_free (GtkIconData *icon_data);
214 static void load_icon_data (IconThemeDir *dir,
218 static IconSuffix theme_dir_get_icon_suffix (IconThemeDir *dir,
219 const gchar *icon_name,
220 gboolean *has_icon_file);
223 static GtkIconInfo *icon_info_new (void);
224 static GtkIconInfo *icon_info_new_builtin (BuiltinIcon *icon);
226 static IconSuffix suffix_from_name (const char *name);
228 static BuiltinIcon *find_builtin_icon (const gchar *icon_name,
230 gint *min_difference_p,
231 gboolean *has_larger_p);
233 static GObjectClass *parent_class = NULL;
235 static guint signal_changed = 0;
237 static GHashTable *icon_theme_builtin_icons;
240 gtk_icon_theme_get_type (void)
242 static GType type = 0;
246 static const GTypeInfo info =
248 sizeof (GtkIconThemeClass),
249 NULL, /* base_init */
250 NULL, /* base_finalize */
251 (GClassInitFunc) gtk_icon_theme_class_init,
252 NULL, /* class_finalize */
253 NULL, /* class_data */
254 sizeof (GtkIconTheme),
256 (GInstanceInitFunc) gtk_icon_theme_init,
259 type = g_type_register_static (G_TYPE_OBJECT, "GtkIconTheme", &info, 0);
266 * gtk_icon_theme_new:
268 * Creates a new icon theme object. Icon theme objects are used
269 * to lookup up an icon by name in a particular icon theme.
270 * Usually, you'll want to use gtk_icon_theme_get_default()
271 * or gtk_icon_theme_get_for_screen() rather than creating
272 * a new icon theme object for scratch.
274 * Return value: the newly created #GtkIconTheme object.
279 gtk_icon_theme_new (void)
281 return g_object_new (GTK_TYPE_ICON_THEME, NULL);
285 * gtk_icon_theme_get_default:
287 * Gets the icon theme for the default screen. See
288 * gtk_icon_theme_get_for_screen().
290 * Return value: A unique #GtkIconTheme associated with
291 * the default screen. This icon theme is associated with
292 * the screen and can be used as long as the screen
293 * is open. Do not ref or unref it.
298 gtk_icon_theme_get_default (void)
300 return gtk_icon_theme_get_for_screen (gdk_screen_get_default ());
304 * gtk_icon_theme_get_for_screen:
305 * @screen: a #GdkScreen
307 * Gets the icon theme object associated with @screen; if this
308 * function has not previously been called for the given
309 * screen, a new icon theme object will be created and
310 * associated with the screen. Icon theme objects are
311 * fairly expensive to create, so using this function
312 * is usually a better choice than calling than gtk_icon_theme_new()
313 * and setting the screen yourself; by using this function
314 * a single icon theme object will be shared between users.
316 * Return value: A unique #GtkIconTheme associated with
317 * the given screen. This icon theme is associated with
318 * the screen and can be used as long as the screen
319 * is open. Do not ref or unref it.
324 gtk_icon_theme_get_for_screen (GdkScreen *screen)
326 GtkIconTheme *icon_theme;
328 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
329 g_return_val_if_fail (!screen->closed, NULL);
331 icon_theme = g_object_get_data (G_OBJECT (screen), "gtk-icon-theme");
334 GtkIconThemePrivate *priv;
336 icon_theme = gtk_icon_theme_new ();
337 gtk_icon_theme_set_screen (icon_theme, screen);
339 priv = icon_theme->priv;
340 priv->is_screen_singleton = TRUE;
342 g_object_set_data (G_OBJECT (screen), "gtk-icon-theme", icon_theme);
349 gtk_icon_theme_class_init (GtkIconThemeClass *klass)
351 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
353 parent_class = g_type_class_peek_parent (klass);
355 gobject_class->finalize = gtk_icon_theme_finalize;
358 * GtkIconTheme::changed
359 * @icon_theme: the icon theme
361 * Emitted when the current icon theme is switched or GTK+ detects
362 * that a change has occurred in the contents of the current
365 signal_changed = g_signal_new ("changed",
366 G_TYPE_FROM_CLASS (klass),
368 G_STRUCT_OFFSET (GtkIconThemeClass, changed),
370 g_cclosure_marshal_VOID__VOID,
373 g_type_class_add_private (klass, sizeof (GtkIconThemePrivate));
377 /* Callback when the display that the icon theme is attached to
378 * is closed; unset the screen, and if it's the unique theme
379 * for the screen, drop the reference
382 display_closed (GdkDisplay *display,
384 GtkIconTheme *icon_theme)
386 GtkIconThemePrivate *priv = icon_theme->priv;
387 GdkScreen *screen = priv->screen;
388 gboolean was_screen_singleton = priv->is_screen_singleton;
390 if (was_screen_singleton)
392 g_object_set_data (G_OBJECT (screen), "gtk-icon-theme", NULL);
393 priv->is_screen_singleton = FALSE;
396 gtk_icon_theme_set_screen (icon_theme, NULL);
398 if (was_screen_singleton)
400 g_object_unref (icon_theme);
405 update_current_theme (GtkIconTheme *icon_theme)
407 GtkIconThemePrivate *priv = icon_theme->priv;
409 if (!priv->custom_theme)
415 GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
416 g_object_get (settings, "gtk-icon-theme-name", &theme, NULL);
420 theme = g_strdup (DEFAULT_THEME_NAME);
422 if (strcmp (priv->current_theme, theme) != 0)
424 g_free (priv->current_theme);
425 priv->current_theme = theme;
427 do_theme_change (icon_theme);
434 /* Callback when the icon theme GtkSetting changes
437 theme_changed (GtkSettings *settings,
439 GtkIconTheme *icon_theme)
441 update_current_theme (icon_theme);
445 unset_screen (GtkIconTheme *icon_theme)
447 GtkIconThemePrivate *priv = icon_theme->priv;
448 GtkSettings *settings;
453 settings = gtk_settings_get_for_screen (priv->screen);
454 display = gdk_screen_get_display (priv->screen);
456 g_signal_handlers_disconnect_by_func (display,
457 (gpointer) display_closed,
459 g_signal_handlers_disconnect_by_func (settings,
460 (gpointer) theme_changed,
468 * gtk_icon_theme_set_screen:
469 * @icon_theme: a #GtkIconTheme
470 * @screen: a #GdkScreen
472 * Sets the screen for an icon theme; the screen is used
473 * to track the user's currently configured icon theme,
474 * which might be different for different screens.
479 gtk_icon_theme_set_screen (GtkIconTheme *icon_theme,
482 GtkIconThemePrivate *priv;
483 GtkSettings *settings;
486 g_return_if_fail (GTK_ICON_THEME (icon_theme));
487 g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
489 priv = icon_theme->priv;
491 unset_screen (icon_theme);
495 display = gdk_screen_get_display (screen);
496 settings = gtk_settings_get_for_screen (screen);
498 priv->screen = screen;
500 g_signal_connect (display, "closed",
501 G_CALLBACK (display_closed), icon_theme);
502 g_signal_connect (settings, "notify::gtk-icon-theme-name",
503 G_CALLBACK (theme_changed), icon_theme);
506 update_current_theme (icon_theme);
509 /* Checks whether a loader for SVG files has been registered
513 pixbuf_supports_svg (void)
515 GSList *formats = gdk_pixbuf_get_formats ();
517 static gboolean found_svg = FALSE;
518 static gboolean value_known = FALSE;
523 for (tmp_list = formats; tmp_list && !found_svg; tmp_list = tmp_list->next)
525 gchar **mime_types = gdk_pixbuf_format_get_mime_types (tmp_list->data);
528 for (mime_type = mime_types; *mime_type && !found_svg; mime_type++)
530 if (strcmp (*mime_type, "image/svg") == 0)
534 g_strfreev (mime_types);
537 g_slist_free (formats);
544 gtk_icon_theme_init (GtkIconTheme *icon_theme)
546 GtkIconThemePrivate *priv;
547 const gchar * const *xdg_data_dirs;
550 priv = g_type_instance_get_private ((GTypeInstance *)icon_theme,
551 GTK_TYPE_ICON_THEME);
552 icon_theme->priv = priv;
554 priv->custom_theme = FALSE;
555 priv->current_theme = g_strdup (DEFAULT_THEME_NAME);
557 xdg_data_dirs = g_get_system_data_dirs ();
558 for (i = 0; xdg_data_dirs[i]; i++) ;
560 priv->search_path_len = 2 * i + 2;
562 priv->search_path = g_new (char *, priv->search_path_len);
565 priv->search_path[i++] = g_build_filename (g_get_home_dir (), ".icons", NULL);
566 priv->search_path[i++] = g_build_filename (g_get_user_data_dir (), "icons", NULL);
568 for (j = 0; xdg_data_dirs[j]; j++)
569 priv->search_path[i++] = g_build_filename (xdg_data_dirs[j], "icons", NULL);
571 for (j = 0; xdg_data_dirs[j]; j++)
572 priv->search_path[i++] = g_build_filename (xdg_data_dirs[j], "pixmaps", NULL);
574 priv->themes_valid = FALSE;
576 priv->unthemed_icons = NULL;
578 priv->pixbuf_supports_svg = pixbuf_supports_svg ();
582 free_dir_mtime (IconThemeDirMtime *dir_mtime)
584 if (dir_mtime->cache)
585 _gtk_icon_cache_unref (dir_mtime->cache);
587 g_free (dir_mtime->dir);
593 reset_styles_idle (gpointer user_data)
595 GtkIconTheme *icon_theme;
596 GtkIconThemePrivate *priv;
598 GDK_THREADS_ENTER ();
600 icon_theme = GTK_ICON_THEME (user_data);
601 priv = icon_theme->priv;
603 if (priv->screen && priv->is_screen_singleton)
605 GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
606 gtk_rc_reset_styles (settings);
609 priv->reset_styles_idle = 0;
611 GDK_THREADS_LEAVE ();
617 do_theme_change (GtkIconTheme *icon_theme)
619 GtkIconThemePrivate *priv = icon_theme->priv;
622 g_print ("change to icon theme \"%s\"\n", priv->current_theme));
623 blow_themes (icon_theme);
624 g_signal_emit (icon_theme, signal_changed, 0);
626 if (!priv->reset_styles_idle)
627 priv->reset_styles_idle =
628 g_idle_add (reset_styles_idle, icon_theme);
632 blow_themes (GtkIconTheme *icon_theme)
634 GtkIconThemePrivate *priv = icon_theme->priv;
636 if (priv->themes_valid)
638 g_hash_table_destroy (priv->all_icons);
639 g_list_foreach (priv->themes, (GFunc)theme_destroy, NULL);
640 g_list_free (priv->themes);
641 g_list_foreach (priv->dir_mtimes, (GFunc)free_dir_mtime, NULL);
642 g_list_free (priv->dir_mtimes);
643 g_hash_table_destroy (priv->unthemed_icons);
646 priv->unthemed_icons = NULL;
647 priv->dir_mtimes = NULL;
648 priv->all_icons = NULL;
649 priv->themes_valid = FALSE;
653 gtk_icon_theme_finalize (GObject *object)
655 GtkIconTheme *icon_theme;
656 GtkIconThemePrivate *priv;
659 icon_theme = GTK_ICON_THEME (object);
660 priv = icon_theme->priv;
662 if (priv->reset_styles_idle)
664 g_source_remove (priv->reset_styles_idle);
665 priv->reset_styles_idle = 0;
668 unset_screen (icon_theme);
670 g_free (priv->current_theme);
671 priv->current_theme = NULL;
673 for (i=0; i < priv->search_path_len; i++)
674 g_free (priv->search_path[i]);
676 g_free (priv->search_path);
677 priv->search_path = NULL;
679 blow_themes (icon_theme);
681 G_OBJECT_CLASS (parent_class)->finalize (object);
685 * gtk_icon_theme_set_search_path:
686 * @icon_theme: a #GtkIconTheme
687 * @path: array of directories that are searched for icon themes
688 * @n_elements: number of elements in @path.
690 * Sets the search path for the icon theme object. When looking
691 * for an icon theme, GTK+ will search for a subdirectory of
692 * one or more of the directories in @path with the same name
693 * as the icon theme. (Themes from multiple of the path elements
694 * are combined to allow themes to be extended by adding icons
695 * in the user's home directory.)
697 * In addition if an icon found isn't found either in the current
698 * icon theme or the default icon theme, and an image file with
699 * the right name is found directly in one of the elements of
700 * @path, then that image will be used for the icon name.
701 * (This is legacy feature, and new icons should be put
702 * into the default icon theme, which is called DEFAULT_THEME_NAME,
703 * rather than directly on the icon path.)
708 gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme,
712 GtkIconThemePrivate *priv;
715 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
717 priv = icon_theme->priv;
718 for (i = 0; i < priv->search_path_len; i++)
719 g_free (priv->search_path[i]);
721 g_free (priv->search_path);
723 priv->search_path = g_new (gchar *, n_elements);
724 priv->search_path_len = n_elements;
725 for (i = 0; i < priv->search_path_len; i++)
726 priv->search_path[i] = g_strdup (path[i]);
728 do_theme_change (icon_theme);
733 * gtk_icon_theme_get_search_path:
734 * @icon_theme: a #GtkIconTheme
735 * @path: location to store a list of icon theme path directories or %NULL
736 * The stored value should be freed with g_strfreev().
737 * @n_elements: location to store number of elements
740 * Gets the current search path. See gtk_icon_theme_set_search_path().
745 gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme,
749 GtkIconThemePrivate *priv;
752 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
754 priv = icon_theme->priv;
757 *n_elements = priv->search_path_len;
761 *path = g_new (gchar *, priv->search_path_len + 1);
762 for (i = 0; i < priv->search_path_len; i++)
763 (*path)[i] = g_strdup (priv->search_path[i]);
769 * gtk_icon_theme_append_search_path:
770 * @icon_theme: a #GtkIconTheme
771 * @path: directory name to append to the icon path
773 * Appends a directory to the search path.
774 * See gtk_icon_theme_set_search_path().
779 gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme,
782 GtkIconThemePrivate *priv;
784 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
785 g_return_if_fail (path != NULL);
787 priv = icon_theme->priv;
789 priv->search_path_len++;
790 priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len);
791 priv->search_path[priv->search_path_len-1] = g_strdup (path);
793 do_theme_change (icon_theme);
797 * gtk_icon_theme_prepend_search_path:
798 * @icon_theme: a #GtkIconTheme
799 * @path: directory name to prepend to the icon path
801 * Prepends a directory to the search path.
802 * See gtk_icon_theme_set_search_path().
807 gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme,
810 GtkIconThemePrivate *priv;
813 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
814 g_return_if_fail (path != NULL);
816 priv = icon_theme->priv;
818 priv->search_path_len++;
819 priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len);
821 for (i = priv->search_path_len - 1; i > 0; i--)
822 priv->search_path[i] = priv->search_path[i - 1];
824 priv->search_path[0] = g_strdup (path);
826 do_theme_change (icon_theme);
830 * gtk_icon_theme_set_custom_theme:
831 * @icon_theme: a #GtkIconTheme
832 * @theme_name: name of icon theme to use instead of configured theme,
833 * or %NULL to unset a previously set custom theme
835 * Sets the name of the icon theme that the #GtkIconTheme object uses
836 * overriding system configuration. This function cannot be called
837 * on the icon theme objects returned from gtk_icon_theme_get_default()
838 * and gtk_icon_theme_get_for_screen().
843 gtk_icon_theme_set_custom_theme (GtkIconTheme *icon_theme,
844 const gchar *theme_name)
846 GtkIconThemePrivate *priv;
848 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
850 priv = icon_theme->priv;
852 g_return_if_fail (!priv->is_screen_singleton);
854 if (theme_name != NULL)
856 priv->custom_theme = TRUE;
857 if (strcmp (theme_name, priv->current_theme) != 0)
859 g_free (priv->current_theme);
860 priv->current_theme = g_strdup (theme_name);
862 do_theme_change (icon_theme);
867 priv->custom_theme = FALSE;
869 update_current_theme (icon_theme);
874 insert_theme (GtkIconTheme *icon_theme, const char *theme_name)
880 GtkIconThemePrivate *priv;
883 GKeyFile *theme_file;
884 GError *error = NULL;
885 IconThemeDirMtime *dir_mtime;
886 struct stat stat_buf;
888 priv = icon_theme->priv;
890 for (l = priv->themes; l != NULL; l = l->next)
893 if (strcmp (theme->name, theme_name) == 0)
897 for (i = 0; i < priv->search_path_len; i++)
899 path = g_build_filename (priv->search_path[i],
902 dir_mtime = g_new (IconThemeDirMtime, 1);
903 dir_mtime->cache = NULL;
904 dir_mtime->dir = path;
905 if (g_stat (path, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
906 dir_mtime->mtime = stat_buf.st_mtime;
908 dir_mtime->mtime = 0;
910 priv->dir_mtimes = g_list_prepend (priv->dir_mtimes, dir_mtime);
912 priv->dir_mtimes = g_list_reverse (priv->dir_mtimes);
915 for (i = 0; i < priv->search_path_len && !theme_file; i++)
917 path = g_build_filename (priv->search_path[i],
921 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
923 theme_file = g_key_file_new ();
924 g_key_file_set_list_separator (theme_file, ',');
925 g_key_file_load_from_file (theme_file, path, 0, &error);
928 g_key_file_free (theme_file);
930 g_error_free (error);
937 if (theme_file == NULL)
940 theme = g_new (IconTheme, 1);
941 theme->display_name =
942 g_key_file_get_locale_string (theme_file, "Icon Theme", "Name", NULL, NULL);
943 if (!theme->display_name)
945 g_warning ("Theme file for %s has no name\n", theme_name);
947 g_key_file_free (theme_file);
951 dirs = g_key_file_get_string_list (theme_file, "Icon Theme", "Directories", NULL, NULL);
954 g_warning ("Theme file for %s has no directories\n", theme_name);
955 g_free (theme->display_name);
957 g_key_file_free (theme_file);
961 theme->name = g_strdup (theme_name);
963 g_key_file_get_locale_string (theme_file,
964 "Icon Theme", "Comment",
967 g_key_file_get_string (theme_file,
968 "Icon Theme", "Example",
972 for (i = 0; dirs[i] != NULL; i++)
973 theme_subdir_load (icon_theme, theme, theme_file, dirs[i]);
977 theme->dirs = g_list_reverse (theme->dirs);
979 /* Prepend the finished theme */
980 priv->themes = g_list_prepend (priv->themes, theme);
982 themes = g_key_file_get_string_list (theme_file,
989 for (i = 0; themes[i] != NULL; i++)
990 insert_theme (icon_theme, themes[i]);
995 g_key_file_free (theme_file);
999 free_unthemed_icon (UnthemedIcon *unthemed_icon)
1001 if (unthemed_icon->svg_filename)
1002 g_free (unthemed_icon->svg_filename);
1003 if (unthemed_icon->no_svg_filename)
1004 g_free (unthemed_icon->no_svg_filename);
1005 g_free (unthemed_icon);
1009 load_themes (GtkIconTheme *icon_theme)
1011 GtkIconThemePrivate *priv;
1014 char *dir, *base_name, *dot;
1017 UnthemedIcon *unthemed_icon;
1018 IconSuffix old_suffix, new_suffix;
1020 IconThemeDirMtime *dir_mtime;
1021 struct stat stat_buf;
1023 priv = icon_theme->priv;
1025 priv->all_icons = g_hash_table_new (g_str_hash, g_str_equal);
1027 insert_theme (icon_theme, priv->current_theme);
1029 /* Always look in the "default" icon theme */
1030 insert_theme (icon_theme, DEFAULT_THEME_NAME);
1031 priv->themes = g_list_reverse (priv->themes);
1034 priv->unthemed_icons = g_hash_table_new_full (g_str_hash, g_str_equal,
1035 g_free, (GDestroyNotify)free_unthemed_icon);
1037 for (base = 0; base < icon_theme->priv->search_path_len; base++)
1039 dir = icon_theme->priv->search_path[base];
1041 dir_mtime = g_new (IconThemeDirMtime, 1);
1042 dir_mtime->cache = _gtk_icon_cache_new_for_path (dir);
1043 dir_mtime->dir = g_strdup (dir);
1044 if (g_stat (dir, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
1045 dir_mtime->mtime = stat_buf.st_mtime;
1047 dir_mtime->mtime = 0;
1049 priv->dir_mtimes = g_list_append (priv->dir_mtimes, dir_mtime);
1051 if (dir_mtime->cache != NULL)
1054 gdir = g_dir_open (dir, 0, NULL);
1059 while ((file = g_dir_read_name (gdir)))
1061 new_suffix = suffix_from_name (file);
1063 if (new_suffix != ICON_SUFFIX_NONE)
1065 abs_file = g_build_filename (dir, file, NULL);
1067 base_name = g_strdup (file);
1069 dot = strrchr (base_name, '.');
1073 if ((unthemed_icon = g_hash_table_lookup (priv->unthemed_icons,
1076 if (new_suffix == ICON_SUFFIX_SVG)
1078 if (unthemed_icon->svg_filename)
1081 unthemed_icon->svg_filename = abs_file;
1085 if (unthemed_icon->no_svg_filename)
1087 old_suffix = suffix_from_name (unthemed_icon->no_svg_filename);
1088 if (new_suffix > old_suffix)
1090 g_free (unthemed_icon->no_svg_filename);
1091 unthemed_icon->no_svg_filename = abs_file;
1097 unthemed_icon->no_svg_filename = abs_file;
1104 unthemed_icon = g_new0 (UnthemedIcon, 1);
1106 if (new_suffix == ICON_SUFFIX_SVG)
1107 unthemed_icon->svg_filename = abs_file;
1109 unthemed_icon->no_svg_filename = abs_file;
1111 g_hash_table_insert (priv->unthemed_icons,
1114 g_hash_table_insert (priv->all_icons,
1122 priv->themes_valid = TRUE;
1124 g_get_current_time(&tv);
1125 priv->last_stat_time = tv.tv_sec;
1129 ensure_valid_themes (GtkIconTheme *icon_theme)
1131 GtkIconThemePrivate *priv = icon_theme->priv;
1134 if (priv->themes_valid)
1136 g_get_current_time (&tv);
1138 if (ABS (tv.tv_sec - priv->last_stat_time) > 5)
1139 gtk_icon_theme_rescan_if_needed (icon_theme);
1142 if (!priv->themes_valid)
1144 load_themes (icon_theme);
1146 if (!priv->check_reload)
1148 static GdkAtom atom_iconthemes = GDK_NONE;
1149 GdkEvent *event = gdk_event_new (GDK_CLIENT_EVENT);
1152 if (!atom_iconthemes)
1153 atom_iconthemes = gdk_atom_intern ("_GTK_LOAD_ICONTHEMES", FALSE);
1155 for (i = 0; i < 5; i++)
1156 event->client.data.l[i] = 0;
1157 event->client.data_format = 32;
1158 event->client.message_type = atom_iconthemes;
1160 gdk_screen_broadcast_client_message (priv->screen, event);
1166 * gtk_icon_theme_lookup_icon:
1167 * @icon_theme: a #GtkIconTheme
1168 * @icon_name: the name of the icon to lookup
1169 * @size: desired icon size
1170 * @flags: flags modifying the behavior of the icon lookup
1172 * Looks up a named icon and returns a structure containing
1173 * information such as the filename of the icon. The icon
1174 * can then be rendered into a pixbuf using
1175 * gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon()
1176 * combines these two steps if all you need is the pixbuf.)
1178 * Return value: a #GtkIconInfo structure containing information
1179 * about the icon, or %NULL if the icon wasn't found. Free with
1180 * gtk_icon_info_free()
1185 gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme,
1186 const gchar *icon_name,
1188 GtkIconLookupFlags flags)
1190 GtkIconThemePrivate *priv;
1192 GtkIconInfo *icon_info = NULL;
1193 UnthemedIcon *unthemed_icon;
1195 gboolean use_builtin;
1196 gboolean found_default;
1198 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
1199 g_return_val_if_fail (icon_name != NULL, NULL);
1200 g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
1201 (flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
1203 priv = icon_theme->priv;
1205 GTK_NOTE (ICONTHEME,
1206 g_print ("gtk_icon_theme_lookup_icon %s\n", icon_name));
1207 if (flags & GTK_ICON_LOOKUP_NO_SVG)
1209 else if (flags & GTK_ICON_LOOKUP_FORCE_SVG)
1212 allow_svg = priv->pixbuf_supports_svg;
1214 use_builtin = (flags & GTK_ICON_LOOKUP_USE_BUILTIN);
1216 ensure_valid_themes (icon_theme);
1218 found_default = FALSE;
1222 IconTheme *theme = l->data;
1224 if (strcmp (theme->name, DEFAULT_THEME_NAME) == 0)
1225 found_default = TRUE;
1227 icon_info = theme_lookup_icon (theme, icon_name, size, allow_svg, use_builtin);
1236 BuiltinIcon *builtin = find_builtin_icon (icon_name, size, NULL, NULL);
1239 icon_info = icon_info_new_builtin (builtin);
1244 unthemed_icon = g_hash_table_lookup (priv->unthemed_icons, icon_name);
1247 icon_info = icon_info_new ();
1249 /* A SVG icon, when allowed, beats out a XPM icon, but not
1253 unthemed_icon->svg_filename &&
1254 (!unthemed_icon->no_svg_filename ||
1255 suffix_from_name (unthemed_icon->no_svg_filename) != ICON_SUFFIX_PNG))
1256 icon_info->filename = g_strdup (unthemed_icon->svg_filename);
1257 else if (unthemed_icon->no_svg_filename)
1258 icon_info->filename = g_strdup (unthemed_icon->no_svg_filename);
1260 icon_info->cp_filename = g_locale_from_utf8 (icon_info->filename,
1261 -1, NULL, NULL, NULL);
1264 icon_info->dir_type = ICON_THEME_DIR_UNTHEMED;
1269 icon_info->desired_size = size;
1272 static gboolean check_for_default_theme = TRUE;
1273 char *default_theme_path;
1274 gboolean found = FALSE;
1277 if (check_for_default_theme)
1279 check_for_default_theme = FALSE;
1281 for (i = 0; !found && i < priv->search_path_len; i++)
1283 default_theme_path = g_build_filename (priv->search_path[i],
1287 found = g_file_test (default_theme_path, G_FILE_TEST_IS_REGULAR);
1288 g_free (default_theme_path);
1292 g_warning (_("Could not find the icon '%s'. The '%s' theme\n"
1293 "was not found either, perhaps you need to install it.\n"
1294 "You can get a copy from:\n"
1296 icon_name, DEFAULT_THEME_NAME, "http://icon-theme.freedesktop.org/releases");
1306 gtk_icon_theme_error_quark (void)
1308 static GQuark q = 0;
1310 q = g_quark_from_static_string ("gtk-icon-theme-error-quark");
1316 * gtk_icon_theme_load_icon:
1317 * @icon_theme: a #GtkIconTheme
1318 * @icon_name: the name of the icon to lookup
1319 * @size: the desired icon size. The resulting icon may not be
1320 * exactly this size; see gtk_icon_info_load_icon().
1321 * @flags: flags modifying the behavior of the icon lookup
1322 * @error: Location to store error information on failure, or %NULL.
1324 * Looks up an icon in an icon theme, scales it to the given size
1325 * and renders it into a pixbuf. This is a convenience function;
1326 * if more details about the icon are needed, use
1327 * gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().
1329 * Note that you probably want to listen for icon theme changes and
1330 * update the icon. This is usually done by connecting to the
1331 * GtkWidget::style-set signal. If for some reason you do not want to
1332 * update the icon when the icon theme changes, you should consider
1333 * using gdk_pixbuf_copy() to make a private copy of the pixbuf
1334 * returned by this function. Otherwise GTK+ may need to keep the old
1335 * icon theme loaded, which would be a waste of memory.
1337 * Return value: the rendered icon; this may be a newly created icon
1338 * or a new reference to an internal icon, so you must not modify
1339 * the icon. Use g_object_unref() to release your reference to the
1340 * icon. %NULL if the icon isn't found.
1345 gtk_icon_theme_load_icon (GtkIconTheme *icon_theme,
1346 const gchar *icon_name,
1348 GtkIconLookupFlags flags,
1351 GtkIconInfo *icon_info;
1352 GdkPixbuf *pixbuf = NULL;
1354 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
1355 g_return_val_if_fail (icon_name != NULL, NULL);
1356 g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
1357 (flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
1358 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1360 icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, size,
1361 flags | GTK_ICON_LOOKUP_USE_BUILTIN);
1364 g_set_error (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND,
1365 _("Icon '%s' not present in theme"), icon_name);
1369 pixbuf = gtk_icon_info_load_icon (icon_info, error);
1370 gtk_icon_info_free (icon_info);
1376 * gtk_icon_theme_has_icon:
1377 * @icon_theme: a #GtkIconTheme
1378 * @icon_name: the name of an icon
1380 * Checks whether an icon theme includes an icon
1381 * for a particular name.
1383 * Return value: %TRUE if @icon_theme includes an
1384 * icon for @icon_name.
1389 gtk_icon_theme_has_icon (GtkIconTheme *icon_theme,
1390 const char *icon_name)
1392 GtkIconThemePrivate *priv;
1395 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE);
1397 priv = icon_theme->priv;
1399 ensure_valid_themes (icon_theme);
1401 for (l = priv->dir_mtimes; l; l = l->next)
1403 IconThemeDirMtime *dir_mtime = l->data;
1404 GtkIconCache *cache = dir_mtime->cache;
1406 if (cache && _gtk_icon_cache_has_icon (cache, icon_name))
1410 if (g_hash_table_lookup_extended (priv->all_icons,
1411 icon_name, NULL, NULL))
1414 if (icon_theme_builtin_icons &&
1415 g_hash_table_lookup_extended (icon_theme_builtin_icons,
1416 icon_name, NULL, NULL))
1423 add_size (gpointer key,
1427 gint **res_p = user_data;
1429 **res_p = GPOINTER_TO_INT (key);
1435 * gtk_icon_theme_get_icon_sizes:
1436 * @icon_theme: a #GtkIconTheme
1437 * @icon_name: the name of an icon
1439 * Returns an array of integers describing the sizes at which
1440 * the icon is available without scaling. A size of -1 means
1441 * that the icon is available in a scalable format. The array
1442 * is zero-terminated.
1444 * Return value: An newly allocated array describing the sizes at
1445 * which the icon is available. The array should be freed with g_free()
1446 * when it is no longer needed.
1451 gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme,
1452 const char *icon_name)
1459 GtkIconThemePrivate *priv;
1461 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
1463 priv = icon_theme->priv;
1465 ensure_valid_themes (icon_theme);
1467 sizes = g_hash_table_new (g_direct_hash, g_direct_equal);
1469 for (l = priv->themes; l; l = l->next)
1471 IconTheme *theme = l->data;
1472 for (d = theme->dirs; d; d = d->next)
1474 IconThemeDir *dir = d->data;
1476 suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
1477 if (suffix != ICON_SUFFIX_NONE)
1479 if (suffix == ICON_SUFFIX_SVG)
1480 g_hash_table_insert (sizes, GINT_TO_POINTER (-1), NULL);
1482 g_hash_table_insert (sizes, GINT_TO_POINTER (dir->size), NULL);
1487 r = result = g_new0 (gint, g_hash_table_size (sizes) + 1);
1489 g_hash_table_foreach (sizes, add_size, &r);
1490 g_hash_table_destroy (sizes);
1496 add_key_to_hash (gpointer key,
1500 GHashTable *hash = user_data;
1502 g_hash_table_insert (hash, key, NULL);
1506 add_key_to_list (gpointer key,
1510 GList **list = user_data;
1512 *list = g_list_prepend (*list, g_strdup (key));
1516 * gtk_icon_theme_list_icons:
1517 * @icon_theme: a #GtkIconTheme
1518 * @context: a string identifying a particular type of icon,
1519 * or %NULL to list all icons.
1521 * Lists the icons in the current icon theme. Only a subset
1522 * of the icons can be listed by providing a context string.
1523 * The set of values for the context string is system dependent,
1524 * but will typically include such values as 'apps' and
1527 * Return value: a #GList list holding the names of all the
1528 * icons in the theme. You must first free each element
1529 * in the list with g_free(), then free the list itself
1530 * with g_list_free().
1535 gtk_icon_theme_list_icons (GtkIconTheme *icon_theme,
1536 const char *context)
1538 GtkIconThemePrivate *priv;
1541 GQuark context_quark;
1543 priv = icon_theme->priv;
1545 ensure_valid_themes (icon_theme);
1549 context_quark = g_quark_try_string (context);
1557 icons = g_hash_table_new (g_str_hash, g_str_equal);
1562 theme_list_icons (l->data, icons, context_quark);
1566 if (context_quark == 0)
1567 g_hash_table_foreach (priv->unthemed_icons,
1573 g_hash_table_foreach (icons,
1577 g_hash_table_destroy (icons);
1583 * gtk_icon_theme_get_example_icon_name:
1584 * @icon_theme: a #GtkIconTheme
1586 * Gets the name of an icon that is representative of the
1587 * current theme (for instance, to use when presenting
1588 * a list of themes to the user.)
1590 * Return value: the name of an example icon or %NULL.
1591 * Free with g_free().
1596 gtk_icon_theme_get_example_icon_name (GtkIconTheme *icon_theme)
1598 GtkIconThemePrivate *priv;
1602 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
1604 priv = icon_theme->priv;
1606 ensure_valid_themes (icon_theme);
1613 return g_strdup (theme->example);
1622 * gtk_icon_theme_rescan_if_needed:
1623 * @icon_theme: a #GtkIconTheme
1625 * Checks to see if the icon theme has changed; if it has, any
1626 * currently cached information is discarded and will be reloaded
1627 * next time @icon_theme is accessed.
1629 * Return value: %TRUE if the icon theme has changed and needed
1635 gtk_icon_theme_rescan_if_needed (GtkIconTheme *icon_theme)
1637 GtkIconThemePrivate *priv;
1638 IconThemeDirMtime *dir_mtime;
1641 struct stat stat_buf;
1644 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE);
1646 priv = icon_theme->priv;
1648 for (d = priv->dir_mtimes; d != NULL; d = d->next)
1650 dir_mtime = d->data;
1652 stat_res = g_stat (dir_mtime->dir, &stat_buf);
1654 /* dir mtime didn't change */
1655 if (stat_res == 0 &&
1656 S_ISDIR (stat_buf.st_mode) &&
1657 dir_mtime->mtime == stat_buf.st_mtime)
1659 /* didn't exist before, and still doesn't */
1660 if (dir_mtime->mtime == 0 &&
1661 (stat_res != 0 || !S_ISDIR (stat_buf.st_mode)))
1664 do_theme_change (icon_theme);
1668 g_get_current_time (&tv);
1669 priv->last_stat_time = tv.tv_sec;
1675 theme_destroy (IconTheme *theme)
1677 g_free (theme->display_name);
1678 g_free (theme->comment);
1679 g_free (theme->name);
1680 g_free (theme->example);
1682 g_list_foreach (theme->dirs, (GFunc)theme_dir_destroy, NULL);
1683 g_list_free (theme->dirs);
1689 theme_dir_destroy (IconThemeDir *dir)
1692 _gtk_icon_cache_unref (dir->cache);
1694 g_hash_table_destroy (dir->icons);
1697 g_hash_table_destroy (dir->icon_data);
1699 g_free (dir->subdir);
1704 theme_dir_size_difference (IconThemeDir *dir, int size, gboolean *smaller)
1709 case ICON_THEME_DIR_FIXED:
1710 *smaller = size < dir->size;
1711 return abs (size - dir->size);
1713 case ICON_THEME_DIR_SCALABLE:
1714 *smaller = size < dir->min_size;
1715 if (size < dir->min_size)
1716 return dir->min_size - size;
1717 if (size > dir->max_size)
1718 return size - dir->max_size;
1721 case ICON_THEME_DIR_THRESHOLD:
1722 min = dir->size - dir->threshold;
1723 max = dir->size + dir->threshold;
1724 *smaller = size < min;
1731 case ICON_THEME_DIR_UNTHEMED:
1732 g_assert_not_reached ();
1735 g_assert_not_reached ();
1740 string_from_suffix (IconSuffix suffix)
1744 case ICON_SUFFIX_XPM:
1746 case ICON_SUFFIX_SVG:
1748 case ICON_SUFFIX_PNG:
1751 g_assert_not_reached();
1757 suffix_from_name (const char *name)
1761 if (g_str_has_suffix (name, ".png"))
1762 retval = ICON_SUFFIX_PNG;
1763 else if (g_str_has_suffix (name, ".svg"))
1764 retval = ICON_SUFFIX_SVG;
1765 else if (g_str_has_suffix (name, ".xpm"))
1766 retval = ICON_SUFFIX_XPM;
1768 retval = ICON_SUFFIX_NONE;
1774 best_suffix (IconSuffix suffix,
1777 if ((suffix & ICON_SUFFIX_PNG) != 0)
1778 return ICON_SUFFIX_PNG;
1779 else if (allow_svg && ((suffix & ICON_SUFFIX_SVG) != 0))
1780 return ICON_SUFFIX_SVG;
1781 else if ((suffix & ICON_SUFFIX_XPM) != 0)
1782 return ICON_SUFFIX_XPM;
1784 return ICON_SUFFIX_NONE;
1789 theme_dir_get_icon_suffix (IconThemeDir *dir,
1790 const gchar *icon_name,
1791 gboolean *has_icon_file)
1797 suffix = (IconSuffix)_gtk_icon_cache_get_icon_flags (dir->cache,
1802 *has_icon_file = suffix & HAS_ICON_FILE;
1804 suffix = suffix & ~HAS_ICON_FILE;
1807 suffix = GPOINTER_TO_UINT (g_hash_table_lookup (dir->icons, icon_name));
1809 GTK_NOTE (ICONTHEME,
1810 g_print ("get_icon_suffix%s %d\n", dir->cache ? " (cached)" : "", suffix));
1815 static GtkIconInfo *
1816 theme_lookup_icon (IconTheme *theme,
1817 const char *icon_name,
1820 gboolean use_builtin)
1823 IconThemeDir *dir, *min_dir;
1825 int min_difference, difference;
1826 BuiltinIcon *closest_builtin = NULL;
1827 gboolean smaller, has_larger;
1830 min_difference = G_MAXINT;
1834 /* Builtin icons are logically part of the default theme and
1835 * are searched before other subdirectories of the default theme.
1837 if (strcmp (theme->name, DEFAULT_THEME_NAME) == 0 && use_builtin)
1839 closest_builtin = find_builtin_icon (icon_name, size,
1843 if (min_difference == 0)
1844 return icon_info_new_builtin (closest_builtin);
1852 GTK_NOTE (ICONTHEME,
1853 g_print ("theme_lookup_icon dir %s\n", dir->dir));
1854 suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
1855 if (best_suffix (suffix, allow_svg) != ICON_SUFFIX_NONE)
1857 difference = theme_dir_size_difference (dir, size, &smaller);
1859 if (difference == 0)
1867 if (difference < min_difference || smaller)
1869 min_difference = difference;
1871 closest_builtin = NULL;
1872 has_larger = smaller;
1877 if (difference < min_difference && smaller)
1879 min_difference = difference;
1881 closest_builtin = NULL;
1890 if (closest_builtin)
1891 return icon_info_new_builtin (closest_builtin);
1895 GtkIconInfo *icon_info = icon_info_new ();
1896 gboolean has_icon_file;
1898 suffix = theme_dir_get_icon_suffix (min_dir, icon_name, &has_icon_file);
1899 suffix = best_suffix (suffix, allow_svg);
1900 g_assert (suffix != ICON_SUFFIX_NONE);
1902 file = g_strconcat (icon_name, string_from_suffix (suffix), NULL);
1903 icon_info->filename = g_build_filename (min_dir->dir, file, NULL);
1906 icon_info->cp_filename = g_locale_from_utf8 (icon_info->filename,
1907 -1, NULL, NULL, NULL);
1910 if (min_dir->icon_data != NULL)
1911 icon_info->data = g_hash_table_lookup (min_dir->icon_data, icon_name);
1913 if (icon_info->data == NULL && min_dir->cache != NULL)
1915 icon_info->data = _gtk_icon_cache_get_icon_data (min_dir->cache, icon_name, min_dir->subdir);
1916 if (icon_info->data)
1918 if (min_dir->icon_data == NULL)
1919 min_dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
1920 g_free, (GDestroyNotify)icon_data_free);
1922 g_hash_table_replace (min_dir->icon_data, g_strdup (icon_name), icon_info->data);
1926 if (icon_info->data == NULL && has_icon_file)
1928 gchar *icon_file_name, *icon_file_path;
1930 icon_file_name = g_strconcat (icon_name, ".icon", NULL);
1931 icon_file_path = g_build_filename (min_dir->dir, icon_file_name, NULL);
1933 if (g_file_test (icon_file_path, G_FILE_TEST_IS_REGULAR))
1935 if (min_dir->icon_data == NULL)
1936 min_dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
1937 g_free, (GDestroyNotify)icon_data_free);
1938 load_icon_data (min_dir, icon_file_path, icon_file_name);
1940 icon_info->data = g_hash_table_lookup (min_dir->icon_data, icon_name);
1942 g_free (icon_file_name);
1943 g_free (icon_file_path);
1948 icon_info->cache_pixbuf = _gtk_icon_cache_get_icon (min_dir->cache, icon_name,
1952 icon_info->dir_type = min_dir->type;
1953 icon_info->dir_size = min_dir->size;
1954 icon_info->threshold = min_dir->threshold;
1963 theme_list_icons (IconTheme *theme, GHashTable *icons,
1966 GList *l = theme->dirs;
1973 if (context == dir->context ||
1978 _gtk_icon_cache_add_icons (dir->cache,
1985 g_hash_table_foreach (dir->icons,
1995 load_icon_data (IconThemeDir *dir, const char *path, const char *name)
1997 GKeyFile *icon_file;
2006 GError *error = NULL;
2010 icon_file = g_key_file_new ();
2011 g_key_file_set_list_separator (icon_file, ',');
2012 g_key_file_load_from_file (icon_file, path, 0, &error);
2015 g_error_free (error);
2020 base_name = g_strdup (name);
2021 dot = strrchr (base_name, '.');
2024 data = g_new0 (GtkIconData, 1);
2025 g_hash_table_replace (dir->icon_data, base_name, data);
2027 ivalues = g_key_file_get_integer_list (icon_file,
2028 "Icon Data", "EmbeddedTextRectangle",
2034 data->has_embedded_rect = TRUE;
2035 data->x0 = ivalues[0];
2036 data->y0 = ivalues[1];
2037 data->x1 = ivalues[2];
2038 data->y1 = ivalues[3];
2044 str = g_key_file_get_string (icon_file, "Icon Data", "AttachPoints", NULL);
2047 split = g_strsplit (str, "|", -1);
2049 data->n_attach_points = g_strv_length (split);
2050 data->attach_points = g_malloc (sizeof (GdkPoint) * data->n_attach_points);
2053 while (split[i] != NULL && i < data->n_attach_points)
2055 split_point = strchr (split[i], ',');
2060 data->attach_points[i].x = atoi (split[i]);
2061 data->attach_points[i].y = atoi (split_point);
2070 data->display_name = g_key_file_get_locale_string (icon_file,
2071 "Icon Data", "DisplayName",
2073 g_key_file_free (icon_file);
2078 scan_directory (GtkIconThemePrivate *icon_theme,
2079 IconThemeDir *dir, char *full_dir)
2083 char *base_name, *dot;
2085 IconSuffix suffix, hash_suffix;
2087 GTK_NOTE (ICONTHEME,
2088 g_print ("scanning directory %s\n", full_dir));
2089 dir->icons = g_hash_table_new_full (g_str_hash, g_str_equal,
2092 gdir = g_dir_open (full_dir, 0, NULL);
2097 while ((name = g_dir_read_name (gdir)))
2099 if (g_str_has_suffix (name, ".icon"))
2101 if (dir->icon_data == NULL)
2102 dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
2103 g_free, (GDestroyNotify)icon_data_free);
2105 path = g_build_filename (full_dir, name, NULL);
2106 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
2107 load_icon_data (dir, path, name);
2114 suffix = suffix_from_name (name);
2115 if (suffix == ICON_SUFFIX_NONE)
2118 base_name = g_strdup (name);
2119 dot = strrchr (base_name, '.');
2122 hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (dir->icons, base_name));
2123 g_hash_table_replace (dir->icons, base_name, GUINT_TO_POINTER (hash_suffix| suffix));
2124 g_hash_table_insert (icon_theme->all_icons, base_name, NULL);
2131 theme_subdir_load (GtkIconTheme *icon_theme,
2133 GKeyFile *theme_file,
2139 IconThemeDirType type;
2140 char *context_string;
2147 GError *error = NULL;
2148 IconThemeDirMtime *dir_mtime;
2150 size = g_key_file_get_integer (theme_file, subdir, "Size", &error);
2153 g_error_free (error);
2154 g_warning ("Theme directory %s of theme %s has no size field\n",
2155 subdir, theme->name);
2159 type = ICON_THEME_DIR_THRESHOLD;
2160 type_string = g_key_file_get_string (theme_file, subdir, "Type", NULL);
2163 if (strcmp (type_string, "Fixed") == 0)
2164 type = ICON_THEME_DIR_FIXED;
2165 else if (strcmp (type_string, "Scalable") == 0)
2166 type = ICON_THEME_DIR_SCALABLE;
2167 else if (strcmp (type_string, "Threshold") == 0)
2168 type = ICON_THEME_DIR_THRESHOLD;
2170 g_free (type_string);
2174 context_string = g_key_file_get_string (theme_file, subdir, "Context", NULL);
2177 context = g_quark_from_string (context_string);
2178 g_free (context_string);
2181 max_size = g_key_file_get_integer (theme_file, subdir, "MaxSize", &error);
2186 g_error_free (error);
2190 min_size = g_key_file_get_integer (theme_file, subdir, "MinSize", &error);
2195 g_error_free (error);
2199 threshold = g_key_file_get_integer (theme_file, subdir, "Threshold", &error);
2204 g_error_free (error);
2208 for (d = icon_theme->priv->dir_mtimes; d; d = d->next)
2210 dir_mtime = (IconThemeDirMtime *)d->data;
2212 if (dir_mtime->mtime == 0)
2213 continue; /* directory doesn't exist */
2215 full_dir = g_build_filename (dir_mtime->dir, subdir, NULL);
2217 /* First, see if we have a cache for the directory */
2218 if (dir_mtime->cache != NULL || g_file_test (full_dir, G_FILE_TEST_IS_DIR))
2220 if (dir_mtime->cache == NULL)
2222 /* This will return NULL if the cache doesn't exist or is outdated */
2223 dir_mtime->cache = _gtk_icon_cache_new_for_path (dir_mtime->dir);
2226 dir = g_new (IconThemeDir, 1);
2228 dir->context = context;
2230 dir->min_size = min_size;
2231 dir->max_size = max_size;
2232 dir->threshold = threshold;
2233 dir->dir = full_dir;
2234 dir->icon_data = NULL;
2235 dir->subdir = g_strdup (subdir);
2236 if (dir_mtime->cache != NULL)
2237 dir->cache = _gtk_icon_cache_ref (dir_mtime->cache);
2241 scan_directory (icon_theme->priv, dir, full_dir);
2244 theme->dirs = g_list_prepend (theme->dirs, dir);
2252 icon_data_free (GtkIconData *icon_data)
2254 g_free (icon_data->attach_points);
2255 g_free (icon_data->display_name);
2263 gtk_icon_info_get_type (void)
2265 static GType our_type = 0;
2268 our_type = g_boxed_type_register_static ("GtkIconInfo",
2269 (GBoxedCopyFunc) gtk_icon_info_copy,
2270 (GBoxedFreeFunc) gtk_icon_info_free);
2275 static GtkIconInfo *
2276 icon_info_new (void)
2278 GtkIconInfo *icon_info = g_new0 (GtkIconInfo, 1);
2280 icon_info->scale = -1.;
2285 static GtkIconInfo *
2286 icon_info_new_builtin (BuiltinIcon *icon)
2288 GtkIconInfo *icon_info = icon_info_new ();
2290 icon_info->builtin_pixbuf = g_object_ref (icon->pixbuf);
2291 icon_info->dir_type = ICON_THEME_DIR_THRESHOLD;
2292 icon_info->dir_size = icon->size;
2293 icon_info->threshold = 2;
2299 * gtk_icon_info_copy:
2300 * @icon_info: a #GtkIconInfo
2302 * Make a copy of a #GtkIconInfo.
2304 * Return value: the new GtkIconInfo
2309 gtk_icon_info_copy (GtkIconInfo *icon_info)
2313 g_return_val_if_fail (icon_info != NULL, NULL);
2315 copy = g_memdup (icon_info, sizeof (GtkIconInfo));
2316 if (copy->builtin_pixbuf)
2317 g_object_ref (copy->builtin_pixbuf);
2319 g_object_ref (copy->pixbuf);
2320 if (copy->load_error)
2321 copy->load_error = g_error_copy (copy->load_error);
2323 copy->filename = g_strdup (copy->filename);
2325 if (copy->cp_filename)
2326 copy->cp_filename = g_strdup (copy->cp_filename);
2333 * gtk_icon_info_free:
2334 * @icon_info: a #GtkIconInfo
2336 * Free a #GtkIconInfo and associated information
2341 gtk_icon_info_free (GtkIconInfo *icon_info)
2343 g_return_if_fail (icon_info != NULL);
2345 if (icon_info->filename)
2346 g_free (icon_info->filename);
2348 if (icon_info->cp_filename)
2349 g_free (icon_info->cp_filename);
2351 if (icon_info->builtin_pixbuf)
2352 g_object_unref (icon_info->builtin_pixbuf);
2353 if (icon_info->pixbuf)
2354 g_object_unref (icon_info->pixbuf);
2355 if (icon_info->cache_pixbuf)
2356 g_object_unref (icon_info->cache_pixbuf);
2362 * gtk_icon_info_get_base_size:
2363 * @icon_info: a #GtkIconInfo
2365 * Gets the base size for the icon. The base size
2366 * is a size for the icon that was specified by
2367 * the icon theme creator. This may be different
2368 * than the actual size of image; an example of
2369 * this is small emblem icons that can be attached
2370 * to a larger icon. These icons will be given
2371 * the same base size as the larger icons to which
2372 * they are attached.
2374 * Return value: the base size, or 0, if no base
2375 * size is known for the icon.
2380 gtk_icon_info_get_base_size (GtkIconInfo *icon_info)
2382 g_return_val_if_fail (icon_info != NULL, 0);
2384 return icon_info->dir_size;
2388 * gtk_icon_info_get_filename:
2389 * @icon_info: a #GtkIconInfo
2391 * Gets the filename for the icon. If the
2392 * %GTK_ICON_LOOKUP_USE_BUILTIN flag was passed
2393 * to gtk_icon_theme_lookup_icon(), there may be
2394 * no filename if a builtin icon is returned; in this
2395 * case, you should use gtk_icon_info_get_builtin_pixbuf().
2397 * Return value: the filename for the icon, or %NULL
2398 * if gtk_icon_info_get_builtin_pixbuf() should
2399 * be used instead. The return value is owned by
2400 * GTK+ and should not be modified or freed.
2404 G_CONST_RETURN gchar *
2405 gtk_icon_info_get_filename (GtkIconInfo *icon_info)
2407 g_return_val_if_fail (icon_info != NULL, NULL);
2409 return icon_info->filename;
2413 * gtk_icon_info_get_builtin_pixbuf:
2414 * @icon_info: a #GtkIconInfo structure
2416 * Gets the built-in image for this icon, if any. To allow
2417 * GTK+ to use built in icon images, you must pass the
2418 * %GTK_ICON_LOOKUP_USE_BUILTIN to
2419 * gtk_icon_theme_lookup_icon().
2421 * Return value: the built-in image pixbuf, or %NULL. No
2422 * extra reference is added to the returned pixbuf, so if
2423 * you want to keep it around, you must use g_object_ref().
2424 * The returned image must not be modified.
2429 gtk_icon_info_get_builtin_pixbuf (GtkIconInfo *icon_info)
2431 g_return_val_if_fail (icon_info != NULL, NULL);
2433 return icon_info->builtin_pixbuf;
2437 load_svg_at_size (const gchar *filename,
2441 GdkPixbuf *pixbuf = NULL;
2442 GdkPixbufLoader *loader = NULL;
2443 gchar *contents = NULL;
2446 if (!g_file_get_contents (filename,
2447 &contents, &length, error))
2450 loader = gdk_pixbuf_loader_new_with_type ("svg", error);
2454 gdk_pixbuf_loader_set_size (loader, size, size);
2456 if (!gdk_pixbuf_loader_write (loader, contents, length, error))
2458 gdk_pixbuf_loader_close (loader, NULL);
2462 if (!gdk_pixbuf_loader_close (loader, error))
2465 pixbuf = g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader));
2469 g_object_unref (loader);
2476 /* This function contains the complicatd logic for deciding
2477 * on the size at which to load the icon and loading it at
2481 icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info,
2482 gboolean scale_only)
2484 int image_width, image_height;
2485 GdkPixbuf *source_pixbuf;
2487 /* First check if we already succeeded have the necessary
2488 * information (or failed earlier)
2490 if (scale_only && icon_info->scale >= 0)
2493 if (icon_info->pixbuf)
2496 if (icon_info->load_error)
2499 /* SVG icons are a special case - we just immediately scale them
2500 * to the desired size
2502 if (icon_info->filename && g_str_has_suffix (icon_info->filename, ".svg"))
2504 icon_info->scale = icon_info->desired_size / 1000.;
2509 icon_info->pixbuf = load_svg_at_size (icon_info->filename,
2510 icon_info->desired_size,
2511 &icon_info->load_error);
2513 return icon_info->pixbuf != NULL;
2516 /* In many cases, the scale can be determined without actual access
2517 * to the icon file. This is generally true when we have a size
2518 * for the directory where the icon is; the image size doesn't
2519 * matter in that case.
2521 if (icon_info->dir_type == ICON_THEME_DIR_FIXED)
2522 icon_info->scale = 1.0;
2523 else if (icon_info->dir_type == ICON_THEME_DIR_THRESHOLD)
2525 if (icon_info->desired_size >= icon_info->dir_size - icon_info->threshold &&
2526 icon_info->desired_size <= icon_info->dir_size + icon_info->threshold)
2527 icon_info->scale = 1.0;
2528 else if (icon_info->dir_size > 0)
2529 icon_info->scale =(gdouble) icon_info->desired_size / icon_info->dir_size;
2531 else if (icon_info->dir_type == ICON_THEME_DIR_SCALABLE)
2533 if (icon_info->dir_size > 0)
2534 icon_info->scale = (gdouble) icon_info->desired_size / icon_info->dir_size;
2537 if (icon_info->scale >= 0. && scale_only)
2540 /* At this point, we need to actually get the icon; either from the
2541 * builting image or by loading the file
2543 if (icon_info->builtin_pixbuf)
2544 source_pixbuf = g_object_ref (icon_info->builtin_pixbuf);
2545 else if (icon_info->cache_pixbuf)
2546 source_pixbuf = g_object_ref (icon_info->cache_pixbuf);
2550 source_pixbuf = gdk_pixbuf_new_from_file (icon_info->filename,
2551 &icon_info->load_error);
2556 /* Do scale calculations that depend on the image size
2558 image_width = gdk_pixbuf_get_width (source_pixbuf);
2559 image_height = gdk_pixbuf_get_height (source_pixbuf);
2561 if (icon_info->scale < 0.0)
2563 gint image_size = MAX (image_width, image_height);
2565 icon_info->scale = icon_info->desired_size / (gdouble)image_size;
2567 icon_info->scale = 1.0;
2569 if (icon_info->dir_type == ICON_THEME_DIR_UNTHEMED)
2570 icon_info->scale = MIN (icon_info->scale, 1.0);
2573 /* We don't short-circuit out here for scale_only, since, now
2574 * we've loaded the icon, we might as well go ahead and finish
2575 * the job. This is a bit of a waste when we scale here
2576 * and never get the final pixbuf; at the cost of a bit of
2577 * extra complexity, we could keep the source pixbuf around
2578 * but not actually scale it until neede.
2581 if (icon_info->scale == 1.0)
2582 icon_info->pixbuf = source_pixbuf;
2585 icon_info->pixbuf = gdk_pixbuf_scale_simple (source_pixbuf,
2586 0.5 + image_width * icon_info->scale,
2587 0.5 + image_height * icon_info->scale,
2588 GDK_INTERP_BILINEAR);
2589 g_object_unref (source_pixbuf);
2596 * gtk_icon_info_load_icon:
2597 * @icon_info: a #GtkIconInfo structure from gtk_icon_theme_lookup_icon()
2598 * @error: location to store error information on failure, or %NULL.
2600 * Renders an icon previously looked up in an icon theme using
2601 * gtk_icon_theme_lookup_icon(); the size will be based on the size
2602 * passed to gtk_icon_theme_lookup_icon(). Note that the resulting
2603 * pixbuf may not be exactly this size; an icon theme may have icons
2604 * that differ slightly from their nominal sizes, and in addition GTK+
2605 * will avoid scaling icons that it considers sufficiently close to the
2606 * requested size or for which the source image would have to be scaled
2607 * up too far. (This maintains sharpness.)
2609 * Return value: the rendered icon; this may be a newly created icon
2610 * or a new reference to an internal icon, so you must not modify
2611 * the icon. Use g_object_unref() to release your reference to the
2617 gtk_icon_info_load_icon (GtkIconInfo *icon_info,
2620 g_return_val_if_fail (icon_info != NULL, NULL);
2622 g_return_val_if_fail (icon_info != NULL, NULL);
2623 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2625 icon_info_ensure_scale_and_pixbuf (icon_info, FALSE);
2627 if (icon_info->load_error)
2629 g_propagate_error (error, icon_info->load_error);
2633 return g_object_ref (icon_info->pixbuf);
2637 * gtk_icon_info_set_raw_coordinates:
2638 * @icon_info: a #GtkIconInfo
2639 * @raw_coordinates: whether the coordinates of embedded rectangles
2640 * and attached points should be returned in their original
2643 * Sets whether the coordinates returned by gtk_icon_info_get_embedded_rect()
2644 * and gtk_icon_info_get_attach_points() should be returned in their
2645 * original form as specified in the icon theme, instead of scaled
2646 * appropriately for the pixbuf returned by gtk_icon_info_load_icon().
2648 * Raw coordinates are somewhat strange; they are specified to be with
2649 * respect to the unscaled pixmap for PNG and XPM icons, but for SVG
2650 * icons, they are in a 1000x1000 coordinate space that is scaled
2651 * to the final size of the icon. You can determine if the icon is an SVG
2652 * icon by using gtk_icon_info_get_filename(), and seeing if it is non-%NULL
2653 * and ends in '.svg'.
2655 * This function is provided primarily to allow compatibility wrappers
2656 * for older API's, and is not expected to be useful for applications.
2661 gtk_icon_info_set_raw_coordinates (GtkIconInfo *icon_info,
2662 gboolean raw_coordinates)
2664 g_return_if_fail (icon_info != NULL);
2666 icon_info->raw_coordinates = raw_coordinates != FALSE;
2669 /* Scale coordinates from the icon data prior to returning
2673 icon_info_scale_point (GtkIconInfo *icon_info,
2679 if (icon_info->raw_coordinates)
2686 if (!icon_info_ensure_scale_and_pixbuf (icon_info, TRUE))
2689 *x_out = 0.5 + x * icon_info->scale;
2690 *y_out = 0.5 + y * icon_info->scale;
2697 * gtk_icon_info_get_embedded_rect:
2698 * @icon_info: a #GtkIconInfo
2699 * @rectangle: #GdkRectangle in which to store embedded
2700 * rectangle coordinates; coordinates are only stored
2701 * when this function returns %TRUE.
2703 * Gets the coordinates of a rectangle within the icon
2704 * that can be used for display of information such
2705 * as a preview of the contents of a text file.
2706 * See gtk_icon_info_set_raw_coordinates() for further
2707 * information about the coordinate system.
2709 * Return value: %TRUE if the icon has an embedded rectangle
2714 gtk_icon_info_get_embedded_rect (GtkIconInfo *icon_info,
2715 GdkRectangle *rectangle)
2717 g_return_val_if_fail (icon_info != NULL, FALSE);
2719 if (icon_info->data && icon_info->data->has_embedded_rect &&
2720 icon_info_ensure_scale_and_pixbuf (icon_info, TRUE))
2722 gint scaled_x0, scaled_y0;
2723 gint scaled_x1, scaled_y1;
2727 icon_info_scale_point (icon_info,
2728 icon_info->data->x0, icon_info->data->y0,
2729 &scaled_x0, &scaled_y0);
2730 icon_info_scale_point (icon_info,
2731 icon_info->data->x1, icon_info->data->y1,
2732 &scaled_x1, &scaled_y1);
2734 rectangle->x = scaled_x0;
2735 rectangle->y = scaled_y0;
2736 rectangle->width = scaled_x1 - rectangle->x;
2737 rectangle->height = scaled_y1 - rectangle->y;
2747 * gtk_icon_info_get_attach_points:
2748 * @icon_info: a #GtkIconInfo
2749 * @points: location to store pointer to an array of points, or %NULL
2750 * free the array of points with g_free().
2751 * @n_points: location to store the number of points in @points, or %NULL
2753 * Fetches the set of attach points for an icon. An attach point
2754 * is a location in the icon that can be used as anchor points for attaching
2755 * emblems or overlays to the icon.
2757 * Return value: %TRUE if there are any attach points for the icon.
2762 gtk_icon_info_get_attach_points (GtkIconInfo *icon_info,
2766 g_return_val_if_fail (icon_info != NULL, FALSE);
2768 if (icon_info->data && icon_info->data->n_attach_points &&
2769 icon_info_ensure_scale_and_pixbuf (icon_info, TRUE))
2775 *points = g_new (GdkPoint, icon_info->data->n_attach_points);
2776 for (i = 0; i < icon_info->data->n_attach_points; i++)
2777 icon_info_scale_point (icon_info,
2778 icon_info->data->attach_points[i].x,
2779 icon_info->data->attach_points[i].y,
2785 *n_points = icon_info->data->n_attach_points;
2801 * gtk_icon_info_get_display_name:
2802 * @icon_info: a #GtkIconInfo
2804 * Gets the display name for an icon. A display name is a
2805 * string to be used in place of the icon name in a user
2806 * visible context like a list of icons.
2808 * Return value: the display name for the icon or %NULL, if
2809 * the icon doesn't have a specified display name. This value
2810 * is owned @icon_info and must not be modified or free.
2814 G_CONST_RETURN gchar *
2815 gtk_icon_info_get_display_name (GtkIconInfo *icon_info)
2817 g_return_val_if_fail (icon_info != NULL, NULL);
2819 if (icon_info->data)
2820 return icon_info->data->display_name;
2831 * gtk_icon_theme_add_builtin_icon:
2832 * @icon_name: the name of the icon to register
2833 * @size: the size at which to register the icon (different
2834 * images can be registered for the same icon name
2835 * at different sizes.)
2836 * @pixbuf: #GdkPixbuf that contains the image to use
2839 * Registers a built-in icon for icon theme lookups. The idea
2840 * of built-in icons is to allow an application or library
2841 * that uses themed icons to function requiring files to
2842 * be present in the file system. For instance, the default
2843 * images for all of GTK+'s stock icons are registered
2846 * In general, if you use gtk_icon_theme_add_builtin_icon()
2847 * you should also install the icon in the icon theme, so
2848 * that the icon is generally available.
2850 * This function will generally be used with pixbufs loaded
2851 * via gdk_pixbuf_new_from_inline().
2856 gtk_icon_theme_add_builtin_icon (const gchar *icon_name,
2860 BuiltinIcon *default_icon;
2864 g_return_if_fail (icon_name != NULL);
2865 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
2867 if (!icon_theme_builtin_icons)
2868 icon_theme_builtin_icons = g_hash_table_new (g_str_hash, g_str_equal);
2870 icons = g_hash_table_lookup (icon_theme_builtin_icons, icon_name);
2872 key = g_strdup (icon_name);
2874 key = (gpointer)icon_name; /* Won't get stored */
2876 default_icon = g_new (BuiltinIcon, 1);
2877 default_icon->size = size;
2878 default_icon->pixbuf = g_object_ref (pixbuf);
2879 icons = g_slist_prepend (icons, default_icon);
2881 /* Replaces value, leaves key untouched
2883 g_hash_table_insert (icon_theme_builtin_icons, key, icons);
2886 /* Look up a builtin icon; the min_difference_p and
2887 * has_larger_p out parameters allow us to combine
2888 * this lookup with searching through the actual directories
2889 * of the "hicolor" icon theme. See theme_lookup_icon()
2890 * for how they are used.
2892 static BuiltinIcon *
2893 find_builtin_icon (const gchar *icon_name,
2895 gint *min_difference_p,
2896 gboolean *has_larger_p)
2898 GSList *icons = NULL;
2899 gint min_difference = G_MAXINT;
2900 gboolean has_larger = FALSE;
2901 BuiltinIcon *min_icon = NULL;
2903 _gtk_icon_factory_ensure_default_icons ();
2905 if (!icon_theme_builtin_icons)
2908 icons = g_hash_table_lookup (icon_theme_builtin_icons, icon_name);
2912 BuiltinIcon *default_icon = icons->data;
2913 int min, max, difference;
2916 min = default_icon->size - 2;
2917 max = default_icon->size + 2;
2918 smaller = size < min;
2920 difference = min - size;
2921 else if (size > max)
2922 difference = size - max;
2926 if (difference == 0)
2928 min_icon = default_icon;
2934 if (difference < min_difference || smaller)
2936 min_difference = difference;
2937 min_icon = default_icon;
2938 has_larger = smaller;
2943 if (difference < min_difference && smaller)
2945 min_difference = difference;
2946 min_icon = default_icon;
2950 icons = icons->next;
2953 if (min_difference_p)
2954 *min_difference_p = min_difference;
2956 *has_larger_p = has_larger;
2962 _gtk_icon_theme_check_reload (GdkDisplay *display)
2966 GtkIconTheme *icon_theme;
2968 n_screens = gdk_display_get_n_screens (display);
2970 for (i = 0; i < n_screens; i++)
2972 screen = gdk_display_get_screen (display, i);
2974 icon_theme = g_object_get_data (G_OBJECT (screen), "gtk-icon-theme");
2977 icon_theme->priv->check_reload = TRUE;
2978 ensure_valid_themes (icon_theme);
2979 icon_theme->priv->check_reload = FALSE;
2986 /* DLL ABI stability backward compatibility versions */
2988 #undef gtk_icon_theme_set_search_path
2991 gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme,
2992 const gchar *path[],
2995 const gchar **utf8_path;
2998 utf8_path = g_new (const gchar *, n_elements);
3000 for (i = 0; i < n_elements; i++)
3001 utf8_path[i] = g_locale_to_utf8 (path[i], -1, NULL, NULL, NULL);
3003 gtk_icon_theme_set_search_path_utf8 (icon_theme, utf8_path, n_elements);
3005 for (i = 0; i < n_elements; i++)
3006 g_free ((gchar *) utf8_path[i]);
3011 #undef gtk_icon_theme_get_search_path
3014 gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme,
3020 gtk_icon_theme_get_search_path_utf8 (icon_theme, path, &n);
3027 for (i = 0; i < n; i++)
3029 gchar *tem = (*path)[i];
3031 (*path)[i] = g_locale_from_utf8 ((*path)[i], -1, NULL, NULL, NULL);
3037 #undef gtk_icon_theme_append_search_path
3040 gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme,
3043 gchar *utf8_path = g_locale_from_utf8 (path, -1, NULL, NULL, NULL);
3045 gtk_icon_theme_append_search_path_utf8 (icon_theme, utf8_path);
3050 #undef gtk_icon_theme_prepend_search_path
3053 gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme,
3056 gchar *utf8_path = g_locale_from_utf8 (path, -1, NULL, NULL, NULL);
3058 gtk_icon_theme_prepend_search_path_utf8 (icon_theme, utf8_path);
3063 #undef gtk_icon_info_get_filename
3065 G_CONST_RETURN gchar *
3066 gtk_icon_info_get_filename (GtkIconInfo *icon_info)
3068 g_return_val_if_fail (icon_info != NULL, NULL);
3070 return icon_info->cp_filename;
3075 #define __GTK_ICON_THEME_C__
3076 #include "gtkaliasdef.c"