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