* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
+#include <config.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <pango/pango-utils.h> /* For pango_scan_* */
#include "gtkiconfactory.h"
-#include "stock-icons/gtkstockpixbufs.h"
+#include "gtkiconcache.h"
#include "gtkdebug.h"
+#include "gtkicontheme.h"
#include "gtksettings.h"
#include "gtkstock.h"
+#include "gtkwidget.h"
#include "gtkintl.h"
+#include "gtkalias.h"
+
static GSList *all_icon_factories = NULL;
+typedef enum {
+ GTK_ICON_SOURCE_EMPTY,
+ GTK_ICON_SOURCE_ICON_NAME,
+ GTK_ICON_SOURCE_STATIC_ICON_NAME,
+ GTK_ICON_SOURCE_FILENAME,
+ GTK_ICON_SOURCE_PIXBUF
+} GtkIconSourceType;
+
struct _GtkIconSource
{
- /* Either filename or pixbuf can be NULL. If both are non-NULL,
- * the pixbuf is assumed to be the already-loaded contents of the
- * file.
- */
- gchar *filename;
- GdkPixbuf *pixbuf;
+ GtkIconSourceType type;
+
+ union {
+ gchar *icon_name;
+ gchar *filename;
+ GdkPixbuf *pixbuf;
+ } source;
+
+ GdkPixbuf *filename_pixbuf;
GtkTextDirection direction;
GtkStateType state;
guint any_direction : 1;
guint any_state : 1;
guint any_size : 1;
+
+#ifdef G_OS_WIN32
+ /* System codepage version of filename, for DLL ABI backward
+ * compatibility functions.
+ */
+ gchar *cp_filename;
+#endif
};
-static gpointer parent_class = NULL;
-static void gtk_icon_factory_init (GtkIconFactory *icon_factory);
-static void gtk_icon_factory_class_init (GtkIconFactoryClass *klass);
static void gtk_icon_factory_finalize (GObject *object);
static void get_default_icons (GtkIconFactory *icon_factory);
+static void icon_source_clear (GtkIconSource *source);
static GtkIconSize icon_size_register_intern (const gchar *name,
gint width,
gint height);
-GType
-gtk_icon_factory_get_type (void)
-{
- static GType icon_factory_type = 0;
+#define GTK_ICON_SOURCE_INIT(any_direction, any_state, any_size) \
+ { GTK_ICON_SOURCE_EMPTY, { NULL }, NULL, \
+ 0, 0, 0, \
+ any_direction, any_state, any_size }
- if (!icon_factory_type)
- {
- static const GTypeInfo icon_factory_info =
- {
- sizeof (GtkIconFactoryClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_icon_factory_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkIconFactory),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_icon_factory_init,
- };
-
- icon_factory_type =
- g_type_register_static (G_TYPE_OBJECT, "GtkIconFactory",
- &icon_factory_info, 0);
- }
-
- return icon_factory_type;
-}
+G_DEFINE_TYPE (GtkIconFactory, gtk_icon_factory, G_TYPE_OBJECT)
static void
gtk_icon_factory_init (GtkIconFactory *factory)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
object_class->finalize = gtk_icon_factory_finalize;
}
g_hash_table_destroy (factory->icons);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtk_icon_factory_parent_class)->finalize (object);
}
/**
g_object_unref (factory);
}
-static void
-ensure_default_icons (void)
+void
+_gtk_icon_factory_ensure_default_icons (void)
{
if (gtk_default_icons == NULL)
{
tmp_list = g_slist_next (tmp_list);
}
- ensure_default_icons ();
+ _gtk_icon_factory_ensure_default_icons ();
return gtk_icon_factory_lookup (gtk_default_icons, stock_id);
}
static void
-add_source (GtkIconSet *set,
- GtkIconSource *source,
- const gchar *inline_data)
-{
- source->pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL);
- g_assert (source->pixbuf);
-
- gtk_icon_set_add_source (set, source);
-
- g_object_unref (source->pixbuf);
-}
-
-#if 0
-static GtkIconSet *
-sized_icon_set_from_inline (const guchar *inline_data,
- GtkIconSize size)
-{
- GtkIconSet *set;
-
- GtkIconSource source = { NULL, NULL, 0, 0, 0,
- TRUE, TRUE, FALSE };
-
- source.size = size;
-
- set = gtk_icon_set_new ();
-
- add_source (set, source, inline_data);
-
- return set;
-}
-#endif
-
-static GtkIconSet *
-sized_with_fallback_icon_set_from_inline (const guchar *fallback_data_ltr,
- const guchar *fallback_data_rtl,
- const guchar *inline_data_ltr,
- const guchar *inline_data_rtl,
- GtkIconSize size)
-{
- GtkIconSet *set;
-
- GtkIconSource source = { NULL, NULL, 0, 0, 0,
- TRUE, TRUE, FALSE };
-
- set = gtk_icon_set_new ();
-
- source.size = size;
- source.any_direction = inline_data_rtl == NULL;
-
- source.direction = GTK_TEXT_DIR_LTR;
- add_source (set, &source, inline_data_ltr);
-
- if (inline_data_rtl != NULL)
- {
- source.direction = GTK_TEXT_DIR_RTL;
- add_source (set, &source, inline_data_rtl);
- }
-
- source.any_size = TRUE;
- source.any_direction = fallback_data_rtl == NULL;
-
- source.direction = GTK_TEXT_DIR_LTR;
- add_source (set, &source, fallback_data_ltr);
-
- if (fallback_data_rtl != NULL)
- {
- source.direction = GTK_TEXT_DIR_RTL;
- add_source (set, &source, fallback_data_rtl);
- }
-
- return set;
-}
-
-static GtkIconSet *
-unsized_icon_set_from_inline (const guchar *inline_data)
-{
- GtkIconSet *set;
-
- /* This icon can be used for any direction/state/size */
- GtkIconSource source = { NULL, NULL, 0, 0, 0,
- TRUE, TRUE, TRUE };
-
- set = gtk_icon_set_new ();
-
- add_source (set, &source, inline_data);
-
- return set;
-}
-
-#if 0
-static void
-add_sized (GtkIconFactory *factory,
- const guchar *inline_data,
- GtkIconSize size,
- const gchar *stock_id)
-{
- GtkIconSet *set;
-
- set = sized_icon_set_from_inline (inline_data, size);
-
- gtk_icon_factory_add (factory, stock_id, set);
-
- gtk_icon_set_unref (set);
-}
-#endif
-
-static void
-add_sized_with_fallback_and_rtl (GtkIconFactory *factory,
- const guchar *fallback_data_ltr,
- const guchar *fallback_data_rtl,
- const guchar *inline_data_ltr,
- const guchar *inline_data_rtl,
- GtkIconSize size,
- const gchar *stock_id)
+register_stock_icon (GtkIconFactory *factory,
+ const gchar *stock_id)
{
- GtkIconSet *set;
+ GtkIconSet *set = gtk_icon_set_new ();
+ GtkIconSource source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
- set = sized_with_fallback_icon_set_from_inline (fallback_data_ltr, fallback_data_rtl,
- inline_data_ltr, inline_data_rtl,
- size);
+ source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
+ source.source.icon_name = (gchar *)stock_id;
+ gtk_icon_set_add_source (set, &source);
gtk_icon_factory_add (factory, stock_id, set);
-
gtk_icon_set_unref (set);
}
static void
-add_sized_with_fallback (GtkIconFactory *factory,
- const guchar *fallback_data,
- const guchar *inline_data,
- GtkIconSize size,
- const gchar *stock_id)
+register_bidi_stock_icon (GtkIconFactory *factory,
+ const gchar *stock_id,
+ const gchar *stock_id_ltr,
+ const gchar *stock_id_rtl)
{
- add_sized_with_fallback_and_rtl (factory,
- fallback_data, NULL,
- inline_data, NULL,
- size, stock_id);
-}
+ GtkIconSet *set = gtk_icon_set_new ();
+ GtkIconSource source = GTK_ICON_SOURCE_INIT (FALSE, TRUE, TRUE);
-static void
-add_unsized (GtkIconFactory *factory,
- const guchar *inline_data,
- const gchar *stock_id)
-{
- GtkIconSet *set;
+ source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
+ source.source.icon_name = (gchar *)stock_id_ltr;
+ source.direction = GTK_TEXT_DIR_LTR;
+ gtk_icon_set_add_source (set, &source);
- set = unsized_icon_set_from_inline (inline_data);
+ source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
+ source.source.icon_name = (gchar *)stock_id_rtl;
+ source.direction = GTK_TEXT_DIR_RTL;
+ gtk_icon_set_add_source (set, &source);
gtk_icon_factory_add (factory, stock_id, set);
-
gtk_icon_set_unref (set);
}
{
/* KEEP IN SYNC with gtkstock.c */
- /* We add all stock icons unsized, since it's confusing if icons only
- * can be loaded at certain sizes.
- */
-
- /* Have dialog size */
- add_unsized (factory, stock_dialog_error_48, GTK_STOCK_DIALOG_ERROR);
- add_unsized (factory, stock_dialog_info_48, GTK_STOCK_DIALOG_INFO);
- add_unsized (factory, stock_dialog_question_48, GTK_STOCK_DIALOG_QUESTION);
- add_unsized (factory, stock_dialog_warning_48,GTK_STOCK_DIALOG_WARNING);
-
- /* Have dnd size */
- add_unsized (factory, stock_dnd_32, GTK_STOCK_DND);
- add_unsized (factory, stock_dnd_multiple_32, GTK_STOCK_DND_MULTIPLE);
-
- /* Have button sizes */
- add_unsized (factory, stock_apply_20, GTK_STOCK_APPLY);
- add_unsized (factory, stock_cancel_20, GTK_STOCK_CANCEL);
- add_unsized (factory, stock_no_20, GTK_STOCK_NO);
- add_unsized (factory, stock_ok_20, GTK_STOCK_OK);
- add_unsized (factory, stock_yes_20, GTK_STOCK_YES);
-
- /* Generic + button sizes */
- add_sized_with_fallback (factory,
- stock_close_24,
- stock_close_20,
- GTK_ICON_SIZE_BUTTON,
- GTK_STOCK_CLOSE);
-
- /* Generic + menu sizes */
- add_sized_with_fallback (factory,
- stock_add_24,
- stock_add_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_ADD);
-
- add_sized_with_fallback (factory,
- stock_align_center_24,
- stock_align_center_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_JUSTIFY_CENTER);
-
- add_sized_with_fallback (factory,
- stock_align_justify_24,
- stock_align_justify_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_JUSTIFY_FILL);
-
- add_sized_with_fallback (factory,
- stock_align_left_24,
- stock_align_left_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_JUSTIFY_LEFT);
-
- add_sized_with_fallback (factory,
- stock_align_right_24,
- stock_align_right_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_JUSTIFY_RIGHT);
-
- add_sized_with_fallback (factory,
- stock_bottom_24,
- stock_bottom_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_GOTO_BOTTOM);
-
- add_sized_with_fallback (factory,
- stock_cdrom_24,
- stock_cdrom_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_CDROM);
-
- add_sized_with_fallback (factory,
- stock_convert_24,
- stock_convert_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_CONVERT);
-
- add_sized_with_fallback (factory,
- stock_copy_24,
- stock_copy_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_COPY);
-
- add_sized_with_fallback (factory,
- stock_cut_24,
- stock_cut_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_CUT);
-
- add_sized_with_fallback (factory,
- stock_down_arrow_24,
- stock_down_arrow_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_GO_DOWN);
-
- add_sized_with_fallback (factory,
- stock_exec_24,
- stock_exec_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_EXECUTE);
-
- add_sized_with_fallback (factory,
- stock_exit_24,
- stock_exit_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_QUIT);
-
- add_sized_with_fallback (factory,
- stock_first_24,
- stock_first_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_GOTO_FIRST);
-
- add_sized_with_fallback (factory,
- stock_font_24,
- stock_font_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_SELECT_FONT);
-
- add_sized_with_fallback (factory,
- stock_help_24,
- stock_help_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_HELP);
-
- add_sized_with_fallback (factory,
- stock_home_24,
- stock_home_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_HOME);
-
- add_sized_with_fallback (factory,
- stock_jump_to_24,
- stock_jump_to_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_JUMP_TO);
-
- add_sized_with_fallback (factory,
- stock_last_24,
- stock_last_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_GOTO_LAST);
-
- add_sized_with_fallback_and_rtl (factory,
- stock_left_arrow_24,
- stock_right_arrow_24,
- stock_left_arrow_16,
- stock_right_arrow_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_GO_BACK);
-
- add_sized_with_fallback (factory,
- stock_missing_image_24,
- stock_missing_image_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_MISSING_IMAGE);
-
- add_sized_with_fallback (factory,
- stock_new_24,
- stock_new_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_NEW);
-
- add_sized_with_fallback (factory,
- stock_open_24,
- stock_open_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_OPEN);
-
- add_sized_with_fallback (factory,
- stock_paste_24,
- stock_paste_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_PASTE);
-
- add_sized_with_fallback (factory,
- stock_preferences_24,
- stock_preferences_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_PREFERENCES);
-
- add_sized_with_fallback (factory,
- stock_print_24,
- stock_print_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_PRINT);
-
- add_sized_with_fallback (factory,
- stock_print_preview_24,
- stock_print_preview_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_PRINT_PREVIEW);
-
- add_sized_with_fallback (factory,
- stock_properties_24,
- stock_properties_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_PROPERTIES);
-
- add_sized_with_fallback (factory,
- stock_redo_24,
- stock_redo_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_REDO);
-
- add_sized_with_fallback (factory,
- stock_remove_24,
- stock_remove_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_REMOVE);
-
- add_sized_with_fallback (factory,
- stock_refresh_24,
- stock_refresh_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_REFRESH);
-
- add_sized_with_fallback (factory,
- stock_revert_24,
- stock_revert_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_REVERT_TO_SAVED);
-
- add_sized_with_fallback_and_rtl (factory,
- stock_right_arrow_24,
- stock_left_arrow_24,
- stock_right_arrow_16,
- stock_left_arrow_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_GO_FORWARD);
-
- add_sized_with_fallback (factory,
- stock_save_24,
- stock_save_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_SAVE);
-
- add_sized_with_fallback (factory,
- stock_save_24,
- stock_save_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_FLOPPY);
-
- add_sized_with_fallback (factory,
- stock_save_as_24,
- stock_save_as_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_SAVE_AS);
-
- add_sized_with_fallback (factory,
- stock_search_24,
- stock_search_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_FIND);
-
- add_sized_with_fallback (factory,
- stock_search_replace_24,
- stock_search_replace_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_FIND_AND_REPLACE);
-
- add_sized_with_fallback (factory,
- stock_sort_descending_24,
- stock_sort_descending_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_SORT_DESCENDING);
-
- add_sized_with_fallback (factory,
- stock_sort_ascending_24,
- stock_sort_ascending_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_SORT_ASCENDING);
-
- add_sized_with_fallback (factory,
- stock_spellcheck_24,
- stock_spellcheck_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_SPELL_CHECK);
-
- add_sized_with_fallback (factory,
- stock_stop_24,
- stock_stop_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_STOP);
-
- add_sized_with_fallback (factory,
- stock_text_bold_24,
- stock_text_bold_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_BOLD);
-
- add_sized_with_fallback (factory,
- stock_text_italic_24,
- stock_text_italic_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_ITALIC);
-
- add_sized_with_fallback (factory,
- stock_text_strikethrough_24,
- stock_text_strikethrough_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_STRIKETHROUGH);
-
- add_sized_with_fallback (factory,
- stock_text_underline_24,
- stock_text_underline_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_UNDERLINE);
-
- add_sized_with_fallback (factory,
- stock_top_24,
- stock_top_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_GOTO_TOP);
-
- add_sized_with_fallback (factory,
- stock_trash_24,
- stock_trash_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_DELETE);
-
- add_sized_with_fallback (factory,
- stock_undelete_24,
- stock_undelete_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_UNDELETE);
-
- add_sized_with_fallback (factory,
- stock_undo_24,
- stock_undo_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_UNDO);
-
- add_sized_with_fallback (factory,
- stock_up_arrow_24,
- stock_up_arrow_16,
- GTK_ICON_SIZE_MENU,
- GTK_STOCK_GO_UP);
-
-/* Generic size only */
-
- add_unsized (factory, stock_clear_24, GTK_STOCK_CLEAR);
- add_unsized (factory, stock_colorselector_24, GTK_STOCK_SELECT_COLOR);
- add_unsized (factory, stock_color_picker_25, GTK_STOCK_COLOR_PICKER);
- add_unsized (factory, stock_index_24, GTK_STOCK_INDEX);
- add_unsized (factory, stock_zoom_1_24, GTK_STOCK_ZOOM_100);
- add_unsized (factory, stock_zoom_fit_24, GTK_STOCK_ZOOM_FIT);
- add_unsized (factory, stock_zoom_in_24, GTK_STOCK_ZOOM_IN);
- add_unsized (factory, stock_zoom_out_24, GTK_STOCK_ZOOM_OUT);
+ register_stock_icon (factory, GTK_STOCK_DIALOG_AUTHENTICATION);
+ register_stock_icon (factory, GTK_STOCK_DIALOG_ERROR);
+ register_stock_icon (factory, GTK_STOCK_DIALOG_INFO);
+ register_stock_icon (factory, GTK_STOCK_DIALOG_QUESTION);
+ register_stock_icon (factory, GTK_STOCK_DIALOG_WARNING);
+ register_stock_icon (factory, GTK_STOCK_DND);
+ register_stock_icon (factory, GTK_STOCK_DND_MULTIPLE);
+ register_stock_icon (factory, GTK_STOCK_APPLY);
+ register_stock_icon (factory, GTK_STOCK_CANCEL);
+ register_stock_icon (factory, GTK_STOCK_NO);
+ register_stock_icon (factory, GTK_STOCK_OK);
+ register_stock_icon (factory, GTK_STOCK_YES);
+ register_stock_icon (factory, GTK_STOCK_CLOSE);
+ register_stock_icon (factory, GTK_STOCK_ADD);
+ register_stock_icon (factory, GTK_STOCK_JUSTIFY_CENTER);
+ register_stock_icon (factory, GTK_STOCK_JUSTIFY_FILL);
+ register_stock_icon (factory, GTK_STOCK_JUSTIFY_LEFT);
+ register_stock_icon (factory, GTK_STOCK_JUSTIFY_RIGHT);
+ register_stock_icon (factory, GTK_STOCK_GOTO_BOTTOM);
+ register_stock_icon (factory, GTK_STOCK_CDROM);
+ register_stock_icon (factory, GTK_STOCK_CONVERT);
+ register_stock_icon (factory, GTK_STOCK_COPY);
+ register_stock_icon (factory, GTK_STOCK_CUT);
+ register_stock_icon (factory, GTK_STOCK_GO_DOWN);
+ register_stock_icon (factory, GTK_STOCK_EXECUTE);
+ register_stock_icon (factory, GTK_STOCK_QUIT);
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_GOTO_FIRST,
+ GTK_STOCK_GOTO_FIRST "-ltr",
+ GTK_STOCK_GOTO_FIRST "-rtl");
+ register_stock_icon (factory, GTK_STOCK_SELECT_FONT);
+ register_stock_icon (factory, GTK_STOCK_FULLSCREEN);
+ register_stock_icon (factory, GTK_STOCK_LEAVE_FULLSCREEN);
+ register_stock_icon (factory, GTK_STOCK_HARDDISK);
+ register_stock_icon (factory, GTK_STOCK_HELP);
+ register_stock_icon (factory, GTK_STOCK_HOME);
+ register_stock_icon (factory, GTK_STOCK_INFO);
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_JUMP_TO,
+ GTK_STOCK_JUMP_TO "-ltr",
+ GTK_STOCK_JUMP_TO "-rtl");
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_GOTO_LAST,
+ GTK_STOCK_GOTO_LAST "-ltr",
+ GTK_STOCK_GOTO_LAST "-rtl");
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_GO_BACK,
+ GTK_STOCK_GO_BACK "-ltr",
+ GTK_STOCK_GO_BACK "-rtl");
+ register_stock_icon (factory, GTK_STOCK_MISSING_IMAGE);
+ register_stock_icon (factory, GTK_STOCK_NETWORK);
+ register_stock_icon (factory, GTK_STOCK_NEW);
+ register_stock_icon (factory, GTK_STOCK_OPEN);
+ register_stock_icon (factory, GTK_STOCK_ORIENTATION_PORTRAIT);
+ register_stock_icon (factory, GTK_STOCK_ORIENTATION_LANDSCAPE);
+ register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT);
+ register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE);
+ register_stock_icon (factory, GTK_STOCK_PASTE);
+ register_stock_icon (factory, GTK_STOCK_PREFERENCES);
+ register_stock_icon (factory, GTK_STOCK_PRINT);
+ register_stock_icon (factory, GTK_STOCK_PRINT_PREVIEW);
+ register_stock_icon (factory, GTK_STOCK_PROPERTIES);
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_REDO,
+ GTK_STOCK_REDO "-ltr",
+ GTK_STOCK_REDO "-rtl");
+ register_stock_icon (factory, GTK_STOCK_REMOVE);
+ register_stock_icon (factory, GTK_STOCK_REFRESH);
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_REVERT_TO_SAVED,
+ GTK_STOCK_REVERT_TO_SAVED "-ltr",
+ GTK_STOCK_REVERT_TO_SAVED "-rtl");
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_GO_FORWARD,
+ GTK_STOCK_GO_FORWARD "-ltr",
+ GTK_STOCK_GO_FORWARD "-rtl");
+ register_stock_icon (factory, GTK_STOCK_SAVE);
+ register_stock_icon (factory, GTK_STOCK_FLOPPY);
+ register_stock_icon (factory, GTK_STOCK_SAVE_AS);
+ register_stock_icon (factory, GTK_STOCK_FIND);
+ register_stock_icon (factory, GTK_STOCK_FIND_AND_REPLACE);
+ register_stock_icon (factory, GTK_STOCK_SORT_DESCENDING);
+ register_stock_icon (factory, GTK_STOCK_SORT_ASCENDING);
+ register_stock_icon (factory, GTK_STOCK_SPELL_CHECK);
+ register_stock_icon (factory, GTK_STOCK_STOP);
+ register_stock_icon (factory, GTK_STOCK_BOLD);
+ register_stock_icon (factory, GTK_STOCK_ITALIC);
+ register_stock_icon (factory, GTK_STOCK_STRIKETHROUGH);
+ register_stock_icon (factory, GTK_STOCK_UNDERLINE);
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_INDENT,
+ GTK_STOCK_INDENT "-ltr",
+ GTK_STOCK_INDENT "-rtl");
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_UNINDENT,
+ GTK_STOCK_UNINDENT "-ltr",
+ GTK_STOCK_UNINDENT "-rtl");
+ register_stock_icon (factory, GTK_STOCK_GOTO_TOP);
+ register_stock_icon (factory, GTK_STOCK_DELETE);
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_UNDELETE,
+ GTK_STOCK_UNDELETE "-ltr",
+ GTK_STOCK_UNDELETE "-rtl");
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_UNDO,
+ GTK_STOCK_UNDO "-ltr",
+ GTK_STOCK_UNDO "-rtl");
+ register_stock_icon (factory, GTK_STOCK_GO_UP);
+ register_stock_icon (factory, GTK_STOCK_FILE);
+ register_stock_icon (factory, GTK_STOCK_DIRECTORY);
+ register_stock_icon (factory, GTK_STOCK_ABOUT);
+ register_stock_icon (factory, GTK_STOCK_CONNECT);
+ register_stock_icon (factory, GTK_STOCK_DISCONNECT);
+ register_stock_icon (factory, GTK_STOCK_EDIT);
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_MEDIA_FORWARD,
+ GTK_STOCK_MEDIA_FORWARD "-ltr",
+ GTK_STOCK_MEDIA_FORWARD "-rtl");
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_MEDIA_NEXT,
+ GTK_STOCK_MEDIA_NEXT "-ltr",
+ GTK_STOCK_MEDIA_NEXT "-rtl");
+ register_stock_icon (factory, GTK_STOCK_MEDIA_PAUSE);
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_MEDIA_PLAY,
+ GTK_STOCK_MEDIA_PLAY "-ltr",
+ GTK_STOCK_MEDIA_PLAY "-rtl");
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_MEDIA_PREVIOUS,
+ GTK_STOCK_MEDIA_PREVIOUS "-ltr",
+ GTK_STOCK_MEDIA_PREVIOUS "-rtl");
+ register_stock_icon (factory, GTK_STOCK_MEDIA_RECORD);
+ register_bidi_stock_icon (factory,
+ GTK_STOCK_MEDIA_REWIND,
+ GTK_STOCK_MEDIA_REWIND "-ltr",
+ GTK_STOCK_MEDIA_REWIND "-rtl");
+ register_stock_icon (factory, GTK_STOCK_MEDIA_STOP);
+ register_stock_icon (factory, GTK_STOCK_INDEX);
+ register_stock_icon (factory, GTK_STOCK_ZOOM_100);
+ register_stock_icon (factory, GTK_STOCK_ZOOM_IN);
+ register_stock_icon (factory, GTK_STOCK_ZOOM_OUT);
+ register_stock_icon (factory, GTK_STOCK_ZOOM_FIT);
+ register_stock_icon (factory, GTK_STOCK_SELECT_ALL);
+ register_stock_icon (factory, GTK_STOCK_CLEAR);
+ register_stock_icon (factory, GTK_STOCK_SELECT_COLOR);
+ register_stock_icon (factory, GTK_STOCK_COLOR_PICKER);
}
/************************************************************
{
icon_size_set_all_from_settings (settings);
- _gtk_rc_reset_styles (settings);
+ gtk_rc_reset_styles (settings);
}
static void
icon_size_set_all_from_settings (settings);
}
-gboolean
+static gboolean
icon_size_lookup_intern (GtkSettings *settings,
GtkIconSize size,
gint *widthp,
init_icon_sizes ();
- if (size >= icon_sizes_used || icon_sizes[size].width < 0)
+ if (size >= icon_sizes_used)
return FALSE;
if (size == GTK_ICON_SIZE_INVALID)
/**
* gtk_icon_size_lookup_for_settings:
- * @GtkSettings: a #GtkSettings object, used to determine
+ * @settings: a #GtkSettings object, used to determine
* which set of user preferences to used.
* @size: an icon size
* @width: location to store icon width
* @height: location to store icon height
*
* Obtains the pixel size of a semantic icon size, possibly
- * modified by user preferences for a particular #GtkSettings
- * Normally @size would be
+ * modified by user preferences for a particular
+ * #GtkSettings. Normally @size would be
* #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc. This function
* isn't normally needed, gtk_widget_render_icon() is the usual
* way to get an icon for rendering, then just look at the size of
* the usual size.
*
* Return value: %TRUE if @size was a valid size
+ *
+ * Since: 2.2
**/
gboolean
gtk_icon_size_lookup_for_settings (GtkSettings *settings,
GtkIconSize size,
- gint *widthp,
- gint *heightp)
+ gint *width,
+ gint *height)
{
g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
- return icon_size_lookup_intern (settings, size, widthp, heightp);
+ return icon_size_lookup_intern (settings, size, width, height);
}
/**
init_icon_sizes ();
if (!icon_size_lookup_intern (NULL, target, NULL, NULL))
- g_warning ("gtk_icon_size_register_alias: Icon size %d does not exist", target);
+ g_warning ("gtk_icon_size_register_alias: Icon size %u does not exist", target);
ia = g_hash_table_lookup (icon_aliases, alias);
if (ia)
/* Icon Set */
-/* Clear icon set contents, drop references to all contained
- * GdkPixbuf objects and forget all GtkIconSources. Used to
- * recycle an icon set.
- */
static GdkPixbuf *find_in_cache (GtkIconSet *icon_set,
GtkStyle *style,
GtkTextDirection direction,
GtkStateType state,
GtkIconSize size,
GdkPixbuf *pixbuf);
+/* Clear icon set contents, drop references to all contained
+ * GdkPixbuf objects and forget all GtkIconSources. Used to
+ * recycle an icon set.
+ */
static void clear_cache (GtkIconSet *icon_set,
gboolean style_detach);
static GSList* copy_cache (GtkIconSet *icon_set,
{
GtkIconSet *set;
- GtkIconSource source = { NULL, NULL, 0, 0, 0,
- TRUE, TRUE, TRUE };
+ GtkIconSource source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
g_return_val_if_fail (pixbuf != NULL, NULL);
set = gtk_icon_set_new ();
- source.pixbuf = pixbuf;
-
+ gtk_icon_source_set_pixbuf (&source, pixbuf);
gtk_icon_set_add_source (set, &source);
+ gtk_icon_source_set_pixbuf (&source, NULL);
return set;
}
tmp_list = g_slist_next (tmp_list);
}
+ g_slist_free (icon_set->sources);
clear_cache (icon_set, TRUE);
static GType our_type = 0;
if (our_type == 0)
- our_type = g_boxed_type_register_static ("GtkIconSet",
+ our_type = g_boxed_type_register_static (I_("GtkIconSet"),
(GBoxedCopyFunc) gtk_icon_set_ref,
(GBoxedFreeFunc) gtk_icon_set_unref);
#endif
}
-static GtkIconSource*
-find_and_prep_icon_source (GtkIconSet *icon_set,
- GtkTextDirection direction,
- GtkStateType state,
- GtkIconSize size)
+static GtkIconSource *
+find_best_matching_source (GtkIconSet *icon_set,
+ GtkTextDirection direction,
+ GtkStateType state,
+ GtkIconSize size,
+ GSList *failed)
{
GtkIconSource *source;
GSList *tmp_list;
-
-
+
/* We need to find the best icon source. Direction matters more
* than state, state matters more than size. icon_set->sources
* is sorted according to wildness, so if we take the first
(s->any_state || (s->state == state)) &&
(s->any_size || (sizes_equivalent (size, s->size))))
{
- source = s;
- break;
- }
-
+ if (!g_slist_find (failed, s))
+ {
+ source = s;
+ break;
+ }
+ }
+
tmp_list = g_slist_next (tmp_list);
}
- if (source == NULL)
- return NULL;
+ return source;
+}
- if (source->pixbuf == NULL)
+static gboolean
+ensure_filename_pixbuf (GtkIconSet *icon_set,
+ GtkIconSource *source)
+{
+ if (source->filename_pixbuf == NULL)
{
GError *error = NULL;
- g_assert (source->filename);
- source->pixbuf = gdk_pixbuf_new_from_file (source->filename, &error);
+ source->filename_pixbuf = gdk_pixbuf_new_from_file (source->source.filename, &error);
+
+ if (source->filename_pixbuf == NULL)
+ {
+ /* Remove this icon source so we don't keep trying to
+ * load it.
+ */
+ g_warning (_("Error loading icon: %s"), error->message);
+ g_error_free (error);
+
+ icon_set->sources = g_slist_remove (icon_set->sources, source);
+
+ gtk_icon_source_free (source);
- if (source->pixbuf == NULL)
- {
- /* Remove this icon source so we don't keep trying to
- * load it.
- */
- g_warning (_("Error loading icon: %s"), error->message);
- g_error_free (error);
-
- icon_set->sources = g_slist_remove (icon_set->sources, source);
-
- gtk_icon_source_free (source);
-
- /* Try to fall back to other sources */
- if (icon_set->sources != NULL)
- return find_and_prep_icon_source (icon_set,
- direction,
- state,
- size);
- else
- return NULL;
- }
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+static GdkPixbuf *
+render_icon_name_pixbuf (GtkIconSource *icon_source,
+ GtkStyle *style,
+ GtkTextDirection direction,
+ GtkStateType state,
+ GtkIconSize size,
+ GtkWidget *widget,
+ const char *detail)
+{
+ GdkPixbuf *pixbuf;
+ GdkPixbuf *tmp_pixbuf;
+ GtkIconSource tmp_source;
+ GdkScreen *screen;
+ GtkIconTheme *icon_theme;
+ GtkSettings *settings;
+ gint width, height, pixel_size;
+ gint *sizes, *s, dist;
+ GError *error = NULL;
+
+ if (widget && gtk_widget_has_screen (widget))
+ screen = gtk_widget_get_screen (widget);
+ else if (style && style->colormap)
+ screen = gdk_colormap_get_screen (style->colormap);
+ else
+ {
+ screen = gdk_screen_get_default ();
+ GTK_NOTE (MULTIHEAD,
+ g_warning ("Using the default screen for gtk_icon_source_render_icon()"));
}
- return source;
+ icon_theme = gtk_icon_theme_get_for_screen (screen);
+ settings = gtk_settings_get_for_screen (screen);
+
+ if (!gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
+ {
+ if (size == -1)
+ {
+ /* Find an available size close to 48
+ */
+ sizes = gtk_icon_theme_get_icon_sizes (icon_theme, icon_source->source.icon_name);
+ dist = 1000;
+ width = height = 48;
+ for (s = sizes; *s; s++)
+ {
+ if (*s == -1)
+ {
+ width = height = 48;
+ break;
+ }
+ if (*s < 48)
+ {
+ if (48 - *s < dist)
+ {
+ width = height = *s;
+ dist = 48 - *s;
+ }
+ }
+ else
+ {
+ if (*s - 48 < dist)
+ {
+ width = height = *s;
+ dist = *s - 48;
+ }
+ }
+ }
+
+ g_free (sizes);
+ }
+ else
+ {
+ g_warning ("Invalid icon size %u\n", size);
+ width = height = 24;
+ }
+ }
+
+ pixel_size = MIN (width, height);
+
+ tmp_pixbuf = gtk_icon_theme_load_icon (icon_theme,
+ icon_source->source.icon_name,
+ pixel_size, 0,
+ &error);
+
+ if (!tmp_pixbuf)
+ {
+ g_warning ("Error loading theme icon for stock: %s", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ tmp_source = *icon_source;
+ tmp_source.type = GTK_ICON_SOURCE_PIXBUF;
+ tmp_source.source.pixbuf = tmp_pixbuf;
+
+ pixbuf = gtk_style_render_icon (style, &tmp_source,
+ direction, state, -1,
+ widget, detail);
+
+ if (!pixbuf)
+ g_warning ("Failed to render icon");
+
+ g_object_unref (tmp_pixbuf);
+
+ return pixbuf;
+}
+
+static GdkPixbuf *
+find_and_render_icon_source (GtkIconSet *icon_set,
+ GtkStyle *style,
+ GtkTextDirection direction,
+ GtkStateType state,
+ GtkIconSize size,
+ GtkWidget *widget,
+ const char *detail)
+{
+ GSList *failed = NULL;
+ GdkPixbuf *pixbuf = NULL;
+
+ /* We treat failure in two different ways:
+ *
+ * A) If loading a source that specifies a filename fails,
+ * we treat that as permanent, and remove the source
+ * from the GtkIconSet. (in ensure_filename_pixbuf ()
+ * B) If loading a themed icon fails, or scaling an icon
+ * fails, we treat that as transient and will try
+ * again next time the icon falls out of the cache
+ * and we need to recreate it.
+ */
+ while (pixbuf == NULL)
+ {
+ GtkIconSource *source = find_best_matching_source (icon_set, direction, state, size, failed);
+
+ if (source == NULL)
+ break;
+
+ switch (source->type)
+ {
+ case GTK_ICON_SOURCE_FILENAME:
+ if (!ensure_filename_pixbuf (icon_set, source))
+ break;
+ /* Fall through */
+ case GTK_ICON_SOURCE_PIXBUF:
+ pixbuf = gtk_style_render_icon (style, source,
+ direction, state, size,
+ widget, detail);
+ if (!pixbuf)
+ {
+ g_warning ("Failed to render icon");
+ failed = g_slist_prepend (failed, source);
+ }
+ break;
+ case GTK_ICON_SOURCE_ICON_NAME:
+ case GTK_ICON_SOURCE_STATIC_ICON_NAME:
+ pixbuf = render_icon_name_pixbuf (source, style,
+ direction, state, size,
+ widget, detail);
+ if (!pixbuf)
+ failed = g_slist_prepend (failed, source);
+ break;
+ case GTK_ICON_SOURCE_EMPTY:
+ g_assert_not_reached ();
+ }
+ }
+
+ g_slist_free (failed);
+
+ return pixbuf;
}
+extern GtkIconCache *_builtin_cache;
+
static GdkPixbuf*
render_fallback_image (GtkStyle *style,
GtkTextDirection direction,
const char *detail)
{
/* This icon can be used for any direction/state/size */
- static GtkIconSource fallback_source = { NULL, NULL, 0, 0, 0, TRUE, TRUE, TRUE };
+ static GtkIconSource fallback_source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
+
+ if (fallback_source.type == GTK_ICON_SOURCE_EMPTY)
+ {
+ GdkPixbuf *pixbuf;
- if (fallback_source.pixbuf == NULL)
- fallback_source.pixbuf = gdk_pixbuf_new_from_inline (-1, stock_missing_image_24, FALSE, NULL);
+ _gtk_icon_theme_ensure_builtin_cache ();
+
+ pixbuf = _gtk_icon_cache_get_icon (_builtin_cache,
+ GTK_STOCK_MISSING_IMAGE,
+ "24");
+ gtk_icon_source_set_pixbuf (&fallback_source, pixbuf);
+ g_object_unref (pixbuf);
+ }
return gtk_style_render_icon (style,
&fallback_source,
* @style: a #GtkStyle associated with @widget, or %NULL
* @direction: text direction
* @state: widget state
- * @size: icon size
- * @widget: widget that will display the icon, or %NULL
- * @detail: detail to pass to the theme engine, or %NULL
+ * @size: icon size. A size of (GtkIconSize)-1
+ * means render at the size of the source and don't scale.
+ * @widget: widget that will display the icon, or %NULL.
+ * The only use that is typically made of this
+ * is to determine the appropriate #GdkScreen.
+ * @detail: detail to pass to the theme engine, or %NULL.
+ * Note that passing a detail of anything but %NULL
+ * will disable caching.
*
* Renders an icon using gtk_style_render_icon(). In most cases,
* gtk_widget_render_icon() is better, since it automatically provides
const char *detail)
{
GdkPixbuf *icon;
- GtkIconSource *source;
g_return_val_if_fail (icon_set != NULL, NULL);
- g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
+ g_return_val_if_fail (style == NULL || GTK_IS_STYLE (style), NULL);
if (icon_set->sources == NULL)
return render_fallback_image (style, direction, state, size, widget, detail);
-
- icon = find_in_cache (icon_set, style, direction,
- state, size);
- if (icon)
+ if (detail == NULL)
{
- g_object_ref (icon);
- return icon;
+ icon = find_in_cache (icon_set, style, direction,
+ state, size);
+
+ if (icon)
+ {
+ g_object_ref (icon);
+ return icon;
+ }
}
-
- source = find_and_prep_icon_source (icon_set, direction, state, size);
- if (source == NULL)
- return render_fallback_image (style, direction, state, size, widget, detail);
-
- g_assert (source->pixbuf != NULL);
-
- icon = gtk_style_render_icon (style,
- source,
- direction,
- state,
- size,
- widget,
- detail);
+ icon = find_and_render_icon_source (icon_set, style, direction, state, size,
+ widget, detail);
if (icon == NULL)
- {
- g_warning ("Theme engine failed to render icon");
- return NULL;
- }
-
- add_to_cache (icon_set, style, direction, state, size, icon);
+ icon = render_fallback_image (style, direction, state, size, widget, detail);
+
+ if (detail == NULL)
+ add_to_cache (icon_set, style, direction, state, size, icon);
return icon;
}
g_return_if_fail (icon_set != NULL);
g_return_if_fail (source != NULL);
- if (source->pixbuf == NULL &&
- source->filename == NULL)
+ if (source->type == GTK_ICON_SOURCE_EMPTY)
{
- g_warning ("Useless GtkIconSource contains NULL filename and pixbuf");
+ g_warning ("Useless empty GtkIconSource");
return;
}
*copy = *source;
- copy->filename = g_strdup (source->filename);
- copy->size = source->size;
- if (copy->pixbuf)
- g_object_ref (copy->pixbuf);
+ switch (copy->type)
+ {
+ case GTK_ICON_SOURCE_EMPTY:
+ case GTK_ICON_SOURCE_STATIC_ICON_NAME:
+ break;
+ case GTK_ICON_SOURCE_ICON_NAME:
+ copy->source.icon_name = g_strdup (copy->source.icon_name);
+ break;
+ case GTK_ICON_SOURCE_FILENAME:
+ copy->source.filename = g_strdup (copy->source.filename);
+#ifdef G_OS_WIN32
+ copy->cp_filename = g_strdup (copy->cp_filename);
+#endif
+ if (copy->filename_pixbuf)
+ g_object_ref (copy->filename_pixbuf);
+ break;
+ case GTK_ICON_SOURCE_PIXBUF:
+ g_object_ref (copy->source.pixbuf);
+ break;
+ default:
+ g_assert_not_reached();
+ }
return copy;
}
{
g_return_if_fail (source != NULL);
- g_free ((char*) source->filename);
- if (source->pixbuf)
- g_object_unref (source->pixbuf);
-
+ icon_source_clear (source);
g_free (source);
}
return our_type;
}
+static void
+icon_source_clear (GtkIconSource *source)
+{
+ switch (source->type)
+ {
+ case GTK_ICON_SOURCE_EMPTY:
+ break;
+ case GTK_ICON_SOURCE_ICON_NAME:
+ g_free (source->source.icon_name);
+ /* fall thru */
+ case GTK_ICON_SOURCE_STATIC_ICON_NAME:
+ source->source.icon_name = NULL;
+ break;
+ case GTK_ICON_SOURCE_FILENAME:
+ g_free (source->source.filename);
+ source->source.filename = NULL;
+#ifdef G_OS_WIN32
+ g_free (source->cp_filename);
+ source->cp_filename = NULL;
+#endif
+ if (source->filename_pixbuf)
+ g_object_unref (source->filename_pixbuf);
+ source->filename_pixbuf = NULL;
+ break;
+ case GTK_ICON_SOURCE_PIXBUF:
+ g_object_unref (source->source.pixbuf);
+ source->source.pixbuf = NULL;
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ source->type = GTK_ICON_SOURCE_EMPTY;
+}
+
/**
* gtk_icon_source_set_filename:
* @source: a #GtkIconSource
g_return_if_fail (source != NULL);
g_return_if_fail (filename == NULL || g_path_is_absolute (filename));
- if (source->filename == filename)
+ if (source->type == GTK_ICON_SOURCE_FILENAME &&
+ source->source.filename == filename)
return;
- if (source->filename)
- g_free (source->filename);
+ icon_source_clear (source);
+
+ if (filename != NULL)
+ {
+ source->type = GTK_ICON_SOURCE_FILENAME;
+ source->source.filename = g_strdup (filename);
+#ifdef G_OS_WIN32
+ source->cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
+#endif
+ }
+}
+
+/**
+ * gtk_icon_source_set_icon_name
+ * @source: a #GtkIconSource
+ * @icon_name: name of icon to use
+ *
+ * Sets the name of an icon to look up in the current icon theme
+ * to use as a base image when creating icon variants for #GtkIconSet.
+ **/
+void
+gtk_icon_source_set_icon_name (GtkIconSource *source,
+ const gchar *icon_name)
+{
+ g_return_if_fail (source != NULL);
- source->filename = g_strdup (filename);
+ if (source->type == GTK_ICON_SOURCE_ICON_NAME &&
+ source->source.icon_name == icon_name)
+ return;
+
+ icon_source_clear (source);
+
+ if (icon_name != NULL)
+ {
+ source->type = GTK_ICON_SOURCE_ICON_NAME;
+ source->source.icon_name = g_strdup (icon_name);
+ }
}
/**
* @pixbuf: pixbuf to use as a source
*
* Sets a pixbuf to use as a base image when creating icon variants
- * for #GtkIconSet. If an icon source has both a filename and a pixbuf
- * set, the pixbuf will take priority.
- *
+ * for #GtkIconSet.
**/
void
gtk_icon_source_set_pixbuf (GtkIconSource *source,
GdkPixbuf *pixbuf)
{
g_return_if_fail (source != NULL);
+ g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
+
+ if (source->type == GTK_ICON_SOURCE_PIXBUF &&
+ source->source.pixbuf == pixbuf)
+ return;
- if (pixbuf)
- g_object_ref (pixbuf);
-
- if (source->pixbuf)
- g_object_unref (source->pixbuf);
-
- source->pixbuf = pixbuf;
+ icon_source_clear (source);
+
+ if (pixbuf != NULL)
+ {
+ source->type = GTK_ICON_SOURCE_PIXBUF;
+ source->source.pixbuf = g_object_ref (pixbuf);
+ }
}
/**
gtk_icon_source_get_filename (const GtkIconSource *source)
{
g_return_val_if_fail (source != NULL, NULL);
-
- return source->filename;
+
+ if (source->type == GTK_ICON_SOURCE_FILENAME)
+ return source->source.filename;
+ else
+ return NULL;
+}
+
+/**
+ * gtk_icon_source_get_icon_name:
+ * @source: a #GtkIconSource
+ *
+ * Retrieves the source icon name, or %NULL if none is set. The
+ * icon_name is not a copy, and should not be modified or expected to
+ * persist beyond the lifetime of the icon source.
+ *
+ * Return value: icon name. This string must not be modified or freed.
+ **/
+G_CONST_RETURN gchar*
+gtk_icon_source_get_icon_name (const GtkIconSource *source)
+{
+ g_return_val_if_fail (source != NULL, NULL);
+
+ if (source->type == GTK_ICON_SOURCE_ICON_NAME ||
+ source->type == GTK_ICON_SOURCE_STATIC_ICON_NAME)
+ return source->source.icon_name;
+ else
+ return NULL;
}
/**
* @source: a #GtkIconSource
*
* Retrieves the source pixbuf, or %NULL if none is set.
- * The reference count on the pixbuf is not incremented.
+ * In addition, if a filename source is in use, this
+ * function in some cases will return the pixbuf from
+ * loaded from the filename. This is, for example, true
+ * for the GtkIconSource passed to the GtkStyle::render_icon()
+ * virtual function. The reference count on the pixbuf is
+ * not incremented.
*
* Return value: source pixbuf
**/
{
g_return_val_if_fail (source != NULL, NULL);
- return source->pixbuf;
+ if (source->type == GTK_ICON_SOURCE_PIXBUF)
+ return source->source.pixbuf;
+ else if (source->type == GTK_ICON_SOURCE_FILENAME)
+ return source->filename_pixbuf;
+ else
+ return NULL;
}
/**
return source->size;
}
-/* Note that the logical maximum is 20 per GtkTextDirection, so we could
- * eventually set this to >20 to never throw anything out.
- */
#define NUM_CACHED_ICONS 8
typedef struct _CachedIcon CachedIcon;
ensure_cache_up_to_date (GtkIconSet *icon_set)
{
if (icon_set->cache_serial != cache_serial)
- clear_cache (icon_set, TRUE);
+ {
+ clear_cache (icon_set, TRUE);
+ icon_set->cache_serial = cache_serial;
+ }
}
static void
{
g_object_unref (icon->pixbuf);
+ if (icon->style)
+ g_object_unref (icon->style);
+
g_free (icon);
}
CachedIcon *icon;
ensure_cache_up_to_date (icon_set);
-
+
g_object_ref (pixbuf);
/* We have to ref the style, since if the style was finalized
if (style)
g_object_ref (style);
-
icon = g_new (CachedIcon, 1);
icon_set->cache = g_slist_prepend (icon_set->cache, icon);
+ icon_set->cache_size++;
icon->style = style;
icon->direction = direction;
if (icon_set->cache_size >= NUM_CACHED_ICONS)
{
/* Remove oldest item in the cache */
-
GSList *tmp_list;
tmp_list = icon_set->cache;
clear_cache (GtkIconSet *icon_set,
gboolean style_detach)
{
- GSList *tmp_list;
+ GSList *cache, *tmp_list;
GtkStyle *last_style = NULL;
- tmp_list = icon_set->cache;
+ cache = icon_set->cache;
+ icon_set->cache = NULL;
+ icon_set->cache_size = 0;
+ tmp_list = cache;
while (tmp_list != NULL)
{
CachedIcon *icon = tmp_list->data;
tmp_list = g_slist_next (tmp_list);
}
- g_slist_free (icon_set->cache);
- icon_set->cache = NULL;
- icon_set->cache_size = 0;
+ g_slist_free (cache);
}
static GSList*
*icon_copy = *icon;
if (icon_copy->style)
- attach_to_style (copy_recipient, icon_copy->style);
+ {
+ attach_to_style (copy_recipient, icon_copy->style);
+ g_object_ref (icon_copy->style);
+ }
g_object_ref (icon_copy->pixbuf);
ids = NULL;
- ensure_default_icons ();
+ _gtk_icon_factory_ensure_default_icons ();
tmp_list = all_icon_factories;
while (tmp_list != NULL)
return ids;
}
+
+#ifdef G_OS_WIN32
+
+/* DLL ABI stability backward compatibility versions */
+
+#undef gtk_icon_source_set_filename
+
+void
+gtk_icon_source_set_filename (GtkIconSource *source,
+ const gchar *filename)
+{
+ gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
+
+ gtk_icon_source_set_filename_utf8 (source, utf8_filename);
+
+ g_free (utf8_filename);
+}
+
+#undef gtk_icon_source_get_filename
+
+G_CONST_RETURN gchar*
+gtk_icon_source_get_filename (const GtkIconSource *source)
+{
+ g_return_val_if_fail (source != NULL, NULL);
+
+ if (source->type == GTK_ICON_SOURCE_FILENAME)
+ return source->cp_filename;
+ else
+ return NULL;
+}
+
+#endif
+
+#define __GTK_ICON_FACTORY_C__
+#include "gtkaliasdef.c"