Remove wrong initialization from max_message_size
[claws.git] / src / stock_pixmap.c
blob90fa053fb955a6ee42a460c81c207b48ada533cc
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2023 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 #if LIBRSVG_CHECK_VERSION(2, 46, 0)
542 if (cairo_status(cr) == CAIRO_STATUS_SUCCESS) {
543 const RsvgRectangle viewport = {
544 .x = 0,
545 .y = 0,
546 .width = width,
547 .height = height,
549 GError *err = NULL;
551 cairo_rectangle(cr, 0, 0, width, height);
552 cairo_clip(cr);
554 rsvg_handle_render_document(handle, cr, &viewport, &err);
555 if (err != NULL) {
556 g_warning("unable to render SVG document (%d): %s", err->code, err->message);
557 g_error_free(err);
560 #else
561 RsvgDimensionData dimensions;
562 double x_factor, y_factor;
563 double scale_factor;
565 rsvg_handle_get_dimensions(handle, &dimensions);
567 x_factor = (double) width / dimensions.width;
568 y_factor = (double) height / dimensions.height;
570 scale_factor = MIN(x_factor, y_factor);
572 cairo_scale(cr, scale_factor, scale_factor);
574 rsvg_handle_render_cairo(handle, cr);
575 #endif
579 * Generates a new Pixbuf from a Cairo context of the given dimensions.
581 * Adapted from https://gist.github.com/bert/985903
583 GdkPixbuf *pixbuf_from_cairo(cairo_t *cr, gboolean alpha, int width, int height)
585 gint p_stride, /* Pixbuf stride value */
586 p_n_channels, /* RGB -> 3, RGBA -> 4 */
587 s_stride; /* Surface stride value */
588 guchar *p_pixels, /* Pixbuf's pixel data */
589 *s_pixels; /* Surface's pixel data */
590 cairo_surface_t *surface; /* Temporary image surface */
591 GdkPixbuf *pixbuf; /* Returned pixbuf */
593 /* Create pixbuf */
594 pixbuf = gdk_pixbuf_new
595 (GDK_COLORSPACE_RGB, alpha, 8, width, height);
596 if (pixbuf == NULL) {
597 g_warning("failed to create a new %d x %d pixbuf", width, height);
598 return NULL;
600 /* Obtain surface from where pixel values will be copied */
601 surface = cairo_get_target(cr);
602 if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
603 g_warning("invalid cairo surface for copying");
604 return NULL;
606 /* Inspect pixbuf */
607 g_object_get(G_OBJECT(pixbuf),
608 "rowstride", &p_stride,
609 "n-channels", &p_n_channels,
610 "pixels", &p_pixels,
611 NULL);
612 /* and surface */
613 s_stride = cairo_image_surface_get_stride(surface);
614 s_pixels = cairo_image_surface_get_data(surface);
616 /* Copy pixel data from surface to pixbuf */
617 while (height--) {
618 gint i;
619 guchar *p_iter = p_pixels, *s_iter = s_pixels;
620 for (i = 0; i < width; i++) {
621 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
622 /* Pixbuf: RGB(A) - Surface: BGRA */
623 gdouble alpha_factor = (gdouble)0xff / s_iter[3];
624 p_iter[0] = (guchar)( s_iter[2] * alpha_factor + .5 );
625 p_iter[1] = (guchar)( s_iter[1] * alpha_factor + .5 );
626 p_iter[2] = (guchar)( s_iter[0] * alpha_factor + .5 );
627 if (p_n_channels == 4)
628 p_iter[3] = s_iter[3];
629 #elif G_BYTE_ORDER == G_BIG_ENDIAN
630 /* Pixbuf: RGB(A) - Surface: ARGB */
631 gdouble alpha_factor = (gdouble)0xff / s_iter[0];
632 p_iter[0] = (guchar)( s_iter[1] * alpha_factor + .5 );
633 p_iter[1] = (guchar)( s_iter[2] * alpha_factor + .5 );
634 p_iter[2] = (guchar)( s_iter[3] * alpha_factor + .5 );
635 if (p_n_channels == 4)
636 p_iter[3] = s_iter[0];
637 #else /* PDP endianness */
638 /* Pixbuf: RGB(A) - Surface: RABG */
639 gdouble alpha_factor = (gdouble)0xff / s_iter[1];
640 p_iter[0] = (guchar)( s_iter[0] * alpha_factor + .5 );
641 p_iter[1] = (guchar)( s_iter[3] * alpha_factor + .5 );
642 p_iter[2] = (guchar)( s_iter[2] * alpha_factor + .5 );
643 if (p_n_channels == 4)
644 p_iter[3] = s_iter[1];
645 #endif
646 s_iter += 4;
647 p_iter += p_n_channels;
649 s_pixels += s_stride;
650 p_pixels += p_stride;
652 /* Destroy context */
653 cairo_destroy(cr);
655 return pixbuf;
659 * Renders a SVG file into a pixbuf with the dimensions of the
660 * given pixmap data (optionally with alpha channel).
662 GdkPixbuf *pixbuf_from_svg_like_icon(char *filename, GError **error, StockPixmapData *icondata, gboolean alpha)
664 int width, height;
665 cairo_surface_t *surface;
666 cairo_t *context;
667 RsvgHandle *handle;
669 cm_return_val_if_fail(filename != NULL, NULL);
670 cm_return_val_if_fail(icondata != NULL, NULL);
672 /* load SVG file */
673 handle = rsvg_handle_new_from_file(filename, error);
674 if (handle == NULL) {
675 g_warning("failed loading SVG '%s': %s (%d)", filename,
676 (*error)->message, (*error)->code);
677 return NULL;
680 /* scale dimensions */
681 if (prefs_common.enable_pixmap_scaling) {
682 /* default is pixmap icon size */
683 if (sscanf((icondata->data)[0], "%d %d ", &width, &height) != 2) {
684 g_warning("failed reading icondata width and height");
685 return NULL;
687 /* which can be modified by some factor */
688 if (prefs_common.pixmap_scaling_ppi > 0) {
689 gdouble factor = (gdouble) prefs_common.pixmap_scaling_ppi / MIN_PPI;
690 width = (int) floor(factor * width);
691 height = (int) floor(factor * height);
693 } else { /* render using SVG size */
694 #if LIBRSVG_CHECK_VERSION(2, 52, 0)
695 double svg_width, svg_height;
697 rsvg_handle_get_intrinsic_size_in_pixels(handle, &svg_width, &svg_height);
698 width = (int) svg_width;
699 height = (int) svg_height;
700 #else
701 RsvgDimensionData dimension;
703 rsvg_handle_get_dimensions (handle, &dimension);
704 width = dimension.width;
705 height = dimension.height;
706 #endif
709 /* create drawing context */
710 surface = cairo_image_surface_create(
711 alpha? CAIRO_FORMAT_ARGB32: CAIRO_FORMAT_RGB24,
712 width, height);
713 if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
714 g_warning("failed to create a cairo surface: %s",
715 cairo_status_to_string(cairo_surface_status(surface)));
716 g_object_unref(handle);
717 return NULL;
719 context = cairo_create(surface);
720 cairo_surface_destroy(surface);
721 if (cairo_status(context) != CAIRO_STATUS_SUCCESS) {
722 g_warning("failed to create a cairo context: %s",
723 cairo_status_to_string(cairo_status(context)));
724 cairo_destroy(context);
725 return NULL;
727 /* render SVG */
728 render_scaled_proportionally(handle, context, width, height);
729 /* build result and destroy context */
730 return pixbuf_from_cairo(context, alpha, width, height);
732 #endif
735 *\brief
737 gint priv_pixbuf_gdk(PrivPixmap icon, GdkPixbuf **pixbuf)
739 PrivPixmapData *pix_d;
741 if (pixbuf)
742 *pixbuf = NULL;
744 cm_return_val_if_fail(icon < N_PRIV_PIXMAPS, -1);
746 pix_d = &privpixmaps[icon];
748 if (!pix_d->pixbuf)
749 pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) pix_d->data);
751 cm_return_val_if_fail(pix_d->pixbuf != NULL, -1);
753 if (pixbuf)
754 *pixbuf = pix_d->pixbuf;
756 /* pixbuf should have one ref outstanding */
758 return 0;
761 gint stock_pixbuf_gdk(StockPixmap icon, GdkPixbuf **pixbuf)
763 StockPixmapData *pix_d;
764 int i = 0;
765 gboolean theme_changed = FALSE;
767 if (pixbuf)
768 *pixbuf = NULL;
770 cm_return_val_if_fail(icon < N_STOCK_PIXMAPS, -1);
772 pix_d = &pixmaps[icon];
774 theme_changed = (g_strcmp0(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0);
775 if (!pix_d->pixbuf || theme_changed) {
776 GdkPixbuf *pix = NULL;
778 if (theme_changed && pix_d->pixmap) {
779 g_object_unref(pix_d->pixmap);
780 pix_d->pixmap = NULL;
783 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
784 if (is_dir_exist(prefs_common.pixmap_theme_path)) {
785 char *icon_file_name;
786 try_next_extension:
787 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
788 G_DIR_SEPARATOR_S,
789 pix_d->file,
790 extension[i],
791 NULL);
792 if (is_file_exist(icon_file_name)) {
793 GError *err = NULL;
794 #ifdef HAVE_SVG
795 if (!strncmp(extension[i], ".svg", 4)) {
796 pix = pixbuf_from_svg_like_icon(icon_file_name, &err, pix_d,
797 prefs_common.enable_alpha_svg);
798 } else {
799 pix = gdk_pixbuf_new_from_file(icon_file_name, &err);
801 #else
802 pix = gdk_pixbuf_new_from_file(icon_file_name, &err);
803 #endif
804 if (err) g_error_free(err);
806 if (pix) {
807 g_free(pix_d->icon_path);
808 pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
810 g_free(icon_file_name);
811 if (!pix) {
812 i++;
813 if (extension[i])
814 goto try_next_extension;
816 } else {
817 /* even the path does not exist (deleted between two sessions), so
818 set the preferences to the internal theme */
819 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
822 pix_d->pixbuf = pix;
825 if (!pix_d->pixbuf) {
826 pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) pix_d->data);
827 if (pix_d->pixbuf) {
828 g_free(pix_d->icon_path);
829 pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);
833 cm_return_val_if_fail(pix_d->pixbuf != NULL, -1);
835 if (pixbuf)
836 *pixbuf = pix_d->pixbuf;
838 /* pixbuf should have one ref outstanding */
840 return 0;
843 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
845 const gchar *entry;
846 gchar *fullentry;
847 GDir *dp;
848 GError *error = NULL;
850 if ((dp = g_dir_open(dirname, 0, &error)) == NULL) {
851 debug_print("skipping theme scan, dir %s could not be opened: %s (%d)\n",
852 dirname ? dirname : "(null)", error->message, error->code);
853 g_error_free(error);
854 return;
857 while ((entry = g_dir_read_name(dp)) != NULL) {
858 fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
860 if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
861 gchar *filetoexist;
862 gboolean found = FALSE;
863 int i;
864 int j;
865 for (i = 0; i < N_STOCK_PIXMAPS && !found; i++) {
866 for (j = 0; extension[j] && !found; j++) {
867 filetoexist = g_strconcat(fullentry, G_DIR_SEPARATOR_S, pixmaps[i].file, extension[j], NULL);
868 if (is_file_exist(filetoexist)) {
869 *list = g_list_append(*list, fullentry);
870 found = TRUE;
872 g_free(filetoexist);
875 if (i == N_STOCK_PIXMAPS)
876 g_free(fullentry);
877 } else
878 g_free(fullentry);
880 g_dir_close(dp);
883 gchar *stock_pixmap_get_system_theme_dir_for_theme(const gchar *theme)
885 if (theme && *theme) {
886 #ifndef G_OS_WIN32
887 return g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
888 PIXMAP_THEME_DIR, G_DIR_SEPARATOR_S, theme, NULL);
889 #else
890 return g_strconcat(w32_get_themes_dir(), G_DIR_SEPARATOR_S, theme, NULL);
891 #endif
892 } else {
893 #ifndef G_OS_WIN32
894 return g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
895 PIXMAP_THEME_DIR, NULL);
896 #else
897 return g_strdup(w32_get_themes_dir());
898 #endif
902 GList *stock_pixmap_themes_list_new(void)
904 gchar *defaulttheme;
905 gchar *userthemes;
906 gchar *systemthemes;
907 GList *list = NULL;
909 defaulttheme = g_strdup(DEFAULT_PIXMAP_THEME);
910 userthemes = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
911 PIXMAP_THEME_DIR, NULL);
912 systemthemes = stock_pixmap_get_system_theme_dir_for_theme(NULL);
914 list = g_list_append(list, defaulttheme);
915 stock_pixmap_find_themes_in_dir(&list, userthemes);
916 stock_pixmap_find_themes_in_dir(&list, systemthemes);
918 g_free(userthemes);
919 g_free(systemthemes);
920 return list;
923 void stock_pixmap_themes_list_free(GList *list)
925 GList *ptr;
927 if (list == NULL)
928 return;
930 for (ptr = g_list_first(list); ptr != NULL; ptr = g_list_next(ptr))
931 g_free(ptr->data);
932 g_list_free(list);
935 gchar *stock_pixmap_get_name (StockPixmap icon)
937 if (icon >= N_STOCK_PIXMAPS)
938 return NULL;
940 return pixmaps[icon].file;
944 PrivPixmap priv_pixmap_get_icon (gchar *file)
946 gint i;
948 for (i = 0; i < N_PRIV_PIXMAPS; i++) {
949 if (strcmp (pixmaps[i].file, file) == 0)
950 return i;
952 return -1;
955 StockPixmap stock_pixmap_get_icon (gchar *file)
957 gint i;
959 for (i = 0; i < N_STOCK_PIXMAPS; i++) {
960 if (strcmp (pixmaps[i].file, file) == 0)
961 return i;
963 return -1;
966 static gboolean do_pix_draw(GtkWidget *widget, cairo_t *cr,
967 OverlayData *data)
969 GdkWindow *drawable = gtk_widget_get_window(widget);
970 gint left = 0;
971 gint top = 0;
973 cm_return_val_if_fail(data->base_pixbuf != NULL, FALSE);
975 if (data->highlight) {
976 MainWindow *mw = NULL;
978 mw = mainwindow_get_mainwindow();
979 if (mw != NULL && mw->menubar != NULL) {
980 cairo_t *cr;
981 GdkRGBA color;
983 GtkStyleContext *context = gtk_widget_get_style_context (mw->menubar);
984 gtk_style_context_lookup_color (context, "selected_bg_color", &color);
985 cairo_region_t * creg = cairo_region_create();
986 GdkDrawingContext * dctx = gdk_window_begin_draw_frame (drawable, creg);
987 cr = gdk_drawing_context_get_cairo_context (dctx);
988 gdk_cairo_set_source_rgba (cr, &color);
989 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
990 cairo_set_line_width(cr, 1.);
991 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
992 cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
993 cairo_rectangle(cr, data->border_x-2, data->border_y-2,
994 data->base_width+3, data->base_height+3);
995 cairo_stroke(cr);
996 gdk_window_end_draw_frame (drawable, dctx);
997 cairo_region_destroy (creg);
1001 gdk_cairo_set_source_pixbuf(cr, data->base_pixbuf, data->border_x, data->border_y);
1002 cairo_paint(cr);
1004 if (data->position != OVERLAY_NONE) {
1006 switch (data->position) {
1007 case OVERLAY_TOP_LEFT:
1008 case OVERLAY_MID_LEFT:
1009 case OVERLAY_BOTTOM_LEFT:
1010 left = 0;
1011 break;
1013 case OVERLAY_TOP_CENTER:
1014 case OVERLAY_MID_CENTER:
1015 case OVERLAY_BOTTOM_CENTER:
1016 left = (data->base_width + data->border_x * 2 - data->overlay_width)/2;
1017 break;
1019 case OVERLAY_TOP_RIGHT:
1020 case OVERLAY_MID_RIGHT:
1021 case OVERLAY_BOTTOM_RIGHT:
1022 left = data->base_width + data->border_x * 2 - data->overlay_width;
1023 break;
1025 default:
1026 break;
1028 switch (data->position) {
1029 case OVERLAY_TOP_LEFT:
1030 case OVERLAY_TOP_CENTER:
1031 case OVERLAY_TOP_RIGHT:
1032 top = 0;
1033 break;
1035 case OVERLAY_MID_LEFT:
1036 case OVERLAY_MID_CENTER:
1037 case OVERLAY_MID_RIGHT:
1038 top = (data->base_height + data->border_y * 2 - data->overlay_height)/2;
1039 break;
1041 case OVERLAY_BOTTOM_LEFT:
1042 case OVERLAY_BOTTOM_CENTER:
1043 case OVERLAY_BOTTOM_RIGHT:
1044 top = data->base_height + data->border_y * 2 - data->overlay_height;
1045 break;
1047 default:
1048 break;
1052 if (data->position != OVERLAY_NONE) {
1053 cm_return_val_if_fail(data->overlay_pixbuf != NULL, FALSE);
1054 gdk_cairo_set_source_pixbuf(cr, data->overlay_pixbuf, left, top);
1055 cairo_paint(cr);
1058 return TRUE;
1061 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, cairo_t *cr,
1062 OverlayData *data)
1064 return do_pix_draw(widget, cr, data);
1067 static void pixmap_with_overlay_destroy_cb(GtkWidget *object, OverlayData *data)
1069 g_object_unref(data->base_pixbuf);
1070 if (data->position != OVERLAY_NONE) {
1071 g_object_unref(data->overlay_pixbuf);
1073 g_free(data);
1077 * \brief Get a widget showing one icon with another overlaid on top of it.
1079 * The base icon is always centralised, the other icon can be positioned.
1080 * The overlay icon is ignored if pos=OVERLAY_NONE is used
1082 * \param window top-level window widget
1083 * \param icon the base icon
1084 * \param overlay the icon to overlay
1085 * \param pos how to align the overlay widget, or OVERLAY_NONE for no overlay
1086 * \param border_x size of the border around the base icon (left and right)
1087 * \param border_y size of the border around the base icon (top and bottom)
1089 GtkWidget *stock_pixmap_widget_with_overlay(StockPixmap icon,
1090 StockPixmap overlay, OverlayPosition pos,
1091 gint border_x, gint border_y)
1093 GdkPixbuf *stock_pixbuf = NULL;
1094 GtkWidget *widget = NULL;
1095 GtkWidget *stock_wid = NULL;
1096 gint height, width;
1097 OverlayData *data = NULL;
1099 data = g_new0(OverlayData, 1);
1101 stock_wid = stock_pixmap_widget(icon);
1102 g_object_ref_sink(stock_wid);
1104 stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
1105 g_object_ref(stock_pixbuf);
1107 height = gdk_pixbuf_get_height(stock_pixbuf);
1108 width = gdk_pixbuf_get_width(stock_pixbuf);
1110 data->base_pixbuf = stock_pixbuf;
1111 data->base_height = height;
1112 data->base_width = width;
1113 g_object_unref(stock_wid);
1115 if (pos != OVERLAY_NONE) {
1116 stock_wid = stock_pixmap_widget(overlay);
1117 g_object_ref_sink(stock_wid);
1119 stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
1120 g_object_ref(stock_pixbuf);
1121 data->overlay_pixbuf = stock_pixbuf;
1122 data->overlay_height = height;
1123 data->overlay_width = width;
1125 g_object_unref(stock_wid);
1128 data->position = pos;
1129 data->border_x = border_x;
1130 data->border_y = border_y;
1131 data->highlight = FALSE;
1133 widget = gtk_drawing_area_new();
1134 gtk_widget_set_size_request(widget, data->base_width + border_x * 2,
1135 data->base_height + border_y * 2);
1136 g_signal_connect(G_OBJECT(widget), "draw",
1137 G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
1138 g_signal_connect(G_OBJECT(widget), "destroy",
1139 G_CALLBACK(pixmap_with_overlay_destroy_cb), data);
1140 g_object_set_data(G_OBJECT(widget), "highlight", &(data->highlight));
1141 return widget;