]> git.sur5r.net Git - glabels/blob - src/stock.c
7f312109d29099670b3cabb0957007b9676dfe8c
[glabels] / src / stock.c
1 /*
2  *  stock.c
3  *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "stock.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27 #include <gdk-pixbuf/gdk-pixbuf.h>
28
29 #include "stock-pixmaps/stockpixbufs.h"
30
31
32 /*========================================================*/
33 /* Private macros and constants.                          */
34 /*========================================================*/
35
36
37 /*========================================================*/
38 /* Private types.                                         */
39 /*========================================================*/
40
41
42 /*===========================================*/
43 /* Private globals                           */
44 /*===========================================*/
45
46
47 /*===========================================*/
48 /* Local function prototypes                 */
49 /*===========================================*/
50
51 static void add_icons (GtkIconFactory *factory,
52                        const gchar    *stock_id,
53                        const guchar   *inline_24,
54                        const guchar   *inline_16);
55
56 static void add_button_icon (GtkIconFactory *factory,
57                              const gchar    *stock_id,
58                              const guchar   *inline_24);
59
60
61 /****************************************************************************/
62 /* Initialize our stock icons.                                              */
63 /****************************************************************************/
64 void
65 gl_stock_init (void)
66 {
67         GtkIconFactory *factory;
68
69         static GtkStockItem items[] = {
70                 { GL_STOCK_ARROW,         N_("_Select Mode"),          0, 0, NULL },
71                 { GL_STOCK_TEXT,          N_("_Text"),                 0, 0, NULL },
72                 { GL_STOCK_LINE,          N_("_Line"),                 0, 0, NULL },
73                 { GL_STOCK_BOX,           N_("_Box"),                  0, 0, NULL },
74                 { GL_STOCK_ELLIPSE,       N_("_Ellipse"),              0, 0, NULL },
75                 { GL_STOCK_IMAGE,         N_("_Image"),                0, 0, NULL },
76                 { GL_STOCK_BARCODE,       N_("Bar_code"),              0, 0, NULL },
77                 { GL_STOCK_MERGE,         N_("_Merge Properties"),     0, 0, NULL },
78                 { GL_STOCK_PROPERTIES,    N_("Object _Properties"),    0, 0, NULL },
79                 { GL_STOCK_ORDER_TOP,     N_("Bring to _Front"),       0, 0, NULL },
80                 { GL_STOCK_ORDER_BOTTOM,  N_("Send to _Back"),         0, 0, NULL },
81                 { GL_STOCK_ROTATE_LEFT,   N_("Rotate _Left"),          0, 0, NULL },
82                 { GL_STOCK_ROTATE_RIGHT,  N_("Rotate _Right"),         0, 0, NULL },
83                 { GL_STOCK_FLIP_HORIZ,    N_("Flip _Horizontally"),    0, 0, NULL },
84                 { GL_STOCK_FLIP_VERT,     N_("Flip _Vertically"),      0, 0, NULL },
85                 { GL_STOCK_ALIGN_LEFT,    N_("_Lefts"),                0, 0, NULL },
86                 { GL_STOCK_ALIGN_RIGHT,   N_("_Rights"),               0, 0, NULL },
87                 { GL_STOCK_ALIGN_HCENTER, N_("_Centers"),              0, 0, NULL },
88                 { GL_STOCK_ALIGN_TOP,     N_("_Tops"),                 0, 0, NULL },
89                 { GL_STOCK_ALIGN_BOTTOM,  N_("Bottoms"),               0, 0, NULL },
90                 { GL_STOCK_ALIGN_VCENTER, N_("Centers"),               0, 0, NULL },
91                 { GL_STOCK_CENTER_HORIZ,  N_("Label Ce_nter"),         0, 0, NULL },
92                 { GL_STOCK_CENTER_VERT,   N_("Label Ce_nter"),         0, 0, NULL },
93                 { GL_STOCK_BUCKET_FILL,   N_("Fill color"),            0, 0, NULL },
94                 { GL_STOCK_PENCIL,        N_("Line color"),            0, 0, NULL },
95                 { GL_STOCK_HCHAIN,        N_("Linked"),                0, 0, NULL },
96                 { GL_STOCK_HCHAIN_BROKEN, N_("Not Linked"),            0, 0, NULL },
97                 { GL_STOCK_VCHAIN,        N_("Linked"),                0, 0, NULL },
98                 { GL_STOCK_VCHAIN_BROKEN, N_("Not Linked"),            0, 0, NULL },
99         };
100
101         gtk_stock_add (items, G_N_ELEMENTS (items));
102
103         factory = gtk_icon_factory_new ();
104         gtk_icon_factory_add_default (factory);
105
106         add_icons (factory, GL_STOCK_ARROW,         stock_arrow_24,   stock_arrow_16);
107         add_icons (factory, GL_STOCK_TEXT,          stock_text_24,    stock_text_16);
108         add_icons (factory, GL_STOCK_LINE,          stock_line_24,    stock_line_16);
109         add_icons (factory, GL_STOCK_BOX,           stock_box_24,     stock_box_16);
110         add_icons (factory, GL_STOCK_ELLIPSE,       stock_ellipse_24, stock_ellipse_16);
111         add_icons (factory, GL_STOCK_IMAGE,         stock_image_24,   stock_image_16);
112         add_icons (factory, GL_STOCK_BARCODE,       stock_barcode_24, stock_barcode_16);
113         add_icons (factory, GL_STOCK_MERGE,         stock_merge_24,   stock_merge_16);
114
115         add_icons (factory, GL_STOCK_PROPERTIES,
116                    stock_properties_24,
117                    stock_properties_16);
118
119         add_icons (factory, GL_STOCK_ORDER_TOP,     NULL, stock_order_top_16);
120         add_icons (factory, GL_STOCK_ORDER_BOTTOM,  NULL, stock_order_bottom_16);
121         add_icons (factory, GL_STOCK_ROTATE_LEFT,   NULL, stock_rotate_left_16);
122         add_icons (factory, GL_STOCK_ROTATE_RIGHT,  NULL, stock_rotate_right_16);
123         add_icons (factory, GL_STOCK_FLIP_HORIZ,    NULL, stock_flip_horiz_16);
124         add_icons (factory, GL_STOCK_FLIP_VERT,     NULL, stock_flip_vert_16);
125         add_icons (factory, GL_STOCK_ALIGN_LEFT,    NULL, stock_align_left_16);
126         add_icons (factory, GL_STOCK_ALIGN_RIGHT,   NULL, stock_align_right_16);
127         add_icons (factory, GL_STOCK_ALIGN_HCENTER, NULL, stock_align_hcenter_16);
128         add_icons (factory, GL_STOCK_ALIGN_TOP,     NULL, stock_align_top_16);
129         add_icons (factory, GL_STOCK_ALIGN_BOTTOM,  NULL, stock_align_bottom_16);
130         add_icons (factory, GL_STOCK_ALIGN_VCENTER, NULL, stock_align_vcenter_16);
131         add_icons (factory, GL_STOCK_CENTER_HORIZ,  NULL, stock_center_horiz_16);
132         add_icons (factory, GL_STOCK_CENTER_VERT,   NULL, stock_center_vert_16);
133
134         add_icons (factory, GL_STOCK_BUCKET_FILL,   stock_bucket_fill_24, stock_bucket_fill_16);
135         add_icons (factory, GL_STOCK_PENCIL,        stock_pencil_24,      stock_pencil_16);
136
137         add_button_icon (factory, GL_STOCK_HCHAIN,        stock_hchain_24);
138         add_button_icon (factory, GL_STOCK_HCHAIN_BROKEN, stock_hchain_broken_24);
139         add_button_icon (factory, GL_STOCK_VCHAIN,        stock_vchain_24);
140         add_button_icon (factory, GL_STOCK_VCHAIN_BROKEN, stock_vchain_broken_24);
141
142         g_object_unref (G_OBJECT(factory));
143 }
144
145
146 /*--------------------------------------------------------------------------*/
147 /* PRIVATE.  Unpack and associate given icons with stock_id.                */
148 /*--------------------------------------------------------------------------*/
149 static void
150 add_icons (GtkIconFactory *factory,
151            const gchar    *stock_id,
152            const guchar   *inline_24,
153            const guchar   *inline_16)
154 {
155         GdkPixbuf      *pixbuf;
156         GtkIconSet     *icon_set;
157         GtkIconSource  *icon_source;
158
159         if ( inline_24 != NULL ) {
160                 /* Create icon set with default image */
161                 pixbuf = gdk_pixbuf_new_from_inline (-1, inline_24, FALSE, NULL);
162                 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
163                 g_object_unref (G_OBJECT(pixbuf));
164         } else {
165                 /* Create an empty icon set */
166                 icon_set = gtk_icon_set_new ();
167         }
168
169         if ( inline_16 != NULL ) {
170                 /* Add 16x16 icon for menus to icon set */
171                 icon_source = gtk_icon_source_new ();
172                 pixbuf = gdk_pixbuf_new_from_inline (-1, inline_16,
173                                                      FALSE, NULL);
174                 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
175                 g_object_unref (G_OBJECT(pixbuf));
176                 gtk_icon_source_set_size_wildcarded (icon_source, FALSE);
177                 gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_MENU);
178                 gtk_icon_set_add_source (icon_set, icon_source);
179                 gtk_icon_source_free (icon_source);
180         }
181
182         /* Now associate icon set with stock id */
183         gtk_icon_factory_add (factory, stock_id, icon_set);
184         gtk_icon_set_unref (icon_set);
185 }
186
187
188 /*--------------------------------------------------------------------------*/
189 /* PRIVATE.  Unpack and associate given button icon with stock_id.          */
190 /*--------------------------------------------------------------------------*/
191 static void
192 add_button_icon (GtkIconFactory *factory,
193                  const gchar    *stock_id,
194                  const guchar   *inline_24)
195 {
196         GtkIconSet     *icon_set;
197         GdkPixbuf      *pixbuf;
198         GtkIconSource  *icon_source;
199
200         icon_set = gtk_icon_set_new ();
201
202         icon_source = gtk_icon_source_new ();
203         pixbuf = gdk_pixbuf_new_from_inline (-1, inline_24, FALSE, NULL);
204         gtk_icon_source_set_pixbuf (icon_source, pixbuf);
205         g_object_unref (G_OBJECT(pixbuf));
206         gtk_icon_source_set_size_wildcarded (icon_source, FALSE);
207         gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_BUTTON);
208         gtk_icon_set_add_source (icon_set, icon_source);
209         gtk_icon_source_free (icon_source);
210
211         /* Now associate icon set with stock id */
212         gtk_icon_factory_add (factory, stock_id, icon_set);
213         gtk_icon_set_unref (icon_set);
214 }
215
216
217
218 /*
219  * Local Variables:       -- emacs
220  * mode: C                -- emacs
221  * c-basic-offset: 8      -- emacs
222  * tab-width: 8           -- emacs
223  * indent-tabs-mode: nil  -- emacs
224  * End:                   -- emacs
225  */