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