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