Mercurial > pidgin
comparison src/gtkstock.c @ 10297:ec140184437b
[gaim-migrate @ 11480]
"After applying this patch, which modifies the make files and makes the
@file/@ingroup markers at the top of several gtk files more uniform,
the following files should be renamed:
dnd-hints.h -> gtkdnd-hints.h
dnd-hints.c -> gtkdnd-hints.c
gaim-disclosure.h -> gtkgaim-disclosure.h
gaim-disclosure.c -> gtkgaim-disclosure.c
stock.h -> gtkstock.h
stock.c -> gtkstock.c
I believe that completes the renaming of files which are explicitly for
gtkgaim; all files in /gaim/src which depend upon gtk should now have
gtk in their name. There are two candidates which might be considered
part of gtkgaim rather than part of the core, but I didn't modify them:
session.c and log.c. Both are quite gaim-UI specific, it seems,
particularly session, but perhaps other UIs could also make use of
their functionality.
-Evan "
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 02 Dec 2004 20:34:19 +0000 |
parents | |
children | 868aafbe859b |
comparison
equal
deleted
inserted
replaced
10296:a7b2fd5efcf2 | 10297:ec140184437b |
---|---|
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" }, | |
41 { GAIM_STOCK_ALIAS, "buttons", "edit.png" }, | |
42 { GAIM_STOCK_BGCOLOR, "buttons", "change-bgcolor-small.png" }, | |
43 { GAIM_STOCK_BLOCK, NULL, GTK_STOCK_STOP }, | |
44 { GAIM_STOCK_CHAT, NULL, GTK_STOCK_JUMP_TO }, | |
45 { GAIM_STOCK_DOWNLOAD, NULL, GTK_STOCK_GO_DOWN }, | |
46 { GAIM_STOCK_DIALOG_AUTH, "dialogs", "gaim_auth.png" }, | |
47 { GAIM_STOCK_DIALOG_COOL, "dialogs", "gaim_cool.png" }, | |
48 { GAIM_STOCK_DIALOG_ERROR, "dialogs", "gaim_error.png" }, | |
49 { GAIM_STOCK_DIALOG_INFO, "dialogs", "gaim_info.png" }, | |
50 { GAIM_STOCK_DIALOG_QUESTION, "dialogs", "gaim_question.png" }, | |
51 { GAIM_STOCK_DIALOG_WARNING, "dialogs", "gaim_warning.png" }, | |
52 { GAIM_STOCK_FGCOLOR, "buttons", "change-fgcolor-small.png" }, | |
53 { GAIM_STOCK_EDIT, "buttons", "edit.png" }, | |
54 { GAIM_STOCK_FILE_CANCELED, NULL, GTK_STOCK_CANCEL }, | |
55 { GAIM_STOCK_FILE_DONE, NULL, GTK_STOCK_APPLY }, | |
56 { GAIM_STOCK_FILE_TRANSFER, NULL, GTK_STOCK_REVERT_TO_SAVED }, | |
57 { GAIM_STOCK_ICON_AWAY, "icons", "away.png" }, | |
58 { GAIM_STOCK_ICON_AWAY_MSG, "icons", "msgpend.png" }, | |
59 { GAIM_STOCK_ICON_CONNECT, "icons", "connect.png" }, | |
60 { GAIM_STOCK_ICON_OFFLINE, "icons", "offline.png" }, | |
61 { GAIM_STOCK_ICON_ONLINE, "icons", "online.png" }, | |
62 { GAIM_STOCK_ICON_ONLINE_MSG, "icons", "msgunread.png" }, | |
63 { GAIM_STOCK_IGNORE, NULL, GTK_STOCK_DIALOG_ERROR }, | |
64 { GAIM_STOCK_IM, "buttons", "send-im.png" }, | |
65 { GAIM_STOCK_IMAGE, "buttons", "insert-image-small.png" }, | |
66 { GAIM_STOCK_INFO, "icons", "info.png", }, | |
67 { GAIM_STOCK_INVITE, NULL, GTK_STOCK_JUMP_TO }, | |
68 { GAIM_STOCK_LINK, "buttons", "insert-link-small.png" }, | |
69 { GAIM_STOCK_LOGO, "gaim", "logo.png" }, | |
70 { GAIM_STOCK_MODIFY, NULL, GTK_STOCK_PREFERENCES }, | |
71 { GAIM_STOCK_PAUSE, "buttons", "pause.png" }, | |
72 { GAIM_STOCK_OPEN_MAIL, NULL, GTK_STOCK_JUMP_TO }, | |
73 { GAIM_STOCK_SEND, "buttons", "send-im.png" }, | |
74 { GAIM_STOCK_SIGN_ON, NULL, GTK_STOCK_EXECUTE }, | |
75 { GAIM_STOCK_SIGN_OFF, NULL, GTK_STOCK_CLOSE }, | |
76 { GAIM_STOCK_SMILEY, "buttons", "insert-smiley-small.png" }, | |
77 { GAIM_STOCK_TEXT_BIGGER, "buttons", "text_bigger.png" }, | |
78 { GAIM_STOCK_TEXT_NORMAL, "buttons", "text_normal.png" }, | |
79 { GAIM_STOCK_TEXT_SMALLER, "buttons", "text_smaller.png" }, | |
80 { GAIM_STOCK_TYPED, "gaim", "typed.png" }, | |
81 { GAIM_STOCK_TYPING, "gaim", "typing.png" }, | |
82 { GAIM_STOCK_UPLOAD, NULL, GTK_STOCK_GO_UP }, | |
83 { GAIM_STOCK_WARN, NULL, GTK_STOCK_DIALOG_WARNING } | |
84 }; | |
85 | |
86 const GtkStockItem stock_items[] = | |
87 { | |
88 { GAIM_STOCK_ALIAS, N_("_Alias"), 0, 0, NULL }, | |
89 { GAIM_STOCK_CHAT, N_("_Join"), 0, 0, NULL }, | |
90 { GAIM_STOCK_INVITE, N_("_Invite"), 0, 0, NULL }, | |
91 { GAIM_STOCK_MODIFY, N_("_Modify"), 0, 0, NULL }, | |
92 { GAIM_STOCK_OPEN_MAIL, N_("_Open Mail"), 0, 0, NULL }, | |
93 { GAIM_STOCK_PAUSE, N_("_Pause"), 0, 0, NULL }, | |
94 { GAIM_STOCK_WARN, N_("_Warn"), 0, 0, NULL } | |
95 }; | |
96 | |
97 static gchar * | |
98 find_file(const char *dir, const char *base) | |
99 { | |
100 char *filename; | |
101 | |
102 if (base == NULL) | |
103 return NULL; | |
104 | |
105 if (!strcmp(dir, "gaim")) | |
106 filename = g_build_filename(DATADIR, "pixmaps", "gaim", base, NULL); | |
107 else | |
108 { | |
109 filename = g_build_filename(DATADIR, "pixmaps", "gaim", dir, | |
110 base, NULL); | |
111 } | |
112 | |
113 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) | |
114 { | |
115 g_critical("Unable to load stock pixmap %s\n", base); | |
116 | |
117 g_free(filename); | |
118 | |
119 return NULL; | |
120 } | |
121 | |
122 return filename; | |
123 } | |
124 | |
125 static void | |
126 gaim_gtk_stock_versionize(GdkPixbuf **original, GtkWidget *widget) { | |
127 GdkPixmap *pixmap; | |
128 GtkStyle *style; | |
129 PangoContext *context; | |
130 PangoLayout *layout; | |
131 gchar *markup; | |
132 gint width, height; | |
133 gint lwidth = 0, lheight = 0; | |
134 | |
135 style = gtk_widget_get_style(widget); | |
136 | |
137 gdk_pixbuf_render_pixmap_and_mask(*original, &pixmap, NULL, 255); | |
138 width = gdk_pixbuf_get_width(*original); | |
139 height = gdk_pixbuf_get_height(*original); | |
140 g_object_unref(G_OBJECT(*original)); | |
141 | |
142 context = gtk_widget_get_pango_context(widget); | |
143 layout = pango_layout_new(context); | |
144 | |
145 markup = g_strdup_printf("<span foreground=\"#FFFFFF\" size=\"larger\">%s</span>", VERSION); | |
146 pango_layout_set_font_description(layout, style->font_desc); | |
147 pango_layout_set_markup(layout, markup, strlen(markup)); | |
148 g_free(markup); | |
149 | |
150 pango_layout_get_pixel_size(layout, &lwidth, &lheight); | |
151 gdk_draw_layout(GDK_DRAWABLE(pixmap), style->bg_gc[GTK_STATE_NORMAL], | |
152 width - (lwidth + 3), height - (lheight + 1), layout); | |
153 g_object_unref(G_OBJECT(layout)); | |
154 | |
155 *original = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, | |
156 0, 0, 0, 0, | |
157 width, height); | |
158 g_object_unref(G_OBJECT(pixmap)); | |
159 } | |
160 | |
161 void | |
162 gaim_gtk_stock_init(void) | |
163 { | |
164 static gboolean stock_initted = FALSE; | |
165 GtkIconFactory *icon_factory; | |
166 int i; | |
167 GtkWidget *win; | |
168 | |
169 if (stock_initted) | |
170 return; | |
171 | |
172 stock_initted = TRUE; | |
173 | |
174 /* Setup the icon factory. */ | |
175 icon_factory = gtk_icon_factory_new(); | |
176 | |
177 gtk_icon_factory_add_default(icon_factory); | |
178 | |
179 /* Er, yeah, a hack, but it works. :) */ | |
180 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
181 gtk_widget_realize(win); | |
182 | |
183 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) | |
184 { | |
185 GdkPixbuf *pixbuf; | |
186 GtkIconSet *iconset; | |
187 gchar *filename; | |
188 | |
189 if (stock_icons[i].dir == NULL) | |
190 { | |
191 /* GTK+ Stock icon */ | |
192 iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win), | |
193 stock_icons[i].filename); | |
194 } | |
195 else | |
196 { | |
197 filename = find_file(stock_icons[i].dir, stock_icons[i].filename); | |
198 | |
199 if (filename == NULL) | |
200 continue; | |
201 | |
202 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
203 | |
204 g_free(filename); | |
205 | |
206 if (!strcmp(stock_icons[i].name, GAIM_STOCK_LOGO)) | |
207 gaim_gtk_stock_versionize(&pixbuf, win); | |
208 | |
209 iconset = gtk_icon_set_new_from_pixbuf(pixbuf); | |
210 | |
211 g_object_unref(G_OBJECT(pixbuf)); | |
212 } | |
213 | |
214 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); | |
215 | |
216 gtk_icon_set_unref(iconset); | |
217 } | |
218 | |
219 gtk_widget_destroy(win); | |
220 | |
221 /* register custom icon sizes */ | |
222 gtk_icon_size_register(GAIM_ICON_SIZE_LOGO, 330, 90); | |
223 gtk_icon_size_register(GAIM_ICON_SIZE_DIALOG_COOL, 40, 60); | |
224 | |
225 g_object_unref(G_OBJECT(icon_factory)); | |
226 | |
227 /* Register the stock items. */ | |
228 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items)); | |
229 } |