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