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