2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 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/>.
22 #include <gtk/gtkwidget.h>
23 #include <gtk/gtkimage.h>
27 #include "stock_pixmap.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/ldap.xpm"
54 #include "pixmaps/linewrap.xpm"
55 #include "pixmaps/linewrapcurrent.xpm"
56 #include "pixmaps/mark.xpm"
57 #include "pixmaps/locked.xpm"
58 #include "pixmaps/new.xpm"
59 #include "pixmaps/replied.xpm"
60 #include "pixmaps/close.xpm"
61 #include "pixmaps/down_arrow.xpm"
62 #include "pixmaps/up_arrow.xpm"
63 #include "pixmaps/exec.xpm"
64 #include "pixmaps/mail.xpm"
65 #include "pixmaps/mail_attach.xpm"
66 #include "pixmaps/mail_compose.xpm"
67 #include "pixmaps/mail_forward.xpm"
68 #include "pixmaps/mail_receive.xpm"
69 #include "pixmaps/mail_receive_all.xpm"
70 #include "pixmaps/mail_reply.xpm"
71 #include "pixmaps/mail_reply_to_all.xpm"
72 #include "pixmaps/mail_reply_to_author.xpm"
73 #include "pixmaps/mail_send.xpm"
74 #include "pixmaps/mail_send_queue.xpm"
75 #include "pixmaps/mail_sign.xpm"
76 #include "pixmaps/open_mail.xpm"
77 #include "pixmaps/news_compose.xpm"
78 #include "pixmaps/paste.xpm"
79 #include "pixmaps/preferences.xpm"
80 #include "pixmaps/properties.xpm"
81 #include "pixmaps/queue_close.xpm"
82 #include "pixmaps/queue_close_hrm.xpm"
83 #include "pixmaps/queue_open.xpm"
84 #include "pixmaps/queue_open_hrm.xpm"
85 #include "pixmaps/claws-mail_icon.xpm"
87 #include "pixmaps/claws-mail_logo.xpm"
89 #include "pixmaps/claws-mail_logo-small.xpm"
91 #include "pixmaps/address_book.xpm"
92 #include "pixmaps/unread.xpm"
93 #include "pixmaps/read.xpm"
94 #include "pixmaps/vcard.xpm"
95 #include "pixmaps/ignorethread.xpm"
96 #include "pixmaps/online.xpm"
97 #include "pixmaps/offline.xpm"
98 #include "pixmaps/notice_warn.xpm"
99 #include "pixmaps/notice_error.xpm"
100 #include "pixmaps/notice_note.xpm"
101 #include "pixmaps/quicksearch.xpm"
102 #include "pixmaps/clip_gpg_signed.xpm"
103 #include "pixmaps/gpg_signed.xpm"
104 #include "pixmaps/go_folders.xpm"
105 #include "pixmaps/mime_text_plain.xpm"
106 #include "pixmaps/mime_text_html.xpm"
107 #include "pixmaps/mime_text_patch.xpm"
108 #include "pixmaps/mime_application.xpm"
109 #include "pixmaps/mime_image.xpm"
110 #include "pixmaps/mime_audio.xpm"
111 #include "pixmaps/mime_text_enriched.xpm"
112 #include "pixmaps/mime_unknown.xpm"
113 #include "pixmaps/mime_pdf.xpm"
114 #include "pixmaps/mime_ps.xpm"
115 #include "pixmaps/mime_calendar.xpm"
116 #include "pixmaps/mime_pgpsig.xpm"
117 #include "pixmaps/printer.xpm"
118 #include "pixmaps/privacy_signed.xpm"
119 #include "pixmaps/privacy_passed.xpm"
120 #include "pixmaps/privacy_failed.xpm"
121 #include "pixmaps/privacy_unknown.xpm"
122 #include "pixmaps/privacy_expired.xpm"
123 #include "pixmaps/privacy_warn.xpm"
124 #include "pixmaps/privacy_emblem_encrypted.xpm"
125 #include "pixmaps/privacy_emblem_signed.xpm"
126 #include "pixmaps/privacy_emblem_passed.xpm"
127 #include "pixmaps/privacy_emblem_failed.xpm"
128 #include "pixmaps/privacy_emblem_warn.xpm"
129 #include "pixmaps/mime_message.xpm"
130 #include "pixmaps/address_search.xpm"
131 #include "pixmaps/check_spelling.xpm"
133 #include "pixmaps/dir_close.xpm"
134 #include "pixmaps/dir_close_hrm.xpm"
135 #include "pixmaps/dir_open.xpm"
136 #include "pixmaps/dir_open_hrm.xpm"
137 #include "pixmaps/inbox_open.xpm"
138 #include "pixmaps/inbox_open_hrm.xpm"
139 #include "pixmaps/inbox_close.xpm"
140 #include "pixmaps/inbox_close_hrm.xpm"
141 #include "pixmaps/outbox_open.xpm"
142 #include "pixmaps/outbox_open_hrm.xpm"
143 #include "pixmaps/outbox_close.xpm"
144 #include "pixmaps/outbox_close_hrm.xpm"
145 #include "pixmaps/trash.xpm"
146 #include "pixmaps/trash_btn.xpm"
147 #include "pixmaps/trash_hrm.xpm"
148 #include "pixmaps/drafts_close.xpm"
149 #include "pixmaps/drafts_open.xpm"
150 #include "pixmaps/dir_close_mark.xpm"
151 #include "pixmaps/dir_close_hrm_mark.xpm"
152 #include "pixmaps/dir_open_mark.xpm"
153 #include "pixmaps/dir_open_hrm_mark.xpm"
154 #include "pixmaps/inbox_open_mark.xpm"
155 #include "pixmaps/inbox_open_hrm_mark.xpm"
156 #include "pixmaps/inbox_close_mark.xpm"
157 #include "pixmaps/inbox_close_hrm_mark.xpm"
158 #include "pixmaps/outbox_open_mark.xpm"
159 #include "pixmaps/outbox_open_hrm_mark.xpm"
160 #include "pixmaps/outbox_close_mark.xpm"
161 #include "pixmaps/outbox_close_hrm_mark.xpm"
162 #include "pixmaps/trash_mark.xpm"
163 #include "pixmaps/queue_close_mark.xpm"
164 #include "pixmaps/queue_close_hrm_mark.xpm"
165 #include "pixmaps/queue_open_mark.xpm"
166 #include "pixmaps/queue_open_hrm_mark.xpm"
167 #include "pixmaps/trash_hrm_mark.xpm"
168 #include "pixmaps/drafts_close_mark.xpm"
169 #include "pixmaps/drafts_open_mark.xpm"
170 #include "pixmaps/dir_noselect.xpm"
171 #include "pixmaps/spam.xpm"
172 #include "pixmaps/spam_btn.xpm"
173 #include "pixmaps/ham_btn.xpm"
174 #include "pixmaps/moved.xpm"
175 #include "pixmaps/copied.xpm"
176 #include "pixmaps/selection.xpm"
177 #include "pixmaps/watchthread.xpm"
178 #include "pixmaps/empty.xpm"
179 #include "pixmaps/tray_newmail.offline.xpm"
180 #include "pixmaps/tray_newmail.xpm"
181 #include "pixmaps/tray_newmarkedmail.offline.xpm"
182 #include "pixmaps/tray_newmarkedmail.xpm"
183 #include "pixmaps/tray_nomail.offline.xpm"
184 #include "pixmaps/tray_nomail.xpm"
185 #include "pixmaps/tray_unreadmail.offline.xpm"
186 #include "pixmaps/tray_unreadmail.xpm"
187 #include "pixmaps/tray_unreadmarkedmail.offline.xpm"
188 #include "pixmaps/tray_unreadmarkedmail.xpm"
190 typedef struct _StockPixmapData StockPixmapData;
192 struct _StockPixmapData
202 typedef struct _OverlayData OverlayData;
207 GdkPixmap *base_pixmap;
208 GdkBitmap *base_mask;
209 GdkPixmap *overlay_pixmap;
210 GdkBitmap *overlay_mask;
212 GdkPixbuf *base_pixbuf;
213 GdkPixbuf *overlay_pixbuf;
217 guint overlay_height;
219 OverlayPosition position;
225 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname);
227 static StockPixmapData pixmaps[] =
229 {addr_one_xpm , NULL, NULL, "addr_one", NULL},
230 {addr_two_xpm , NULL, NULL, "addr_two", NULL},
231 {address_xpm , NULL, NULL, "address", NULL},
232 {address_book_xpm , NULL, NULL, "address_book", NULL},
233 {address_search_xpm , NULL, NULL, "address_search", NULL},
234 {anonymous_xpm , NULL, NULL, "anonymous", NULL},
235 {book_xpm , NULL, NULL, "book", NULL},
236 {category_xpm , NULL, NULL, "category", NULL},
237 {checkbox_off_xpm , NULL, NULL, "checkbox_off", NULL},
238 {checkbox_on_xpm , NULL, NULL, "checkbox_on", NULL},
239 {check_spelling_xpm , NULL, NULL, "check_spelling", NULL},
240 {clip_xpm , NULL, NULL, "clip", NULL},
241 {clipkey_xpm , NULL, NULL, "clipkey", NULL},
242 {clip_gpg_signed_xpm , NULL, NULL, "clip_gpg_signed", NULL},
243 {close_xpm , NULL, NULL, "close", NULL},
244 {complete_xpm , NULL, NULL, "complete", NULL},
245 {continue_xpm , NULL, NULL, "continue", NULL},
246 {deleted_xpm , NULL, NULL, "deleted", NULL},
247 {dir_close_xpm , NULL, NULL, "dir_close", NULL},
248 {dir_close_hrm_xpm , NULL, NULL, "dir_close_hrm", NULL},
249 {dir_open_xpm , NULL, NULL, "dir_open", NULL},
250 {dir_open_hrm_xpm , NULL, NULL, "dir_open_hrm", NULL},
251 {dir_close_mark_xpm , NULL, NULL, "dir_close_mark", NULL},
252 {dir_close_hrm_mark_xpm , NULL, NULL, "dir_close_hrm_mark", NULL},
253 {dir_open_mark_xpm , NULL, NULL, "dir_open_mark", NULL},
254 {dir_open_hrm_mark_xpm , NULL, NULL, "dir_open_hrm_mark", NULL},
255 {down_arrow_xpm , NULL, NULL, "down_arrow", NULL},
256 {up_arrow_xpm , NULL, NULL, "up_arrow", NULL},
257 {edit_extern_xpm , NULL, NULL, "edit_extern", NULL},
258 {error_xpm , NULL, NULL, "error", NULL},
259 {exec_xpm , NULL, NULL, "exec", NULL},
260 {forwarded_xpm , NULL, NULL, "forwarded", NULL},
261 {group_xpm , NULL, NULL, "group", NULL},
262 {ignorethread_xpm , NULL, NULL, "ignorethread", NULL},
263 {inbox_close_xpm , NULL, NULL, "inbox_close", NULL},
264 {inbox_close_hrm_xpm , NULL, NULL, "inbox_close_hrm", NULL},
265 {inbox_open_xpm , NULL, NULL, "inbox_open", NULL},
266 {inbox_open_hrm_xpm , NULL, NULL, "inbox_open_hrm", NULL},
267 {inbox_close_mark_xpm , NULL, NULL, "inbox_close_mark", NULL},
268 {inbox_close_hrm_mark_xpm , NULL, NULL, "inbox_close_hrm_mark", NULL},
269 {inbox_open_mark_xpm , NULL, NULL, "inbox_open_mark", NULL},
270 {inbox_open_hrm_mark_xpm , NULL, NULL, "inbox_open_hrm_mark", NULL},
271 {insert_file_xpm , NULL, NULL, "insert_file", NULL},
272 {interface_xpm , NULL, NULL, "interface", NULL},
273 {jpilot_xpm , NULL, NULL, "jpilot", NULL},
274 {key_xpm , NULL, NULL, "key", NULL},
275 {ldap_xpm , NULL, NULL, "ldap", NULL},
276 {linewrapcurrent_xpm , NULL, NULL, "linewrapcurrent", NULL},
277 {linewrap_xpm , NULL, NULL, "linewrap", NULL},
278 {locked_xpm , NULL, NULL, "locked", NULL},
279 {mail_xpm , NULL, NULL, "mail", NULL},
280 {mail_attach_xpm , NULL, NULL, "mail_attach", NULL},
281 {mail_compose_xpm , NULL, NULL, "mail_compose", NULL},
282 {mail_forward_xpm , NULL, NULL, "mail_forward", NULL},
283 {mail_receive_xpm , NULL, NULL, "mail_receive", NULL},
284 {mail_receive_all_xpm , NULL, NULL, "mail_receive_all", NULL},
285 {mail_reply_xpm , NULL, NULL, "mail_reply", NULL},
286 {mail_reply_to_all_xpm , NULL, NULL, "mail_reply_to_all", NULL},
287 {mail_reply_to_author_xpm , NULL, NULL, "mail_reply_to_author", NULL},
288 {mail_send_xpm , NULL, NULL, "mail_send", NULL},
289 {mail_send_queue_xpm , NULL, NULL, "mail_send_queue", NULL},
290 {mail_sign_xpm , NULL, NULL, "mail_sign", NULL},
291 {open_mail_xpm , NULL, NULL, "open_mail", NULL},
292 {mark_xpm , NULL, NULL, "mark", NULL},
293 {new_xpm , NULL, NULL, "new", NULL},
294 {news_compose_xpm , NULL, NULL, "news_compose", NULL},
295 {outbox_close_xpm , NULL, NULL, "outbox_close", NULL},
296 {outbox_close_hrm_xpm , NULL, NULL, "outbox_close_hrm", NULL},
297 {outbox_open_xpm , NULL, NULL, "outbox_open", NULL},
298 {outbox_open_hrm_xpm , NULL, NULL, "outbox_open_hrm", NULL},
299 {outbox_close_mark_xpm , NULL, NULL, "outbox_close_mark", NULL},
300 {outbox_close_hrm_mark_xpm , NULL, NULL, "outbox_close_hrm_mark", NULL},
301 {outbox_open_mark_xpm , NULL, NULL, "outbox_open_mark", NULL},
302 {outbox_open_hrm_mark_xpm , NULL, NULL, "outbox_open_hrm_mark", NULL},
303 {replied_xpm , NULL, NULL, "replied", NULL},
304 {paste_xpm , NULL, NULL, "paste", NULL},
305 {preferences_xpm , NULL, NULL, "preferences", NULL},
306 {properties_xpm , NULL, NULL, "properties", NULL},
307 {queue_close_xpm , NULL, NULL, "queue_close", NULL},
308 {queue_close_hrm_xpm , NULL, NULL, "queue_close_hrm", NULL},
309 {queue_open_xpm , NULL, NULL, "queue_open", NULL},
310 {queue_open_hrm_xpm , NULL, NULL, "queue_open_hrm", NULL},
311 {trash_xpm , NULL, NULL, "trash_open", NULL},
312 {trash_hrm_xpm , NULL, NULL, "trash_open_hrm", NULL},
313 {trash_xpm , NULL, NULL, "trash_close", NULL},
314 {trash_hrm_xpm , NULL, NULL, "trash_close_hrm", NULL},
315 {queue_close_mark_xpm , NULL, NULL, "queue_close_mark", NULL},
316 {queue_close_hrm_mark_xpm , NULL, NULL, "queue_close_hrm_mark", NULL},
317 {queue_open_mark_xpm , NULL, NULL, "queue_open_mark", NULL},
318 {queue_open_hrm_mark_xpm , NULL, NULL, "queue_open_hrm_mark", NULL},
319 {trash_mark_xpm , NULL, NULL, "trash_open_mark", NULL},
320 {trash_hrm_mark_xpm , NULL, NULL, "trash_open_hrm_mark", NULL},
321 {trash_mark_xpm , NULL, NULL, "trash_close_mark", NULL},
322 {trash_hrm_mark_xpm , NULL, NULL, "trash_close_hrm_mark", NULL},
323 {unread_xpm , NULL, NULL, "unread", NULL},
324 {vcard_xpm , NULL, NULL, "vcard", NULL},
325 {online_xpm , NULL, NULL, "online", NULL},
326 {offline_xpm , NULL, NULL, "offline", NULL},
327 {notice_warn_xpm , NULL, NULL, "notice_warn", NULL},
328 {notice_error_xpm , NULL, NULL, "notice_error", NULL},
329 {notice_note_xpm , NULL, NULL, "notice_note", NULL},
330 {quicksearch_xpm , NULL, NULL, "quicksearch", NULL},
331 {gpg_signed_xpm , NULL, NULL, "gpg_signed", NULL},
332 {go_folders_xpm , NULL, NULL, "go_folders", NULL},
333 {drafts_close_xpm , NULL, NULL, "drafts_close", NULL},
334 {drafts_open_xpm , NULL, NULL, "drafts_open", NULL},
335 {drafts_close_mark_xpm , NULL, NULL, "drafts_close_mark", NULL},
336 {drafts_open_mark_xpm , NULL, NULL, "drafts_open_mark", NULL},
337 {mime_text_plain_xpm , NULL, NULL, "mime_text_plain", NULL},
338 {mime_text_html_xpm , NULL, NULL, "mime_text_html", NULL},
339 {mime_text_patch_xpm , NULL, NULL, "mime_text_patch", NULL},
340 {mime_application_xpm , NULL, NULL, "mime_application", NULL},
341 {mime_image_xpm , NULL, NULL, "mime_image", NULL},
342 {mime_audio_xpm , NULL, NULL, "mime_audio", NULL},
343 {mime_text_enriched_xpm , NULL, NULL, "mime_text_enriched", NULL},
344 {mime_unknown_xpm , NULL, NULL, "mime_unknown", NULL},
345 {mime_pdf_xpm , NULL, NULL, "mime_pdf", NULL},
346 {mime_ps_xpm , NULL, NULL, "mime_ps", NULL},
347 {mime_calendar_xpm , NULL, NULL, "mime_calendar", NULL},
348 {mime_pgpsig_xpm , NULL, NULL, "mime_pgpsig", NULL},
349 {printer_xpm , NULL, NULL, "printer", NULL},
350 {privacy_signed_xpm , NULL, NULL, "privacy_signed", NULL},
351 {privacy_passed_xpm , NULL, NULL, "privacy_passed", NULL},
352 {privacy_failed_xpm , NULL, NULL, "privacy_failed", NULL},
353 {privacy_unknown_xpm , NULL, NULL, "privacy_unknown", NULL},
354 {privacy_expired_xpm , NULL, NULL, "privacy_expired", NULL},
355 {privacy_warn_xpm , NULL, NULL, "privacy_warn", NULL},
356 {privacy_emblem_encrypted_xpm , NULL, NULL, "privacy_emblem_encrypted", NULL},
357 {privacy_emblem_signed_xpm , NULL, NULL, "privacy_emblem_signed", NULL},
358 {privacy_emblem_passed_xpm , NULL, NULL, "privacy_emblem_passed", NULL},
359 {privacy_emblem_failed_xpm , NULL, NULL, "privacy_emblem_failed", NULL},
360 {privacy_emblem_warn_xpm , NULL, NULL, "privacy_emblem_warn", NULL},
361 {mime_message_xpm , NULL, NULL, "mime_message", NULL},
362 {claws_mail_icon_xpm , NULL, NULL, "claws_mail_icon", NULL},
363 {read_xpm , NULL, NULL, "read", NULL},
364 {trash_btn_xpm , NULL, NULL, "trash_btn", NULL},
366 {claws_mail_logo_xpm , NULL, NULL, "claws_mail_logo", NULL},
368 {claws_mail_logo_small_xpm , NULL, NULL, "claws_mail_logo_small", NULL},
370 {dir_noselect_xpm , NULL, NULL, "dir_noselect" , NULL},
371 {spam_xpm , NULL, NULL, "spam" , NULL},
372 {spam_btn_xpm , NULL, NULL, "spam_btn" , NULL},
373 {ham_btn_xpm , NULL, NULL, "ham_btn" , NULL},
374 {moved_xpm , NULL, NULL, "moved", NULL},
375 {copied_xpm , NULL, NULL, "copied", NULL},
376 {selection_xpm , NULL, NULL, "selection", NULL},
377 {watchthread_xpm , NULL, NULL, "watchthread", NULL},
378 {tray_newmail_offline_xpm , NULL, NULL, "tray_newmail_offline", NULL},
379 {tray_newmail_xpm , NULL, NULL, "tray_newmail", NULL},
380 {tray_newmarkedmail_offline_xpm , NULL, NULL, "tray_newmarkedmail_offline", NULL},
381 {tray_newmarkedmail_xpm , NULL, NULL, "tray_newmarkedmail", NULL},
382 {tray_nomail_offline_xpm , NULL, NULL, "tray_nomail_offline", NULL},
383 {tray_nomail_xpm , NULL, NULL, "tray_nomail", NULL},
384 {tray_unreadmail_offline_xpm , NULL, NULL, "tray_unreadmail_offline", NULL},
385 {tray_unreadmail_xpm , NULL, NULL, "tray_unreadmail", NULL},
386 {tray_unreadmarkedmail_offline_xpm , NULL, NULL, "tray_unreadmarkedmail_offline", NULL},
387 {tray_unreadmarkedmail_xpm , NULL, NULL, "tray_unreadmarkedmail", NULL},
388 {empty_xpm , NULL, NULL, "empty" , NULL}
391 /* return newly constructed GtkPixmap from GdkPixmap */
392 GtkWidget *stock_pixmap_widget(GtkWidget *window, StockPixmap icon)
396 g_return_val_if_fail(window != NULL, NULL);
397 g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
399 if (stock_pixbuf_gdk(window, icon, &pixbuf) != -1)
400 return gtk_image_new_from_pixbuf(pixbuf);
408 gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
410 StockPixmapData *pix_d;
411 static const char *extension[]={".png", ".xpm", NULL};
417 g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
419 pix_d = &pixmaps[icon];
421 if (!pix_d->pixbuf || (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0)) {
422 GdkPixbuf *pix = NULL;
424 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
425 if (is_dir_exist(prefs_common.pixmap_theme_path)) {
426 char *icon_file_name;
428 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
433 if (is_file_exist(icon_file_name)) {
435 pix = gdk_pixbuf_new_from_file(icon_file_name, &err);
436 if (err) g_error_free(err);
439 g_free(pix_d->icon_path);
440 pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
442 g_free(icon_file_name);
446 goto try_next_extension;
449 /* even the path does not exist (deleted between two sessions), so
450 set the preferences to the internal theme */
451 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
457 if (!pix_d->pixbuf) {
458 pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) pix_d->data);
460 g_free(pix_d->icon_path);
461 pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);
465 g_return_val_if_fail(pix_d->pixbuf != NULL, -1);
468 *pixbuf = pix_d->pixbuf;
470 /* pixbuf should have one ref outstanding */
475 /* create GdkPixmap if it has not created yet */
476 gint stock_pixmap_gdk(GtkWidget *window, StockPixmap icon,
477 GdkPixmap **pixmap, GdkBitmap **mask)
479 StockPixmapData *pix_d;
480 static const char *extension[]={".png", ".xpm", NULL};
483 if (pixmap) *pixmap = NULL;
484 if (mask) *mask = NULL;
486 g_return_val_if_fail(window != NULL, -1);
487 g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
489 pix_d = &pixmaps[icon];
491 if (!pix_d->pixmap || (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0)) {
492 GdkPixmap *pix = NULL;
494 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
495 if ( is_dir_exist(prefs_common.pixmap_theme_path) ) {
496 char *icon_file_name;
498 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
503 if (is_file_exist(icon_file_name))
504 PIXMAP_CREATE_FROM_FILE(window, pix, pix_d->mask, icon_file_name);
506 g_free(pix_d->icon_path);
507 pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
509 g_free(icon_file_name);
513 goto try_next_extension;
516 /* even the path does not exist (deleted between two sessions), so
517 set the preferences to the internal theme */
518 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
524 if (!pix_d->pixmap) {
525 PIXMAP_CREATE(window, pix_d->pixmap, pix_d->mask, pix_d->data);
527 g_free(pix_d->icon_path);
528 pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);
532 g_return_val_if_fail(pix_d->pixmap != NULL, -1);
535 *pixmap = pix_d->pixmap;
542 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
546 static const char *extension[]={".png", ".xpm", NULL};
548 if ((dp = opendir(dirname)) == NULL) {
549 debug_print("dir %s not found, skipping theme scan", dirname?dirname:"(null)");
553 while ((d = readdir(dp)) != NULL) {
558 fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
560 if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
562 gboolean found = FALSE;
565 for (i = 0; i < N_STOCK_PIXMAPS && !found; i++) {
566 for (j = 0; extension[j] && !found; j++) {
567 filetoexist = g_strconcat(fullentry, G_DIR_SEPARATOR_S, pixmaps[i].file, extension[j], NULL);
568 if (is_file_exist(filetoexist)) {
569 *list = g_list_append(*list, fullentry);
575 if (i == N_STOCK_PIXMAPS)
583 GList *stock_pixmap_themes_list_new(void)
590 defaulttheme = g_strdup(DEFAULT_PIXMAP_THEME);
591 userthemes = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
592 PIXMAP_THEME_DIR, NULL);
593 systemthemes = g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
594 PIXMAP_THEME_DIR, NULL);
596 list = g_list_append(list, defaulttheme);
598 stock_pixmap_find_themes_in_dir(&list, userthemes);
599 stock_pixmap_find_themes_in_dir(&list, systemthemes);
602 g_free(systemthemes);
606 void stock_pixmap_themes_list_free(GList *list)
610 for (ptr = g_list_first(list); ptr != NULL; ptr = g_list_next(ptr))
615 gchar *stock_pixmap_get_name (StockPixmap icon)
617 g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
619 return pixmaps[icon].file;
623 StockPixmap stock_pixmap_get_icon (gchar *file)
627 for (i = 0; i < N_STOCK_PIXMAPS; i++) {
628 if (strcmp (pixmaps[i].file, file) == 0)
634 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventExpose *expose,
637 GdkDrawable *drawable = widget->window;
642 if (data->is_pixmap) {
643 g_return_val_if_fail(data->base_pixmap != NULL, FALSE);
644 g_return_val_if_fail(data->base_mask != NULL, FALSE);
646 g_return_val_if_fail(data->base_pixbuf != NULL, FALSE);
648 gc_pix = gdk_gc_new((GdkWindow *)drawable);
650 gdk_window_clear_area (drawable, expose->area.x, expose->area.y,
651 expose->area.width, expose->area.height);
653 if (data->highlight) {
654 MainWindow *mw = NULL;
656 mw = mainwindow_get_mainwindow();
657 if (mw != NULL && mw->menubar != NULL) {
658 GdkGC *gc_frame = gdk_gc_new((GdkWindow *)drawable);
659 GdkColor color = gtk_widget_get_style(mw->menubar)->base[GTK_STATE_SELECTED];
661 gdk_gc_set_foreground(gc_frame, &color);
662 gdk_gc_set_line_attributes(gc_frame, 1, GDK_LINE_SOLID,
663 GDK_CAP_BUTT, GDK_JOIN_BEVEL);
664 gdk_draw_rectangle(drawable, gc_frame, FALSE, data->border_x-2, data->border_y-2,
665 data->base_width+3, data->base_height+3);
666 g_object_unref(gc_frame);
670 if (data->is_pixmap) {
671 gdk_gc_set_tile(gc_pix, data->base_pixmap);
672 gdk_gc_set_ts_origin(gc_pix, data->border_x, data->border_y);
673 gdk_gc_set_clip_mask(gc_pix, data->base_mask);
674 gdk_gc_set_clip_origin(gc_pix, data->border_x, data->border_y);
675 gdk_gc_set_fill(gc_pix, GDK_TILED);
676 gdk_draw_rectangle(drawable, gc_pix, TRUE, data->border_x, data->border_y,
677 data->base_width, data->base_height);
679 gdk_draw_pixbuf(drawable, gc_pix, data->base_pixbuf,
680 0, 0, data->border_x, data->border_y,
681 -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
685 if (data->position != OVERLAY_NONE) {
687 switch (data->position) {
688 case OVERLAY_TOP_LEFT:
689 case OVERLAY_MID_LEFT:
690 case OVERLAY_BOTTOM_LEFT:
694 case OVERLAY_TOP_CENTER:
695 case OVERLAY_MID_CENTER:
696 case OVERLAY_BOTTOM_CENTER:
697 left = (data->base_width + data->border_x * 2 - data->overlay_width)/2;
700 case OVERLAY_TOP_RIGHT:
701 case OVERLAY_MID_RIGHT:
702 case OVERLAY_BOTTOM_RIGHT:
703 left = data->base_width + data->border_x * 2 - data->overlay_width;
709 switch (data->position) {
710 case OVERLAY_TOP_LEFT:
711 case OVERLAY_TOP_CENTER:
712 case OVERLAY_TOP_RIGHT:
716 case OVERLAY_MID_LEFT:
717 case OVERLAY_MID_CENTER:
718 case OVERLAY_MID_RIGHT:
719 top = (data->base_height + data->border_y * 2 - data->overlay_height)/2;
722 case OVERLAY_BOTTOM_LEFT:
723 case OVERLAY_BOTTOM_CENTER:
724 case OVERLAY_BOTTOM_RIGHT:
725 top = data->base_height + data->border_y * 2 - data->overlay_height;
732 if (data->position != OVERLAY_NONE) {
733 if (data->is_pixmap) {
734 g_return_val_if_fail(data->overlay_pixmap != NULL, FALSE);
735 g_return_val_if_fail(data->overlay_mask != NULL, FALSE);
736 gdk_gc_set_tile(gc_pix, data->overlay_pixmap);
737 gdk_gc_set_clip_mask(gc_pix, data->overlay_mask);
739 gdk_gc_set_ts_origin(gc_pix, left, top);
740 gdk_gc_set_clip_origin(gc_pix, left, top);
741 gdk_gc_set_fill(gc_pix, GDK_TILED);
742 gdk_draw_rectangle(drawable, gc_pix, TRUE, left, top,
743 data->overlay_width, data->overlay_height);
745 g_return_val_if_fail(data->overlay_pixbuf != NULL, FALSE);
746 gdk_draw_pixbuf(drawable, gc_pix, data->overlay_pixbuf,
748 -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
752 g_object_unref(gc_pix);
757 static void pixmap_with_overlay_destroy_cb(GtkObject *object, OverlayData *data)
759 if (data->is_pixmap) {
760 g_object_unref(data->base_pixmap);
761 g_object_unref(data->base_mask);
762 if (data->position != OVERLAY_NONE) {
763 g_object_unref(data->overlay_pixmap);
764 g_object_unref(data->overlay_mask);
767 g_object_unref(data->base_pixbuf);
768 if (data->position != OVERLAY_NONE) {
769 g_object_unref(data->overlay_pixbuf);
776 * \brief Get a widget showing one icon with another overlaid on top of it.
778 * The base icon is always centralised, the other icon can be positioned.
779 * The overlay icon is ignored if pos=OVERLAY_NONE is used
781 * \param window top-level window widget
782 * \param icon the base icon
783 * \param overlay the icon to overlay
784 * \param pos how to align the overlay widget, or OVERLAY_NONE for no overlay
785 * \param border_x size of the border around the base icon (left and right)
786 * \param border_y size of the border around the base icon (top and bottom)
788 GtkWidget *stock_pixmap_widget_with_overlay(GtkWidget *window, StockPixmap icon,
789 StockPixmap overlay, OverlayPosition pos,
790 gint border_x, gint border_y)
792 GdkPixmap *stock_pixmap = NULL;
793 GdkBitmap *stock_mask = NULL;
794 GdkPixbuf *stock_pixbuf = NULL;
795 GtkWidget *widget = NULL;
796 GtkWidget *stock_wid = NULL;
797 OverlayData *data = NULL;
799 data = g_new0(OverlayData, 1);
801 stock_wid = stock_pixmap_widget(window, icon);
803 if (gtk_image_get_storage_type(GTK_IMAGE(stock_wid)) == GTK_IMAGE_PIXMAP)
804 data->is_pixmap = TRUE;
806 data->is_pixmap = FALSE;
808 if (data->is_pixmap) {
809 gtk_image_get_pixmap(GTK_IMAGE(stock_wid), &stock_pixmap, &stock_mask);
810 g_object_ref(stock_pixmap);
811 g_object_ref(stock_mask);
812 data->base_pixmap = stock_pixmap;
813 data->base_mask = stock_mask;
814 data->base_height = stock_wid->requisition.height;
815 data->base_width = stock_wid->requisition.width;
816 gtk_widget_destroy(stock_wid);
818 if (pos == OVERLAY_NONE) {
819 data->overlay_pixmap = NULL;
820 data->overlay_mask = NULL;
822 stock_wid = stock_pixmap_widget(window, overlay);
823 gtk_image_get_pixmap(GTK_IMAGE(stock_wid), &stock_pixmap, &stock_mask);
824 g_object_ref(stock_pixmap);
825 g_object_ref(stock_mask);
826 data->overlay_pixmap = stock_pixmap;
827 data->overlay_mask = stock_mask;
828 data->overlay_height = stock_wid->requisition.height;
829 data->overlay_width = stock_wid->requisition.width;
831 gtk_widget_destroy(stock_wid);
834 data->is_pixmap = FALSE;
835 stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
836 g_object_ref(stock_pixbuf);
837 data->base_pixbuf = stock_pixbuf;
838 data->base_height = stock_wid->requisition.height;
839 data->base_width = stock_wid->requisition.width;
840 gtk_widget_destroy(stock_wid);
841 if (pos == OVERLAY_NONE) {
842 data->overlay_pixmap = NULL;
843 data->overlay_mask = NULL;
845 stock_wid = stock_pixmap_widget(window, overlay);
846 stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
847 g_object_ref(stock_pixbuf);
848 data->overlay_pixbuf = stock_pixbuf;
849 data->overlay_height = stock_wid->requisition.height;
850 data->overlay_width = stock_wid->requisition.width;
852 gtk_widget_destroy(stock_wid);
855 data->position = pos;
856 data->border_x = border_x;
857 data->border_y = border_y;
858 data->highlight = FALSE;
860 widget = gtk_drawing_area_new();
861 gtk_drawing_area_size(GTK_DRAWING_AREA(widget), data->base_width + border_x * 2,
862 data->base_height + border_y * 2);
863 g_signal_connect(G_OBJECT(widget), "expose_event",
864 G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
865 g_signal_connect(G_OBJECT(widget), "destroy",
866 G_CALLBACK(pixmap_with_overlay_destroy_cb), data);
867 g_object_set_data(G_OBJECT(widget), "highlight", &(data->highlight));