Mercurial > pidgin
annotate src/gtkstock.c @ 11888:7d2d926704aa
[gaim-migrate @ 14179]
Gtk 2.0 support. Deja Vu.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 29 Oct 2005 14:45:15 +0000 |
parents | c9188d3eb9d3 |
children | e67993da8a22 |
rev | line source |
---|---|
10297 | 1 /** |
2 * @file gtkstock.c GTK+ Stock resources | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 * | |
25 */ | |
26 #include "internal.h" | |
27 #include "gtkgaim.h" | |
28 | |
29 #include "gtkstock.h" | |
30 | |
31 static struct StockIcon | |
32 { | |
33 const char *name; | |
34 const char *dir; | |
35 const char *filename; | |
36 | |
37 } const stock_icons[] = | |
38 { | |
39 { GAIM_STOCK_ABOUT, "buttons", "about_menu.png" }, | |
40 { GAIM_STOCK_ACCOUNTS, "buttons", "accounts.png" }, | |
11370
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
41 #if GTK_CHECK_VERSION(2,6,0) |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
42 { GAIM_STOCK_ALIAS, NULL, GTK_STOCK_EDIT }, |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
43 #else |
10297 | 44 { GAIM_STOCK_ALIAS, "buttons", "edit.png" }, |
11370
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
45 #endif |
10297 | 46 { GAIM_STOCK_BGCOLOR, "buttons", "change-bgcolor-small.png" }, |
47 { GAIM_STOCK_BLOCK, NULL, GTK_STOCK_STOP }, | |
48 { GAIM_STOCK_CHAT, NULL, GTK_STOCK_JUMP_TO }, | |
11370
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
49 { GAIM_STOCK_CLEAR, NULL, GTK_STOCK_CLEAR }, |
10297 | 50 { GAIM_STOCK_DOWNLOAD, NULL, GTK_STOCK_GO_DOWN }, |
51 { GAIM_STOCK_DIALOG_AUTH, "dialogs", "gaim_auth.png" }, | |
52 { GAIM_STOCK_DIALOG_COOL, "dialogs", "gaim_cool.png" }, | |
53 { GAIM_STOCK_DIALOG_ERROR, "dialogs", "gaim_error.png" }, | |
54 { GAIM_STOCK_DIALOG_INFO, "dialogs", "gaim_info.png" }, | |
55 { GAIM_STOCK_DIALOG_QUESTION, "dialogs", "gaim_question.png" }, | |
56 { GAIM_STOCK_DIALOG_WARNING, "dialogs", "gaim_warning.png" }, | |
57 { GAIM_STOCK_FGCOLOR, "buttons", "change-fgcolor-small.png" }, | |
11370
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
58 #if GTK_CHECK_VERSION(2,6,0) |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
59 { GAIM_STOCK_EDIT, NULL, GTK_STOCK_EDIT }, |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
60 #else |
10297 | 61 { GAIM_STOCK_EDIT, "buttons", "edit.png" }, |
11370
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
62 #endif |
10297 | 63 { GAIM_STOCK_FILE_CANCELED, NULL, GTK_STOCK_CANCEL }, |
64 { GAIM_STOCK_FILE_DONE, NULL, GTK_STOCK_APPLY }, | |
65 { GAIM_STOCK_FILE_TRANSFER, NULL, GTK_STOCK_REVERT_TO_SAVED }, | |
66 { GAIM_STOCK_ICON_AWAY, "icons", "away.png" }, | |
67 { GAIM_STOCK_ICON_AWAY_MSG, "icons", "msgpend.png" }, | |
68 { GAIM_STOCK_ICON_CONNECT, "icons", "connect.png" }, | |
69 { GAIM_STOCK_ICON_OFFLINE, "icons", "offline.png" }, | |
70 { GAIM_STOCK_ICON_ONLINE, "icons", "online.png" }, | |
71 { GAIM_STOCK_ICON_ONLINE_MSG, "icons", "msgunread.png" }, | |
72 { GAIM_STOCK_IGNORE, NULL, GTK_STOCK_DIALOG_ERROR }, | |
11271
b33eccbc3a10
[gaim-migrate @ 13454]
Richard Laager <rlaager@wiktel.com>
parents:
10871
diff
changeset
|
73 { GAIM_STOCK_IM, "buttons", "send-im.png" }, |
10297 | 74 { GAIM_STOCK_IMAGE, "buttons", "insert-image-small.png" }, |
11370
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
75 #if GTK_CHECK_VERSION(2,8,0) |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
76 { GAIM_STOCK_INFO, NULL, GTK_STOCK_INFO }, |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
77 #else |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
78 { GAIM_STOCK_INFO, "icons", "info.png" }, |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
79 #endif |
10297 | 80 { GAIM_STOCK_INVITE, NULL, GTK_STOCK_JUMP_TO }, |
81 { GAIM_STOCK_LINK, "buttons", "insert-link-small.png" }, | |
82 { GAIM_STOCK_LOGO, "gaim", "logo.png" }, | |
83 { GAIM_STOCK_MODIFY, NULL, GTK_STOCK_PREFERENCES }, | |
11370
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
84 #if GTK_CHECK_VERSION(2,6,0) |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
85 { GAIM_STOCK_PAUSE, NULL, GTK_STOCK_MEDIA_PAUSE }, |
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
86 #else |
10297 | 87 { GAIM_STOCK_PAUSE, "buttons", "pause.png" }, |
11370
2c3fb4a0f785
[gaim-migrate @ 13595]
Richard Laager <rlaager@wiktel.com>
parents:
11271
diff
changeset
|
88 #endif |
10297 | 89 { GAIM_STOCK_OPEN_MAIL, NULL, GTK_STOCK_JUMP_TO }, |
90 { GAIM_STOCK_SEND, "buttons", "send-im.png" }, | |
91 { GAIM_STOCK_SIGN_ON, NULL, GTK_STOCK_EXECUTE }, | |
92 { GAIM_STOCK_SIGN_OFF, NULL, GTK_STOCK_CLOSE }, | |
93 { GAIM_STOCK_SMILEY, "buttons", "insert-smiley-small.png" }, | |
94 { GAIM_STOCK_TEXT_BIGGER, "buttons", "text_bigger.png" }, | |
95 { GAIM_STOCK_TEXT_NORMAL, "buttons", "text_normal.png" }, | |
96 { GAIM_STOCK_TEXT_SMALLER, "buttons", "text_smaller.png" }, | |
97 { GAIM_STOCK_TYPED, "gaim", "typed.png" }, | |
98 { GAIM_STOCK_TYPING, "gaim", "typing.png" }, | |
10643 | 99 { GAIM_STOCK_STATUS_ONLINE, "gaim", "status-online.png" }, |
100 { GAIM_STOCK_STATUS_OFFLINE, "gaim", "status-offline.png" }, | |
101 { GAIM_STOCK_STATUS_AWAY, "gaim", "status-away.png" }, | |
102 { GAIM_STOCK_STATUS_INVISIBLE,"gaim", "status-invisible.png" }, | |
103 { GAIM_STOCK_STATUS_TYPING0, "gaim", "status-typing0.png" }, | |
104 { GAIM_STOCK_STATUS_TYPING1, "gaim", "status-typing1.png" }, | |
105 { GAIM_STOCK_STATUS_TYPING2, "gaim", "status-typing2.png" }, | |
106 { GAIM_STOCK_STATUS_TYPING3, "gaim", "status-typing3.png" }, | |
107 { GAIM_STOCK_STATUS_CONNECT0, "gaim", "status-connect0.png" }, | |
108 { GAIM_STOCK_STATUS_CONNECT1, "gaim", "status-connect1.png" }, | |
109 { GAIM_STOCK_STATUS_CONNECT2, "gaim", "status-connect2.png" }, | |
110 { GAIM_STOCK_STATUS_CONNECT3, "gaim", "status-connect3.png" }, | |
10297 | 111 { GAIM_STOCK_UPLOAD, NULL, GTK_STOCK_GO_UP }, |
112 { GAIM_STOCK_WARN, NULL, GTK_STOCK_DIALOG_WARNING } | |
113 }; | |
114 | |
10871 | 115 static const GtkStockItem stock_items[] = |
10297 | 116 { |
117 { GAIM_STOCK_ALIAS, N_("_Alias"), 0, 0, NULL }, | |
118 { GAIM_STOCK_CHAT, N_("_Join"), 0, 0, NULL }, | |
119 { GAIM_STOCK_INVITE, N_("_Invite"), 0, 0, NULL }, | |
120 { GAIM_STOCK_MODIFY, N_("_Modify"), 0, 0, NULL }, | |
121 { GAIM_STOCK_OPEN_MAIL, N_("_Open Mail"), 0, 0, NULL }, | |
122 { GAIM_STOCK_PAUSE, N_("_Pause"), 0, 0, NULL }, | |
123 { GAIM_STOCK_WARN, N_("_Warn"), 0, 0, NULL } | |
124 }; | |
125 | |
126 static gchar * | |
127 find_file(const char *dir, const char *base) | |
128 { | |
129 char *filename; | |
130 | |
131 if (base == NULL) | |
132 return NULL; | |
133 | |
134 if (!strcmp(dir, "gaim")) | |
135 filename = g_build_filename(DATADIR, "pixmaps", "gaim", base, NULL); | |
136 else | |
137 { | |
138 filename = g_build_filename(DATADIR, "pixmaps", "gaim", dir, | |
139 base, NULL); | |
140 } | |
141 | |
142 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) | |
143 { | |
144 g_critical("Unable to load stock pixmap %s\n", base); | |
145 | |
146 g_free(filename); | |
147 | |
148 return NULL; | |
149 } | |
150 | |
151 return filename; | |
152 } | |
153 | |
154 static void | |
155 gaim_gtk_stock_versionize(GdkPixbuf **original, GtkWidget *widget) { | |
156 GdkPixmap *pixmap; | |
157 GtkStyle *style; | |
158 PangoContext *context; | |
159 PangoLayout *layout; | |
160 gchar *markup; | |
161 gint width, height; | |
162 gint lwidth = 0, lheight = 0; | |
163 | |
164 style = gtk_widget_get_style(widget); | |
165 | |
166 gdk_pixbuf_render_pixmap_and_mask(*original, &pixmap, NULL, 255); | |
167 width = gdk_pixbuf_get_width(*original); | |
168 height = gdk_pixbuf_get_height(*original); | |
169 g_object_unref(G_OBJECT(*original)); | |
170 | |
171 context = gtk_widget_get_pango_context(widget); | |
172 layout = pango_layout_new(context); | |
173 | |
174 markup = g_strdup_printf("<span foreground=\"#FFFFFF\" size=\"larger\">%s</span>", VERSION); | |
175 pango_layout_set_font_description(layout, style->font_desc); | |
176 pango_layout_set_markup(layout, markup, strlen(markup)); | |
177 g_free(markup); | |
178 | |
179 pango_layout_get_pixel_size(layout, &lwidth, &lheight); | |
180 gdk_draw_layout(GDK_DRAWABLE(pixmap), style->bg_gc[GTK_STATE_NORMAL], | |
181 width - (lwidth + 3), height - (lheight + 1), layout); | |
182 g_object_unref(G_OBJECT(layout)); | |
183 | |
184 *original = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, | |
185 0, 0, 0, 0, | |
186 width, height); | |
187 g_object_unref(G_OBJECT(pixmap)); | |
188 } | |
189 | |
190 void | |
191 gaim_gtk_stock_init(void) | |
192 { | |
193 static gboolean stock_initted = FALSE; | |
194 GtkIconFactory *icon_factory; | |
195 int i; | |
196 GtkWidget *win; | |
197 | |
198 if (stock_initted) | |
199 return; | |
200 | |
201 stock_initted = TRUE; | |
202 | |
203 /* Setup the icon factory. */ | |
204 icon_factory = gtk_icon_factory_new(); | |
205 | |
206 gtk_icon_factory_add_default(icon_factory); | |
207 | |
208 /* Er, yeah, a hack, but it works. :) */ | |
209 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
210 gtk_widget_realize(win); | |
211 | |
212 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) | |
213 { | |
214 GdkPixbuf *pixbuf; | |
215 GtkIconSet *iconset; | |
216 gchar *filename; | |
217 | |
218 if (stock_icons[i].dir == NULL) | |
219 { | |
220 /* GTK+ Stock icon */ | |
221 iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win), | |
222 stock_icons[i].filename); | |
223 } | |
224 else | |
225 { | |
226 filename = find_file(stock_icons[i].dir, stock_icons[i].filename); | |
227 | |
228 if (filename == NULL) | |
229 continue; | |
230 | |
231 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
232 | |
233 g_free(filename); | |
234 | |
235 if (!strcmp(stock_icons[i].name, GAIM_STOCK_LOGO)) | |
236 gaim_gtk_stock_versionize(&pixbuf, win); | |
237 | |
238 iconset = gtk_icon_set_new_from_pixbuf(pixbuf); | |
239 | |
240 g_object_unref(G_OBJECT(pixbuf)); | |
241 } | |
242 | |
243 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); | |
244 | |
245 gtk_icon_set_unref(iconset); | |
246 } | |
247 | |
248 gtk_widget_destroy(win); | |
249 | |
250 /* register custom icon sizes */ | |
251 gtk_icon_size_register(GAIM_ICON_SIZE_LOGO, 330, 90); | |
252 gtk_icon_size_register(GAIM_ICON_SIZE_DIALOG_COOL, 40, 60); | |
10643 | 253 gtk_icon_size_register(GAIM_ICON_SIZE_STATUS, 30, 30); |
10297 | 254 |
255 g_object_unref(G_OBJECT(icon_factory)); | |
256 | |
257 /* Register the stock items. */ | |
258 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items)); | |
259 } |