diff --git a/moo/mooedit/mooeditwindow.c b/moo/mooedit/mooeditwindow.c index 7f4a4672..fba314e1 100644 --- a/moo/mooedit/mooeditwindow.c +++ b/moo/mooedit/mooeditwindow.c @@ -2269,7 +2269,7 @@ setup_notebook (MooEditWindow *window) G_CALLBACK (action_close_tab), window); moo_bind_bool_property (button, "sensitive", window, "has-open-document", FALSE); - icon = gtk_image_new_from_stock (MOO_STOCK_CLOSE, MOO_ICON_SIZE_REAL_SMALL); + icon = _moo_create_small_icon (MOO_SMALL_ICON_CLOSE); gtk_container_add (GTK_CONTAINER (button), icon); gtk_container_add (GTK_CONTAINER (frame), button); diff --git a/moo/moopython/pygtk/mooutils-mod.c b/moo/moopython/pygtk/mooutils-mod.c index f5c8ad51..68800df0 100644 --- a/moo/moopython/pygtk/mooutils-mod.c +++ b/moo/moopython/pygtk/mooutils-mod.c @@ -72,11 +72,6 @@ _moo_utils_mod_init (void) add_constant (mod, "STOCK_TERMINAL", MOO_STOCK_TERMINAL); add_constant (mod, "STOCK_KEYBOARD", MOO_STOCK_KEYBOARD); add_constant (mod, "STOCK_RESTART", MOO_STOCK_RESTART); - add_constant (mod, "STOCK_CLOSE", MOO_STOCK_CLOSE); - add_constant (mod, "STOCK_STICKY", MOO_STOCK_STICKY); - add_constant (mod, "STOCK_DETACH", MOO_STOCK_DETACH); - add_constant (mod, "STOCK_ATTACH", MOO_STOCK_ATTACH); - add_constant (mod, "STOCK_KEEP_ON_TOP", MOO_STOCK_KEEP_ON_TOP); add_constant (mod, "STOCK_DOC_DELETED", MOO_STOCK_DOC_DELETED); add_constant (mod, "STOCK_DOC_MODIFIED_ON_DISK", MOO_STOCK_DOC_MODIFIED_ON_DISK); add_constant (mod, "STOCK_DOC_DELETED", MOO_STOCK_DOC_DELETED); diff --git a/moo/mooutils/Makefile.am b/moo/mooutils/Makefile.am index 403a893d..81484b3a 100644 --- a/moo/mooutils/Makefile.am +++ b/moo/mooutils/Makefile.am @@ -123,6 +123,7 @@ mooutils_sources = \ mooutils-treeview.h \ mooutils-treeview.c \ moowindow.c \ + stock-medit.h \ stock-file-24.h \ stock-file-selector-24.h \ stock-select-all-16.h \ @@ -200,7 +201,6 @@ CLEANFILES += $(glade_sources) EXTRA_DIST += $(glade_files) mooutils_pixmaps = \ - $(srcdir)/pixmaps/medit.png \ $(srcdir)/pixmaps/hide.png \ $(srcdir)/pixmaps/close.png \ $(srcdir)/pixmaps/detach.png \ @@ -208,12 +208,11 @@ mooutils_pixmaps = \ $(srcdir)/pixmaps/keepontop.png \ $(srcdir)/pixmaps/sticky.png -CLEANFILES += stock-moo.h -BUILT_SOURCES += stock-moo.h -nodist_mooutils_sources += stock-moo.h +CLEANFILES += stock-moo.h stock-medit.h +BUILT_SOURCES += stock-moo.h stock-medit.h +nodist_mooutils_sources += stock-moo.h stock-medit.h stock-moo.h: $(mooutils_pixmaps) gdk-pixbuf-csource --static --build-list \ - MEDIT_ICON $(srcdir)/pixmaps/medit.png \ MOO_HIDE_ICON $(srcdir)/pixmaps/hide.png \ MOO_CLOSE_ICON $(srcdir)/pixmaps/close.png \ MOO_STICKY_ICON $(srcdir)/pixmaps/sticky.png \ @@ -221,6 +220,10 @@ stock-moo.h: $(mooutils_pixmaps) MOO_ATTACH_ICON $(srcdir)/pixmaps/attach.png \ MOO_KEEP_ON_TOP_ICON $(srcdir)/pixmaps/keepontop.png \ > $@.tmp && mv $@.tmp $@ +stock-medit.h: pixmaps/medit.png + gdk-pixbuf-csource --static --build-list \ + MEDIT_ICON $(srcdir)/pixmaps/medit.png \ + > $@.tmp && mv $@.tmp $@ noinst_LTLIBRARIES = libmooutils.la libmooutils_la_SOURCES = $(mooutils_sources) diff --git a/moo/mooutils/moopane.c b/moo/mooutils/moopane.c index 4f6fe9fc..9ade1066 100644 --- a/moo/mooutils/moopane.c +++ b/moo/mooutils/moopane.c @@ -16,6 +16,7 @@ #include "moomarshals.h" #include "moopaned.h" +#include "stock-moo.h" #include #include @@ -25,7 +26,6 @@ #ifdef MOO_COMPILATION -#include "moostock.h" #include "mooutils-misc.h" #include "moohelp.h" #include "mooutils-gobject.h" @@ -35,15 +35,6 @@ #define _(s) s -#include "stock-moo.h" - -#define MOO_STOCK_HIDE ((const char*)MOO_HIDE_ICON) -#define MOO_STOCK_STICKY ((const char*)MOO_STICKY_ICON) -#define MOO_STOCK_CLOSE ((const char*)MOO_CLOSE_ICON) -#define MOO_STOCK_DETACH ((const char*)MOO_DETACH_ICON) -#define MOO_STOCK_ATTACH ((const char*)MOO_ATTACH_ICON) -#define MOO_STOCK_KEEP_ON_TOP ((const char*)MOO_KEEP_ON_TOP_ICON) - static void _moo_widget_set_tooltip (GtkWidget *widget, const char *tip) @@ -390,10 +381,6 @@ moo_pane_init (MooPane *pane) pane->window = NULL; pane->keep_on_top_button = NULL; pane->window_child_holder = NULL; - -#ifdef MOO_COMPILATION - _moo_stock_init (); -#endif } static void @@ -543,15 +530,15 @@ update_sticky_button (MooPane *pane) static GtkWidget * -create_button (MooPane *pane, - GtkWidget *toolbar, - const char *tip, - gboolean toggle, - int padding, - const char *data) +create_button (MooPane *pane, + GtkWidget *toolbar, + const char *tip, + gboolean toggle, + int padding, + MooSmallIcon icon) { GtkWidget *button; - GtkWidget *icon; + GtkWidget *icon_widget; if (toggle) button = gtk_toggle_button_new (); @@ -563,18 +550,8 @@ create_button (MooPane *pane, gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); _moo_widget_set_tooltip (button, tip); -#ifdef MOO_COMPILATION - icon = gtk_image_new_from_stock (data, MOO_ICON_SIZE_REAL_SMALL); -#else - { - GdkPixbuf *pixbuf; - pixbuf = gdk_pixbuf_new_from_inline (-1, (const guchar*)data, FALSE, NULL); - icon = gtk_image_new_from_pixbuf (pixbuf); - g_object_unref (pixbuf); - } -#endif - - gtk_container_add (GTK_CONTAINER (button), icon); + icon_widget = _moo_create_small_icon (icon); + gtk_container_add (GTK_CONTAINER (button), icon_widget); gtk_box_pack_end (GTK_BOX (toolbar), button, FALSE, FALSE, padding); gtk_widget_show_all (button); @@ -604,7 +581,7 @@ create_frame_widget (MooPane *pane, pane->close_button = create_button (pane, toolbar, _("Remove pane"), FALSE, 3, - MOO_STOCK_CLOSE); + MOO_SMALL_ICON_CLOSE); g_object_set_data (G_OBJECT (pane->close_button), "moo-pane", pane); g_signal_connect_swapped (pane->close_button, "clicked", G_CALLBACK (close_button_clicked), @@ -612,15 +589,15 @@ create_frame_widget (MooPane *pane, hide_button = create_button (pane, toolbar, _("Hide pane"), FALSE, 0, - MOO_STOCK_HIDE); + MOO_SMALL_ICON_HIDE); pane->sticky_button = create_button (pane, toolbar, _("Sticky"), TRUE, 0, - MOO_STOCK_STICKY); + MOO_SMALL_ICON_STICKY); pane->detach_button = create_button (pane, toolbar, _("Detach pane"), FALSE, 0, - MOO_STOCK_DETACH); + MOO_SMALL_ICON_DETACH); g_signal_connect_swapped (hide_button, "clicked", G_CALLBACK (hide_button_clicked), pane); @@ -633,11 +610,11 @@ create_frame_widget (MooPane *pane, attach_button = create_button (pane, toolbar, _("Attach"), FALSE, 0, - MOO_STOCK_ATTACH); + MOO_SMALL_ICON_ATTACH); pane->keep_on_top_button = create_button (pane, toolbar, _("Keep on top"), TRUE, 0, - MOO_STOCK_KEEP_ON_TOP); + MOO_SMALL_ICON_KEEP_ON_TOP); g_object_set_data (G_OBJECT (attach_button), "moo-pane", pane); g_signal_connect_swapped (attach_button, "clicked", @@ -1289,3 +1266,167 @@ moo_pane_get_index (MooPane *pane) else return -1; } + + +typedef struct { + GtkWidget base; + GdkPixbuf **pixbufs; + const guchar *data; +} MooIconWidget; + +typedef struct { + GtkWidgetClass base_class; +} MooIconWidgetClass; + +GType _moo_icon_widget_get_type (void) G_GNUC_CONST; + +G_DEFINE_TYPE (MooIconWidget, _moo_icon_widget, GTK_TYPE_WIDGET) + +static void +_moo_icon_widget_init (MooIconWidget *icon) +{ + GTK_WIDGET_SET_FLAGS (icon, GTK_NO_WINDOW); + icon->pixbufs = NULL; + icon->data = NULL; +} + +static void +free_pixbufs (MooIconWidget *icon) +{ + if (icon->pixbufs) + { + int i; + for (i = 0; i < 5 /* magic */; ++i) + g_object_unref (icon->pixbufs[i]); + g_free (icon->pixbufs); + icon->pixbufs = NULL; + } +} + +static void +moo_icon_widget_style_set (GtkWidget *widget, + GtkStyle *old_style) +{ + GTK_WIDGET_CLASS (_moo_icon_widget_parent_class)->style_set (widget, old_style); + free_pixbufs ((MooIconWidget*) widget); +} + +static GdkPixbuf * +get_pixbuf (MooIconWidget *icon) +{ + if (!icon->pixbufs) + { + int state; + GtkWidget *widget = GTK_WIDGET (icon); + + g_return_val_if_fail (icon->data != NULL, NULL); + + icon->pixbufs = g_new0 (GdkPixbuf*, 5 /* magic */); + + for (state = 0; state < 5 /* magic */; ++state) + { + GdkPixbuf *pixbuf; + guchar *pixels, *p; + int width, height, rowstride, n_channels; + GdkColor *color; + int x, y; + + pixbuf = gdk_pixbuf_new_from_inline (-1, icon->data, TRUE, NULL); + g_return_val_if_fail (pixbuf != NULL, NULL); + + icon->pixbufs[state] = pixbuf; + + pixels = gdk_pixbuf_get_pixels (pixbuf); + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + n_channels = gdk_pixbuf_get_n_channels (pixbuf); + g_assert (n_channels == 4); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + + color = &widget->style->fg[state]; + + for (x = 0; x < width; ++x) + { + for (y = 0; y < height; ++y) + { + p = pixels + y * rowstride + x * n_channels; + + if (p[3] != 0) + { + p[0] = color->red >> 8; + p[1] = color->green >> 8; + p[2] = color->blue >> 8; + } + } + } + } + } + + return icon->pixbufs[GTK_WIDGET_STATE (icon)]; +} + +static gboolean +moo_icon_widget_expose_event (GtkWidget *widget, + GdkEventExpose *event) +{ + GdkPixbuf *pixbuf; + + pixbuf = get_pixbuf ((MooIconWidget*) widget); + g_return_val_if_fail (pixbuf != NULL, FALSE); + + gdk_draw_pixbuf (event->window, + widget->style->black_gc, + pixbuf, + 0, 0, + widget->allocation.x, widget->allocation.y, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + GDK_RGB_DITHER_NORMAL, 0, 0); + + return FALSE; +} + +static void +_moo_icon_widget_class_init (MooIconWidgetClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + widget_class->style_set = moo_icon_widget_style_set; + widget_class->expose_event = moo_icon_widget_expose_event; +} + +GtkWidget * +_moo_create_small_icon (MooSmallIcon icon) +{ + MooIconWidget *icon_widget; + const guchar *data = NULL; + + switch (icon) + { + case MOO_SMALL_ICON_HIDE: + data = MOO_HIDE_ICON; + break; + case MOO_SMALL_ICON_STICKY: + data = MOO_STICKY_ICON; + break; + case MOO_SMALL_ICON_CLOSE: + data = MOO_CLOSE_ICON; + break; + case MOO_SMALL_ICON_DETACH: + data = MOO_DETACH_ICON; + break; + case MOO_SMALL_ICON_ATTACH: + data = MOO_ATTACH_ICON; + break; + case MOO_SMALL_ICON_KEEP_ON_TOP: + data = MOO_KEEP_ON_TOP_ICON; + break; + } + + g_return_val_if_fail (data != NULL, NULL); + + icon_widget = g_object_new (_moo_icon_widget_get_type (), NULL); + icon_widget->data = data; + gtk_widget_set_size_request (GTK_WIDGET (icon_widget), 7, 7 /* magic */); + + return GTK_WIDGET (icon_widget); +} diff --git a/moo/mooutils/moopane.h b/moo/mooutils/moopane.h index b35af2f9..8c805843 100644 --- a/moo/mooutils/moopane.h +++ b/moo/mooutils/moopane.h @@ -121,6 +121,17 @@ void _moo_pane_set_parent (MooPane *pane, void _moo_pane_unparent (MooPane *pane); void _moo_pane_try_remove (MooPane *pane); +typedef enum { + MOO_SMALL_ICON_HIDE, + MOO_SMALL_ICON_STICKY, + MOO_SMALL_ICON_CLOSE, + MOO_SMALL_ICON_DETACH, + MOO_SMALL_ICON_ATTACH, + MOO_SMALL_ICON_KEEP_ON_TOP +} MooSmallIcon; + +GtkWidget *_moo_create_small_icon (MooSmallIcon icon); + G_END_DECLS diff --git a/moo/mooutils/moostock.c b/moo/mooutils/moostock.c index bae76ae6..b32afd63 100644 --- a/moo/mooutils/moostock.c +++ b/moo/mooutils/moostock.c @@ -15,7 +15,7 @@ #include "mooutils/stock-terminal-24.h" #include "mooutils/stock-file-selector-24.h" #include "mooutils/stock-file-24.h" -#include "mooutils/stock-moo.h" +#include "mooutils/stock-medit.h" #include "mooutils/mooi18n.h" #include #include @@ -158,18 +158,6 @@ static void add_icon2 (GtkIconFactory *factory, #endif /* !GTK_CHECK_VERSION(2,10,0) */ -GtkIconSize -_moo_get_icon_size_real_small (void) -{ - static GtkIconSize size = 0; - - if (!size) - size = gtk_icon_size_register ("moo-real-small", 4, 4); - - return size; -} - - static void register_stock_icon_alias (GtkIconFactory *factory, const char *stock_id, @@ -233,12 +221,6 @@ _moo_stock_init (void) add_icon (factory, MOO_STOCK_TERMINAL, "terminal", 24, MOO_GNOME_TERMINAL_ICON); add_icon (factory, MOO_STOCK_MEDIT, "medit", 24, MEDIT_ICON); - add_icon (factory, MOO_STOCK_HIDE, NULL, REAL_SMALL, MOO_HIDE_ICON); - add_icon (factory, MOO_STOCK_CLOSE, NULL, REAL_SMALL, MOO_CLOSE_ICON); - add_icon (factory, MOO_STOCK_STICKY, NULL, REAL_SMALL, MOO_STICKY_ICON); - add_icon (factory, MOO_STOCK_DETACH, NULL, REAL_SMALL, MOO_DETACH_ICON); - add_icon (factory, MOO_STOCK_ATTACH, NULL, REAL_SMALL, MOO_ATTACH_ICON); - add_icon (factory, MOO_STOCK_KEEP_ON_TOP, NULL, REAL_SMALL, MOO_KEEP_ON_TOP_ICON); #if !GTK_CHECK_VERSION(2,10,0) add_icon2 (factory, GTK_STOCK_SELECT_ALL, "edit-select-all", diff --git a/moo/mooutils/moostock.h b/moo/mooutils/moostock.h index a5bff66a..4bdd1126 100644 --- a/moo/mooutils/moostock.h +++ b/moo/mooutils/moostock.h @@ -24,12 +24,6 @@ G_BEGIN_DECLS #define MOO_STOCK_KEYBOARD GTK_STOCK_SELECT_FONT #define MOO_STOCK_MENU GTK_STOCK_INDEX #define MOO_STOCK_RESTART GTK_STOCK_REFRESH -#define MOO_STOCK_HIDE "moo-hide" -#define MOO_STOCK_CLOSE "moo-close" -#define MOO_STOCK_STICKY "moo-sticky" -#define MOO_STOCK_DETACH "moo-detach" -#define MOO_STOCK_ATTACH "moo-attach" -#define MOO_STOCK_KEEP_ON_TOP "moo-keep-on-top" #define MOO_STOCK_DOC_DELETED GTK_STOCK_DIALOG_ERROR #define MOO_STOCK_DOC_MODIFIED_ON_DISK GTK_STOCK_DIALOG_WARNING @@ -46,8 +40,6 @@ G_BEGIN_DECLS #define MOO_STOCK_SAVE_NONE "moo-save-none" #define MOO_STOCK_SAVE_SELECTED "moo-save-selected" -#define MOO_ICON_SIZE_REAL_SMALL (_moo_get_icon_size_real_small ()) - #define MOO_STOCK_NEW_PROJECT "moo-new-project" #define MOO_STOCK_OPEN_PROJECT "moo-open-project" #define MOO_STOCK_CLOSE_PROJECT "moo-close-project" @@ -71,7 +63,6 @@ G_BEGIN_DECLS void _moo_stock_init (void); -GtkIconSize _moo_get_icon_size_real_small (void) G_GNUC_CONST; G_END_DECLS