Added custom stock icons
This commit is contained in:
parent
dbcccd2df6
commit
9a094ccf28
|
@ -12,8 +12,56 @@
|
|||
|
||||
static GList *gm_pixbuf_directories = NULL;
|
||||
static GList *gm_pixbufs = NULL;
|
||||
static GtkIconFactory *factory = NULL;
|
||||
|
||||
GdkPixbuf *gm_pixbuf_create(const gchar * filename, int width, int height);
|
||||
static void on_gm_pixbuf_theme_changed(GtkIconTheme *theme, gpointer user_data);
|
||||
|
||||
static GdkPixbuf *
|
||||
gm_pixbuf_create_save_close() {
|
||||
GError *error = NULL;
|
||||
GtkIconTheme *icon_theme;
|
||||
GdkPixbuf *pixbuf, *close, *save;
|
||||
gint w1, h1, w2, h2;
|
||||
|
||||
icon_theme = gtk_icon_theme_get_default();
|
||||
gtk_icon_size_lookup(GTK_ICON_SIZE_LARGE_TOOLBAR, &w1, &h1);
|
||||
save = gtk_icon_theme_load_icon(icon_theme, GTK_STOCK_SAVE, w1, 0,
|
||||
&error);
|
||||
|
||||
if (error) {
|
||||
g_error_free(error);
|
||||
error = NULL;
|
||||
}
|
||||
|
||||
if (save == NULL) {
|
||||
gm_debug_msg(DEBUG_DEFAULT, "Couldn't find save icon for the save and close composite icon");
|
||||
return gm_pixbuf_get("saveclose.xpm");
|
||||
}
|
||||
|
||||
pixbuf = gdk_pixbuf_copy(save);
|
||||
g_object_unref(save);
|
||||
|
||||
gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &w2, &h2);
|
||||
close = gtk_icon_theme_load_icon(icon_theme, GTK_STOCK_CLOSE, w2, 0,
|
||||
&error);
|
||||
|
||||
if (error) {
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
if (close == NULL) {
|
||||
gm_debug_msg(DEBUG_DEFAULT, "Couldn't find close icon for the save and close composite icon");
|
||||
return gm_pixbuf_get("saveclose.xpm");
|
||||
}
|
||||
|
||||
gdk_pixbuf_composite(close, pixbuf, w1 - w2, 0, w2, h2, w1 - w2, 0, 1, 1,
|
||||
GDK_INTERP_NEAREST, 255);
|
||||
|
||||
g_object_unref(close);
|
||||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
void
|
||||
gm_pixbuf_add_directory(const gchar *directory) {
|
||||
|
@ -21,9 +69,31 @@ gm_pixbuf_add_directory(const gchar *directory) {
|
|||
g_list_prepend(gm_pixbuf_directories, g_strdup(directory));
|
||||
}
|
||||
|
||||
void
|
||||
gm_pixbuf_populate_factory() {
|
||||
GdkPixbuf *pixbuf = gm_pixbuf_create_save_close();
|
||||
GtkIconSet *set;
|
||||
|
||||
set = gtk_icon_set_new_from_pixbuf(pixbuf);
|
||||
gtk_icon_factory_add(factory, GM_STOCK_SAVE_CLOSE, set);
|
||||
g_object_unref(pixbuf);
|
||||
}
|
||||
|
||||
void
|
||||
gm_pixbuf_init() {
|
||||
GtkIconTheme *theme;
|
||||
|
||||
gm_pixbuf_add_directory(PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
|
||||
|
||||
theme = gtk_icon_theme_get_default();
|
||||
|
||||
g_signal_connect(theme, "changed", G_CALLBACK(on_gm_pixbuf_theme_changed),
|
||||
NULL);
|
||||
|
||||
factory = gtk_icon_factory_new();
|
||||
gtk_icon_factory_add_default(factory);
|
||||
|
||||
gm_pixbuf_populate_factory();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -45,6 +115,9 @@ gm_pixbuf_fini() {
|
|||
}
|
||||
|
||||
g_list_free(gm_pixbufs);
|
||||
|
||||
gtk_icon_factory_remove_default(factory);
|
||||
g_object_unref(factory);
|
||||
}
|
||||
|
||||
gchar *
|
||||
|
@ -180,3 +253,8 @@ void gm_pixbuf_set_alpha(GdkPixbuf **pixs, guchar alpha) {
|
|||
|
||||
*pixs = pix;
|
||||
}
|
||||
|
||||
static void
|
||||
on_gm_pixbuf_theme_changed(GtkIconTheme *theme, gpointer user_data) {
|
||||
gm_pixbuf_populate_factory();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ typedef struct _GmPixbufInfo {
|
|||
GdkPixbuf *pixbuf;
|
||||
} GmPixbufInfo;
|
||||
|
||||
/* Stock items */
|
||||
#define GM_STOCK_SAVE_CLOSE "gm-stock-save-close"
|
||||
|
||||
void gm_pixbuf_init();
|
||||
void gm_pixbuf_fini();
|
||||
|
||||
|
|
Reference in New Issue