Adjust yet another addressbook icon
[claws.git] / src / stock_pixmap.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2016 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 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #include "claws-features.h"
22 #endif
23
24 #include <glib.h>
25 #include <gtk/gtk.h>
26 #include <string.h>
27 #include <dirent.h>
28 #ifdef HAVE_SVG
29 #include <librsvg/rsvg.h>
30 #include <math.h>
31 #endif
32
33 #include "defs.h"
34 #include "stock_pixmap.h"
35 #include "gtkutils.h"
36 #include "utils.h"
37 #include "prefs_common.h"
38
39 #include "pixmaps/addr_one.xpm"
40 #include "pixmaps/addr_two.xpm"
41 #include "pixmaps/address.xpm"
42 #include "pixmaps/anonymous.xpm"
43 #include "pixmaps/book.xpm"
44 #include "pixmaps/category.xpm"
45 #include "pixmaps/checkbox_off.xpm"
46 #include "pixmaps/checkbox_on.xpm"
47 #include "pixmaps/clip.xpm"
48 #include "pixmaps/clipkey.xpm"
49 #include "pixmaps/complete.xpm"
50 #include "pixmaps/continue.xpm"
51 #include "pixmaps/deleted.xpm"
52 #include "pixmaps/error.xpm"
53 #include "pixmaps/edit_extern.xpm"
54 #include "pixmaps/forwarded.xpm"
55 #include "pixmaps/group.xpm"
56 #include "pixmaps/insert_file.xpm"
57 #include "pixmaps/interface.xpm"
58 #include "pixmaps/jpilot.xpm"
59 #include "pixmaps/key.xpm"
60 #include "pixmaps/key_gpg_signed.xpm"
61 #include "pixmaps/ldap.xpm"
62 #include "pixmaps/linewrap.xpm"
63 #include "pixmaps/linewrapcurrent.xpm"
64 #include "pixmaps/mark.xpm"
65 #include "pixmaps/locked.xpm"
66 #include "pixmaps/new.xpm"
67 #include "pixmaps/replied.xpm"
68 #include "pixmaps/replied_and_forwarded.xpm"
69 #include "pixmaps/close.xpm"
70 #include "pixmaps/down_arrow.xpm"
71 #include "pixmaps/up_arrow.xpm"
72 #include "pixmaps/exec.xpm"
73 #include "pixmaps/mail_draft.xpm"
74 #include "pixmaps/mail_attach.xpm"
75 #include "pixmaps/mail_compose.xpm"
76 #include "pixmaps/mail_forward.xpm"
77 #include "pixmaps/mail_receive.xpm"
78 #include "pixmaps/mail_receive_all.xpm"
79 #include "pixmaps/mail_reply.xpm"
80 #include "pixmaps/mail_reply_to_all.xpm"
81 #include "pixmaps/mail_reply_to_author.xpm"
82 #include "pixmaps/mail_reply_to_list.xpm"
83 #include "pixmaps/mail_send.xpm"
84 #include "pixmaps/mail_send_queue.xpm"
85 #include "pixmaps/mail_sign.xpm"
86 #include "pixmaps/open_mail.xpm"
87 #include "pixmaps/news_compose.xpm"
88 #include "pixmaps/paste.xpm"
89 #include "pixmaps/preferences.xpm"
90 #include "pixmaps/properties.xpm"
91 #include "pixmaps/queue_close.xpm"
92 #include "pixmaps/queue_close_hrm.xpm"
93 #include "pixmaps/queue_open.xpm"
94 #include "pixmaps/queue_open_hrm.xpm"
95 #include "pixmaps/claws_mail_icon.xpm"
96 #include "pixmaps/claws_mail_icon_64.xpm"
97 #include "pixmaps/claws_mail_compose_logo.xpm"
98 #ifndef GENERIC_UMPC
99 #include "pixmaps/claws_mail_logo.xpm"
100 #else
101 #include "pixmaps/claws_mail_logo_small.xpm"
102 #endif
103 #include "pixmaps/address_book.xpm"
104 #include "pixmaps/unread.xpm"
105 #include "pixmaps/read.xpm"
106 #include "pixmaps/vcard.xpm"
107 #include "pixmaps/ignorethread.xpm"
108 #include "pixmaps/online.xpm"
109 #include "pixmaps/offline.xpm"
110 #include "pixmaps/notice_warn.xpm"
111 #include "pixmaps/notice_error.xpm"
112 #include "pixmaps/notice_note.xpm"
113 #include "pixmaps/quicksearch.xpm"
114 #include "pixmaps/clip_gpg_signed.xpm"
115 #include "pixmaps/gpg_signed.xpm"
116 #include "pixmaps/go_folders.xpm"
117 #include "pixmaps/mime_text_plain.xpm"
118 #include "pixmaps/mime_text_html.xpm"
119 #include "pixmaps/mime_text_patch.xpm"
120 #include "pixmaps/mime_application.xpm"
121 #include "pixmaps/mime_image.xpm"
122 #include "pixmaps/mime_audio.xpm"
123 #include "pixmaps/mime_text_enriched.xpm"
124 #include "pixmaps/mime_unknown.xpm"
125 #include "pixmaps/mime_pdf.xpm"
126 #include "pixmaps/mime_ps.xpm"
127 #include "pixmaps/mime_calendar.xpm"
128 #include "pixmaps/mime_pgpsig.xpm"
129 #include "pixmaps/printer.xpm"
130 #include "pixmaps/printer_btn.xpm"
131 #include "pixmaps/privacy_signed.xpm"
132 #include "pixmaps/privacy_passed.xpm"
133 #include "pixmaps/privacy_failed.xpm"
134 #include "pixmaps/privacy_unknown.xpm"
135 #include "pixmaps/privacy_expired.xpm"
136 #include "pixmaps/privacy_warn.xpm"
137 #include "pixmaps/privacy_emblem_encrypted.xpm"
138 #include "pixmaps/privacy_emblem_signed.xpm"
139 #include "pixmaps/privacy_emblem_passed.xpm"
140 #include "pixmaps/privacy_emblem_failed.xpm"
141 #include "pixmaps/privacy_emblem_warn.xpm"
142 #include "pixmaps/mime_message.xpm"
143 #include "pixmaps/address_search.xpm"
144 #include "pixmaps/check_spelling.xpm"
145 #include "pixmaps/dir_close.xpm"
146 #include "pixmaps/dir_close_hrm.xpm"
147 #include "pixmaps/dir_open.xpm"
148 #include "pixmaps/dir_open_hrm.xpm"
149 #include "pixmaps/inbox_open.xpm"
150 #include "pixmaps/inbox_open_hrm.xpm"
151 #include "pixmaps/inbox_close.xpm"
152 #include "pixmaps/inbox_close_hrm.xpm"
153 #include "pixmaps/outbox_open.xpm"
154 #include "pixmaps/outbox_open_hrm.xpm"
155 #include "pixmaps/outbox_close.xpm"
156 #include "pixmaps/outbox_close_hrm.xpm"
157 #include "pixmaps/trash_open.xpm"
158 #include "pixmaps/trash_close.xpm"
159 #include "pixmaps/delete_btn.xpm"
160 #include "pixmaps/delete_dup_btn.xpm"
161 #include "pixmaps/cancel.xpm"
162 #include "pixmaps/trash_btn.xpm"
163 #include "pixmaps/trash_open_hrm.xpm"
164 #include "pixmaps/trash_close_hrm.xpm"
165 #include "pixmaps/drafts_close.xpm"
166 #include "pixmaps/drafts_open.xpm"
167 #include "pixmaps/dir_close_mark.xpm"
168 #include "pixmaps/dir_close_hrm_mark.xpm"
169 #include "pixmaps/dir_open_mark.xpm"
170 #include "pixmaps/dir_open_hrm_mark.xpm"
171 #include "pixmaps/inbox_open_mark.xpm"
172 #include "pixmaps/inbox_open_hrm_mark.xpm"
173 #include "pixmaps/inbox_close_mark.xpm"
174 #include "pixmaps/inbox_close_hrm_mark.xpm"
175 #include "pixmaps/outbox_open_mark.xpm"
176 #include "pixmaps/outbox_open_hrm_mark.xpm"
177 #include "pixmaps/outbox_close_mark.xpm"
178 #include "pixmaps/outbox_close_hrm_mark.xpm"
179 #include "pixmaps/trash_open_mark.xpm"
180 #include "pixmaps/trash_close_mark.xpm"
181 #include "pixmaps/queue_close_mark.xpm"
182 #include "pixmaps/queue_close_hrm_mark.xpm"
183 #include "pixmaps/queue_open_mark.xpm"
184 #include "pixmaps/queue_open_hrm_mark.xpm"
185 #include "pixmaps/trash_open_hrm_mark.xpm"
186 #include "pixmaps/trash_close_hrm_mark.xpm"
187 #include "pixmaps/drafts_close_mark.xpm"
188 #include "pixmaps/drafts_open_mark.xpm"
189 #include "pixmaps/dir_noselect_close.xpm"
190 #include "pixmaps/dir_noselect_close_mark.xpm"
191 #include "pixmaps/dir_noselect_open.xpm"
192 #include "pixmaps/dir_subs_close_mark.xpm"
193 #include "pixmaps/dir_subs_close.xpm"
194 #include "pixmaps/dir_subs_open.xpm"
195 #include "pixmaps/spam.xpm"
196 #include "pixmaps/spam_btn.xpm"
197 #include "pixmaps/ham_btn.xpm"
198 #include "pixmaps/moved.xpm"
199 #include "pixmaps/copied.xpm"
200 #include "pixmaps/selection.xpm"
201 #include "pixmaps/watchthread.xpm"
202 #include "pixmaps/empty.xpm"
203 #include "pixmaps/tray_newmail_offline.xpm"
204 #include "pixmaps/tray_newmail.xpm"
205 #include "pixmaps/tray_newmarkedmail_offline.xpm"
206 #include "pixmaps/tray_newmarkedmail.xpm"
207 #include "pixmaps/tray_nomail_offline.xpm"
208 #include "pixmaps/tray_nomail.xpm"
209 #include "pixmaps/tray_unreadmail_offline.xpm"
210 #include "pixmaps/tray_unreadmail.xpm"
211 #include "pixmaps/tray_unreadmarkedmail_offline.xpm"
212 #include "pixmaps/tray_unreadmarkedmail.xpm"
213 #include "pixmaps/doc_index.xpm"
214 #include "pixmaps/doc_index_close.xpm"
215 #include "pixmaps/doc_info.xpm"
216 #include "pixmaps/first_arrow.xpm"
217 #include "pixmaps/last_arrow.xpm"
218 #include "pixmaps/left_arrow.xpm"
219 #include "pixmaps/right_arrow.xpm"
220 #include "pixmaps/rotate_left.xpm"
221 #include "pixmaps/rotate_right.xpm"
222 #include "pixmaps/zoom_fit.xpm"
223 #include "pixmaps/zoom_in.xpm"
224 #include "pixmaps/zoom_out.xpm"
225 #include "pixmaps/zoom_width.xpm"
226 #include "pixmaps/mark_ignorethread.xpm"
227 #include "pixmaps/mark_watchthread.xpm"
228 #include "pixmaps/mark_mark.xpm"
229 #include "pixmaps/mark_unmark.xpm"
230 #include "pixmaps/mark_locked.xpm"
231 #include "pixmaps/mark_unlocked.xpm"
232 #include "pixmaps/mark_allread.xpm"
233 #include "pixmaps/mark_allunread.xpm"
234 #include "pixmaps/mark_read.xpm"
235 #include "pixmaps/mark_unread.xpm"
236
237 typedef struct _StockPixmapData StockPixmapData;
238
239 struct _StockPixmapData
240 {
241         gchar **data;
242         cairo_surface_t *pixmap;
243         cairo_pattern_t *mask;
244         gchar *file;
245         gchar *icon_path;
246         GdkPixbuf *pixbuf;
247 };
248
249 typedef struct _OverlayData OverlayData;
250
251 struct _OverlayData
252 {
253         gboolean is_pixmap;
254         cairo_surface_t *base_pixmap;
255         cairo_surface_t *overlay_pixmap;
256
257         GdkPixbuf *base_pixbuf;
258         GdkPixbuf *overlay_pixbuf;
259
260         guint base_height;
261         guint base_width;
262         guint overlay_height;
263         guint overlay_width;
264         OverlayPosition position;
265         gint border_x;
266         gint border_y;
267         gboolean highlight;
268 };
269
270 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname);
271
272 static StockPixmapData pixmaps[] =
273 {
274     {addr_one_xpm                     , NULL, NULL, "addr_one", NULL, NULL},
275     {addr_two_xpm                     , NULL, NULL, "addr_two", NULL, NULL},
276     {address_xpm                      , NULL, NULL, "address", NULL, NULL},
277     {address_book_xpm                 , NULL, NULL, "address_book", NULL, NULL},
278     {address_search_xpm               , NULL, NULL, "address_search", NULL, NULL},
279     {anonymous_xpm                    , NULL, NULL, "anonymous", NULL, NULL},
280     {book_xpm                         , NULL, NULL, "book", NULL, NULL},
281     {category_xpm                     , NULL, NULL, "category", NULL, NULL},
282     {checkbox_off_xpm                 , NULL, NULL, "checkbox_off", NULL, NULL},
283     {checkbox_on_xpm                  , NULL, NULL, "checkbox_on", NULL, NULL},
284     {check_spelling_xpm               , NULL, NULL, "check_spelling", NULL, NULL},
285     {clip_xpm                         , NULL, NULL, "clip", NULL, NULL},
286     {clipkey_xpm                      , NULL, NULL, "clipkey", NULL, NULL},
287     {clip_gpg_signed_xpm              , NULL, NULL, "clip_gpg_signed", NULL, NULL},
288     {close_xpm                        , NULL, NULL, "close", NULL, NULL},
289     {complete_xpm                     , NULL, NULL, "complete", NULL, NULL},
290     {continue_xpm                     , NULL, NULL, "continue", NULL, NULL},
291     {deleted_xpm                      , NULL, NULL, "deleted", NULL, NULL},
292     {dir_close_xpm                    , NULL, NULL, "dir_close", NULL, NULL},
293     {dir_close_hrm_xpm                , NULL, NULL, "dir_close_hrm", NULL, NULL},
294     {dir_open_xpm                     , NULL, NULL, "dir_open", NULL, NULL},
295     {dir_open_hrm_xpm                 , NULL, NULL, "dir_open_hrm", NULL, NULL},
296     {dir_close_mark_xpm               , NULL, NULL, "dir_close_mark", NULL, NULL},
297     {dir_close_hrm_mark_xpm           , NULL, NULL, "dir_close_hrm_mark", NULL, NULL},
298     {dir_open_mark_xpm                , NULL, NULL, "dir_open_mark", NULL, NULL},
299     {dir_open_hrm_mark_xpm            , NULL, NULL, "dir_open_hrm_mark", NULL, NULL},
300     {down_arrow_xpm                   , NULL, NULL, "down_arrow", NULL, NULL},
301     {up_arrow_xpm                     , NULL, NULL, "up_arrow", NULL, NULL},
302     {edit_extern_xpm                  , NULL, NULL, "edit_extern", NULL, NULL},
303     {error_xpm                        , NULL, NULL, "error", NULL, NULL},
304     {exec_xpm                         , NULL, NULL, "exec", NULL, NULL},
305     {forwarded_xpm                    , NULL, NULL, "forwarded", NULL, NULL},
306     {group_xpm                        , NULL, NULL, "group", NULL, NULL},
307     {ignorethread_xpm                 , NULL, NULL, "ignorethread", NULL, NULL},
308     {inbox_close_xpm                  , NULL, NULL, "inbox_close", NULL, NULL},
309     {inbox_close_hrm_xpm              , NULL, NULL, "inbox_close_hrm", NULL, NULL},
310     {inbox_open_xpm                   , NULL, NULL, "inbox_open", NULL, NULL},
311     {inbox_open_hrm_xpm               , NULL, NULL, "inbox_open_hrm", NULL, NULL},
312     {inbox_close_mark_xpm             , NULL, NULL, "inbox_close_mark", NULL, NULL},
313     {inbox_close_hrm_mark_xpm         , NULL, NULL, "inbox_close_hrm_mark", NULL, NULL},
314     {inbox_open_mark_xpm              , NULL, NULL, "inbox_open_mark", NULL, NULL},
315     {inbox_open_hrm_mark_xpm          , NULL, NULL, "inbox_open_hrm_mark", NULL, NULL},
316     {insert_file_xpm                  , NULL, NULL, "insert_file", NULL, NULL},
317     {interface_xpm                    , NULL, NULL, "interface", NULL, NULL},
318     {jpilot_xpm                       , NULL, NULL, "jpilot", NULL, NULL},
319     {key_xpm                          , NULL, NULL, "key", NULL, NULL},
320     {key_gpg_signed_xpm               , NULL, NULL, "key_gpg_signed", NULL, NULL},
321     {ldap_xpm                         , NULL, NULL, "ldap", NULL, NULL},
322     {linewrapcurrent_xpm              , NULL, NULL, "linewrapcurrent", NULL, NULL},
323     {linewrap_xpm                     , NULL, NULL, "linewrap", NULL, NULL},
324     {locked_xpm                       , NULL, NULL, "locked", NULL, NULL},
325     {mail_draft_xpm                   , NULL, NULL, "mail_draft", NULL, NULL},
326     {mail_attach_xpm                  , NULL, NULL, "mail_attach", NULL, NULL},
327     {mail_compose_xpm                 , NULL, NULL, "mail_compose", NULL, NULL},
328     {mail_forward_xpm                 , NULL, NULL, "mail_forward", NULL, NULL},
329     {mail_receive_xpm                 , NULL, NULL, "mail_receive", NULL, NULL},
330     {mail_receive_all_xpm             , NULL, NULL, "mail_receive_all", NULL, NULL},
331     {mail_reply_xpm                   , NULL, NULL, "mail_reply", NULL, NULL},
332     {mail_reply_to_all_xpm            , NULL, NULL, "mail_reply_to_all", NULL, NULL},
333     {mail_reply_to_author_xpm         , NULL, NULL, "mail_reply_to_author", NULL, NULL},
334     {mail_reply_to_list_xpm           , NULL, NULL, "mail_reply_to_list", NULL, NULL},
335     {mail_send_xpm                    , NULL, NULL, "mail_send", NULL, NULL},
336     {mail_send_queue_xpm              , NULL, NULL, "mail_send_queue", NULL, NULL},
337     {mail_sign_xpm                    , NULL, NULL, "mail_sign", NULL, NULL},
338     {open_mail_xpm                    , NULL, NULL, "open_mail", NULL, NULL},
339     {mark_xpm                         , NULL, NULL, "mark", NULL, NULL},
340     {new_xpm                          , NULL, NULL, "new", NULL, NULL},
341     {news_compose_xpm                 , NULL, NULL, "news_compose", NULL, NULL},
342     {outbox_close_xpm                 , NULL, NULL, "outbox_close", NULL, NULL},
343     {outbox_close_hrm_xpm             , NULL, NULL, "outbox_close_hrm", NULL, NULL},
344     {outbox_open_xpm                  , NULL, NULL, "outbox_open", NULL, NULL},
345     {outbox_open_hrm_xpm              , NULL, NULL, "outbox_open_hrm", NULL, NULL},
346     {outbox_close_mark_xpm            , NULL, NULL, "outbox_close_mark", NULL, NULL},
347     {outbox_close_hrm_mark_xpm        , NULL, NULL, "outbox_close_hrm_mark", NULL, NULL},
348     {outbox_open_mark_xpm             , NULL, NULL, "outbox_open_mark", NULL, NULL},
349     {outbox_open_hrm_mark_xpm         , NULL, NULL, "outbox_open_hrm_mark", NULL, NULL},
350     {replied_xpm                      , NULL, NULL, "replied", NULL, NULL},
351     {replied_and_forwarded_xpm        , NULL, NULL, "replied_and_forwarded", NULL, NULL},
352     {paste_xpm                        , NULL, NULL, "paste", NULL, NULL},
353     {preferences_xpm                  , NULL, NULL, "preferences", NULL, NULL},
354     {properties_xpm                   , NULL, NULL, "properties", NULL, NULL},
355     {queue_close_xpm                  , NULL, NULL, "queue_close", NULL, NULL},
356     {queue_close_hrm_xpm              , NULL, NULL, "queue_close_hrm", NULL, NULL},
357     {queue_open_xpm                   , NULL, NULL, "queue_open", NULL, NULL},
358     {queue_open_hrm_xpm               , NULL, NULL, "queue_open_hrm", NULL, NULL},
359     {trash_open_xpm                   , NULL, NULL, "trash_open", NULL, NULL},
360     {trash_open_hrm_xpm               , NULL, NULL, "trash_open_hrm", NULL, NULL},
361     {trash_close_xpm                  , NULL, NULL, "trash_close", NULL, NULL},
362     {trash_close_hrm_xpm              , NULL, NULL, "trash_close_hrm", NULL, NULL},
363     {queue_close_mark_xpm             , NULL, NULL, "queue_close_mark", NULL, NULL},
364     {queue_close_hrm_mark_xpm         , NULL, NULL, "queue_close_hrm_mark", NULL, NULL},
365     {queue_open_mark_xpm              , NULL, NULL, "queue_open_mark", NULL, NULL},
366     {queue_open_hrm_mark_xpm          , NULL, NULL, "queue_open_hrm_mark", NULL, NULL},
367     {trash_open_mark_xpm              , NULL, NULL, "trash_open_mark", NULL, NULL},
368     {trash_open_hrm_mark_xpm          , NULL, NULL, "trash_open_hrm_mark", NULL, NULL},
369     {trash_close_mark_xpm             , NULL, NULL, "trash_close_mark", NULL, NULL},
370     {trash_close_hrm_mark_xpm         , NULL, NULL, "trash_close_hrm_mark", NULL, NULL},
371     {unread_xpm                       , NULL, NULL, "unread", NULL, NULL},
372     {vcard_xpm                        , NULL, NULL, "vcard", NULL, NULL},
373     {online_xpm                       , NULL, NULL, "online", NULL, NULL},
374     {offline_xpm                      , NULL, NULL, "offline", NULL, NULL},
375     {notice_warn_xpm                  , NULL, NULL, "notice_warn",  NULL, NULL},
376     {notice_error_xpm                 , NULL, NULL, "notice_error",  NULL, NULL},
377     {notice_note_xpm                  , NULL, NULL, "notice_note",  NULL, NULL},
378     {quicksearch_xpm                  , NULL, NULL, "quicksearch",  NULL, NULL},
379     {gpg_signed_xpm                   , NULL, NULL, "gpg_signed", NULL, NULL},
380     {go_folders_xpm                   , NULL, NULL, "go_folders", NULL, NULL},
381     {drafts_close_xpm                 , NULL, NULL, "drafts_close", NULL, NULL},
382     {drafts_open_xpm                  , NULL, NULL, "drafts_open", NULL, NULL},
383     {drafts_close_mark_xpm            , NULL, NULL, "drafts_close_mark", NULL, NULL},
384     {drafts_open_mark_xpm             , NULL, NULL, "drafts_open_mark", NULL, NULL},
385     {mime_text_plain_xpm              , NULL, NULL, "mime_text_plain", NULL, NULL},
386     {mime_text_html_xpm               , NULL, NULL, "mime_text_html", NULL, NULL},
387     {mime_text_patch_xpm              , NULL, NULL, "mime_text_patch", NULL, NULL},
388     {mime_application_xpm             , NULL, NULL, "mime_application", NULL, NULL},
389     {mime_image_xpm                   , NULL, NULL, "mime_image", NULL, NULL},
390     {mime_audio_xpm                   , NULL, NULL, "mime_audio", NULL, NULL},
391     {mime_text_enriched_xpm           , NULL, NULL, "mime_text_enriched", NULL, NULL},
392     {mime_unknown_xpm                 , NULL, NULL, "mime_unknown", NULL, NULL},
393     {mime_pdf_xpm                     , NULL, NULL, "mime_pdf", NULL, NULL},
394     {mime_ps_xpm                      , NULL, NULL, "mime_ps", NULL, NULL},
395     {mime_calendar_xpm                , NULL, NULL, "mime_calendar", NULL, NULL},
396     {mime_pgpsig_xpm                  , NULL, NULL, "mime_pgpsig", NULL, NULL},
397     {printer_btn_xpm                  , NULL, NULL, "printer_btn", NULL, NULL},
398     {printer_xpm                      , NULL, NULL, "printer", NULL, NULL},
399     {privacy_signed_xpm               , NULL, NULL, "privacy_signed", NULL, NULL},
400     {privacy_passed_xpm               , NULL, NULL, "privacy_passed", NULL, NULL},
401     {privacy_failed_xpm               , NULL, NULL, "privacy_failed", NULL, NULL},
402     {privacy_unknown_xpm              , NULL, NULL, "privacy_unknown", NULL, NULL},
403     {privacy_expired_xpm              , NULL, NULL, "privacy_expired", NULL, NULL},
404     {privacy_warn_xpm                 , NULL, NULL, "privacy_warn", NULL, NULL},
405     {privacy_emblem_encrypted_xpm     , NULL, NULL, "privacy_emblem_encrypted", NULL, NULL},
406     {privacy_emblem_signed_xpm        , NULL, NULL, "privacy_emblem_signed", NULL, NULL},
407     {privacy_emblem_passed_xpm        , NULL, NULL, "privacy_emblem_passed", NULL, NULL},
408     {privacy_emblem_failed_xpm        , NULL, NULL, "privacy_emblem_failed", NULL, NULL},
409     {privacy_emblem_warn_xpm          , NULL, NULL, "privacy_emblem_warn", NULL, NULL},
410     {mime_message_xpm                 , NULL, NULL, "mime_message", NULL, NULL},
411     {claws_mail_icon_xpm              , NULL, NULL, "claws_mail_icon", NULL, NULL},
412     {claws_mail_icon_64_xpm           , NULL, NULL, "claws_mail_icon_64", NULL, NULL},
413     {read_xpm                         , NULL, NULL, "read", NULL, NULL},
414     {delete_btn_xpm                   , NULL, NULL, "delete_btn", NULL, NULL},
415     {delete_dup_btn_xpm               , NULL, NULL, "delete_dup_btn", NULL, NULL},
416     {cancel_xpm                       , NULL, NULL, "cancel", NULL, NULL},
417     {trash_btn_xpm                    , NULL, NULL, "trash_btn", NULL, NULL},
418     {claws_mail_compose_logo_xpm      , NULL, NULL, "claws_mail_compose_logo", NULL, NULL},
419 #ifndef GENERIC_UMPC
420     {claws_mail_logo_xpm              , NULL, NULL, "claws_mail_logo", NULL, NULL},
421 #else
422     {claws_mail_logo_small_xpm        , NULL, NULL, "claws_mail_logo_small", NULL, NULL},
423 #endif
424     {dir_noselect_close_xpm           , NULL, NULL, "dir_noselect_close", NULL, NULL},
425     {dir_noselect_close_mark_xpm      , NULL, NULL, "dir_noselect_close_mark", NULL, NULL},
426     {dir_noselect_open_xpm            , NULL, NULL, "dir_noselect_open", NULL, NULL},
427     {dir_subs_close_mark_xpm          , NULL, NULL, "dir_subs_close_mark", NULL, NULL},
428     {dir_subs_close_xpm               , NULL, NULL, "dir_subs_close", NULL, NULL},
429     {dir_subs_open_xpm                , NULL, NULL, "dir_subs_open", NULL, NULL},
430     {spam_xpm                         , NULL, NULL, "spam", NULL, NULL},
431     {spam_btn_xpm                     , NULL, NULL, "spam_btn", NULL, NULL},
432     {ham_btn_xpm                      , NULL, NULL, "ham_btn", NULL, NULL},
433     {moved_xpm                        , NULL, NULL, "moved", NULL, NULL},
434     {copied_xpm                       , NULL, NULL, "copied", NULL, NULL},
435     {selection_xpm                    , NULL, NULL, "selection", NULL, NULL},
436     {watchthread_xpm                  , NULL, NULL, "watchthread", NULL, NULL},
437     {tray_newmail_offline_xpm         , NULL, NULL, "tray_newmail_offline", NULL, NULL},
438     {tray_newmail_xpm                 , NULL, NULL, "tray_newmail", NULL, NULL},
439     {tray_newmarkedmail_offline_xpm   , NULL, NULL, "tray_newmarkedmail_offline", NULL, NULL},
440     {tray_newmarkedmail_xpm           , NULL, NULL, "tray_newmarkedmail", NULL, NULL},
441     {tray_nomail_offline_xpm          , NULL, NULL, "tray_nomail_offline", NULL, NULL},
442     {tray_nomail_xpm                  , NULL, NULL, "tray_nomail", NULL, NULL},
443     {tray_unreadmail_offline_xpm      , NULL, NULL, "tray_unreadmail_offline", NULL, NULL},
444     {tray_unreadmail_xpm              , NULL, NULL, "tray_unreadmail", NULL, NULL},
445     {tray_unreadmarkedmail_offline_xpm, NULL, NULL, "tray_unreadmarkedmail_offline", NULL, NULL},
446     {tray_unreadmarkedmail_xpm        , NULL, NULL, "tray_unreadmarkedmail", NULL, NULL},
447     {doc_index_xpm                    , NULL, NULL, "doc_index", NULL, NULL},
448     {doc_index_close_xpm              , NULL, NULL, "doc_index_close", NULL, NULL},
449     {doc_info_xpm                     , NULL, NULL, "doc_info", NULL, NULL},
450     {first_arrow_xpm                  , NULL, NULL, "first_arrow", NULL, NULL},
451     {last_arrow_xpm                   , NULL, NULL, "last_arrow", NULL, NULL},
452     {left_arrow_xpm                   , NULL, NULL, "left_arrow", NULL, NULL},
453     {right_arrow_xpm                  , NULL, NULL, "right_arrow", NULL, NULL},
454     {rotate_left_xpm                  , NULL, NULL, "rotate_left", NULL, NULL},
455     {rotate_right_xpm                 , NULL, NULL, "rotate_right", NULL, NULL},
456     {zoom_fit_xpm                     , NULL, NULL, "zoom_fit", NULL, NULL},
457     {zoom_in_xpm                      , NULL, NULL, "zoom_in", NULL, NULL},
458     {zoom_out_xpm                     , NULL, NULL, "zoom_out", NULL, NULL},
459     {zoom_width_xpm                   , NULL, NULL, "zoom_width", NULL, NULL},
460     {mark_ignorethread_xpm            , NULL, NULL, "mark_ignorethread", NULL, NULL},
461     {mark_watchthread_xpm             , NULL, NULL, "mark_watchthread", NULL, NULL},
462     {mark_mark_xpm                    , NULL, NULL, "mark_mark", NULL, NULL},
463     {mark_unmark_xpm                  , NULL, NULL, "mark_unmark", NULL, NULL},
464     {mark_locked_xpm                  , NULL, NULL, "mark_locked", NULL, NULL},
465     {mark_unlocked_xpm                , NULL, NULL, "mark_unlocked", NULL, NULL},
466     {mark_allread_xpm                 , NULL, NULL, "mark_allread", NULL, NULL},
467     {mark_allunread_xpm               , NULL, NULL, "mark_allunread", NULL, NULL},
468     {mark_read_xpm                    , NULL, NULL, "mark_read", NULL, NULL},
469     {mark_unread_xpm                  , NULL, NULL, "mark_unread", NULL, NULL},
470     {empty_xpm                        , NULL, NULL, "empty", NULL, NULL}
471 };
472
473 /* Supported theme extensions */
474 static const char *extension[] = {
475         ".png",
476         ".xpm",
477 #ifdef HAVE_SVG
478         ".svg",
479 #endif
480         NULL
481 };
482
483 /* return current supported extensions */
484 const char **stock_pixmap_theme_extensions(void)
485 {
486         return extension;
487 }
488
489 /* return newly constructed GtkPixmap from GdkPixmap */
490 GtkWidget *stock_pixmap_widget(StockPixmap icon)
491 {
492         GdkPixbuf *pixbuf;
493
494         cm_return_val_if_fail(icon < N_STOCK_PIXMAPS, NULL);
495
496         if (stock_pixbuf_gdk(icon, &pixbuf) != -1)
497                 return gtk_image_new_from_pixbuf(pixbuf);
498
499         return NULL;
500 }
501
502 #ifdef HAVE_SVG
503 /*
504  * Renders a SVG into a Cairo context at the given dimensions keeping
505  * the aspect ratio.
506  *
507  * Adapted from https://developer.gnome.org/rsvg/2.40/RsvgHandle.html
508  * #rsvg-handle-set-size-callback
509  */
510 void render_scaled_proportionally(RsvgHandle *handle, cairo_t *cr, int width, int height)
511 {
512         RsvgDimensionData dimensions;
513         double x_factor, y_factor;
514         double scale_factor;
515
516         rsvg_handle_get_dimensions(handle, &dimensions);
517
518         x_factor = (double) width / dimensions.width;
519         y_factor = (double) height / dimensions.height;
520
521         scale_factor = MIN(x_factor, y_factor);
522
523         cairo_scale(cr, scale_factor, scale_factor);
524
525         rsvg_handle_render_cairo(handle, cr);
526 }
527
528 /*
529  * Generates a new Pixbuf from a Cairo context of the given dimensions.
530  *
531  * Adapted from https://gist.github.com/bert/985903
532  */
533 GdkPixbuf *pixbuf_from_cairo(cairo_t *cr, gboolean alpha, int width, int height)
534 {
535         gint p_stride, /* Pixbuf stride value */
536              p_n_channels, /* RGB -> 3, RGBA -> 4 */
537              s_stride; /* Surface stride value */
538         guchar *p_pixels, /* Pixbuf's pixel data */
539                *s_pixels; /* Surface's pixel data */
540         cairo_surface_t *surface; /* Temporary image surface */
541         GdkPixbuf *pixbuf; /* Returned pixbuf */
542
543         /* Create pixbuf */
544         pixbuf = gdk_pixbuf_new
545                         (GDK_COLORSPACE_RGB, alpha, 8, width, height);
546         if (pixbuf == NULL) {
547                 g_warning("failed to create a new %d x %d pixbuf", width, height);
548                 return NULL;
549         }
550         /* Obtain surface from where pixel values will be copied */
551         surface = cairo_get_target(cr);
552         if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
553                 g_warning("invalid cairo surface for copying");
554                 return NULL;
555         }
556         /* Inspect pixbuf */
557         g_object_get(G_OBJECT(pixbuf),
558                 "rowstride", &p_stride,
559                 "n-channels", &p_n_channels,
560                 "pixels", &p_pixels,
561                 NULL);
562         /* and surface */
563         s_stride = cairo_image_surface_get_stride(surface);
564         s_pixels = cairo_image_surface_get_data(surface);
565
566         /* Copy pixel data from surface to pixbuf */
567         while (height--) {
568                 gint i;
569                 guchar *p_iter = p_pixels, *s_iter = s_pixels;
570                 for (i = 0; i < width; i++) {
571 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
572                         /* Pixbuf: RGB(A) - Surface: BGRA */
573                         gdouble alpha_factor = (gdouble)0xff / s_iter[3];
574                         p_iter[0] = (guchar)( s_iter[2] * alpha_factor + .5 );
575                         p_iter[1] = (guchar)( s_iter[1] * alpha_factor + .5 );
576                         p_iter[2] = (guchar)( s_iter[0] * alpha_factor + .5 );
577                         if (p_n_channels == 4)
578                                  p_iter[3] = s_iter[3];
579 #elif G_BYTE_ORDER == G_BIG_ENDIAN
580                         /* Pixbuf: RGB(A) - Surface: ARGB */
581                         gdouble alpha_factor = (gdouble)0xff / s_iter[0];
582                         p_iter[0] = (guchar)( s_iter[1] * alpha_factor + .5 );
583                         p_iter[1] = (guchar)( s_iter[2] * alpha_factor + .5 );
584                         p_iter[2] = (guchar)( s_iter[3] * alpha_factor + .5 );
585                         if (p_n_channels == 4)
586                                 p_iter[3] = s_iter[0];
587 #else /* PDP endianness */
588                         /* Pixbuf: RGB(A) - Surface: RABG */
589                         gdouble alpha_factor = (gdouble)0xff / s_iter[1];
590                         p_iter[0] = (guchar)( s_iter[0] * alpha_factor + .5 );
591                         p_iter[1] = (guchar)( s_iter[3] * alpha_factor + .5 );
592                         p_iter[2] = (guchar)( s_iter[2] * alpha_factor + .5 );
593                         if (p_n_channels == 4)
594                                 p_iter[3] = s_iter[1];
595 #endif
596                         s_iter += 4;
597                         p_iter += p_n_channels;
598                 }
599                 s_pixels += s_stride;
600                 p_pixels += p_stride;
601         }
602         /* Destroy context */
603         cairo_destroy(cr);
604
605         return pixbuf;
606 }
607
608 /*
609  * Renders a SVG file into a pixbuf with the dimensions of the
610  * given pixmap data (optionally with alpha channel).
611  */
612 GdkPixbuf *pixbuf_from_svg_like_icon(char *filename, GError **error, StockPixmapData *icondata, gboolean alpha)
613 {
614         int width, height;
615         cairo_surface_t *surface;
616         cairo_t *context;
617         RsvgHandle *handle;
618
619         cm_return_val_if_fail(filename != NULL, NULL);
620         cm_return_val_if_fail(icondata != NULL, NULL);
621
622         /* load SVG file */
623         handle = rsvg_handle_new_from_file(filename, error);
624         if (handle == NULL) {
625                 g_warning("failed loading SVG '%s': %s (%d)", filename,
626                                 (*error)->message, (*error)->code);
627                 return NULL;
628         }
629
630         /* scale dimensions */
631         if (prefs_common.enable_pixmap_scaling) {
632                 /* default is pixmap icon size */
633                 if (sscanf((icondata->data)[0], "%d %d ", &width, &height) != 2) {
634                         g_warning("failed reading icondata width and height");
635                         return NULL;
636                 }
637                 /* which can be modified by some factor */
638                 if (prefs_common.pixmap_scaling_ppi > 0) {
639                         gdouble factor = (gdouble) prefs_common.pixmap_scaling_ppi / MIN_PPI;
640                         width = (int) floor(factor * width);
641                         height = (int) floor(factor * height);
642                 }
643         } else { /* render using SVG size */
644                 RsvgDimensionData dimension;
645
646                 rsvg_handle_get_dimensions (handle, &dimension);
647                 width = dimension.width;
648                 height = dimension.height;
649         }
650
651         /* create drawing context */
652         surface = cairo_image_surface_create(
653                         alpha? CAIRO_FORMAT_ARGB32: CAIRO_FORMAT_RGB24,
654                         width, height);
655         if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
656                 g_warning("failed to create a cairo surface: %s",
657                                 cairo_status_to_string(cairo_surface_status(surface)));
658                 g_object_unref(handle);
659                 return NULL;
660         }
661         context = cairo_create(surface);
662         cairo_surface_destroy(surface);
663         if (cairo_status(context) != CAIRO_STATUS_SUCCESS) {
664                 g_warning("failed to create a cairo context: %s",
665                                 cairo_status_to_string(cairo_status(context)));
666                 cairo_destroy(context);
667                 return NULL;
668         }
669         /* render SVG */
670         render_scaled_proportionally(handle, context, width, height);
671         /* build result and destroy context */
672         return pixbuf_from_cairo(context, alpha, width, height);
673 }
674 #endif
675
676 /*!
677  *\brief
678  */
679 gint stock_pixbuf_gdk(StockPixmap icon, GdkPixbuf **pixbuf)
680 {
681         StockPixmapData *pix_d;
682         int i = 0;
683         gboolean theme_changed = FALSE;
684
685         if (pixbuf)
686                 *pixbuf = NULL;
687
688         cm_return_val_if_fail(icon < N_STOCK_PIXMAPS, -1);
689
690         pix_d = &pixmaps[icon];
691
692         theme_changed = (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0);
693         if (!pix_d->pixbuf || theme_changed) {
694                 GdkPixbuf *pix = NULL;
695
696                 if (theme_changed && pix_d->pixmap) {
697                         g_object_unref(pix_d->pixmap);
698                         pix_d->pixmap = NULL;
699                 }
700
701                 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
702                         if (is_dir_exist(prefs_common.pixmap_theme_path)) {
703                                 char *icon_file_name;
704 try_next_extension:
705                                 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
706                                                              G_DIR_SEPARATOR_S,
707                                                              pix_d->file,
708                                                              extension[i],
709                                                              NULL);
710                                 if (is_file_exist(icon_file_name)) {
711                                         GError *err = NULL;
712 #ifdef HAVE_SVG
713                                         if (!strncmp(extension[i], ".svg", 4)) {
714                                                 pix = pixbuf_from_svg_like_icon(icon_file_name, &err, pix_d,
715                                                                 prefs_common.enable_alpha_svg);
716                                         } else {
717                                                 pix = gdk_pixbuf_new_from_file(icon_file_name, &err);
718                                         }
719 #else
720                                         pix = gdk_pixbuf_new_from_file(icon_file_name, &err);
721 #endif
722                                         if (err) g_error_free(err);
723                                 }
724                                 if (pix) {
725                                         g_free(pix_d->icon_path);
726                                         pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
727                                 }
728                                 g_free(icon_file_name);
729                                 if (!pix) {
730                                         i++;
731                                         if (extension[i])
732                                                 goto try_next_extension;
733                                 }
734                         } else {
735                                 /* even the path does not exist (deleted between two sessions), so
736                                 set the preferences to the internal theme */
737                                 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
738                         }
739                 }
740                 pix_d->pixbuf = pix;
741         }
742
743         if (!pix_d->pixbuf) {
744                 pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) pix_d->data);
745                 if (pix_d->pixbuf) {
746                         g_free(pix_d->icon_path);
747                         pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);
748                 }
749         }
750
751         cm_return_val_if_fail(pix_d->pixbuf != NULL, -1);
752
753         if (pixbuf)
754                 *pixbuf = pix_d->pixbuf;
755
756         /* pixbuf should have one ref outstanding */
757
758         return 0;
759 }
760
761 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
762 {
763         const gchar *entry;
764         gchar *fullentry;
765         GDir *dp;
766         GError *error = NULL;
767
768         if ((dp = g_dir_open(dirname, 0, &error)) == NULL) {
769                 debug_print("skipping theme scan, dir %s could not be opened: %s (%d)\n",
770                                 dirname ? dirname : "(null)", error->message, error->code);
771                 g_error_free(error);
772                 return;
773         }
774
775         while ((entry = g_dir_read_name(dp)) != NULL) {
776                 fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
777
778                 if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
779                         gchar *filetoexist;
780                         gboolean found = FALSE;
781                         int i;
782                         int j;
783                         for (i = 0; i < N_STOCK_PIXMAPS && !found; i++) {
784                                 for (j = 0; extension[j] && !found; j++) {
785                                         filetoexist = g_strconcat(fullentry, G_DIR_SEPARATOR_S, pixmaps[i].file, extension[j], NULL);
786                                         if (is_file_exist(filetoexist)) {
787                                                 *list = g_list_append(*list, fullentry);
788                                                 found = TRUE;
789                                         }
790                                         g_free(filetoexist);
791                                 }
792                         }
793                         if (i == N_STOCK_PIXMAPS)
794                                 g_free(fullentry);
795                 } else
796                         g_free(fullentry);
797         }
798         g_dir_close(dp);
799 }
800
801 gchar *stock_pixmap_get_system_theme_dir_for_theme(const gchar *theme)
802 {
803         const gchar *sep = NULL;
804         if (theme && *theme)
805                 sep = G_DIR_SEPARATOR_S;
806 #ifndef G_OS_WIN32
807         return g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
808                            PIXMAP_THEME_DIR, sep, theme, NULL);
809 #else
810         return g_strconcat(w32_get_themes_dir(), sep, theme, NULL);
811 #endif
812 }
813
814 GList *stock_pixmap_themes_list_new(void)
815 {
816         gchar *defaulttheme;
817         gchar *userthemes;
818         gchar *systemthemes;
819         GList *list = NULL;
820
821         defaulttheme = g_strdup(DEFAULT_PIXMAP_THEME);
822         userthemes   = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
823                                    PIXMAP_THEME_DIR, NULL);
824         systemthemes = stock_pixmap_get_system_theme_dir_for_theme(NULL);
825
826         list = g_list_append(list, defaulttheme);
827         stock_pixmap_find_themes_in_dir(&list, userthemes);
828         stock_pixmap_find_themes_in_dir(&list, systemthemes);
829
830         g_free(userthemes);
831         g_free(systemthemes);
832         return list;
833 }
834
835 void stock_pixmap_themes_list_free(GList *list)
836 {
837         GList *ptr;
838
839         for (ptr = g_list_first(list); ptr != NULL; ptr = g_list_next(ptr))
840                 g_free(ptr->data);
841         g_list_free(list);
842 }
843
844 void stock_pixmap_invalidate_all_icons(void)
845 {
846         StockPixmapData *pix_d;
847         int i = 0;
848
849         while (i < N_STOCK_PIXMAPS) {
850                 pix_d = &pixmaps[i];
851                 if (pix_d->pixbuf) {
852                         g_object_unref(G_OBJECT(pix_d->pixbuf));
853                         pix_d->pixbuf = NULL;
854                 }
855                 if (pix_d->pixmap) {
856                         g_object_unref(G_OBJECT(pix_d->pixmap));
857                         pix_d->pixmap = NULL;
858                 }
859                 i++;
860         }
861 }
862
863 gchar *stock_pixmap_get_name (StockPixmap icon)
864 {
865         if (icon >= N_STOCK_PIXMAPS)
866                 return NULL;
867
868         return pixmaps[icon].file;
869
870 }
871
872 StockPixmap stock_pixmap_get_icon (gchar *file)
873 {
874         gint i;
875
876         for (i = 0; i < N_STOCK_PIXMAPS; i++) {
877                 if (strcmp (pixmaps[i].file, file) == 0)
878                         return i;
879         }
880         return -1;
881 }
882
883 static gboolean do_pix_draw(GtkWidget *widget, cairo_t *cr,
884                             OverlayData *data)
885 {
886         GdkWindow *drawable = gtk_widget_get_window(widget);
887         gint left = 0;
888         gint top = 0;
889
890         if (data->is_pixmap) {
891                 cm_return_val_if_fail(data->base_pixmap != NULL, FALSE);
892         } else {
893                 cm_return_val_if_fail(data->base_pixbuf != NULL, FALSE);
894         }
895
896         if (data->highlight) {
897                 MainWindow *mw = NULL;
898
899                 mw = mainwindow_get_mainwindow();
900                 if (mw != NULL && mw->menubar != NULL) {
901                         cairo_t *cr;
902                         GdkColor color = gtk_widget_get_style(mw->menubar)->base[GTK_STATE_SELECTED];
903
904                         cr = gdk_cairo_create(drawable);
905                         gdk_cairo_set_source_color(cr, &color);
906                         cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
907                         cairo_set_line_width(cr, 1.);
908                         cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
909                         cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
910                         cairo_rectangle(cr, data->border_x-2, data->border_y-2,
911                             data->base_width+3, data->base_height+3);
912                         cairo_stroke(cr);
913                         cairo_destroy(cr);
914                 }
915         }
916
917         if (data->is_pixmap) {
918                 cairo_set_source_surface(cr, data->base_pixmap, data->border_x, data->border_y);
919                 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
920                 cairo_rectangle(cr, data->border_x, data->border_y, data->base_width, data->base_height);
921                 cairo_fill(cr);
922         } else {
923                 gdk_cairo_set_source_pixbuf(cr, data->base_pixbuf, data->border_x, data->border_y);
924                 cairo_paint(cr);
925         }
926
927         if (data->position != OVERLAY_NONE) {
928
929                 switch (data->position) {
930                         case OVERLAY_TOP_LEFT:
931                         case OVERLAY_MID_LEFT:
932                         case OVERLAY_BOTTOM_LEFT:
933                                 left = 0;
934                                 break;
935
936                         case OVERLAY_TOP_CENTER:
937                         case OVERLAY_MID_CENTER:
938                         case OVERLAY_BOTTOM_CENTER:
939                                 left = (data->base_width + data->border_x * 2 - data->overlay_width)/2;
940                                 break;
941
942                         case OVERLAY_TOP_RIGHT:
943                         case OVERLAY_MID_RIGHT:
944                         case OVERLAY_BOTTOM_RIGHT:
945                                 left = data->base_width + data->border_x * 2 - data->overlay_width;
946                                 break;
947
948                         default:
949                                 break;
950                 }
951                 switch (data->position) {
952                         case OVERLAY_TOP_LEFT:
953                         case OVERLAY_TOP_CENTER:
954                         case OVERLAY_TOP_RIGHT:
955                                 top = 0;
956                                 break;
957
958                         case OVERLAY_MID_LEFT:
959                         case OVERLAY_MID_CENTER:
960                         case OVERLAY_MID_RIGHT:
961                                 top = (data->base_height + data->border_y * 2 - data->overlay_height)/2;
962                                 break;
963
964                         case OVERLAY_BOTTOM_LEFT:
965                         case OVERLAY_BOTTOM_CENTER:
966                         case OVERLAY_BOTTOM_RIGHT:
967                                 top = data->base_height + data->border_y * 2 - data->overlay_height;
968                                 break;
969
970                         default:
971                                 break;
972                 }
973         }
974
975         if (data->position != OVERLAY_NONE) {
976                 if (data->is_pixmap) {
977                         cm_return_val_if_fail(data->overlay_pixmap != NULL, FALSE);
978                         cairo_set_source_surface(cr, data->overlay_pixmap, left, top);
979                         cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
980                         cairo_rectangle (cr, left, top, data->overlay_width, data->overlay_height);
981                         cairo_fill(cr);
982                 } else {
983       cm_return_val_if_fail(data->overlay_pixbuf != NULL, FALSE);
984       gdk_cairo_set_source_pixbuf(cr, data->overlay_pixbuf, left, top);
985       cairo_paint(cr);
986                 }
987         }
988
989         return TRUE;
990 }
991
992 #if !GTK_CHECK_VERSION(3,0,0)
993 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventExpose *expose,
994                                                    OverlayData *data)
995 #else
996 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, cairo_t *cr,
997                                                     OverlayData *data)
998 #endif
999 {
1000 #if !GTK_CHECK_VERSION(3,0,0)
1001         cairo_t *cr;
1002         GdkWindow *drawable = gtk_widget_get_window(widget);
1003         gboolean result;
1004
1005         cr = gdk_cairo_create(drawable);
1006         gdk_window_clear_area (drawable, expose->area.x, expose->area.y,
1007                                expose->area.width, expose->area.height);
1008
1009         result = do_pix_draw(widget, cr, data);
1010         cairo_destroy(cr);
1011         return result;
1012 #else
1013         return do_pix_draw(widget, cr, data);
1014 #endif
1015 }
1016
1017 static void pixmap_with_overlay_destroy_cb(GtkWidget *object, OverlayData *data)
1018 {
1019         if (data->is_pixmap) {
1020                 cairo_surface_destroy(data->base_pixmap);
1021                 if (data->position != OVERLAY_NONE) {
1022                         cairo_surface_destroy(data->overlay_pixmap);
1023                 }
1024         } else {
1025                 g_object_unref(data->base_pixbuf);
1026                 if (data->position != OVERLAY_NONE) {
1027                         g_object_unref(data->overlay_pixbuf);
1028                 }
1029         }
1030         g_free(data);
1031 }
1032
1033 /**
1034  * \brief Get a widget showing one icon with another overlaid on top of it.
1035  *
1036  * The base icon is always centralised, the other icon can be positioned.
1037  * The overlay icon is ignored if pos=OVERLAY_NONE is used
1038  *
1039  * \param window   top-level window widget
1040  * \param icon     the base icon
1041  * \param overlay  the icon to overlay
1042  * \param pos      how to align the overlay widget, or OVERLAY_NONE for no overlay
1043  * \param border_x size of the border around the base icon (left and right)
1044  * \param border_y size of the border around the base icon (top and bottom)
1045  */
1046 GtkWidget *stock_pixmap_widget_with_overlay(StockPixmap icon,
1047                                             StockPixmap overlay, OverlayPosition pos,
1048                                             gint border_x, gint border_y)
1049 {
1050         cairo_surface_t *stock_pixmap = NULL;
1051         GdkPixbuf *stock_pixbuf = NULL;
1052         GtkWidget *widget = NULL;
1053         GtkWidget *stock_wid = NULL;
1054         GtkRequisition requisition;
1055         OverlayData *data = NULL;
1056
1057         data = g_new0(OverlayData, 1);
1058
1059         stock_wid = stock_pixmap_widget(icon);
1060         gtk_widget_get_requisition(stock_wid, &requisition);
1061
1062 #if !GTK_CHECK_VERSION(3, 0, 0)
1063         if (gtk_image_get_storage_type(GTK_IMAGE(stock_wid)) == GTK_IMAGE_PIXMAP)
1064                 data->is_pixmap = TRUE;
1065         else
1066 #endif
1067                 data->is_pixmap = FALSE;
1068
1069         if (data->is_pixmap) {
1070                 cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(stock_wid));
1071                 stock_pixmap = cairo_get_target(cr);
1072                 cairo_surface_reference(stock_pixmap);
1073                 cairo_destroy(cr);
1074                 data->base_pixmap = stock_pixmap;
1075                 data->base_height = requisition.height;
1076                 data->base_width  = requisition.width;
1077                 gtk_widget_destroy(stock_wid);
1078
1079                 if (pos == OVERLAY_NONE) {
1080                         data->overlay_pixmap = NULL;
1081                 } else {
1082                         stock_wid = stock_pixmap_widget(overlay);
1083                         cr = gdk_cairo_create(gtk_widget_get_window(stock_wid));
1084                         stock_pixmap = cairo_get_target(cr);
1085                         cairo_surface_reference(stock_pixmap);
1086                         cairo_destroy(cr);
1087                         data->overlay_pixmap = stock_pixmap;
1088                         data->overlay_height = requisition.height;
1089                         data->overlay_width  = requisition.width;
1090
1091                         gtk_widget_destroy(stock_wid);
1092                 }
1093         } else {
1094                 data->is_pixmap = FALSE;
1095                 stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
1096                 g_object_ref(stock_pixbuf);
1097                 data->base_pixbuf = stock_pixbuf;
1098                 data->base_height = requisition.height;
1099                 data->base_width  = requisition.width;
1100                 gtk_widget_destroy(stock_wid);
1101                 if (pos == OVERLAY_NONE) {
1102                         data->overlay_pixmap = NULL;
1103                 } else {
1104                         stock_wid = stock_pixmap_widget(overlay);
1105                         stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
1106                         g_object_ref(stock_pixbuf);
1107                         data->overlay_pixbuf = stock_pixbuf;
1108                         data->overlay_height = requisition.height;
1109                         data->overlay_width  = requisition.width;
1110
1111                         gtk_widget_destroy(stock_wid);
1112                 }
1113         }
1114         data->position = pos;
1115         data->border_x = border_x;
1116         data->border_y = border_y;
1117         data->highlight = FALSE;
1118
1119         widget = gtk_drawing_area_new();
1120         gtk_widget_set_size_request(widget, data->base_width + border_x * 2,
1121                               data->base_height + border_y * 2);
1122 #if !GTK_CHECK_VERSION(3, 0, 0)
1123         g_signal_connect(G_OBJECT(widget), "expose_event",
1124                          G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
1125 #else
1126         g_signal_connect(G_OBJECT(widget), "draw",
1127                          G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
1128 #endif
1129         g_signal_connect(G_OBJECT(widget), "destroy",
1130                          G_CALLBACK(pixmap_with_overlay_destroy_cb), data);
1131         g_object_set_data(G_OBJECT(widget), "highlight", &(data->highlight));
1132         return widget;
1133
1134 }