From ba5fd945cba4073b4947d9a072aaf63cbc712b80 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Mon, 9 Sep 2002 04:58:24 +0000 Subject: [PATCH] Created add_icons() and added code to add both 24x24 and 16x16 icons for a given stock id. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@101 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/stock.c | 143 ++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 76 deletions(-) diff --git a/glabels2/src/stock.c b/glabels2/src/stock.c index 653a68c1..15c81ab3 100644 --- a/glabels2/src/stock.c +++ b/glabels2/src/stock.c @@ -26,13 +26,36 @@ #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); + + +/****************************************************************************/ +/* 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 }, @@ -50,88 +73,56 @@ gl_stock_init (void) 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)); -} -- 2.39.5