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