Better stock icons business: use icon themes more

master
Yevgen Muntyan 2007-04-07 12:36:10 -05:00
parent 3baa694bfe
commit dc9eb4abff
1 changed files with 120 additions and 71 deletions

View File

@ -52,24 +52,55 @@ static GtkStockItem stock_items_2_10[] = {
#if GTK_CHECK_VERSION(2,4,0) #if GTK_CHECK_VERSION(2,4,0)
static void register_stock_icon (GtkIconFactory *factory, static void
const gchar *stock_id) add_icon_name_if_present (GtkIconSet *set,
const char *icon_name)
{ {
GtkIconSet *set = gtk_icon_set_new (); GtkIconTheme *theme;
GtkIconSource *source = gtk_icon_source_new ();
gtk_icon_source_set_icon_name (source, stock_id); g_return_if_fail (icon_name);
gtk_icon_set_add_source (set, source);
theme = gtk_icon_theme_get_default ();
if (gtk_icon_theme_has_icon (theme, icon_name))
{
GtkIconSource *source;
source = gtk_icon_source_new ();
gtk_icon_source_set_icon_name (source, icon_name);
gtk_icon_set_add_source (set, source);
gtk_icon_source_free (source);
}
#if 0
else
{
g_message ("no icon '%s'", icon_name);
}
#endif
}
static void
register_stock_icon (GtkIconFactory *factory,
const char *stock_id,
const char *icon_name)
{
GtkIconSet *set;
set = gtk_icon_set_new ();
add_icon_name_if_present (set, stock_id);
if (icon_name)
add_icon_name_if_present (set, icon_name);
gtk_icon_factory_add (factory, stock_id, set); gtk_icon_factory_add (factory, stock_id, set);
gtk_icon_set_unref (set); gtk_icon_set_unref (set);
gtk_icon_source_free (source);
} }
static void add_default_image (const gchar *stock_id, static void
gint size, add_default_image (const gchar *stock_id,
const guchar *inline_data) gint size,
const guchar *inline_data)
{ {
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL);
g_return_if_fail (pixbuf != NULL); g_return_if_fail (pixbuf != NULL);
@ -80,18 +111,37 @@ static void add_default_image (const gchar *stock_id,
} }
static void add_icon (GtkIconFactory *factory, static void
const gchar *stock_id, add_icon (GtkIconFactory *factory,
gint size, const char *stock_id,
const guchar *data) const char *icon_name,
gint size,
const guchar *data)
{ {
add_default_image (stock_id, size, data); if (data)
register_stock_icon (factory, stock_id); add_default_image (stock_id, size, data);
register_stock_icon (factory, stock_id, icon_name);
}
static void
add_icon_name (GtkIconFactory *factory,
const char *stock_id,
const char *icon_name)
{
GtkIconSet *set;
g_return_if_fail (icon_name != NULL);
set = gtk_icon_factory_lookup (factory, stock_id);
g_return_if_fail (set != NULL);
add_icon_name_if_present (set, icon_name);
} }
#if !GTK_CHECK_VERSION(2,10,0) #if !GTK_CHECK_VERSION(2,10,0)
static void add_icon2 (GtkIconFactory *factory, static void add_icon2 (GtkIconFactory *factory,
const gchar *stock_id, const char *stock_id,
const char *icon_name,
gint size1, gint size1,
const guchar *data1, const guchar *data1,
gint size2, gint size2,
@ -99,7 +149,7 @@ static void add_icon2 (GtkIconFactory *factory,
{ {
add_default_image (stock_id, size1, data1); add_default_image (stock_id, size1, data1);
add_default_image (stock_id, size2, data2); add_default_image (stock_id, size2, data2);
register_stock_icon (factory, stock_id); register_stock_icon (factory, stock_id, icon_name);
} }
#endif /* !GTK_CHECK_VERSION(2,10,0) */ #endif /* !GTK_CHECK_VERSION(2,10,0) */
@ -109,10 +159,12 @@ static void add_icon2 (GtkIconFactory *factory,
/* TODO: take code from gtk */ /* TODO: take code from gtk */
static void add_icon (GtkIconFactory *factory, static void
const gchar *stock_id, add_icon (GtkIconFactory *factory,
G_GNUC_UNUSED gint size, const char *stock_id,
const guchar *data) G_GNUC_UNUSED const char *icon_name,
G_GNUC_UNUSED gint size,
const guchar *data)
{ {
GtkIconSet *set = NULL; GtkIconSet *set = NULL;
GdkPixbuf *pixbuf = NULL; GdkPixbuf *pixbuf = NULL;
@ -133,14 +185,16 @@ static void add_icon (GtkIconFactory *factory,
gtk_icon_set_unref (set); gtk_icon_set_unref (set);
} }
static void add_icon2 (GtkIconFactory *factory, static void
const gchar *stock_id, add_icon2 (GtkIconFactory *factory,
gint size1, const char *stock_id,
const guchar *data1, const char *icon_name,
G_GNUC_UNUSED gint size2, gint size1,
G_GNUC_UNUSED const guchar *data2) const guchar *data1,
G_GNUC_UNUSED gint size2,
G_GNUC_UNUSED const guchar *data2)
{ {
add_icon (factory, stock_id, size1, data1); add_icon (factory, stock_id, icon_name, size1, data1);
} }
@ -159,14 +213,18 @@ _moo_get_icon_size_real_small (void)
} }
static void register_stock_icon_alias (GtkIconFactory *factory, static void
const gchar *stock_id, register_stock_icon_alias (GtkIconFactory *factory,
const gchar *new_stock_id) const char *stock_id,
const char *new_stock_id,
const char *icon_name)
{ {
/* must use gtk_icon_factory_lookup_default() to initialize gtk icons */ /* must use gtk_icon_factory_lookup_default() to initialize gtk icons */
GtkIconSet *set = gtk_icon_factory_lookup_default (stock_id); GtkIconSet *set = gtk_icon_factory_lookup_default (stock_id);
g_return_if_fail (set != NULL); g_return_if_fail (set != NULL);
gtk_icon_factory_add (factory, new_stock_id, set); gtk_icon_factory_add (factory, new_stock_id, set);
if (icon_name)
add_icon (factory, new_stock_id, icon_name, 0, NULL);
} }
@ -185,59 +243,50 @@ _moo_stock_init (void)
gtk_icon_factory_add_default (factory); gtk_icon_factory_add_default (factory);
add_icon (factory, MOO_STOCK_TERMINAL, add_icon (factory, MOO_STOCK_TERMINAL, "terminal", 24, MOO_GNOME_TERMINAL_ICON);
24, MOO_GNOME_TERMINAL_ICON);
add_icon (factory, MOO_STOCK_MEDIT, add_icon (factory, MOO_STOCK_MEDIT, "medit", 24, MEDIT_ICON);
24, MEDIT_ICON); add_icon (factory, MOO_STOCK_CLOSE, NULL, REAL_SMALL, MOO_CLOSE_ICON);
add_icon (factory, MOO_STOCK_CLOSE, add_icon (factory, MOO_STOCK_STICKY, NULL, REAL_SMALL, MOO_STICKY_ICON);
REAL_SMALL, MOO_CLOSE_ICON); add_icon (factory, MOO_STOCK_DETACH, NULL, REAL_SMALL, MOO_DETACH_ICON);
add_icon (factory, MOO_STOCK_STICKY, add_icon (factory, MOO_STOCK_ATTACH, NULL, REAL_SMALL, MOO_ATTACH_ICON);
REAL_SMALL, MOO_STICKY_ICON); add_icon (factory, MOO_STOCK_KEEP_ON_TOP, NULL, REAL_SMALL, MOO_KEEP_ON_TOP_ICON);
add_icon (factory, MOO_STOCK_DETACH,
REAL_SMALL, MOO_DETACH_ICON);
add_icon (factory, MOO_STOCK_ATTACH,
REAL_SMALL, MOO_ATTACH_ICON);
add_icon (factory, MOO_STOCK_KEEP_ON_TOP,
REAL_SMALL, MOO_KEEP_ON_TOP_ICON);
#if !GTK_CHECK_VERSION(2,6,0) #if !GTK_CHECK_VERSION(2,6,0)
add_icon2 (factory, GTK_STOCK_ABOUT, add_icon2 (factory, GTK_STOCK_ABOUT, "stock_about",
24, STOCK_ABOUT_24, 24, STOCK_ABOUT_24, 16, STOCK_ABOUT_16);
16, STOCK_ABOUT_16); add_icon2 (factory, GTK_STOCK_EDIT, "stock_edit",
add_icon2 (factory, GTK_STOCK_ABOUT, 24, STOCK_EDIT_24, 16, STOCK_EDIT_16);
24, STOCK_EDIT_24,
16, STOCK_EDIT_16);
#endif #endif
#if !GTK_CHECK_VERSION(2,10,0) #if !GTK_CHECK_VERSION(2,10,0)
add_icon2 (factory, GTK_STOCK_SELECT_ALL, add_icon2 (factory, GTK_STOCK_SELECT_ALL, "edit-select-all",
24, STOCK_SELECT_ALL_24, 24, STOCK_SELECT_ALL_24, 16, STOCK_SELECT_ALL_16);
16, STOCK_SELECT_ALL_16);
gtk_stock_add_static (stock_items_2_10, G_N_ELEMENTS (stock_items_2_10)); gtk_stock_add_static (stock_items_2_10, G_N_ELEMENTS (stock_items_2_10));
#endif #endif
gtk_stock_add_static (stock_items, G_N_ELEMENTS (stock_items)); gtk_stock_add_static (stock_items, G_N_ELEMENTS (stock_items));
register_stock_icon_alias (factory, GTK_STOCK_NO, MOO_STOCK_SAVE_NONE);
register_stock_icon_alias (factory, GTK_STOCK_SAVE, MOO_STOCK_SAVE_SELECTED);
register_stock_icon_alias (factory, GTK_STOCK_COPY, MOO_STOCK_FILE_COPY); register_stock_icon_alias (factory, GTK_STOCK_NO, MOO_STOCK_SAVE_NONE, "no");
register_stock_icon_alias (factory, GTK_STOCK_SAVE, MOO_STOCK_FILE_SAVE_COPY); register_stock_icon_alias (factory, GTK_STOCK_SAVE, MOO_STOCK_SAVE_SELECTED, "filesave");
register_stock_icon_alias (factory, GTK_STOCK_SAVE_AS, MOO_STOCK_FILE_SAVE_AS);
register_stock_icon_alias (factory, GTK_STOCK_NEW, MOO_STOCK_NEW_PROJECT); register_stock_icon_alias (factory, GTK_STOCK_COPY, MOO_STOCK_FILE_COPY, "editcopy");
register_stock_icon_alias (factory, GTK_STOCK_OPEN, MOO_STOCK_OPEN_PROJECT); register_stock_icon_alias (factory, GTK_STOCK_SAVE, MOO_STOCK_FILE_SAVE_COPY, "filesave");
register_stock_icon_alias (factory, GTK_STOCK_CLOSE, MOO_STOCK_CLOSE_PROJECT); register_stock_icon_alias (factory, GTK_STOCK_SAVE_AS, MOO_STOCK_FILE_SAVE_AS, "filesaveas");
register_stock_icon_alias (factory, GTK_STOCK_PREFERENCES, MOO_STOCK_PROJECT_OPTIONS);
register_stock_icon_alias (factory, GTK_STOCK_GOTO_BOTTOM, MOO_STOCK_BUILD);
register_stock_icon_alias (factory, GTK_STOCK_GO_DOWN, MOO_STOCK_COMPILE);
register_stock_icon_alias (factory, GTK_STOCK_EXECUTE, MOO_STOCK_EXECUTE);
register_stock_icon_alias (factory, GTK_STOCK_FIND, MOO_STOCK_FIND_IN_FILES); register_stock_icon_alias (factory, GTK_STOCK_NEW, MOO_STOCK_NEW_PROJECT, NULL);
register_stock_icon_alias (factory, GTK_STOCK_FIND, MOO_STOCK_FIND_FILE); register_stock_icon_alias (factory, GTK_STOCK_OPEN, MOO_STOCK_OPEN_PROJECT, NULL);
register_stock_icon_alias (factory, GTK_STOCK_CLOSE, MOO_STOCK_CLOSE_PROJECT, NULL);
register_stock_icon_alias (factory, GTK_STOCK_PREFERENCES, MOO_STOCK_PROJECT_OPTIONS, NULL);
register_stock_icon_alias (factory, GTK_STOCK_GOTO_BOTTOM, MOO_STOCK_BUILD, NULL);
register_stock_icon_alias (factory, GTK_STOCK_GO_DOWN, MOO_STOCK_COMPILE, NULL);
register_stock_icon_alias (factory, GTK_STOCK_EXECUTE, MOO_STOCK_EXECUTE, NULL);
register_stock_icon_alias (factory, GTK_STOCK_ABOUT, MOO_STOCK_EDIT_BOOKMARK); register_stock_icon_alias (factory, GTK_STOCK_FIND, MOO_STOCK_FIND_IN_FILES, NULL);
register_stock_icon_alias (factory, GTK_STOCK_FIND, MOO_STOCK_FIND_FILE, NULL);
add_default_image ("medit", 48, MEDIT_ICON); register_stock_icon_alias (factory, GTK_STOCK_ABOUT, MOO_STOCK_EDIT_BOOKMARK, "gnome-fs-bookmark");
add_icon_name (factory, MOO_STOCK_EDIT_BOOKMARK, "bookmark");
g_object_unref (G_OBJECT (factory)); g_object_unref (G_OBJECT (factory));
} }