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