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