1 /* Bluefish HTML Editor
2 * pixmap.c
3 *
4 * Copyright (C) 2002-2011 Oliver Sessink
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <gtk/gtk.h>
21 #include <gdk-pixbuf/gdk-pixbuf.h>
22
23 #include "bluefish.h"
24 #include "pixmap.h"
25 #include "pixmaps/toolbar_icons.c"
26
27 typedef struct {
28 const guint id;
29 const guint8 *data;
30 } Tpixmap;
31
32 typedef struct {
33 const guint id;
34 const gchar *stock_id;
35 } Tstockpixmap;
36
37 static Tpixmap tp[] = {
38 /* {0, pixmap_new},*/
39 /* {1, open}, */
40 /* {2, save}, */
41 /* {3, save_as}, */
42 /* {4, pixmap_close}, */
43 /* {5, copy}, */
44 /* {6, cut}, */
45 /* {7, paste}, */
46 /* {8, search}, */
47 /* {9, search_replace}, */
48 /* {10, undo}, */
49 /* {11, redo}, */
50 /* {12, preferences}, */
51 {102, pixmap_view_in_browser},
52 {104, pixmap_bookmarks},
53 {105, pixmap_filetree},
54 /* {106, pixmap_fref},
55 {107, pixmap_frinfo},
56 {108, pixmap_frdialog},
57 {109, pixmap_frsearch},*/
58 /* {110, pixmap_indent},
59 {111, pixmap_unindent},*/
60 /* {112, pixmap_open_small},*/
61 /* {150, pixmap_prefseditor},
62 {151, pixmap_prefsexternal},
63 {152, pixmap_prefsfiles},
64 {153, pixmap_prefsfiletypes},
65 {154, pixmap_prefshtml},
66 {155, pixmap_prefsimages},
67 {156, pixmap_prefsinterface},
68 {157, pixmap_prefsoutputparser},
69 {158, pixmap_prefssyntax},*/
70 /* {159, pixmap_nothing},*/
71 /* {160, pixmap_frhide},
72 {161, pixmap_frdialog2},
73 {162, pixmap_frlibrary},
74 {170, pixmap_frlibrary_ro},
75 {163, pixmap_frgroup},
76 {164, pixmap_frnote},
77 {165, pixmap_frfunction},
78 {166, pixmap_frtag},
79 {167, pixmap_frvar},
80 {168, pixmap_frcss},
81 {169, pixmap_frsnippet}*/
82 };
83
84 static Tstockpixmap tsp[] = {
85 {1000, GTK_STOCK_FIND},
86 {1001, GTK_STOCK_FIND_AND_REPLACE},
87 {1002, GTK_STOCK_PREFERENCES},
88 {1003, GTK_STOCK_GO_UP},
89 {1004, GTK_STOCK_GO_DOWN} ,
90 {1005, GTK_STOCK_SPELL_CHECK}
91 };
92
new_pixmap(gint type)93 GtkWidget *new_pixmap(gint type) {
94 GtkWidget *widget;
95 gint i;
96 if (type < 1000) {
97 GdkPixbuf *pixbuf;
98 for (i=0;i<(sizeof(tp)/sizeof(Tpixmap));i++) {
99 if (tp[i].id == type) {
100 break;
101 }
102 }
103 if (i >= sizeof(tp)/sizeof(Tpixmap)) {
104 g_print("new_pixmap, requested unknown type %d\n", type);
105 i = sizeof(tp)/sizeof(Tpixmap)-1;
106 }
107 pixbuf = gdk_pixbuf_new_from_inline(-1,tp[i].data,FALSE,NULL);
108 widget = gtk_image_new_from_pixbuf(pixbuf);
109 g_object_unref(pixbuf);
110 } else {
111 for (i=0;i<(sizeof(tsp)/sizeof(Tstockpixmap));i++) {
112 if (tsp[i].id == type) {
113 break;
114 }
115 }
116 if (i >= sizeof(tp)/sizeof(Tpixmap)) {
117 g_print("new_pixmap, requested unknown type %d\n", type);
118 i = sizeof(tp)/sizeof(Tpixmap)-1;
119 }
120 widget = gtk_image_new_from_stock(tsp[i].stock_id,GTK_ICON_SIZE_BUTTON);
121 }
122 return widget;
123 }
124
125 void
register_bf_stock_icons(void)126 register_bf_stock_icons(void)
127 {
128 static struct {
129 const guint8 *data;
130 gchar *stock_id;
131 } stock_icons[] = {
132 {pixmap_view_in_browser, BF_STOCK_BROWSER_PREVIEW}
133 };
134
135 GtkIconFactory *icon_factory;
136 GtkIconSet *icon_set;
137 gint i;
138
139 icon_factory = gtk_icon_factory_new();
140 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) {
141 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_inline(-1,stock_icons[i].data,FALSE,NULL);
142 icon_set = gtk_icon_set_new_from_pixbuf(pixbuf);
143
144 gtk_icon_factory_add(icon_factory, stock_icons[i].stock_id, icon_set);
145 gtk_icon_set_unref(icon_set);
146
147 gtk_icon_theme_add_builtin_icon(stock_icons[i].stock_id,gdk_pixbuf_get_width(pixbuf), pixbuf);
148
149 g_object_unref(pixbuf);
150 }
151 gtk_icon_factory_add_default(icon_factory);
152 g_object_unref(icon_factory);
153 }
154
155
156
set_default_icon(void)157 void set_default_icon(void) {
158 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_inline(-1,pixmap_bluefish_icon1,FALSE,NULL);
159 GList *tmplist = g_list_append(NULL, pixbuf);
160 gtk_window_set_default_icon_list(tmplist);
161 g_list_free(tmplist);
162 g_object_unref(pixbuf);
163 }
164