2013-02-27 [mones] 3.9.0cvs104
[claws.git] / src / stock_pixmap.c
blob8cc23ff230ef3e6b779c6a87792fe256fdc0e0b7
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "defs.h"
21 #include <glib.h>
22 #include <gtk/gtk.h>
23 #include <string.h>
24 #include <dirent.h>
26 #include "config.h"
27 #include "stock_pixmap.h"
28 #include "gtkutils.h"
29 #include "utils.h"
30 #include "prefs_common.h"
32 #include "pixmaps/addr_one.xpm"
33 #include "pixmaps/addr_two.xpm"
34 #include "pixmaps/address.xpm"
35 #include "pixmaps/anonymous.xpm"
36 #include "pixmaps/book.xpm"
37 #include "pixmaps/category.xpm"
38 #include "pixmaps/checkbox_off.xpm"
39 #include "pixmaps/checkbox_on.xpm"
40 #include "pixmaps/clip.xpm"
41 #include "pixmaps/clipkey.xpm"
42 #include "pixmaps/complete.xpm"
43 #include "pixmaps/continue.xpm"
44 #include "pixmaps/deleted.xpm"
45 #include "pixmaps/error.xpm"
46 #include "pixmaps/edit_extern.xpm"
47 #include "pixmaps/forwarded.xpm"
48 #include "pixmaps/group.xpm"
49 #include "pixmaps/insert_file.xpm"
50 #include "pixmaps/interface.xpm"
51 #include "pixmaps/jpilot.xpm"
52 #include "pixmaps/key.xpm"
53 #include "pixmaps/key_gpg_signed.xpm"
54 #include "pixmaps/ldap.xpm"
55 #include "pixmaps/linewrap.xpm"
56 #include "pixmaps/linewrapcurrent.xpm"
57 #include "pixmaps/mark.xpm"
58 #include "pixmaps/locked.xpm"
59 #include "pixmaps/new.xpm"
60 #include "pixmaps/replied.xpm"
61 #include "pixmaps/replied_and_forwarded.xpm"
62 #include "pixmaps/close.xpm"
63 #include "pixmaps/down_arrow.xpm"
64 #include "pixmaps/up_arrow.xpm"
65 #include "pixmaps/exec.xpm"
66 #include "pixmaps/mail.xpm"
67 #include "pixmaps/mail_attach.xpm"
68 #include "pixmaps/mail_compose.xpm"
69 #include "pixmaps/mail_forward.xpm"
70 #include "pixmaps/mail_receive.xpm"
71 #include "pixmaps/mail_receive_all.xpm"
72 #include "pixmaps/mail_reply.xpm"
73 #include "pixmaps/mail_reply_to_all.xpm"
74 #include "pixmaps/mail_reply_to_author.xpm"
75 #include "pixmaps/mail_reply_to_list.xpm"
76 #include "pixmaps/mail_send.xpm"
77 #include "pixmaps/mail_send_queue.xpm"
78 #include "pixmaps/mail_sign.xpm"
79 #include "pixmaps/open_mail.xpm"
80 #include "pixmaps/news_compose.xpm"
81 #include "pixmaps/paste.xpm"
82 #include "pixmaps/preferences.xpm"
83 #include "pixmaps/properties.xpm"
84 #include "pixmaps/queue_close.xpm"
85 #include "pixmaps/queue_close_hrm.xpm"
86 #include "pixmaps/queue_open.xpm"
87 #include "pixmaps/queue_open_hrm.xpm"
88 #include "pixmaps/claws-mail_icon.xpm"
89 #ifndef GENERIC_UMPC
90 #include "pixmaps/claws-mail_logo.xpm"
91 #else
92 #include "pixmaps/claws-mail_logo-small.xpm"
93 #endif
94 #include "pixmaps/address_book.xpm"
95 #include "pixmaps/unread.xpm"
96 #include "pixmaps/read.xpm"
97 #include "pixmaps/vcard.xpm"
98 #include "pixmaps/ignorethread.xpm"
99 #include "pixmaps/online.xpm"
100 #include "pixmaps/offline.xpm"
101 #include "pixmaps/notice_warn.xpm"
102 #include "pixmaps/notice_error.xpm"
103 #include "pixmaps/notice_note.xpm"
104 #include "pixmaps/quicksearch.xpm"
105 #include "pixmaps/clip_gpg_signed.xpm"
106 #include "pixmaps/gpg_signed.xpm"
107 #include "pixmaps/go_folders.xpm"
108 #include "pixmaps/mime_text_plain.xpm"
109 #include "pixmaps/mime_text_html.xpm"
110 #include "pixmaps/mime_text_patch.xpm"
111 #include "pixmaps/mime_application.xpm"
112 #include "pixmaps/mime_image.xpm"
113 #include "pixmaps/mime_audio.xpm"
114 #include "pixmaps/mime_text_enriched.xpm"
115 #include "pixmaps/mime_unknown.xpm"
116 #include "pixmaps/mime_pdf.xpm"
117 #include "pixmaps/mime_ps.xpm"
118 #include "pixmaps/mime_calendar.xpm"
119 #include "pixmaps/mime_pgpsig.xpm"
120 #include "pixmaps/printer.xpm"
121 #include "pixmaps/privacy_signed.xpm"
122 #include "pixmaps/privacy_passed.xpm"
123 #include "pixmaps/privacy_failed.xpm"
124 #include "pixmaps/privacy_unknown.xpm"
125 #include "pixmaps/privacy_expired.xpm"
126 #include "pixmaps/privacy_warn.xpm"
127 #include "pixmaps/privacy_emblem_encrypted.xpm"
128 #include "pixmaps/privacy_emblem_signed.xpm"
129 #include "pixmaps/privacy_emblem_passed.xpm"
130 #include "pixmaps/privacy_emblem_failed.xpm"
131 #include "pixmaps/privacy_emblem_warn.xpm"
132 #include "pixmaps/mime_message.xpm"
133 #include "pixmaps/address_search.xpm"
134 #include "pixmaps/check_spelling.xpm"
136 #include "pixmaps/dir_close.xpm"
137 #include "pixmaps/dir_close_hrm.xpm"
138 #include "pixmaps/dir_open.xpm"
139 #include "pixmaps/dir_open_hrm.xpm"
140 #include "pixmaps/inbox_open.xpm"
141 #include "pixmaps/inbox_open_hrm.xpm"
142 #include "pixmaps/inbox_close.xpm"
143 #include "pixmaps/inbox_close_hrm.xpm"
144 #include "pixmaps/outbox_open.xpm"
145 #include "pixmaps/outbox_open_hrm.xpm"
146 #include "pixmaps/outbox_close.xpm"
147 #include "pixmaps/outbox_close_hrm.xpm"
148 #include "pixmaps/trash.xpm"
149 #include "pixmaps/delete_btn.xpm"
150 #include "pixmaps/cancel.xpm"
151 #include "pixmaps/trash_btn.xpm"
152 #include "pixmaps/trash_hrm.xpm"
153 #include "pixmaps/drafts_close.xpm"
154 #include "pixmaps/drafts_open.xpm"
155 #include "pixmaps/dir_close_mark.xpm"
156 #include "pixmaps/dir_close_hrm_mark.xpm"
157 #include "pixmaps/dir_open_mark.xpm"
158 #include "pixmaps/dir_open_hrm_mark.xpm"
159 #include "pixmaps/inbox_open_mark.xpm"
160 #include "pixmaps/inbox_open_hrm_mark.xpm"
161 #include "pixmaps/inbox_close_mark.xpm"
162 #include "pixmaps/inbox_close_hrm_mark.xpm"
163 #include "pixmaps/outbox_open_mark.xpm"
164 #include "pixmaps/outbox_open_hrm_mark.xpm"
165 #include "pixmaps/outbox_close_mark.xpm"
166 #include "pixmaps/outbox_close_hrm_mark.xpm"
167 #include "pixmaps/trash_mark.xpm"
168 #include "pixmaps/queue_close_mark.xpm"
169 #include "pixmaps/queue_close_hrm_mark.xpm"
170 #include "pixmaps/queue_open_mark.xpm"
171 #include "pixmaps/queue_open_hrm_mark.xpm"
172 #include "pixmaps/trash_hrm_mark.xpm"
173 #include "pixmaps/drafts_close_mark.xpm"
174 #include "pixmaps/drafts_open_mark.xpm"
175 #include "pixmaps/dir_noselect.xpm"
176 #include "pixmaps/spam.xpm"
177 #include "pixmaps/spam_btn.xpm"
178 #include "pixmaps/ham_btn.xpm"
179 #include "pixmaps/moved.xpm"
180 #include "pixmaps/copied.xpm"
181 #include "pixmaps/selection.xpm"
182 #include "pixmaps/watchthread.xpm"
183 #include "pixmaps/empty.xpm"
184 #include "pixmaps/tray_newmail.offline.xpm"
185 #include "pixmaps/tray_newmail.xpm"
186 #include "pixmaps/tray_newmarkedmail.offline.xpm"
187 #include "pixmaps/tray_newmarkedmail.xpm"
188 #include "pixmaps/tray_nomail.offline.xpm"
189 #include "pixmaps/tray_nomail.xpm"
190 #include "pixmaps/tray_unreadmail.offline.xpm"
191 #include "pixmaps/tray_unreadmail.xpm"
192 #include "pixmaps/tray_unreadmarkedmail.offline.xpm"
193 #include "pixmaps/tray_unreadmarkedmail.xpm"
195 typedef struct _StockPixmapData StockPixmapData;
197 struct _StockPixmapData
199 gchar **data;
200 cairo_surface_t *pixmap;
201 cairo_pattern_t *mask;
202 gchar *file;
203 gchar *icon_path;
204 GdkPixbuf *pixbuf;
207 typedef struct _OverlayData OverlayData;
209 struct _OverlayData
211 gboolean is_pixmap;
212 cairo_surface_t *base_pixmap;
213 cairo_surface_t *overlay_pixmap;
215 GdkPixbuf *base_pixbuf;
216 GdkPixbuf *overlay_pixbuf;
218 guint base_height;
219 guint base_width;
220 guint overlay_height;
221 guint overlay_width;
222 OverlayPosition position;
223 gint border_x;
224 gint border_y;
225 gboolean highlight;
228 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname);
230 static StockPixmapData pixmaps[] =
232 {addr_one_xpm , NULL, NULL, "addr_one", NULL},
233 {addr_two_xpm , NULL, NULL, "addr_two", NULL},
234 {address_xpm , NULL, NULL, "address", NULL},
235 {address_book_xpm , NULL, NULL, "address_book", NULL},
236 {address_search_xpm , NULL, NULL, "address_search", NULL},
237 {anonymous_xpm , NULL, NULL, "anonymous", NULL},
238 {book_xpm , NULL, NULL, "book", NULL},
239 {category_xpm , NULL, NULL, "category", NULL},
240 {checkbox_off_xpm , NULL, NULL, "checkbox_off", NULL},
241 {checkbox_on_xpm , NULL, NULL, "checkbox_on", NULL},
242 {check_spelling_xpm , NULL, NULL, "check_spelling", NULL},
243 {clip_xpm , NULL, NULL, "clip", NULL},
244 {clipkey_xpm , NULL, NULL, "clipkey", NULL},
245 {clip_gpg_signed_xpm , NULL, NULL, "clip_gpg_signed", NULL},
246 {close_xpm , NULL, NULL, "close", NULL},
247 {complete_xpm , NULL, NULL, "complete", NULL},
248 {continue_xpm , NULL, NULL, "continue", NULL},
249 {deleted_xpm , NULL, NULL, "deleted", NULL},
250 {dir_close_xpm , NULL, NULL, "dir_close", NULL},
251 {dir_close_hrm_xpm , NULL, NULL, "dir_close_hrm", NULL},
252 {dir_open_xpm , NULL, NULL, "dir_open", NULL},
253 {dir_open_hrm_xpm , NULL, NULL, "dir_open_hrm", NULL},
254 {dir_close_mark_xpm , NULL, NULL, "dir_close_mark", NULL},
255 {dir_close_hrm_mark_xpm , NULL, NULL, "dir_close_hrm_mark", NULL},
256 {dir_open_mark_xpm , NULL, NULL, "dir_open_mark", NULL},
257 {dir_open_hrm_mark_xpm , NULL, NULL, "dir_open_hrm_mark", NULL},
258 {down_arrow_xpm , NULL, NULL, "down_arrow", NULL},
259 {up_arrow_xpm , NULL, NULL, "up_arrow", NULL},
260 {edit_extern_xpm , NULL, NULL, "edit_extern", NULL},
261 {error_xpm , NULL, NULL, "error", NULL},
262 {exec_xpm , NULL, NULL, "exec", NULL},
263 {forwarded_xpm , NULL, NULL, "forwarded", NULL},
264 {group_xpm , NULL, NULL, "group", NULL},
265 {ignorethread_xpm , NULL, NULL, "ignorethread", NULL},
266 {inbox_close_xpm , NULL, NULL, "inbox_close", NULL},
267 {inbox_close_hrm_xpm , NULL, NULL, "inbox_close_hrm", NULL},
268 {inbox_open_xpm , NULL, NULL, "inbox_open", NULL},
269 {inbox_open_hrm_xpm , NULL, NULL, "inbox_open_hrm", NULL},
270 {inbox_close_mark_xpm , NULL, NULL, "inbox_close_mark", NULL},
271 {inbox_close_hrm_mark_xpm , NULL, NULL, "inbox_close_hrm_mark", NULL},
272 {inbox_open_mark_xpm , NULL, NULL, "inbox_open_mark", NULL},
273 {inbox_open_hrm_mark_xpm , NULL, NULL, "inbox_open_hrm_mark", NULL},
274 {insert_file_xpm , NULL, NULL, "insert_file", NULL},
275 {interface_xpm , NULL, NULL, "interface", NULL},
276 {jpilot_xpm , NULL, NULL, "jpilot", NULL},
277 {key_xpm , NULL, NULL, "key", NULL},
278 {key_gpg_signed_xpm , NULL, NULL, "key_gpg_signed_xpm", NULL},
279 {ldap_xpm , NULL, NULL, "ldap", NULL},
280 {linewrapcurrent_xpm , NULL, NULL, "linewrapcurrent", NULL},
281 {linewrap_xpm , NULL, NULL, "linewrap", NULL},
282 {locked_xpm , NULL, NULL, "locked", NULL},
283 {mail_xpm , NULL, NULL, "mail", NULL},
284 {mail_attach_xpm , NULL, NULL, "mail_attach", NULL},
285 {mail_compose_xpm , NULL, NULL, "mail_compose", NULL},
286 {mail_forward_xpm , NULL, NULL, "mail_forward", NULL},
287 {mail_receive_xpm , NULL, NULL, "mail_receive", NULL},
288 {mail_receive_all_xpm , NULL, NULL, "mail_receive_all", NULL},
289 {mail_reply_xpm , NULL, NULL, "mail_reply", NULL},
290 {mail_reply_to_all_xpm , NULL, NULL, "mail_reply_to_all", NULL},
291 {mail_reply_to_author_xpm , NULL, NULL, "mail_reply_to_author", NULL},
292 {mail_reply_to_list_xpm , NULL, NULL, "mail_reply_to_list", NULL},
293 {mail_send_xpm , NULL, NULL, "mail_send", NULL},
294 {mail_send_queue_xpm , NULL, NULL, "mail_send_queue", NULL},
295 {mail_sign_xpm , NULL, NULL, "mail_sign", NULL},
296 {open_mail_xpm , NULL, NULL, "open_mail", NULL},
297 {mark_xpm , NULL, NULL, "mark", NULL},
298 {new_xpm , NULL, NULL, "new", NULL},
299 {news_compose_xpm , NULL, NULL, "news_compose", NULL},
300 {outbox_close_xpm , NULL, NULL, "outbox_close", NULL},
301 {outbox_close_hrm_xpm , NULL, NULL, "outbox_close_hrm", NULL},
302 {outbox_open_xpm , NULL, NULL, "outbox_open", NULL},
303 {outbox_open_hrm_xpm , NULL, NULL, "outbox_open_hrm", NULL},
304 {outbox_close_mark_xpm , NULL, NULL, "outbox_close_mark", NULL},
305 {outbox_close_hrm_mark_xpm , NULL, NULL, "outbox_close_hrm_mark", NULL},
306 {outbox_open_mark_xpm , NULL, NULL, "outbox_open_mark", NULL},
307 {outbox_open_hrm_mark_xpm , NULL, NULL, "outbox_open_hrm_mark", NULL},
308 {replied_xpm , NULL, NULL, "replied", NULL},
309 {replied_and_forwarded_xpm , NULL, NULL, "replied_and_forwarded", NULL},
310 {paste_xpm , NULL, NULL, "paste", NULL},
311 {preferences_xpm , NULL, NULL, "preferences", NULL},
312 {properties_xpm , NULL, NULL, "properties", NULL},
313 {queue_close_xpm , NULL, NULL, "queue_close", NULL},
314 {queue_close_hrm_xpm , NULL, NULL, "queue_close_hrm", NULL},
315 {queue_open_xpm , NULL, NULL, "queue_open", NULL},
316 {queue_open_hrm_xpm , NULL, NULL, "queue_open_hrm", NULL},
317 {trash_xpm , NULL, NULL, "trash_open", NULL},
318 {trash_hrm_xpm , NULL, NULL, "trash_open_hrm", NULL},
319 {trash_xpm , NULL, NULL, "trash_close", NULL},
320 {trash_hrm_xpm , NULL, NULL, "trash_close_hrm", NULL},
321 {queue_close_mark_xpm , NULL, NULL, "queue_close_mark", NULL},
322 {queue_close_hrm_mark_xpm , NULL, NULL, "queue_close_hrm_mark", NULL},
323 {queue_open_mark_xpm , NULL, NULL, "queue_open_mark", NULL},
324 {queue_open_hrm_mark_xpm , NULL, NULL, "queue_open_hrm_mark", NULL},
325 {trash_mark_xpm , NULL, NULL, "trash_open_mark", NULL},
326 {trash_hrm_mark_xpm , NULL, NULL, "trash_open_hrm_mark", NULL},
327 {trash_mark_xpm , NULL, NULL, "trash_close_mark", NULL},
328 {trash_hrm_mark_xpm , NULL, NULL, "trash_close_hrm_mark", NULL},
329 {unread_xpm , NULL, NULL, "unread", NULL},
330 {vcard_xpm , NULL, NULL, "vcard", NULL},
331 {online_xpm , NULL, NULL, "online", NULL},
332 {offline_xpm , NULL, NULL, "offline", NULL},
333 {notice_warn_xpm , NULL, NULL, "notice_warn", NULL},
334 {notice_error_xpm , NULL, NULL, "notice_error", NULL},
335 {notice_note_xpm , NULL, NULL, "notice_note", NULL},
336 {quicksearch_xpm , NULL, NULL, "quicksearch", NULL},
337 {gpg_signed_xpm , NULL, NULL, "gpg_signed", NULL},
338 {go_folders_xpm , NULL, NULL, "go_folders", NULL},
339 {drafts_close_xpm , NULL, NULL, "drafts_close", NULL},
340 {drafts_open_xpm , NULL, NULL, "drafts_open", NULL},
341 {drafts_close_mark_xpm , NULL, NULL, "drafts_close_mark", NULL},
342 {drafts_open_mark_xpm , NULL, NULL, "drafts_open_mark", NULL},
343 {mime_text_plain_xpm , NULL, NULL, "mime_text_plain", NULL},
344 {mime_text_html_xpm , NULL, NULL, "mime_text_html", NULL},
345 {mime_text_patch_xpm , NULL, NULL, "mime_text_patch", NULL},
346 {mime_application_xpm , NULL, NULL, "mime_application", NULL},
347 {mime_image_xpm , NULL, NULL, "mime_image", NULL},
348 {mime_audio_xpm , NULL, NULL, "mime_audio", NULL},
349 {mime_text_enriched_xpm , NULL, NULL, "mime_text_enriched", NULL},
350 {mime_unknown_xpm , NULL, NULL, "mime_unknown", NULL},
351 {mime_pdf_xpm , NULL, NULL, "mime_pdf", NULL},
352 {mime_ps_xpm , NULL, NULL, "mime_ps", NULL},
353 {mime_calendar_xpm , NULL, NULL, "mime_calendar", NULL},
354 {mime_pgpsig_xpm , NULL, NULL, "mime_pgpsig", NULL},
355 {printer_xpm , NULL, NULL, "printer", NULL},
356 {privacy_signed_xpm , NULL, NULL, "privacy_signed", NULL},
357 {privacy_passed_xpm , NULL, NULL, "privacy_passed", NULL},
358 {privacy_failed_xpm , NULL, NULL, "privacy_failed", NULL},
359 {privacy_unknown_xpm , NULL, NULL, "privacy_unknown", NULL},
360 {privacy_expired_xpm , NULL, NULL, "privacy_expired", NULL},
361 {privacy_warn_xpm , NULL, NULL, "privacy_warn", NULL},
362 {privacy_emblem_encrypted_xpm , NULL, NULL, "privacy_emblem_encrypted", NULL},
363 {privacy_emblem_signed_xpm , NULL, NULL, "privacy_emblem_signed", NULL},
364 {privacy_emblem_passed_xpm , NULL, NULL, "privacy_emblem_passed", NULL},
365 {privacy_emblem_failed_xpm , NULL, NULL, "privacy_emblem_failed", NULL},
366 {privacy_emblem_warn_xpm , NULL, NULL, "privacy_emblem_warn", NULL},
367 {mime_message_xpm , NULL, NULL, "mime_message", NULL},
368 {claws_mail_icon_xpm , NULL, NULL, "claws_mail_icon", NULL},
369 {read_xpm , NULL, NULL, "read", NULL},
370 {delete_btn_xpm , NULL, NULL, "delete_btn", NULL},
371 {cancel_xpm , NULL, NULL, "cancel", NULL},
372 {trash_btn_xpm , NULL, NULL, "trash_btn", NULL},
373 #ifndef GENERIC_UMPC
374 {claws_mail_logo_xpm , NULL, NULL, "claws_mail_logo", NULL},
375 #else
376 {claws_mail_logo_small_xpm , NULL, NULL, "claws_mail_logo_small", NULL},
377 #endif
378 {dir_noselect_xpm , NULL, NULL, "dir_noselect" , NULL},
379 {spam_xpm , NULL, NULL, "spam" , NULL},
380 {spam_btn_xpm , NULL, NULL, "spam_btn" , NULL},
381 {ham_btn_xpm , NULL, NULL, "ham_btn" , NULL},
382 {moved_xpm , NULL, NULL, "moved", NULL},
383 {copied_xpm , NULL, NULL, "copied", NULL},
384 {selection_xpm , NULL, NULL, "selection", NULL},
385 {watchthread_xpm , NULL, NULL, "watchthread", NULL},
386 {tray_newmail_offline_xpm , NULL, NULL, "tray_newmail.offline", NULL},
387 {tray_newmail_xpm , NULL, NULL, "tray_newmail", NULL},
388 {tray_newmarkedmail_offline_xpm , NULL, NULL, "tray_newmarkedmail.offline", NULL},
389 {tray_newmarkedmail_xpm , NULL, NULL, "tray_newmarkedmail", NULL},
390 {tray_nomail_offline_xpm , NULL, NULL, "tray_nomail.offline", NULL},
391 {tray_nomail_xpm , NULL, NULL, "tray_nomail", NULL},
392 {tray_unreadmail_offline_xpm , NULL, NULL, "tray_unreadmail.offline", NULL},
393 {tray_unreadmail_xpm , NULL, NULL, "tray_unreadmail", NULL},
394 {tray_unreadmarkedmail_offline_xpm , NULL, NULL, "tray_unreadmarkedmail.offline", NULL},
395 {tray_unreadmarkedmail_xpm , NULL, NULL, "tray_unreadmarkedmail", NULL},
396 {empty_xpm , NULL, NULL, "empty" , NULL}
399 /* return newly constructed GtkPixmap from GdkPixmap */
400 GtkWidget *stock_pixmap_widget(GtkWidget *window, StockPixmap icon)
402 GdkPixbuf *pixbuf;
404 cm_return_val_if_fail(window != NULL, NULL);
405 cm_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
407 if (stock_pixbuf_gdk(window, icon, &pixbuf) != -1)
408 return gtk_image_new_from_pixbuf(pixbuf);
410 return NULL;
414 *\brief
416 gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
418 StockPixmapData *pix_d;
419 static const char *extension[]={".png", ".xpm", NULL};
420 int i = 0;
421 gboolean theme_changed = FALSE;
423 if (pixbuf)
424 *pixbuf = NULL;
426 cm_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
428 pix_d = &pixmaps[icon];
430 theme_changed = (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0);
431 if (!pix_d->pixbuf || theme_changed) {
432 GdkPixbuf *pix = NULL;
434 if (theme_changed && pix_d->pixmap) {
435 g_object_unref(pix_d->pixmap);
436 pix_d->pixmap = NULL;
439 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
440 if (is_dir_exist(prefs_common.pixmap_theme_path)) {
441 char *icon_file_name;
442 try_next_extension:
443 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
444 G_DIR_SEPARATOR_S,
445 pix_d->file,
446 extension[i],
447 NULL);
448 if (is_file_exist(icon_file_name)) {
449 GError *err = NULL;
450 pix = gdk_pixbuf_new_from_file(icon_file_name, &err);
451 if (err) g_error_free(err);
453 if (pix) {
454 g_free(pix_d->icon_path);
455 pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
457 g_free(icon_file_name);
458 if (!pix) {
459 i++;
460 if (extension[i])
461 goto try_next_extension;
463 } else {
464 /* even the path does not exist (deleted between two sessions), so
465 set the preferences to the internal theme */
466 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
469 pix_d->pixbuf = pix;
472 if (!pix_d->pixbuf) {
473 pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) pix_d->data);
474 if (pix_d->pixbuf) {
475 g_free(pix_d->icon_path);
476 pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);
480 cm_return_val_if_fail(pix_d->pixbuf != NULL, -1);
482 if (pixbuf)
483 *pixbuf = pix_d->pixbuf;
485 /* pixbuf should have one ref outstanding */
487 return 0;
490 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
492 struct dirent *d;
493 DIR *dp;
494 static const char *extension[]={".png", ".xpm", NULL};
496 if ((dp = opendir(dirname)) == NULL) {
497 debug_print("dir %s not found, skipping theme scan\n", dirname?dirname:"(null)");
498 return;
501 while ((d = readdir(dp)) != NULL) {
502 gchar *entry;
503 gchar *fullentry;
505 entry = d->d_name;
506 fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
508 if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
509 gchar *filetoexist;
510 gboolean found = FALSE;
511 int i;
512 int j;
513 for (i = 0; i < N_STOCK_PIXMAPS && !found; i++) {
514 for (j = 0; extension[j] && !found; j++) {
515 filetoexist = g_strconcat(fullentry, G_DIR_SEPARATOR_S, pixmaps[i].file, extension[j], NULL);
516 if (is_file_exist(filetoexist)) {
517 *list = g_list_append(*list, fullentry);
518 found = TRUE;
520 g_free(filetoexist);
523 if (i == N_STOCK_PIXMAPS)
524 g_free(fullentry);
525 } else
526 g_free(fullentry);
528 closedir(dp);
531 gchar *stock_pixmap_get_system_theme_dir_for_theme(const gchar *theme)
533 const gchar *sep = NULL;
534 if (theme && *theme)
535 sep = G_DIR_SEPARATOR_S;
536 #ifndef G_OS_WIN32
537 return g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
538 PIXMAP_THEME_DIR, sep, theme, NULL);
539 #else
540 return g_strconcat(get_themes_dir(), sep, theme, NULL);
541 #endif
544 GList *stock_pixmap_themes_list_new(void)
546 gchar *defaulttheme;
547 gchar *userthemes;
548 gchar *systemthemes;
549 GList *list = NULL;
551 defaulttheme = g_strdup(DEFAULT_PIXMAP_THEME);
552 userthemes = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
553 PIXMAP_THEME_DIR, NULL);
554 systemthemes = stock_pixmap_get_system_theme_dir_for_theme(NULL);
556 list = g_list_append(list, defaulttheme);
557 stock_pixmap_find_themes_in_dir(&list, userthemes);
558 stock_pixmap_find_themes_in_dir(&list, systemthemes);
560 g_free(userthemes);
561 g_free(systemthemes);
562 return list;
565 void stock_pixmap_themes_list_free(GList *list)
567 GList *ptr;
569 for (ptr = g_list_first(list); ptr != NULL; ptr = g_list_next(ptr))
570 g_free(ptr->data);
571 g_list_free(list);
574 gchar *stock_pixmap_get_name (StockPixmap icon)
576 if (icon < 0 || icon >= N_STOCK_PIXMAPS)
577 return NULL;
579 return pixmaps[icon].file;
583 StockPixmap stock_pixmap_get_icon (gchar *file)
585 gint i;
587 for (i = 0; i < N_STOCK_PIXMAPS; i++) {
588 if (strcmp (pixmaps[i].file, file) == 0)
589 return i;
591 return -1;
594 static gboolean do_pix_draw(GtkWidget *widget, cairo_t *cr,
595 OverlayData *data)
597 GdkWindow *drawable = gtk_widget_get_window(widget);
598 gint left = 0;
599 gint top = 0;
601 if (data->is_pixmap) {
602 cm_return_val_if_fail(data->base_pixmap != NULL, FALSE);
603 } else {
604 cm_return_val_if_fail(data->base_pixbuf != NULL, FALSE);
607 if (data->highlight) {
608 MainWindow *mw = NULL;
610 mw = mainwindow_get_mainwindow();
611 if (mw != NULL && mw->menubar != NULL) {
612 cairo_t *cr;
613 GdkColor color = gtk_widget_get_style(mw->menubar)->base[GTK_STATE_SELECTED];
615 cr = gdk_cairo_create(drawable);
616 gdk_cairo_set_source_color(cr, &color);
617 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
618 cairo_set_line_width(cr, 1.);
619 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
620 cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
621 cairo_rectangle(cr, data->border_x-2, data->border_y-2,
622 data->base_width+3, data->base_height+3);
623 cairo_stroke(cr);
624 cairo_destroy(cr);
628 if (data->is_pixmap) {
629 cairo_set_source_surface(cr, data->base_pixmap, data->border_x, data->border_y);
630 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
631 cairo_rectangle(cr, data->border_x, data->border_y, data->base_width, data->base_height);
632 cairo_fill(cr);
633 } else {
634 gdk_cairo_set_source_pixbuf(cr, data->base_pixbuf, data->border_x, data->border_y);
635 cairo_paint(cr);
638 if (data->position != OVERLAY_NONE) {
640 switch (data->position) {
641 case OVERLAY_TOP_LEFT:
642 case OVERLAY_MID_LEFT:
643 case OVERLAY_BOTTOM_LEFT:
644 left = 0;
645 break;
647 case OVERLAY_TOP_CENTER:
648 case OVERLAY_MID_CENTER:
649 case OVERLAY_BOTTOM_CENTER:
650 left = (data->base_width + data->border_x * 2 - data->overlay_width)/2;
651 break;
653 case OVERLAY_TOP_RIGHT:
654 case OVERLAY_MID_RIGHT:
655 case OVERLAY_BOTTOM_RIGHT:
656 left = data->base_width + data->border_x * 2 - data->overlay_width;
657 break;
659 default:
660 break;
662 switch (data->position) {
663 case OVERLAY_TOP_LEFT:
664 case OVERLAY_TOP_CENTER:
665 case OVERLAY_TOP_RIGHT:
666 top = 0;
667 break;
669 case OVERLAY_MID_LEFT:
670 case OVERLAY_MID_CENTER:
671 case OVERLAY_MID_RIGHT:
672 top = (data->base_height + data->border_y * 2 - data->overlay_height)/2;
673 break;
675 case OVERLAY_BOTTOM_LEFT:
676 case OVERLAY_BOTTOM_CENTER:
677 case OVERLAY_BOTTOM_RIGHT:
678 top = data->base_height + data->border_y * 2 - data->overlay_height;
679 break;
681 default:
682 break;
686 if (data->position != OVERLAY_NONE) {
687 if (data->is_pixmap) {
688 cm_return_val_if_fail(data->overlay_pixmap != NULL, FALSE);
689 cairo_set_source_surface(cr, data->overlay_pixmap, left, top);
690 cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
691 cairo_rectangle (cr, left, top, data->overlay_width, data->overlay_height);
692 cairo_fill(cr);
693 } else {
694 cm_return_val_if_fail(data->overlay_pixbuf != NULL, FALSE);
695 gdk_cairo_set_source_pixbuf(cr, data->overlay_pixbuf, left, top);
696 cairo_paint(cr);
700 return TRUE;
703 #if !GTK_CHECK_VERSION(3,0,0)
704 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventExpose *expose,
705 OverlayData *data)
706 #else
707 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, cairo_t *cr,
708 OverlayData *data)
709 #endif
711 #if !GTK_CHECK_VERSION(3,0,0)
712 cairo_t *cr;
713 GdkWindow *drawable = gtk_widget_get_window(widget);
714 gboolean result;
716 cr = gdk_cairo_create(drawable);
717 gdk_window_clear_area (drawable, expose->area.x, expose->area.y,
718 expose->area.width, expose->area.height);
720 result = do_pix_draw(widget, cr, data);
721 cairo_destroy(cr);
722 return result;
723 #else
724 return do_pix_draw(widget, cr, data);
725 #endif
728 static void pixmap_with_overlay_destroy_cb(GtkWidget *object, OverlayData *data)
730 if (data->is_pixmap) {
731 cairo_surface_destroy(data->base_pixmap);
732 if (data->position != OVERLAY_NONE) {
733 cairo_surface_destroy(data->overlay_pixmap);
735 } else {
736 g_object_unref(data->base_pixbuf);
737 if (data->position != OVERLAY_NONE) {
738 g_object_unref(data->overlay_pixbuf);
741 g_free(data);
745 * \brief Get a widget showing one icon with another overlaid on top of it.
747 * The base icon is always centralised, the other icon can be positioned.
748 * The overlay icon is ignored if pos=OVERLAY_NONE is used
750 * \param window top-level window widget
751 * \param icon the base icon
752 * \param overlay the icon to overlay
753 * \param pos how to align the overlay widget, or OVERLAY_NONE for no overlay
754 * \param border_x size of the border around the base icon (left and right)
755 * \param border_y size of the border around the base icon (top and bottom)
757 GtkWidget *stock_pixmap_widget_with_overlay(GtkWidget *window, StockPixmap icon,
758 StockPixmap overlay, OverlayPosition pos,
759 gint border_x, gint border_y)
761 cairo_surface_t *stock_pixmap = NULL;
762 GdkPixbuf *stock_pixbuf = NULL;
763 GtkWidget *widget = NULL;
764 GtkWidget *stock_wid = NULL;
765 GtkRequisition requisition;
766 OverlayData *data = NULL;
768 data = g_new0(OverlayData, 1);
770 stock_wid = stock_pixmap_widget(window, icon);
771 gtk_widget_get_requisition(stock_wid, &requisition);
773 #if !GTK_CHECK_VERSION(3, 0, 0)
774 if (gtk_image_get_storage_type(GTK_IMAGE(stock_wid)) == GTK_IMAGE_PIXMAP)
775 data->is_pixmap = TRUE;
776 else
777 #endif
778 data->is_pixmap = FALSE;
780 if (data->is_pixmap) {
781 cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(stock_wid));
782 stock_pixmap = cairo_get_target(cr);
783 cairo_surface_reference(stock_pixmap);
784 cairo_destroy(cr);
785 data->base_pixmap = stock_pixmap;
786 data->base_height = requisition.height;
787 data->base_width = requisition.width;
788 gtk_widget_destroy(stock_wid);
790 if (pos == OVERLAY_NONE) {
791 data->overlay_pixmap = NULL;
792 } else {
793 stock_wid = stock_pixmap_widget(window, overlay);
794 cr = gdk_cairo_create(gtk_widget_get_window(stock_wid));
795 stock_pixmap = cairo_get_target(cr);
796 cairo_surface_reference(stock_pixmap);
797 cairo_destroy(cr);
798 data->overlay_pixmap = stock_pixmap;
799 data->overlay_height = requisition.height;
800 data->overlay_width = requisition.width;
802 gtk_widget_destroy(stock_wid);
804 } else {
805 data->is_pixmap = FALSE;
806 stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
807 g_object_ref(stock_pixbuf);
808 data->base_pixbuf = stock_pixbuf;
809 data->base_height = requisition.height;
810 data->base_width = requisition.width;
811 gtk_widget_destroy(stock_wid);
812 if (pos == OVERLAY_NONE) {
813 data->overlay_pixmap = NULL;
814 } else {
815 stock_wid = stock_pixmap_widget(window, overlay);
816 stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
817 g_object_ref(stock_pixbuf);
818 data->overlay_pixbuf = stock_pixbuf;
819 data->overlay_height = requisition.height;
820 data->overlay_width = requisition.width;
822 gtk_widget_destroy(stock_wid);
825 data->position = pos;
826 data->border_x = border_x;
827 data->border_y = border_y;
828 data->highlight = FALSE;
830 widget = gtk_drawing_area_new();
831 gtk_widget_set_size_request(widget, data->base_width + border_x * 2,
832 data->base_height + border_y * 2);
833 #if !GTK_CHECK_VERSION(3, 0, 0)
834 g_signal_connect(G_OBJECT(widget), "expose_event",
835 G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
836 #else
837 g_signal_connect(G_OBJECT(widget), "draw",
838 G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
839 #endif
840 g_signal_connect(G_OBJECT(widget), "destroy",
841 G_CALLBACK(pixmap_with_overlay_destroy_cb), data);
842 g_object_set_data(G_OBJECT(widget), "highlight", &(data->highlight));
843 return widget;