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