#include "stock.h"
#include "stock-pixmaps/stockpixbufs.h"
+
+/*========================================================*/
+/* Private macros and constants. */
+/*========================================================*/
+
+/*========================================================*/
+/* Private types. */
+/*========================================================*/
+
+/*===========================================*/
+/* Private globals */
+/*===========================================*/
+
+/*===========================================*/
+/* Local function prototypes */
+/*===========================================*/
+
+static add_icons (GtkIconFactory *factory,
+ const gchar *stock_id,
+ const guchar *inline_24,
+ const guchar *inline_16);
+
+\f
+/****************************************************************************/
+/* Initialize our stock icons. */
+/****************************************************************************/
void
gl_stock_init (void)
{
- GdkPixbuf *pixbuf;
GtkIconFactory *factory;
- GtkIconSet *icon_set;
- GdkPixdata *pixdata;
static GtkStockItem items[] = {
{ GL_STOCK_ARROW, "Arrow", 0, 0, NULL },
factory = gtk_icon_factory_new ();
gtk_icon_factory_add_default (factory);
- pixdata = g_new0 (GdkPixdata, 1);
+ add_icons (factory, GL_STOCK_ARROW, stock_arrow_24, stock_arrow_16);
+ add_icons (factory, GL_STOCK_TEXT, stock_text_24, NULL);
+ add_icons (factory, GL_STOCK_LINE, stock_line_24, NULL);
+ add_icons (factory, GL_STOCK_BOX, stock_box_24, NULL);
+ add_icons (factory, GL_STOCK_ELLIPSE, stock_ellipse_24, NULL);
+ add_icons (factory, GL_STOCK_IMAGE, stock_image_24, NULL);
+ add_icons (factory, GL_STOCK_BARCODE, stock_barcode_24, NULL);
+ add_icons (factory, GL_STOCK_MERGE, stock_merge_24, NULL);
- /* Arrow */
- gdk_pixdata_deserialize (pixdata,
- sizeof(stock_arrow_24), stock_arrow_24,
- NULL);
- pixbuf = gdk_pixbuf_from_pixdata (pixdata, FALSE, NULL);
- icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
- gtk_icon_factory_add (factory, GL_STOCK_ARROW, icon_set);
- gtk_icon_set_unref (icon_set);
- g_object_unref (G_OBJECT(pixbuf));
+ g_object_unref (G_OBJECT(factory));
+}
- /* Text */
- gdk_pixdata_deserialize (pixdata,
- sizeof(stock_text_24), stock_text_24,
- NULL);
- pixbuf = gdk_pixbuf_from_pixdata (pixdata, FALSE, NULL);
- icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
- gtk_icon_factory_add (factory, GL_STOCK_TEXT, icon_set);
- gtk_icon_set_unref (icon_set);
- g_object_unref (G_OBJECT(pixbuf));
+/*--------------------------------------------------------------------------*/
+/* PRIVATE. Unpack and associate given icons with stock_id. */
+/*--------------------------------------------------------------------------*/
+static add_icons (GtkIconFactory *factory,
+ const gchar *stock_id,
+ const guchar *inline_24,
+ const guchar *inline_16)
+{
+ GdkPixbuf *pixbuf;
+ GtkIconSet *icon_set;
+ GtkIconSource *icon_source;
- /* Line */
- gdk_pixdata_deserialize (pixdata,
- sizeof(stock_line_24), stock_line_24,
- NULL);
- pixbuf = gdk_pixbuf_from_pixdata (pixdata, FALSE, NULL);
+ /* Create icon set with default image */
+ pixbuf = gdk_pixbuf_new_from_inline (-1, inline_24, FALSE, NULL);
icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
- gtk_icon_factory_add (factory, GL_STOCK_LINE, icon_set);
- gtk_icon_set_unref (icon_set);
g_object_unref (G_OBJECT(pixbuf));
- /* Box */
- gdk_pixdata_deserialize (pixdata,
- sizeof(stock_box_24), stock_box_24,
- NULL);
- pixbuf = gdk_pixbuf_from_pixdata (pixdata, FALSE, NULL);
- icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
- gtk_icon_factory_add (factory, GL_STOCK_BOX, icon_set);
- gtk_icon_set_unref (icon_set);
- g_object_unref (G_OBJECT(pixbuf));
+ /* Add 16x16 icon for menus to icon set */
+ if ( inline_16 != NULL ) {
+ icon_source = gtk_icon_source_new ();
+ pixbuf = gdk_pixbuf_new_from_inline (-1, inline_16,
+ FALSE, NULL);
+ gtk_icon_source_set_pixbuf (icon_source, pixbuf);
+ g_object_unref (G_OBJECT(pixbuf));
+ gtk_icon_source_set_size_wildcarded (icon_source, FALSE);
+ gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_MENU);
+ gtk_icon_set_add_source (icon_set, icon_source);
+ g_object_unref (G_OBJECT(icon_source));
+ }
- /* Ellipse */
- gdk_pixdata_deserialize (pixdata,
- sizeof(stock_ellipse_24), stock_ellipse_24,
- NULL);
- pixbuf = gdk_pixbuf_from_pixdata (pixdata, FALSE, NULL);
- icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
- gtk_icon_factory_add (factory, GL_STOCK_ELLIPSE, icon_set);
+ /* Now associate icon set with stock id */
+ gtk_icon_factory_add (factory, stock_id, icon_set);
gtk_icon_set_unref (icon_set);
- g_object_unref (G_OBJECT(pixbuf));
+}
+
+
+
- /* Image */
- gdk_pixdata_deserialize (pixdata,
- sizeof(stock_image_24), stock_image_24,
- NULL);
- pixbuf = gdk_pixbuf_from_pixdata (pixdata, FALSE, NULL);
- icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
- gtk_icon_factory_add (factory, GL_STOCK_IMAGE, icon_set);
- gtk_icon_set_unref (icon_set);
- g_object_unref (G_OBJECT(pixbuf));
- /* Barcode */
- gdk_pixdata_deserialize (pixdata,
- sizeof(stock_barcode_24), stock_barcode_24,
- NULL);
- pixbuf = gdk_pixbuf_from_pixdata (pixdata, FALSE, NULL);
- icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
- gtk_icon_factory_add (factory, GL_STOCK_BARCODE, icon_set);
- gtk_icon_set_unref (icon_set);
- g_object_unref (G_OBJECT(pixbuf));
- /* Merge */
- gdk_pixdata_deserialize (pixdata,
- sizeof(stock_merge_24), stock_merge_24,
- NULL);
- pixbuf = gdk_pixbuf_from_pixdata (pixdata, FALSE, NULL);
- icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
- gtk_icon_factory_add (factory, GL_STOCK_MERGE, icon_set);
- gtk_icon_set_unref (icon_set);
- g_object_unref (G_OBJECT(pixbuf));
- g_free (pixdata);
- g_object_unref (G_OBJECT(factory));
-}