559a3eb835ceced53eca802b374f3e18b7affc60
[claws.git] / src / stock_pixmap.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include "defs.h"
21 #include <glib.h>
22 #include <gtk/gtkwidget.h>
23 #include <gtk/gtkimage.h>
24 #include <string.h>
25 #include <dirent.h>
26
27 #include "stock_pixmap.h"
28 #include "gtkutils.h"
29 #include "utils.h"
30 #include "prefs_common.h"
31
32 #include "pixmaps/address.xpm"
33 #include "pixmaps/book.xpm"
34 #include "pixmaps/category.xpm"
35 #include "pixmaps/checkbox_off.xpm"
36 #include "pixmaps/checkbox_on.xpm"
37 #include "pixmaps/clip.xpm"
38 #include "pixmaps/clipkey.xpm"
39 #include "pixmaps/complete.xpm"
40 #include "pixmaps/continue.xpm"
41 #include "pixmaps/deleted.xpm"
42 #include "pixmaps/error.xpm"
43 #include "pixmaps/forwarded.xpm"
44 #include "pixmaps/group.xpm"
45 #include "pixmaps/interface.xpm"
46 #include "pixmaps/jpilot.xpm"
47 #include "pixmaps/key.xpm"
48 #include "pixmaps/ldap.xpm"
49 #include "pixmaps/linewrap.xpm"
50 #include "pixmaps/linewrapcurrent.xpm"
51 #include "pixmaps/mark.xpm"
52 #include "pixmaps/locked.xpm"
53 #include "pixmaps/new.xpm"
54 #include "pixmaps/replied.xpm"
55 #include "pixmaps/close.xpm"
56 #include "pixmaps/down_arrow.xpm"
57 #include "pixmaps/up_arrow.xpm"
58 #include "pixmaps/exec.xpm"
59 #include "pixmaps/mail.xpm"
60 #include "pixmaps/mail_attach.xpm"
61 #include "pixmaps/mail_compose.xpm"
62 #include "pixmaps/mail_forward.xpm"
63 #include "pixmaps/mail_receive.xpm"
64 #include "pixmaps/mail_receive_all.xpm"
65 #include "pixmaps/mail_reply.xpm"
66 #include "pixmaps/mail_reply_to_all.xpm"
67 #include "pixmaps/mail_reply_to_author.xpm"
68 #include "pixmaps/mail_send.xpm"
69 #include "pixmaps/mail_send_queue.xpm"
70 #include "pixmaps/news_compose.xpm"
71 #include "pixmaps/paste.xpm"
72 #include "pixmaps/preferences.xpm"
73 #include "pixmaps/properties.xpm"
74 #include "pixmaps/sylpheed_icon.xpm"
75 #include "pixmaps/sylpheed_logo.xpm"
76 #include "pixmaps/address_book.xpm"
77 #include "pixmaps/unread.xpm"
78 #include "pixmaps/read.xpm"
79 #include "pixmaps/vcard.xpm"
80 #include "pixmaps/ignorethread.xpm"
81 #include "pixmaps/online.xpm"
82 #include "pixmaps/offline.xpm"
83 #include "pixmaps/notice_warn.xpm"
84 #include "pixmaps/notice_error.xpm"
85 #include "pixmaps/notice_note.xpm"
86 #include "pixmaps/quicksearch.xpm"
87 #include "pixmaps/clip_gpg_signed.xpm"
88 #include "pixmaps/gpg_signed.xpm"
89 #include "pixmaps/mime_text_plain.xpm"
90 #include "pixmaps/mime_text_html.xpm"
91 #include "pixmaps/mime_application.xpm"
92 #include "pixmaps/mime_image.xpm"
93 #include "pixmaps/mime_audio.xpm"
94 #include "pixmaps/mime_text_enriched.xpm"
95 #include "pixmaps/mime_unknown.xpm"
96 #include "pixmaps/privacy_signed.xpm"
97 #include "pixmaps/privacy_passed.xpm"
98 #include "pixmaps/privacy_failed.xpm"
99 #include "pixmaps/privacy_unknown.xpm"
100 #include "pixmaps/privacy_expired.xpm"
101 #include "pixmaps/privacy_warn.xpm"                 
102 #include "pixmaps/privacy_emblem_encrypted.xpm"
103 #include "pixmaps/privacy_emblem_signed.xpm"
104 #include "pixmaps/privacy_emblem_passed.xpm"
105 #include "pixmaps/privacy_emblem_failed.xpm"
106 #include "pixmaps/privacy_emblem_warn.xpm"
107 #include "pixmaps/mime_message.xpm"                  
108 #include "pixmaps/address_search.xpm"
109 #include "pixmaps/check_spelling.xpm"
110
111 #include "pixmaps/dir_close.xpm"
112 #include "pixmaps/dir_open.xpm"
113 #include "pixmaps/dir_open_hrm.xpm"
114 #include "pixmaps/inbox.xpm"
115 #include "pixmaps/inbox_hrm.xpm"
116 #include "pixmaps/outbox.xpm"
117 #include "pixmaps/outbox_hrm.xpm"
118 #include "pixmaps/trash.xpm"
119 #include "pixmaps/trash_btn.xpm"
120 #include "pixmaps/trash_hrm.xpm"
121 #include "pixmaps/drafts_close.xpm"
122 #include "pixmaps/drafts_open.xpm"
123 #include "pixmaps/dir_close_mark.xpm"
124 #include "pixmaps/dir_open_mark.xpm"
125 #include "pixmaps/dir_open_hrm_mark.xpm"
126 #include "pixmaps/inbox_mark.xpm"
127 #include "pixmaps/inbox_hrm_mark.xpm"
128 #include "pixmaps/outbox_mark.xpm"
129 #include "pixmaps/outbox_hrm_mark.xpm"
130 #include "pixmaps/trash_mark.xpm"
131 #include "pixmaps/trash_hrm_mark.xpm"
132 #include "pixmaps/drafts_close_mark.xpm"
133 #include "pixmaps/drafts_open_mark.xpm"
134 #include "pixmaps/dir_noselect.xpm"
135
136 typedef struct _StockPixmapData StockPixmapData;
137
138 struct _StockPixmapData
139 {
140         gchar **data;
141         GdkPixmap *pixmap;
142         GdkBitmap *mask;
143         gchar *file;
144         gchar *icon_path;
145         GdkPixbuf *pixbuf;
146 };
147
148 typedef struct _OverlayData OverlayData;
149
150 struct _OverlayData
151 {
152         GdkPixmap *base_pixmap;
153         GdkBitmap *base_mask;
154         GdkPixmap *overlay_pixmap;
155         GdkBitmap *overlay_mask;
156         guint base_height;
157         guint base_width;
158         guint overlay_height;
159         guint overlay_width;
160         OverlayPosition position;
161         gint border_x;
162         gint border_y;
163 };
164
165 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname);
166
167 static StockPixmapData pixmaps[] =
168 {
169         {address_xpm                            , NULL, NULL, "address", NULL},
170         {address_book_xpm                       , NULL, NULL, "address_book", NULL},
171         {address_search_xpm                     , NULL, NULL, "address_search", NULL},
172         {book_xpm                               , NULL, NULL, "book", NULL},
173         {category_xpm                           , NULL, NULL, "category", NULL},
174         {checkbox_off_xpm                       , NULL, NULL, "checkbox_off", NULL},
175         {checkbox_on_xpm                        , NULL, NULL, "checkbox_on", NULL},
176         {check_spelling_xpm                     , NULL, NULL, "check_spelling", NULL},
177         {clip_xpm                               , NULL, NULL, "clip", NULL},
178         {clipkey_xpm                            , NULL, NULL, "clipkey", NULL},
179         {clip_gpg_signed_xpm                    , NULL, NULL, "clip_gpg_signed", NULL},
180         {close_xpm                              , NULL, NULL, "close", NULL},
181         {complete_xpm                           , NULL, NULL, "complete", NULL},
182         {continue_xpm                           , NULL, NULL, "continue", NULL},
183         {deleted_xpm                            , NULL, NULL, "deleted", NULL},
184         {dir_close_xpm                          , NULL, NULL, "dir_close", NULL},
185         {dir_close_xpm                          , NULL, NULL, "dir_close_hrm", NULL},
186         {dir_open_xpm                           , NULL, NULL, "dir_open", NULL},
187         {dir_open_hrm_xpm                       , NULL, NULL, "dir_open_hrm", NULL},
188         {dir_close_mark_xpm                     , NULL, NULL, "dir_close_mark", NULL},
189         {dir_close_mark_xpm                     , NULL, NULL, "dir_close_hrm_mark", NULL},
190         {dir_open_mark_xpm                      , NULL, NULL, "dir_open_mark", NULL},
191         {dir_open_hrm_mark_xpm                  , NULL, NULL, "dir_open_hrm_mark", NULL},
192         {down_arrow_xpm                         , NULL, NULL, "down_arrow", NULL},
193         {up_arrow_xpm                           , NULL, NULL, "up_arrow", NULL},
194         {mail_compose_xpm                       , NULL, NULL, "edit_extern", NULL},
195         {error_xpm                              , NULL, NULL, "error", NULL},
196         {exec_xpm                               , NULL, NULL, "exec", NULL},
197         {forwarded_xpm                          , NULL, NULL, "forwarded", NULL},
198         {group_xpm                              , NULL, NULL, "group", NULL},
199         {ignorethread_xpm                       , NULL, NULL, "ignorethread", NULL},
200         {inbox_xpm                              , NULL, NULL, "inbox_close", NULL},
201         {inbox_hrm_xpm                          , NULL, NULL, "inbox_close_hrm", NULL},
202         {inbox_xpm                              , NULL, NULL, "inbox_open", NULL},
203         {inbox_hrm_xpm                          , NULL, NULL, "inbox_open_hrm", NULL},
204         {inbox_mark_xpm                         , NULL, NULL, "inbox_close_mark", NULL},
205         {inbox_hrm_mark_xpm                     , NULL, NULL, "inbox_close_hrm_mark", NULL},
206         {inbox_mark_xpm                         , NULL, NULL, "inbox_open_mark", NULL},
207         {inbox_hrm_mark_xpm                     , NULL, NULL, "inbox_open_hrm_mark", NULL},
208         {paste_xpm                              , NULL, NULL, "insert_file", NULL},
209         {interface_xpm                          , NULL, NULL, "interface", NULL},
210         {jpilot_xpm                             , NULL, NULL, "jpilot", NULL},
211         {key_xpm                                , NULL, NULL, "key", NULL},
212         {ldap_xpm                               , NULL, NULL, "ldap", NULL},
213         {linewrapcurrent_xpm                    , NULL, NULL, "linewrapcurrent", NULL},
214         {linewrap_xpm                           , NULL, NULL, "linewrap", NULL},
215         {locked_xpm                             , NULL, NULL, "locked", NULL},
216         {mail_xpm                               , NULL, NULL, "mail", NULL},
217         {mail_attach_xpm                        , NULL, NULL, "mail_attach", NULL},
218         {mail_compose_xpm                       , NULL, NULL, "mail_compose", NULL},
219         {mail_forward_xpm                       , NULL, NULL, "mail_forward", NULL},
220         {mail_receive_xpm                       , NULL, NULL, "mail_receive", NULL},
221         {mail_receive_all_xpm                   , NULL, NULL, "mail_receive_all", NULL},
222         {mail_reply_xpm                         , NULL, NULL, "mail_reply", NULL},
223         {mail_reply_to_all_xpm                  , NULL, NULL, "mail_reply_to_all", NULL},
224         {mail_reply_to_author_xpm               , NULL, NULL, "mail_reply_to_author", NULL},
225         {mail_send_xpm                          , NULL, NULL, "mail_send", NULL},
226         {mail_send_queue_xpm                    , NULL, NULL, "mail_send_queue", NULL},
227         {mail_xpm                               , NULL, NULL, "mail_sign", NULL},
228         {mark_xpm                               , NULL, NULL, "mark", NULL},
229         {new_xpm                                , NULL, NULL, "new", NULL},
230         {news_compose_xpm                       , NULL, NULL, "news_compose", NULL},
231         {outbox_xpm                             , NULL, NULL, "outbox_close", NULL},
232         {outbox_hrm_xpm                         , NULL, NULL, "outbox_close_hrm", NULL},
233         {outbox_xpm                             , NULL, NULL, "outbox_open", NULL},
234         {outbox_hrm_xpm                         , NULL, NULL, "outbox_open_hrm", NULL},
235         {outbox_mark_xpm                        , NULL, NULL, "outbox_close_mark", NULL},
236         {outbox_hrm_mark_xpm                    , NULL, NULL, "outbox_close_hrm_mark", NULL},
237         {outbox_mark_xpm                        , NULL, NULL, "outbox_open_mark", NULL},
238         {outbox_hrm_mark_xpm                    , NULL, NULL, "outbox_open_hrm_mark", NULL},
239         {replied_xpm                            , NULL, NULL, "replied", NULL},
240         {paste_xpm                              , NULL, NULL, "paste", NULL},
241         {preferences_xpm                        , NULL, NULL, "preferences", NULL},
242         {properties_xpm                         , NULL, NULL, "properties", NULL},
243         {outbox_xpm                             , NULL, NULL, "queue_close", NULL},
244         {outbox_hrm_xpm                         , NULL, NULL, "queue_close_hrm", NULL},
245         {outbox_xpm                             , NULL, NULL, "queue_open", NULL},
246         {outbox_hrm_xpm                         , NULL, NULL, "queue_open_hrm", NULL},
247         {trash_xpm                              , NULL, NULL, "trash_open", NULL},
248         {trash_hrm_xpm                          , NULL, NULL, "trash_open_hrm", NULL},
249         {trash_xpm                              , NULL, NULL, "trash_close", NULL},
250         {trash_hrm_xpm                          , NULL, NULL, "trash_close_hrm", NULL},
251         {outbox_mark_xpm                        , NULL, NULL, "queue_close_mark", NULL},
252         {outbox_hrm_mark_xpm                    , NULL, NULL, "queue_close_hrm_mark", NULL},
253         {outbox_mark_xpm                        , NULL, NULL, "queue_open_mark", NULL},
254         {outbox_hrm_mark_xpm                    , NULL, NULL, "queue_open_hrm_mark", NULL},
255         {trash_mark_xpm                         , NULL, NULL, "trash_open_mark", NULL},
256         {trash_hrm_mark_xpm                     , NULL, NULL, "trash_open_hrm_mark", NULL},
257         {trash_mark_xpm                         , NULL, NULL, "trash_close_mark", NULL},
258         {trash_hrm_mark_xpm                     , NULL, NULL, "trash_close_hrm_mark", NULL},
259         {unread_xpm                             , NULL, NULL, "unread", NULL},
260         {vcard_xpm                              , NULL, NULL, "vcard", NULL},
261         {online_xpm                             , NULL, NULL, "online", NULL},
262         {offline_xpm                            , NULL, NULL, "offline", NULL},
263         {notice_warn_xpm                        , NULL, NULL, "notice_warn",  NULL},
264         {notice_error_xpm                       , NULL, NULL, "notice_error",  NULL},
265         {notice_note_xpm                        , NULL, NULL, "notice_note",  NULL},
266         {quicksearch_xpm                        , NULL, NULL, "quicksearch",  NULL},
267         {gpg_signed_xpm                         , NULL, NULL, "gpg_signed", NULL},
268         {drafts_close_xpm                       , NULL, NULL, "drafts_close", NULL},
269         {drafts_open_xpm                        , NULL, NULL, "drafts_open", NULL},
270         {drafts_close_mark_xpm                  , NULL, NULL, "drafts_close_mark", NULL},
271         {drafts_open_mark_xpm                   , NULL, NULL, "drafts_open_mark", NULL},
272         {mime_text_plain_xpm                    , NULL, NULL, "mime_text_plain", NULL},
273         {mime_text_html_xpm                     , NULL, NULL, "mime_text_html", NULL},
274         {mime_application_xpm                   , NULL, NULL, "mime_application", NULL},
275         {mime_image_xpm                         , NULL, NULL, "mime_image", NULL},
276         {mime_audio_xpm                         , NULL, NULL, "mime_audio", NULL},
277         {mime_text_enriched_xpm                 , NULL, NULL, "mime_text_enriched", NULL},
278         {mime_unknown_xpm                       , NULL, NULL, "mime_unknown", NULL},    
279         {privacy_signed_xpm                     , NULL, NULL, "privacy_signed", NULL},
280         {privacy_passed_xpm                     , NULL, NULL, "privacy_passed", NULL},
281         {privacy_failed_xpm                     , NULL, NULL, "privacy_failed", NULL},  
282         {privacy_unknown_xpm                    , NULL, NULL, "privacy_unknown", NULL},
283         {privacy_expired_xpm                    , NULL, NULL, "privacy_expired", NULL},
284         {privacy_warn_xpm                       , NULL, NULL, "privacy_warn", NULL},
285         {privacy_emblem_encrypted_xpm           , NULL, NULL, "privacy_emblem_encrypted", NULL},
286         {privacy_emblem_signed_xpm              , NULL, NULL, "privacy_emblem_signed", NULL},
287         {privacy_emblem_passed_xpm              , NULL, NULL, "privacy_emblem_passed", NULL},
288         {privacy_emblem_failed_xpm              , NULL, NULL, "privacy_emblem_failed", NULL},   
289         {privacy_emblem_warn_xpm                , NULL, NULL, "privacy_emblem_warn", NULL},
290         {mime_message_xpm                       , NULL, NULL, "mime_message", NULL},
291         {sylpheed_icon_xpm                      , NULL, NULL, "sylpheed_icon", NULL},
292         {read_xpm                               , NULL, NULL, "read", NULL},
293         {trash_btn_xpm                          , NULL, NULL, "trash_btn", NULL},
294         {sylpheed_logo_xpm                      , NULL, NULL, "sylpheed_logo", NULL},
295         {dir_noselect_xpm                       , NULL, NULL, "dir_noselect" , NULL}
296 };
297
298 /* return newly constructed GtkPixmap from GdkPixmap */
299 GtkWidget *stock_pixmap_widget(GtkWidget *window, StockPixmap icon)
300 {
301         GdkPixmap *pixmap;
302         GdkBitmap *mask;
303
304         g_return_val_if_fail(window != NULL, NULL);
305         g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
306
307         if (stock_pixmap_gdk(window, icon, &pixmap, &mask) != -1)
308                 return gtk_image_new_from_pixmap(pixmap, mask);
309         
310         return NULL;
311 }
312
313 /*!
314  *\brief        
315  */
316 gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
317 {
318         StockPixmapData *pix_d;
319
320         if (pixbuf)
321                 *pixbuf = NULL;
322                 
323         g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
324
325         pix_d = &pixmaps[icon];
326
327         if (!pix_d->pixbuf || (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0)) {
328                 GdkPixbuf *pix = NULL;
329         
330                 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
331                         if (is_dir_exist(prefs_common.pixmap_theme_path)) {
332                                 char *icon_file_name; 
333                                 
334                                 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
335                                                              G_DIR_SEPARATOR_S,
336                                                              pix_d->file,
337                                                              ".xpm",
338                                                              NULL);
339                                 if (is_file_exist(icon_file_name)) {
340                                         GError *err = NULL;
341                                         pix = gdk_pixbuf_new_from_file(icon_file_name, &err);   
342                                         if (err) g_error_free(err);
343                                 }                                       
344                                 if (pix) {
345                                         if (pix_d->icon_path != NULL) g_free(pix_d->icon_path);
346                                         pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
347                                 }
348                                 g_free(icon_file_name);
349                         } else {
350                                 /* even the path does not exist (deleted between two sessions), so
351                                 set the preferences to the internal theme */
352                                 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
353                         }
354                 }
355                 pix_d->pixbuf = pix;
356         }
357
358         if (!pix_d->pixbuf) {
359                 pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) pix_d->data);
360                 if (pix_d->pixbuf) {
361                         if (pix_d->icon_path != NULL) g_free(pix_d->icon_path);
362                         pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);      
363                 }
364         }
365
366         g_return_val_if_fail(pix_d->pixbuf != NULL, -1);
367
368         if (pixbuf)
369                 *pixbuf = pix_d->pixbuf;
370
371         /* pixbuf should have one ref outstanding */            
372
373         return 0;
374 }
375
376 /* create GdkPixmap if it has not created yet */
377 gint stock_pixmap_gdk(GtkWidget *window, StockPixmap icon,
378                       GdkPixmap **pixmap, GdkBitmap **mask)
379 {
380         StockPixmapData *pix_d;
381
382         if (pixmap) *pixmap = NULL;
383         if (mask)   *mask   = NULL;
384
385         g_return_val_if_fail(window != NULL, -1);
386         g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
387
388         pix_d = &pixmaps[icon];
389
390         if (!pix_d->pixmap || (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0)) {
391                 GdkPixmap *pix = NULL;
392         
393                 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
394                         if ( is_dir_exist(prefs_common.pixmap_theme_path) ) {
395                                 char *icon_file_name; 
396                                 
397                                 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
398                                                              G_DIR_SEPARATOR_S,
399                                                              pix_d->file,
400                                                              ".xpm",
401                                                              NULL);
402                                 if (is_file_exist(icon_file_name))
403                                         PIXMAP_CREATE_FROM_FILE(window, pix, pix_d->mask, icon_file_name);
404                                 if (pix) {
405                                         if (pix_d->icon_path != NULL) g_free(pix_d->icon_path);
406                                         pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
407                                 }
408                                 g_free(icon_file_name);
409                         } else {
410                                 /* even the path does not exist (deleted between two sessions), so
411                                 set the preferences to the internal theme */
412                                 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
413                         }
414                 }
415                 pix_d->pixmap = pix;
416         }
417
418         if (!pix_d->pixmap) {
419                 PIXMAP_CREATE(window, pix_d->pixmap, pix_d->mask, pix_d->data);
420                 if (pix_d->pixmap) {
421                         if (pix_d->icon_path != NULL) g_free(pix_d->icon_path);
422                         pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);      
423                 }
424         }
425
426         g_return_val_if_fail(pix_d->pixmap != NULL, -1);
427         
428         if (pixmap) 
429                 *pixmap = pix_d->pixmap;
430         if (mask)   
431                 *mask   = pix_d->mask;
432
433         return 0;
434 }
435
436 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
437 {
438         struct dirent *d;
439         DIR *dp;
440         
441         if ((dp = opendir(dirname)) == NULL) {
442                 debug_print("dir %s not found, skipping theme scan", dirname);
443                 return;
444         }
445         
446         while ((d = readdir(dp)) != NULL) {
447                 gchar *entry;
448                 gchar *fullentry;
449
450                 entry     = d->d_name;
451                 fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
452                 
453                 if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
454                         gchar *filetoexist;
455                         int i;
456                         
457                         for (i = 0; i < N_STOCK_PIXMAPS; i++) {
458                                 filetoexist = g_strconcat(fullentry, G_DIR_SEPARATOR_S, pixmaps[i].file, ".xpm", NULL);
459                                 if (is_file_exist(filetoexist)) {
460                                         *list = g_list_append(*list, fullentry);
461                                         break;
462                                 }
463                         }
464                         g_free(filetoexist);
465                         if (i == N_STOCK_PIXMAPS) 
466                                 g_free(fullentry);
467                 } else 
468                         g_free(fullentry);
469         }
470         closedir(dp);
471 }
472
473 GList *stock_pixmap_themes_list_new(void)
474 {
475         gchar *defaulttheme;
476         gchar *userthemes;
477         gchar *systemthemes;
478         GList *list = NULL;
479         
480         defaulttheme = g_strdup(DEFAULT_PIXMAP_THEME);
481         userthemes   = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
482                                    RC_DIR, G_DIR_SEPARATOR_S, 
483                                    PIXMAP_THEME_DIR, NULL);
484         systemthemes = g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
485                                    PIXMAP_THEME_DIR, NULL);
486
487         list = g_list_append(list, defaulttheme);
488         
489         stock_pixmap_find_themes_in_dir(&list, userthemes);
490         stock_pixmap_find_themes_in_dir(&list, systemthemes);
491
492         g_free(userthemes);
493         g_free(systemthemes);
494         return list;
495 }
496
497 void stock_pixmap_themes_list_free(GList *list)
498 {
499         GList *ptr;
500
501         for (ptr = g_list_first(list); ptr != NULL; ptr = g_list_next(ptr)) 
502                 if (ptr->data)
503                         g_free(ptr->data);
504         g_list_free(list);              
505 }
506
507 gchar *stock_pixmap_get_name (StockPixmap icon)
508 {
509         g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
510         
511         return pixmaps[icon].file;
512
513 }
514
515 StockPixmap stock_pixmap_get_icon (gchar *file)
516 {
517         gint i;
518         
519         for (i = 0; i < N_STOCK_PIXMAPS; i++) {
520                 if (strcmp (pixmaps[i].file, file) == 0)
521                         return i;
522         }
523         return -1;
524 }
525
526 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventExpose *expose,
527                                                     OverlayData *data) 
528 {
529         GdkDrawable *drawable = widget->window; 
530         GdkGC *gc_pix;
531         gint left = 0;
532         gint top = 0;
533
534         g_return_val_if_fail(data->base_pixmap != NULL, FALSE);
535         g_return_val_if_fail(data->base_mask != NULL, FALSE);
536
537         gc_pix = gdk_gc_new((GdkWindow *)drawable);
538                                                  
539         gdk_window_clear_area (drawable, expose->area.x, expose->area.y,
540                                expose->area.width, expose->area.height);
541
542         gdk_gc_set_tile(gc_pix, data->base_pixmap);
543         gdk_gc_set_ts_origin(gc_pix, data->border_x, data->border_y);
544         gdk_gc_set_clip_mask(gc_pix, data->base_mask);
545         gdk_gc_set_clip_origin(gc_pix, data->border_x, data->border_y);
546         gdk_gc_set_fill(gc_pix, GDK_TILED);
547
548         gdk_draw_rectangle(drawable, gc_pix, TRUE, data->border_x, data->border_y, 
549                            data->base_width, data->base_height);
550
551         if (data->position != OVERLAY_NONE) {
552                 g_return_val_if_fail(data->overlay_pixmap != NULL, FALSE);
553                 g_return_val_if_fail(data->overlay_mask != NULL, FALSE);
554
555                 gdk_gc_set_tile(gc_pix, data->overlay_pixmap);
556                 gdk_gc_set_clip_mask(gc_pix, data->overlay_mask);
557
558                 switch (data->position) {
559                         case OVERLAY_TOP_LEFT:
560                         case OVERLAY_MID_LEFT:
561                         case OVERLAY_BOTTOM_LEFT:
562                                 left = 0;
563                                 break;
564
565                         case OVERLAY_TOP_CENTER:
566                         case OVERLAY_MID_CENTER:
567                         case OVERLAY_BOTTOM_CENTER:
568                                 left = (data->base_width + data->border_x * 2  - data->overlay_width)/2;
569                                 break;
570
571                         case OVERLAY_TOP_RIGHT:
572                         case OVERLAY_MID_RIGHT:
573                         case OVERLAY_BOTTOM_RIGHT:
574                                 left = data->base_width + data->border_x * 2 - data->overlay_width;
575                                 break;
576
577                         default:
578                                 break;
579                 }
580                 switch (data->position) {
581                         case OVERLAY_TOP_LEFT:
582                         case OVERLAY_TOP_CENTER:
583                         case OVERLAY_TOP_RIGHT:
584                                 top = 0;
585                                 break;
586
587                         case OVERLAY_MID_LEFT:
588                         case OVERLAY_MID_CENTER:
589                         case OVERLAY_MID_RIGHT:
590                                 top = (data->base_height + data->border_y * 2  - data->overlay_height)/2;
591                                 break;
592                                         
593                         case OVERLAY_BOTTOM_LEFT:
594                         case OVERLAY_BOTTOM_CENTER:
595                         case OVERLAY_BOTTOM_RIGHT:
596                                 top = data->base_height + data->border_y * 2 - data->overlay_height;
597                                 break;
598
599                         default:
600                                 break;
601                 }
602
603                 gdk_gc_set_ts_origin(gc_pix, left, top);
604                 gdk_gc_set_clip_origin(gc_pix, left, top);
605                 gdk_gc_set_fill(gc_pix, GDK_TILED);
606                 gdk_draw_rectangle(drawable, gc_pix, TRUE, left, top, 
607                                    data->overlay_width, data->overlay_height);
608         }
609         g_object_unref(gc_pix);
610         
611         return TRUE;
612 }
613
614 static void pixmap_with_overlay_destroy_cb(GtkObject *object, OverlayData *data) 
615 {
616         g_object_unref(data->base_pixmap);
617         g_object_unref(data->base_mask);
618         if (data->position != OVERLAY_NONE) {
619                 g_object_unref(data->overlay_pixmap);
620                 g_object_unref(data->overlay_mask);
621         }
622         g_free(data);
623 }
624
625 /**
626  * \brief Get a widget showing one icon with another overlaid on top of it.
627  *
628  * The base icon is always centralised, the other icon can be positioned.
629  * The overlay icon is ignored if pos=OVERLAY_NONE is used
630  *
631  * \param window   top-level window widget
632  * \param icon     the base icon
633  * \param overlay  the icon to overlay
634  * \param pos      how to align the overlay widget, or OVERLAY_NONE for no overlay
635  * \param border_x size of the border around the base icon (left and right)
636  * \param border_y size of the border around the base icon (top and bottom)
637  */
638 GtkWidget *stock_pixmap_widget_with_overlay(GtkWidget *window, StockPixmap icon,
639                                             StockPixmap overlay, OverlayPosition pos,
640                                             gint border_x, gint border_y)
641 {
642         GdkPixmap *stock_pixmap;
643         GdkBitmap *stock_mask;
644         GtkWidget *widget;
645         GtkWidget *stock_wid;
646         OverlayData *data;
647         
648         data = g_new0(OverlayData, 1);
649
650         stock_wid = stock_pixmap_widget(window, icon);
651         gtk_image_get_pixmap(GTK_IMAGE(stock_wid), &stock_pixmap, &stock_mask);
652         g_object_ref(stock_pixmap);
653         g_object_ref(stock_mask);
654         data->base_pixmap = stock_pixmap;
655         data->base_mask   = stock_mask;
656         data->base_height = stock_wid->requisition.height;
657         data->base_width  = stock_wid->requisition.width;
658         gtk_widget_destroy(stock_wid);
659
660         if (pos == OVERLAY_NONE) {
661                 data->overlay_pixmap = NULL;
662                 data->overlay_mask   = NULL;
663         } else {
664                 stock_wid = stock_pixmap_widget(window, overlay);
665                 gtk_image_get_pixmap(GTK_IMAGE(stock_wid), &stock_pixmap, &stock_mask);
666                 g_object_ref(stock_pixmap);
667                 g_object_ref(stock_mask);
668                 data->overlay_pixmap = stock_pixmap;
669                 data->overlay_mask   = stock_mask;
670                 data->overlay_height = stock_wid->requisition.height;
671                 data->overlay_width  = stock_wid->requisition.width;
672
673                 gtk_widget_destroy(stock_wid);
674         }
675         
676         data->position = pos;
677         data->border_x = border_x;
678         data->border_y = border_y;
679
680         widget = gtk_drawing_area_new();
681         gtk_drawing_area_size(GTK_DRAWING_AREA(widget), data->base_width + border_x * 2, 
682                               data->base_height + border_y * 2);
683         g_signal_connect(G_OBJECT(widget), "expose_event", 
684                          G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
685         g_signal_connect(G_OBJECT(widget), "destroy",
686                          G_CALLBACK(pixmap_with_overlay_destroy_cb), data);
687         return widget;
688
689 }