2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 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 2 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <gtk/gtkwidget.h>
23 #include <gtk/gtkimage.h>
27 #include "stock_pixmap.h"
30 #include "prefs_common.h"
32 #include "pixmaps/addr_one.xpm"
33 #include "pixmaps/addr_two.xpm"
34 #include "pixmaps/address.xpm"
35 #include "pixmaps/book.xpm"
36 #include "pixmaps/category.xpm"
37 #include "pixmaps/checkbox_off.xpm"
38 #include "pixmaps/checkbox_on.xpm"
39 #include "pixmaps/clip.xpm"
40 #include "pixmaps/clipkey.xpm"
41 #include "pixmaps/complete.xpm"
42 #include "pixmaps/continue.xpm"
43 #include "pixmaps/deleted.xpm"
44 #include "pixmaps/error.xpm"
45 #include "pixmaps/edit_extern.xpm"
46 #include "pixmaps/forwarded.xpm"
47 #include "pixmaps/group.xpm"
48 #include "pixmaps/interface.xpm"
49 #include "pixmaps/jpilot.xpm"
50 #include "pixmaps/key.xpm"
51 #include "pixmaps/ldap.xpm"
52 #include "pixmaps/linewrap.xpm"
53 #include "pixmaps/linewrapcurrent.xpm"
54 #include "pixmaps/mark.xpm"
55 #include "pixmaps/locked.xpm"
56 #include "pixmaps/new.xpm"
57 #include "pixmaps/replied.xpm"
58 #include "pixmaps/close.xpm"
59 #include "pixmaps/down_arrow.xpm"
60 #include "pixmaps/up_arrow.xpm"
61 #include "pixmaps/exec.xpm"
62 #include "pixmaps/mail.xpm"
63 #include "pixmaps/mail_attach.xpm"
64 #include "pixmaps/mail_compose.xpm"
65 #include "pixmaps/mail_forward.xpm"
66 #include "pixmaps/mail_receive.xpm"
67 #include "pixmaps/mail_receive_all.xpm"
68 #include "pixmaps/mail_reply.xpm"
69 #include "pixmaps/mail_reply_to_all.xpm"
70 #include "pixmaps/mail_reply_to_author.xpm"
71 #include "pixmaps/mail_send.xpm"
72 #include "pixmaps/mail_send_queue.xpm"
73 #include "pixmaps/mail_sign.xpm"
74 #include "pixmaps/open_mail.xpm"
75 #include "pixmaps/news_compose.xpm"
76 #include "pixmaps/paste.xpm"
77 #include "pixmaps/preferences.xpm"
78 #include "pixmaps/properties.xpm"
79 #include "pixmaps/queue_close.xpm"
80 #include "pixmaps/queue_close_hrm.xpm"
81 #include "pixmaps/queue_open.xpm"
82 #include "pixmaps/queue_open_hrm.xpm"
83 #include "pixmaps/claws-mail_icon.xpm"
84 #include "pixmaps/claws-mail_logo.xpm"
85 #include "pixmaps/address_book.xpm"
86 #include "pixmaps/unread.xpm"
87 #include "pixmaps/read.xpm"
88 #include "pixmaps/vcard.xpm"
89 #include "pixmaps/ignorethread.xpm"
90 #include "pixmaps/online.xpm"
91 #include "pixmaps/offline.xpm"
92 #include "pixmaps/notice_warn.xpm"
93 #include "pixmaps/notice_error.xpm"
94 #include "pixmaps/notice_note.xpm"
95 #include "pixmaps/quicksearch.xpm"
96 #include "pixmaps/clip_gpg_signed.xpm"
97 #include "pixmaps/gpg_signed.xpm"
98 #include "pixmaps/mime_text_plain.xpm"
99 #include "pixmaps/mime_text_html.xpm"
100 #include "pixmaps/mime_application.xpm"
101 #include "pixmaps/mime_image.xpm"
102 #include "pixmaps/mime_audio.xpm"
103 #include "pixmaps/mime_text_enriched.xpm"
104 #include "pixmaps/mime_unknown.xpm"
105 #include "pixmaps/mime_pdf.xpm"
106 #include "pixmaps/mime_ps.xpm"
107 #include "pixmaps/mime_calendar.xpm"
108 #include "pixmaps/mime_pgpsig.xpm"
109 #include "pixmaps/printer.xpm"
110 #include "pixmaps/privacy_signed.xpm"
111 #include "pixmaps/privacy_passed.xpm"
112 #include "pixmaps/privacy_failed.xpm"
113 #include "pixmaps/privacy_unknown.xpm"
114 #include "pixmaps/privacy_expired.xpm"
115 #include "pixmaps/privacy_warn.xpm"
116 #include "pixmaps/privacy_emblem_encrypted.xpm"
117 #include "pixmaps/privacy_emblem_signed.xpm"
118 #include "pixmaps/privacy_emblem_passed.xpm"
119 #include "pixmaps/privacy_emblem_failed.xpm"
120 #include "pixmaps/privacy_emblem_warn.xpm"
121 #include "pixmaps/mime_message.xpm"
122 #include "pixmaps/address_search.xpm"
123 #include "pixmaps/check_spelling.xpm"
125 #include "pixmaps/dir_close.xpm"
126 #include "pixmaps/dir_close_hrm.xpm"
127 #include "pixmaps/dir_open.xpm"
128 #include "pixmaps/dir_open_hrm.xpm"
129 #include "pixmaps/inbox_open.xpm"
130 #include "pixmaps/inbox_open_hrm.xpm"
131 #include "pixmaps/inbox_close.xpm"
132 #include "pixmaps/inbox_close_hrm.xpm"
133 #include "pixmaps/outbox_open.xpm"
134 #include "pixmaps/outbox_open_hrm.xpm"
135 #include "pixmaps/outbox_close.xpm"
136 #include "pixmaps/outbox_close_hrm.xpm"
137 #include "pixmaps/trash.xpm"
138 #include "pixmaps/trash_btn.xpm"
139 #include "pixmaps/trash_hrm.xpm"
140 #include "pixmaps/drafts_close.xpm"
141 #include "pixmaps/drafts_open.xpm"
142 #include "pixmaps/dir_close_mark.xpm"
143 #include "pixmaps/dir_close_hrm_mark.xpm"
144 #include "pixmaps/dir_open_mark.xpm"
145 #include "pixmaps/dir_open_hrm_mark.xpm"
146 #include "pixmaps/inbox_open_mark.xpm"
147 #include "pixmaps/inbox_open_hrm_mark.xpm"
148 #include "pixmaps/inbox_close_mark.xpm"
149 #include "pixmaps/inbox_close_hrm_mark.xpm"
150 #include "pixmaps/outbox_open_mark.xpm"
151 #include "pixmaps/outbox_open_hrm_mark.xpm"
152 #include "pixmaps/outbox_close_mark.xpm"
153 #include "pixmaps/outbox_close_hrm_mark.xpm"
154 #include "pixmaps/trash_mark.xpm"
155 #include "pixmaps/queue_close_mark.xpm"
156 #include "pixmaps/queue_close_hrm_mark.xpm"
157 #include "pixmaps/queue_open_mark.xpm"
158 #include "pixmaps/queue_open_hrm_mark.xpm"
159 #include "pixmaps/trash_hrm_mark.xpm"
160 #include "pixmaps/drafts_close_mark.xpm"
161 #include "pixmaps/drafts_open_mark.xpm"
162 #include "pixmaps/dir_noselect.xpm"
163 #include "pixmaps/spam.xpm"
164 #include "pixmaps/spam_btn.xpm"
165 #include "pixmaps/ham_btn.xpm"
166 #include "pixmaps/moved.xpm"
167 #include "pixmaps/copied.xpm"
168 #include "pixmaps/selection.xpm"
169 #include "pixmaps/empty.xpm"
171 typedef struct _StockPixmapData StockPixmapData
;
173 struct _StockPixmapData
183 typedef struct _OverlayData OverlayData
;
187 GdkPixmap
*base_pixmap
;
188 GdkBitmap
*base_mask
;
189 GdkPixmap
*overlay_pixmap
;
190 GdkBitmap
*overlay_mask
;
193 guint overlay_height
;
195 OverlayPosition position
;
200 static void stock_pixmap_find_themes_in_dir(GList
**list
, const gchar
*dirname
);
202 static StockPixmapData pixmaps
[] =
204 {addr_one_xpm
, NULL
, NULL
, "addr_one", NULL
},
205 {addr_two_xpm
, NULL
, NULL
, "addr_two", NULL
},
206 {address_xpm
, NULL
, NULL
, "address", NULL
},
207 {address_book_xpm
, NULL
, NULL
, "address_book", NULL
},
208 {address_search_xpm
, NULL
, NULL
, "address_search", NULL
},
209 {book_xpm
, NULL
, NULL
, "book", NULL
},
210 {category_xpm
, NULL
, NULL
, "category", NULL
},
211 {checkbox_off_xpm
, NULL
, NULL
, "checkbox_off", NULL
},
212 {checkbox_on_xpm
, NULL
, NULL
, "checkbox_on", NULL
},
213 {check_spelling_xpm
, NULL
, NULL
, "check_spelling", NULL
},
214 {clip_xpm
, NULL
, NULL
, "clip", NULL
},
215 {clipkey_xpm
, NULL
, NULL
, "clipkey", NULL
},
216 {clip_gpg_signed_xpm
, NULL
, NULL
, "clip_gpg_signed", NULL
},
217 {close_xpm
, NULL
, NULL
, "close", NULL
},
218 {complete_xpm
, NULL
, NULL
, "complete", NULL
},
219 {continue_xpm
, NULL
, NULL
, "continue", NULL
},
220 {deleted_xpm
, NULL
, NULL
, "deleted", NULL
},
221 {dir_close_xpm
, NULL
, NULL
, "dir_close", NULL
},
222 {dir_close_hrm_xpm
, NULL
, NULL
, "dir_close_hrm", NULL
},
223 {dir_open_xpm
, NULL
, NULL
, "dir_open", NULL
},
224 {dir_open_hrm_xpm
, NULL
, NULL
, "dir_open_hrm", NULL
},
225 {dir_close_mark_xpm
, NULL
, NULL
, "dir_close_mark", NULL
},
226 {dir_close_hrm_mark_xpm
, NULL
, NULL
, "dir_close_hrm_mark", NULL
},
227 {dir_open_mark_xpm
, NULL
, NULL
, "dir_open_mark", NULL
},
228 {dir_open_hrm_mark_xpm
, NULL
, NULL
, "dir_open_hrm_mark", NULL
},
229 {down_arrow_xpm
, NULL
, NULL
, "down_arrow", NULL
},
230 {up_arrow_xpm
, NULL
, NULL
, "up_arrow", NULL
},
231 {edit_extern_xpm
, NULL
, NULL
, "edit_extern", NULL
},
232 {error_xpm
, NULL
, NULL
, "error", NULL
},
233 {exec_xpm
, NULL
, NULL
, "exec", NULL
},
234 {forwarded_xpm
, NULL
, NULL
, "forwarded", NULL
},
235 {group_xpm
, NULL
, NULL
, "group", NULL
},
236 {ignorethread_xpm
, NULL
, NULL
, "ignorethread", NULL
},
237 {inbox_close_xpm
, NULL
, NULL
, "inbox_close", NULL
},
238 {inbox_close_hrm_xpm
, NULL
, NULL
, "inbox_close_hrm", NULL
},
239 {inbox_open_xpm
, NULL
, NULL
, "inbox_open", NULL
},
240 {inbox_open_hrm_xpm
, NULL
, NULL
, "inbox_open_hrm", NULL
},
241 {inbox_close_mark_xpm
, NULL
, NULL
, "inbox_close_mark", NULL
},
242 {inbox_close_hrm_mark_xpm
, NULL
, NULL
, "inbox_close_hrm_mark", NULL
},
243 {inbox_open_mark_xpm
, NULL
, NULL
, "inbox_open_mark", NULL
},
244 {inbox_open_hrm_mark_xpm
, NULL
, NULL
, "inbox_open_hrm_mark", NULL
},
245 {paste_xpm
, NULL
, NULL
, "insert_file", NULL
},
246 {interface_xpm
, NULL
, NULL
, "interface", NULL
},
247 {jpilot_xpm
, NULL
, NULL
, "jpilot", NULL
},
248 {key_xpm
, NULL
, NULL
, "key", NULL
},
249 {ldap_xpm
, NULL
, NULL
, "ldap", NULL
},
250 {linewrapcurrent_xpm
, NULL
, NULL
, "linewrapcurrent", NULL
},
251 {linewrap_xpm
, NULL
, NULL
, "linewrap", NULL
},
252 {locked_xpm
, NULL
, NULL
, "locked", NULL
},
253 {mail_xpm
, NULL
, NULL
, "mail", NULL
},
254 {mail_attach_xpm
, NULL
, NULL
, "mail_attach", NULL
},
255 {mail_compose_xpm
, NULL
, NULL
, "mail_compose", NULL
},
256 {mail_forward_xpm
, NULL
, NULL
, "mail_forward", NULL
},
257 {mail_receive_xpm
, NULL
, NULL
, "mail_receive", NULL
},
258 {mail_receive_all_xpm
, NULL
, NULL
, "mail_receive_all", NULL
},
259 {mail_reply_xpm
, NULL
, NULL
, "mail_reply", NULL
},
260 {mail_reply_to_all_xpm
, NULL
, NULL
, "mail_reply_to_all", NULL
},
261 {mail_reply_to_author_xpm
, NULL
, NULL
, "mail_reply_to_author", NULL
},
262 {mail_send_xpm
, NULL
, NULL
, "mail_send", NULL
},
263 {mail_send_queue_xpm
, NULL
, NULL
, "mail_send_queue", NULL
},
264 {mail_sign_xpm
, NULL
, NULL
, "mail_sign", NULL
},
265 {open_mail_xpm
, NULL
, NULL
, "open_mail", NULL
},
266 {mark_xpm
, NULL
, NULL
, "mark", NULL
},
267 {new_xpm
, NULL
, NULL
, "new", NULL
},
268 {news_compose_xpm
, NULL
, NULL
, "news_compose", NULL
},
269 {outbox_close_xpm
, NULL
, NULL
, "outbox_close", NULL
},
270 {outbox_close_hrm_xpm
, NULL
, NULL
, "outbox_close_hrm", NULL
},
271 {outbox_open_xpm
, NULL
, NULL
, "outbox_open", NULL
},
272 {outbox_open_hrm_xpm
, NULL
, NULL
, "outbox_open_hrm", NULL
},
273 {outbox_close_mark_xpm
, NULL
, NULL
, "outbox_close_mark", NULL
},
274 {outbox_close_hrm_mark_xpm
, NULL
, NULL
, "outbox_close_hrm_mark", NULL
},
275 {outbox_open_mark_xpm
, NULL
, NULL
, "outbox_open_mark", NULL
},
276 {outbox_open_hrm_mark_xpm
, NULL
, NULL
, "outbox_open_hrm_mark", NULL
},
277 {replied_xpm
, NULL
, NULL
, "replied", NULL
},
278 {paste_xpm
, NULL
, NULL
, "paste", NULL
},
279 {preferences_xpm
, NULL
, NULL
, "preferences", NULL
},
280 {properties_xpm
, NULL
, NULL
, "properties", NULL
},
281 {queue_close_xpm
, NULL
, NULL
, "queue_close", NULL
},
282 {queue_close_hrm_xpm
, NULL
, NULL
, "queue_close_hrm", NULL
},
283 {queue_open_xpm
, NULL
, NULL
, "queue_open", NULL
},
284 {queue_open_hrm_xpm
, NULL
, NULL
, "queue_open_hrm", NULL
},
285 {trash_xpm
, NULL
, NULL
, "trash_open", NULL
},
286 {trash_hrm_xpm
, NULL
, NULL
, "trash_open_hrm", NULL
},
287 {trash_xpm
, NULL
, NULL
, "trash_close", NULL
},
288 {trash_hrm_xpm
, NULL
, NULL
, "trash_close_hrm", NULL
},
289 {queue_close_mark_xpm
, NULL
, NULL
, "queue_close_mark", NULL
},
290 {queue_close_hrm_mark_xpm
, NULL
, NULL
, "queue_close_hrm_mark", NULL
},
291 {queue_open_mark_xpm
, NULL
, NULL
, "queue_open_mark", NULL
},
292 {queue_open_hrm_mark_xpm
, NULL
, NULL
, "queue_open_hrm_mark", NULL
},
293 {trash_mark_xpm
, NULL
, NULL
, "trash_open_mark", NULL
},
294 {trash_hrm_mark_xpm
, NULL
, NULL
, "trash_open_hrm_mark", NULL
},
295 {trash_mark_xpm
, NULL
, NULL
, "trash_close_mark", NULL
},
296 {trash_hrm_mark_xpm
, NULL
, NULL
, "trash_close_hrm_mark", NULL
},
297 {unread_xpm
, NULL
, NULL
, "unread", NULL
},
298 {vcard_xpm
, NULL
, NULL
, "vcard", NULL
},
299 {online_xpm
, NULL
, NULL
, "online", NULL
},
300 {offline_xpm
, NULL
, NULL
, "offline", NULL
},
301 {notice_warn_xpm
, NULL
, NULL
, "notice_warn", NULL
},
302 {notice_error_xpm
, NULL
, NULL
, "notice_error", NULL
},
303 {notice_note_xpm
, NULL
, NULL
, "notice_note", NULL
},
304 {quicksearch_xpm
, NULL
, NULL
, "quicksearch", NULL
},
305 {gpg_signed_xpm
, NULL
, NULL
, "gpg_signed", NULL
},
306 {drafts_close_xpm
, NULL
, NULL
, "drafts_close", NULL
},
307 {drafts_open_xpm
, NULL
, NULL
, "drafts_open", NULL
},
308 {drafts_close_mark_xpm
, NULL
, NULL
, "drafts_close_mark", NULL
},
309 {drafts_open_mark_xpm
, NULL
, NULL
, "drafts_open_mark", NULL
},
310 {mime_text_plain_xpm
, NULL
, NULL
, "mime_text_plain", NULL
},
311 {mime_text_html_xpm
, NULL
, NULL
, "mime_text_html", NULL
},
312 {mime_application_xpm
, NULL
, NULL
, "mime_application", NULL
},
313 {mime_image_xpm
, NULL
, NULL
, "mime_image", NULL
},
314 {mime_audio_xpm
, NULL
, NULL
, "mime_audio", NULL
},
315 {mime_text_enriched_xpm
, NULL
, NULL
, "mime_text_enriched", NULL
},
316 {mime_unknown_xpm
, NULL
, NULL
, "mime_unknown", NULL
},
317 {mime_pdf_xpm
, NULL
, NULL
, "mime_pdf", NULL
},
318 {mime_ps_xpm
, NULL
, NULL
, "mime_ps", NULL
},
319 {mime_calendar_xpm
, NULL
, NULL
, "mime_calendar", NULL
},
320 {mime_pgpsig_xpm
, NULL
, NULL
, "mime_pgpsig", NULL
},
321 {printer_xpm
, NULL
, NULL
, "printer", NULL
},
322 {privacy_signed_xpm
, NULL
, NULL
, "privacy_signed", NULL
},
323 {privacy_passed_xpm
, NULL
, NULL
, "privacy_passed", NULL
},
324 {privacy_failed_xpm
, NULL
, NULL
, "privacy_failed", NULL
},
325 {privacy_unknown_xpm
, NULL
, NULL
, "privacy_unknown", NULL
},
326 {privacy_expired_xpm
, NULL
, NULL
, "privacy_expired", NULL
},
327 {privacy_warn_xpm
, NULL
, NULL
, "privacy_warn", NULL
},
328 {privacy_emblem_encrypted_xpm
, NULL
, NULL
, "privacy_emblem_encrypted", NULL
},
329 {privacy_emblem_signed_xpm
, NULL
, NULL
, "privacy_emblem_signed", NULL
},
330 {privacy_emblem_passed_xpm
, NULL
, NULL
, "privacy_emblem_passed", NULL
},
331 {privacy_emblem_failed_xpm
, NULL
, NULL
, "privacy_emblem_failed", NULL
},
332 {privacy_emblem_warn_xpm
, NULL
, NULL
, "privacy_emblem_warn", NULL
},
333 {mime_message_xpm
, NULL
, NULL
, "mime_message", NULL
},
334 {claws_mail_icon_xpm
, NULL
, NULL
, "claws_mail_icon", NULL
},
335 {read_xpm
, NULL
, NULL
, "read", NULL
},
336 {trash_btn_xpm
, NULL
, NULL
, "trash_btn", NULL
},
337 {claws_mail_logo_xpm
, NULL
, NULL
, "claws_mail_logo", NULL
},
338 {dir_noselect_xpm
, NULL
, NULL
, "dir_noselect" , NULL
},
339 {spam_xpm
, NULL
, NULL
, "spam" , NULL
},
340 {spam_btn_xpm
, NULL
, NULL
, "spam_btn" , NULL
},
341 {ham_btn_xpm
, NULL
, NULL
, "ham_btn" , NULL
},
342 {moved_xpm
, NULL
, NULL
, "moved", NULL
},
343 {copied_xpm
, NULL
, NULL
, "copied", NULL
},
344 {selection_xpm
, NULL
, NULL
, "selection", NULL
},
345 {empty_xpm
, NULL
, NULL
, "empty" , NULL
}
348 /* return newly constructed GtkPixmap from GdkPixmap */
349 GtkWidget
*stock_pixmap_widget(GtkWidget
*window
, StockPixmap icon
)
354 g_return_val_if_fail(window
!= NULL
, NULL
);
355 g_return_val_if_fail(icon
>= 0 && icon
< N_STOCK_PIXMAPS
, NULL
);
357 if (stock_pixmap_gdk(window
, icon
, &pixmap
, &mask
) != -1)
358 return gtk_image_new_from_pixmap(pixmap
, mask
);
366 gint
stock_pixbuf_gdk(GtkWidget
*window
, StockPixmap icon
, GdkPixbuf
**pixbuf
)
368 StockPixmapData
*pix_d
;
373 g_return_val_if_fail(icon
>= 0 && icon
< N_STOCK_PIXMAPS
, -1);
375 pix_d
= &pixmaps
[icon
];
377 if (!pix_d
->pixbuf
|| (strcmp2(pix_d
->icon_path
, prefs_common
.pixmap_theme_path
) != 0)) {
378 GdkPixbuf
*pix
= NULL
;
380 if (strcmp(prefs_common
.pixmap_theme_path
, DEFAULT_PIXMAP_THEME
) != 0) {
381 if (is_dir_exist(prefs_common
.pixmap_theme_path
)) {
382 char *icon_file_name
;
384 icon_file_name
= g_strconcat(prefs_common
.pixmap_theme_path
,
389 if (is_file_exist(icon_file_name
)) {
391 pix
= gdk_pixbuf_new_from_file(icon_file_name
, &err
);
392 if (err
) g_error_free(err
);
395 g_free(pix_d
->icon_path
);
396 pix_d
->icon_path
= g_strdup(prefs_common
.pixmap_theme_path
);
398 g_free(icon_file_name
);
400 /* even the path does not exist (deleted between two sessions), so
401 set the preferences to the internal theme */
402 prefs_common
.pixmap_theme_path
= g_strdup(DEFAULT_PIXMAP_THEME
);
408 if (!pix_d
->pixbuf
) {
409 pix_d
->pixbuf
= gdk_pixbuf_new_from_xpm_data((const gchar
**) pix_d
->data
);
411 g_free(pix_d
->icon_path
);
412 pix_d
->icon_path
= g_strdup(DEFAULT_PIXMAP_THEME
);
416 g_return_val_if_fail(pix_d
->pixbuf
!= NULL
, -1);
419 *pixbuf
= pix_d
->pixbuf
;
421 /* pixbuf should have one ref outstanding */
426 /* create GdkPixmap if it has not created yet */
427 gint
stock_pixmap_gdk(GtkWidget
*window
, StockPixmap icon
,
428 GdkPixmap
**pixmap
, GdkBitmap
**mask
)
430 StockPixmapData
*pix_d
;
432 if (pixmap
) *pixmap
= NULL
;
433 if (mask
) *mask
= NULL
;
435 g_return_val_if_fail(window
!= NULL
, -1);
436 g_return_val_if_fail(icon
>= 0 && icon
< N_STOCK_PIXMAPS
, -1);
438 pix_d
= &pixmaps
[icon
];
440 if (!pix_d
->pixmap
|| (strcmp2(pix_d
->icon_path
, prefs_common
.pixmap_theme_path
) != 0)) {
441 GdkPixmap
*pix
= NULL
;
443 if (strcmp(prefs_common
.pixmap_theme_path
, DEFAULT_PIXMAP_THEME
) != 0) {
444 if ( is_dir_exist(prefs_common
.pixmap_theme_path
) ) {
445 char *icon_file_name
;
447 icon_file_name
= g_strconcat(prefs_common
.pixmap_theme_path
,
452 if (is_file_exist(icon_file_name
))
453 PIXMAP_CREATE_FROM_FILE(window
, pix
, pix_d
->mask
, icon_file_name
);
455 g_free(pix_d
->icon_path
);
456 pix_d
->icon_path
= g_strdup(prefs_common
.pixmap_theme_path
);
458 g_free(icon_file_name
);
460 /* even the path does not exist (deleted between two sessions), so
461 set the preferences to the internal theme */
462 prefs_common
.pixmap_theme_path
= g_strdup(DEFAULT_PIXMAP_THEME
);
468 if (!pix_d
->pixmap
) {
469 PIXMAP_CREATE(window
, pix_d
->pixmap
, pix_d
->mask
, pix_d
->data
);
471 g_free(pix_d
->icon_path
);
472 pix_d
->icon_path
= g_strdup(DEFAULT_PIXMAP_THEME
);
476 g_return_val_if_fail(pix_d
->pixmap
!= NULL
, -1);
479 *pixmap
= pix_d
->pixmap
;
486 static void stock_pixmap_find_themes_in_dir(GList
**list
, const gchar
*dirname
)
491 if ((dp
= opendir(dirname
)) == NULL
) {
492 debug_print("dir %s not found, skipping theme scan", dirname
);
496 while ((d
= readdir(dp
)) != NULL
) {
501 fullentry
= g_strconcat(dirname
, G_DIR_SEPARATOR_S
, entry
, NULL
);
503 if (strcmp(entry
, ".") != 0 && strcmp(entry
, "..") != 0 && is_dir_exist(fullentry
)) {
507 for (i
= 0; i
< N_STOCK_PIXMAPS
; i
++) {
508 filetoexist
= g_strconcat(fullentry
, G_DIR_SEPARATOR_S
, pixmaps
[i
].file
, ".xpm", NULL
);
509 if (is_file_exist(filetoexist
)) {
510 *list
= g_list_append(*list
, fullentry
);
516 if (i
== N_STOCK_PIXMAPS
)
524 GList
*stock_pixmap_themes_list_new(void)
531 defaulttheme
= g_strdup(DEFAULT_PIXMAP_THEME
);
532 userthemes
= g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S
,
533 RC_DIR
, G_DIR_SEPARATOR_S
,
534 PIXMAP_THEME_DIR
, NULL
);
535 systemthemes
= g_strconcat(PACKAGE_DATA_DIR
, G_DIR_SEPARATOR_S
,
536 PIXMAP_THEME_DIR
, NULL
);
538 list
= g_list_append(list
, defaulttheme
);
540 stock_pixmap_find_themes_in_dir(&list
, userthemes
);
541 stock_pixmap_find_themes_in_dir(&list
, systemthemes
);
544 g_free(systemthemes
);
548 void stock_pixmap_themes_list_free(GList
*list
)
552 for (ptr
= g_list_first(list
); ptr
!= NULL
; ptr
= g_list_next(ptr
))
557 gchar
*stock_pixmap_get_name (StockPixmap icon
)
559 g_return_val_if_fail(icon
>= 0 && icon
< N_STOCK_PIXMAPS
, NULL
);
561 return pixmaps
[icon
].file
;
565 StockPixmap
stock_pixmap_get_icon (gchar
*file
)
569 for (i
= 0; i
< N_STOCK_PIXMAPS
; i
++) {
570 if (strcmp (pixmaps
[i
].file
, file
) == 0)
576 static gboolean
pixmap_with_overlay_expose_event_cb(GtkWidget
*widget
, GdkEventExpose
*expose
,
579 GdkDrawable
*drawable
= widget
->window
;
584 g_return_val_if_fail(data
->base_pixmap
!= NULL
, FALSE
);
585 g_return_val_if_fail(data
->base_mask
!= NULL
, FALSE
);
587 gc_pix
= gdk_gc_new((GdkWindow
*)drawable
);
589 gdk_window_clear_area (drawable
, expose
->area
.x
, expose
->area
.y
,
590 expose
->area
.width
, expose
->area
.height
);
592 gdk_gc_set_tile(gc_pix
, data
->base_pixmap
);
593 gdk_gc_set_ts_origin(gc_pix
, data
->border_x
, data
->border_y
);
594 gdk_gc_set_clip_mask(gc_pix
, data
->base_mask
);
595 gdk_gc_set_clip_origin(gc_pix
, data
->border_x
, data
->border_y
);
596 gdk_gc_set_fill(gc_pix
, GDK_TILED
);
598 gdk_draw_rectangle(drawable
, gc_pix
, TRUE
, data
->border_x
, data
->border_y
,
599 data
->base_width
, data
->base_height
);
601 if (data
->position
!= OVERLAY_NONE
) {
602 g_return_val_if_fail(data
->overlay_pixmap
!= NULL
, FALSE
);
603 g_return_val_if_fail(data
->overlay_mask
!= NULL
, FALSE
);
605 gdk_gc_set_tile(gc_pix
, data
->overlay_pixmap
);
606 gdk_gc_set_clip_mask(gc_pix
, data
->overlay_mask
);
608 switch (data
->position
) {
609 case OVERLAY_TOP_LEFT
:
610 case OVERLAY_MID_LEFT
:
611 case OVERLAY_BOTTOM_LEFT
:
615 case OVERLAY_TOP_CENTER
:
616 case OVERLAY_MID_CENTER
:
617 case OVERLAY_BOTTOM_CENTER
:
618 left
= (data
->base_width
+ data
->border_x
* 2 - data
->overlay_width
)/2;
621 case OVERLAY_TOP_RIGHT
:
622 case OVERLAY_MID_RIGHT
:
623 case OVERLAY_BOTTOM_RIGHT
:
624 left
= data
->base_width
+ data
->border_x
* 2 - data
->overlay_width
;
630 switch (data
->position
) {
631 case OVERLAY_TOP_LEFT
:
632 case OVERLAY_TOP_CENTER
:
633 case OVERLAY_TOP_RIGHT
:
637 case OVERLAY_MID_LEFT
:
638 case OVERLAY_MID_CENTER
:
639 case OVERLAY_MID_RIGHT
:
640 top
= (data
->base_height
+ data
->border_y
* 2 - data
->overlay_height
)/2;
643 case OVERLAY_BOTTOM_LEFT
:
644 case OVERLAY_BOTTOM_CENTER
:
645 case OVERLAY_BOTTOM_RIGHT
:
646 top
= data
->base_height
+ data
->border_y
* 2 - data
->overlay_height
;
653 gdk_gc_set_ts_origin(gc_pix
, left
, top
);
654 gdk_gc_set_clip_origin(gc_pix
, left
, top
);
655 gdk_gc_set_fill(gc_pix
, GDK_TILED
);
656 gdk_draw_rectangle(drawable
, gc_pix
, TRUE
, left
, top
,
657 data
->overlay_width
, data
->overlay_height
);
659 g_object_unref(gc_pix
);
664 static void pixmap_with_overlay_destroy_cb(GtkObject
*object
, OverlayData
*data
)
666 g_object_unref(data
->base_pixmap
);
667 g_object_unref(data
->base_mask
);
668 if (data
->position
!= OVERLAY_NONE
) {
669 g_object_unref(data
->overlay_pixmap
);
670 g_object_unref(data
->overlay_mask
);
676 * \brief Get a widget showing one icon with another overlaid on top of it.
678 * The base icon is always centralised, the other icon can be positioned.
679 * The overlay icon is ignored if pos=OVERLAY_NONE is used
681 * \param window top-level window widget
682 * \param icon the base icon
683 * \param overlay the icon to overlay
684 * \param pos how to align the overlay widget, or OVERLAY_NONE for no overlay
685 * \param border_x size of the border around the base icon (left and right)
686 * \param border_y size of the border around the base icon (top and bottom)
688 GtkWidget
*stock_pixmap_widget_with_overlay(GtkWidget
*window
, StockPixmap icon
,
689 StockPixmap overlay
, OverlayPosition pos
,
690 gint border_x
, gint border_y
)
692 GdkPixmap
*stock_pixmap
;
693 GdkBitmap
*stock_mask
;
695 GtkWidget
*stock_wid
;
698 data
= g_new0(OverlayData
, 1);
700 stock_wid
= stock_pixmap_widget(window
, icon
);
701 gtk_image_get_pixmap(GTK_IMAGE(stock_wid
), &stock_pixmap
, &stock_mask
);
702 g_object_ref(stock_pixmap
);
703 g_object_ref(stock_mask
);
704 data
->base_pixmap
= stock_pixmap
;
705 data
->base_mask
= stock_mask
;
706 data
->base_height
= stock_wid
->requisition
.height
;
707 data
->base_width
= stock_wid
->requisition
.width
;
708 gtk_widget_destroy(stock_wid
);
710 if (pos
== OVERLAY_NONE
) {
711 data
->overlay_pixmap
= NULL
;
712 data
->overlay_mask
= NULL
;
714 stock_wid
= stock_pixmap_widget(window
, overlay
);
715 gtk_image_get_pixmap(GTK_IMAGE(stock_wid
), &stock_pixmap
, &stock_mask
);
716 g_object_ref(stock_pixmap
);
717 g_object_ref(stock_mask
);
718 data
->overlay_pixmap
= stock_pixmap
;
719 data
->overlay_mask
= stock_mask
;
720 data
->overlay_height
= stock_wid
->requisition
.height
;
721 data
->overlay_width
= stock_wid
->requisition
.width
;
723 gtk_widget_destroy(stock_wid
);
726 data
->position
= pos
;
727 data
->border_x
= border_x
;
728 data
->border_y
= border_y
;
730 widget
= gtk_drawing_area_new();
731 gtk_drawing_area_size(GTK_DRAWING_AREA(widget
), data
->base_width
+ border_x
* 2,
732 data
->base_height
+ border_y
* 2);
733 g_signal_connect(G_OBJECT(widget
), "expose_event",
734 G_CALLBACK(pixmap_with_overlay_expose_event_cb
), data
);
735 g_signal_connect(G_OBJECT(widget
), "destroy",
736 G_CALLBACK(pixmap_with_overlay_destroy_cb
), data
);