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