]> git.sur5r.net Git - glabels/blob - glabels2/src/stock.c
Added menu icons for order, rotation, and flipping commands.
[glabels] / glabels2 / src / stock.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  stock.h:  Stock image module header file
5  *
6  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 #include <config.h>
24 #include <gnome.h>
25 #include <gdk-pixbuf/gdk-pixdata.h>
26 #include "stock.h"
27 #include "stock-pixmaps/stockpixbufs.h"
28
29
30 /*========================================================*/
31 /* Private macros and constants.                          */
32 /*========================================================*/
33
34 /*========================================================*/
35 /* Private types.                                         */
36 /*========================================================*/
37
38 /*===========================================*/
39 /* Private globals                           */
40 /*===========================================*/
41
42 /*===========================================*/
43 /* Local function prototypes                 */
44 /*===========================================*/
45
46 static add_icons (GtkIconFactory *factory,
47                   const gchar    *stock_id,
48                   const guchar   *inline_24,
49                   const guchar   *inline_16);
50
51 \f
52 /****************************************************************************/
53 /* Initialize our stock icons.                                              */
54 /****************************************************************************/
55 void
56 gl_stock_init (void)
57 {
58         GtkIconFactory *factory;
59
60         static GtkStockItem items[] = {
61                 { GL_STOCK_ARROW,         "Arrow",          0, 0, NULL },
62                 { GL_STOCK_TEXT,          "Text",           0, 0, NULL },
63                 { GL_STOCK_LINE,          "Line",           0, 0, NULL },
64                 { GL_STOCK_BOX,           "Box",            0, 0, NULL },
65                 { GL_STOCK_ELLIPSE,       "Ellipse",        0, 0, NULL },
66                 { GL_STOCK_IMAGE,         "Image",          0, 0, NULL },
67                 { GL_STOCK_BARCODE,       "Barcode",        0, 0, NULL },
68                 { GL_STOCK_MERGE,         "Merge",          0, 0, NULL },
69                 { GL_STOCK_ORDER_TOP,     "OrderTop",       0, 0, NULL },
70                 { GL_STOCK_ORDER_BOTTOM,  "OrderBottom",    0, 0, NULL },
71                 { GL_STOCK_ROTATE_LEFT,   "RotateLeft",     0, 0, NULL },
72                 { GL_STOCK_ROTATE_RIGHT,  "RotateRight",    0, 0, NULL },
73                 { GL_STOCK_FLIP_HORIZ,    "FlipHoriz",      0, 0, NULL },
74                 { GL_STOCK_FLIP_VERT,     "FlipVert",       0, 0, NULL },
75                 { GL_STOCK_ALIGN_LEFT,    "AlignLeft",      0, 0, NULL },
76                 { GL_STOCK_ALIGN_RIGHT,   "AlignRight",     0, 0, NULL },
77                 { GL_STOCK_ALIGN_HCENTER, "AlignHCenter",   0, 0, NULL },
78                 { GL_STOCK_ALIGN_TOP,     "AlignTop",       0, 0, NULL },
79                 { GL_STOCK_ALIGN_BOTTOM,  "AlignBottom",    0, 0, NULL },
80                 { GL_STOCK_ALIGN_VCENTER, "AlignVCenter",   0, 0, NULL },
81         };
82
83         gtk_stock_add (items, G_N_ELEMENTS (items));
84
85         factory = gtk_icon_factory_new ();
86         gtk_icon_factory_add_default (factory);
87
88         add_icons (factory, GL_STOCK_ARROW,         stock_arrow_24,   stock_arrow_16);
89         add_icons (factory, GL_STOCK_TEXT,          stock_text_24,    stock_text_16);
90         add_icons (factory, GL_STOCK_LINE,          stock_line_24,    stock_line_16);
91         add_icons (factory, GL_STOCK_BOX,           stock_box_24,     stock_box_16);
92         add_icons (factory, GL_STOCK_ELLIPSE,       stock_ellipse_24, stock_ellipse_16);
93         add_icons (factory, GL_STOCK_IMAGE,         stock_image_24,   stock_image_16);
94         add_icons (factory, GL_STOCK_BARCODE,       stock_barcode_24, stock_barcode_16);
95         add_icons (factory, GL_STOCK_MERGE,         stock_merge_24,   stock_merge_16);
96
97         add_icons (factory, GL_STOCK_ORDER_TOP,     NULL, stock_order_top_16);
98         add_icons (factory, GL_STOCK_ORDER_BOTTOM,  NULL, stock_order_bottom_16);
99         add_icons (factory, GL_STOCK_ROTATE_LEFT,   NULL, stock_rotate_left_16);
100         add_icons (factory, GL_STOCK_ROTATE_RIGHT,  NULL, stock_rotate_right_16);
101         add_icons (factory, GL_STOCK_FLIP_HORIZ,    NULL, stock_flip_horiz_16);
102         add_icons (factory, GL_STOCK_FLIP_VERT,     NULL, stock_flip_vert_16);
103         add_icons (factory, GL_STOCK_ALIGN_LEFT,    NULL, stock_align_left_16);
104         add_icons (factory, GL_STOCK_ALIGN_RIGHT,   NULL, stock_align_right_16);
105         add_icons (factory, GL_STOCK_ALIGN_HCENTER, NULL, stock_align_hcenter_16);
106         add_icons (factory, GL_STOCK_ALIGN_TOP,     NULL, stock_align_top_16);
107         add_icons (factory, GL_STOCK_ALIGN_BOTTOM,  NULL, stock_align_bottom_16);
108         add_icons (factory, GL_STOCK_ALIGN_VCENTER, NULL, stock_align_vcenter_16);
109
110         g_object_unref (G_OBJECT(factory));
111 }
112
113 /*--------------------------------------------------------------------------*/
114 /* PRIVATE.  Unpack and associate given icons with stock_id.                */
115 /*--------------------------------------------------------------------------*/
116 static add_icons (GtkIconFactory *factory,
117                   const gchar    *stock_id,
118                   const guchar   *inline_24,
119                   const guchar   *inline_16)
120 {
121         GdkPixbuf      *pixbuf;
122         GtkIconSet     *icon_set;
123         GtkIconSource  *icon_source;
124
125         if ( inline_24 != NULL ) {
126                 /* Create icon set with default image */
127                 pixbuf = gdk_pixbuf_new_from_inline (-1, inline_24, FALSE, NULL);
128                 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
129                 g_object_unref (G_OBJECT(pixbuf));
130         } else {
131                 /* Create an empty icon set */
132                 icon_set = gtk_icon_set_new ();
133         }
134
135         if ( inline_16 != NULL ) {
136                 /* Add 16x16 icon for menus to icon set */
137                 icon_source = gtk_icon_source_new ();
138                 pixbuf = gdk_pixbuf_new_from_inline (-1, inline_16,
139                                                      FALSE, NULL);
140                 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
141                 g_object_unref (G_OBJECT(pixbuf));
142                 gtk_icon_source_set_size_wildcarded (icon_source, FALSE);
143                 gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_MENU);
144                 gtk_icon_set_add_source (icon_set, icon_source);
145                 g_free (icon_source);
146         }
147
148         /* Now associate icon set with stock id */
149         gtk_icon_factory_add (factory, stock_id, icon_set);
150         gtk_icon_set_unref (icon_set);
151 }
152
153
154
155
156
157
158