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