Statistics
| Revision:

root / src / stock_pixmap.c @ 424

History | View | Annotate | Download (7.4 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2005 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 <glib.h>
21
#include <gtk/gtkwidget.h>
22
#include <gtk/gtkpixmap.h>
23
#include <gtk/gtkimage.h>
24
#include <gtk/gtkicontheme.h>
25

    
26
#include "stock_pixmap.h"
27
#include "gtkutils.h"
28

    
29
#include "pixmaps/address.xpm"
30
#include "pixmaps/book.xpm"
31
#include "pixmaps/category.xpm"
32
#include "pixmaps/clip.xpm"
33
#include "pixmaps/complete.xpm"
34
#include "pixmaps/continue.xpm"
35
#include "pixmaps/deleted.xpm"
36
#include "pixmaps/dir-close.xpm"
37
#include "pixmaps/dir-open.xpm"
38
#include "pixmaps/dir-noselect.xpm"
39
#include "pixmaps/error.xpm"
40
#include "pixmaps/forwarded.xpm"
41
#include "pixmaps/group.xpm"
42
#include "pixmaps/interface.xpm"
43
#include "pixmaps/jpilot.xpm"
44
#include "pixmaps/ldap.xpm"
45
#include "pixmaps/linewrap.xpm"
46
#include "pixmaps/mark.xpm"
47
#include "pixmaps/new.xpm"
48
#include "pixmaps/replied.xpm"
49
#include "pixmaps/unread.xpm"
50
#include "pixmaps/vcard.xpm"
51
#include "pixmaps/online.xpm"
52
#include "pixmaps/offline.xpm"
53
#include "pixmaps/mail.xpm"
54
#include "pixmaps/stock_inbox.h"
55
#include "pixmaps/stock_outbox.h"
56
#include "pixmaps/stock_mail.h"
57
#include "pixmaps/stock_attach.h"
58
#include "pixmaps/stock_mail-compose.h"
59
#include "pixmaps/stock_mail-compose_16.h"
60
#include "pixmaps/stock_mail-forward.h"
61
#include "pixmaps/stock_mail-receive.h"
62
#include "pixmaps/stock_mail_receive_all.h"
63
#include "pixmaps/stock_mail-reply.h"
64
#include "pixmaps/stock_mail-reply-to-all.h"
65
#include "pixmaps/stock_mail-send.h"
66
#include "pixmaps/stock_mail_send_queue.h"
67
#include "pixmaps/stock_insert-file.h"
68
#include "pixmaps/stock_addressbook.h"
69
#include "pixmaps/stock_delete.h"
70
#include "pixmaps/stock_delete_16.h"
71
#include "pixmaps/stock_spam.h"
72
#include "pixmaps/stock_hand-signed.h"
73
#include "pixmaps/stock_sylpheed.h"
74
#include "pixmaps/sylpheed-logo.h"
75

    
76
typedef struct _StockPixmapData        StockPixmapData;
77

    
78
struct _StockPixmapData
79
{
80
        gchar **data;
81
        GdkPixmap *pixmap;
82
        GdkBitmap *mask;
83
        GdkPixbuf *pixbuf;
84
        const guint8 *pixbuf_data;
85
        gint pixbuf_data_len;
86
        gchar *icon_name;
87
        gint size;
88
};
89

    
90
static StockPixmapData pixmaps[] =
91
{
92
        {address_xpm         , NULL, NULL},
93
        {book_xpm         , NULL, NULL},
94
        {category_xpm         , NULL, NULL},
95
        {clip_xpm         , NULL, NULL},
96
        {complete_xpm         , NULL, NULL},
97
        {continue_xpm         , NULL, NULL},
98
        {deleted_xpm         , NULL, NULL},
99
        {dir_close_xpm         , NULL, NULL},
100
        {dir_open_xpm         , NULL, NULL},
101
        {dir_noselect_xpm, NULL, NULL},
102
        {error_xpm         , NULL, NULL},
103
        {forwarded_xpm         , NULL, NULL},
104
        {group_xpm         , NULL, NULL},
105
        {interface_xpm         , NULL, NULL},
106
        {jpilot_xpm         , NULL, NULL},
107
        {ldap_xpm         , NULL, NULL},
108
        {linewrap_xpm         , NULL, NULL},
109
        {mark_xpm         , NULL, NULL},
110
        {new_xpm         , NULL, NULL},
111
        {replied_xpm         , NULL, NULL},
112
        {unread_xpm         , NULL, NULL},
113
        {vcard_xpm         , NULL, NULL},
114
        {online_xpm         , NULL, NULL},
115
        {offline_xpm         , NULL, NULL},
116
        {mail_xpm         , NULL, NULL},
117

    
118
        {NULL, NULL, NULL, NULL, stock_inbox, sizeof(stock_inbox), "stock_inbox", 16},
119
        {NULL, NULL, NULL, NULL, stock_outbox, sizeof(stock_outbox), "stock_outbox", 16},
120
        {NULL, NULL, NULL, NULL, stock_mail_compose_16, sizeof(stock_mail_compose_16), "stock_mail-compose", 16},
121
        {NULL, NULL, NULL, NULL, stock_delete_16, sizeof(stock_delete_16), GTK_STOCK_DELETE, 16},
122
        {NULL, NULL, NULL, NULL, stock_mail, sizeof(stock_mail), "stock_mail", 24},
123
        {NULL, NULL, NULL, NULL, stock_attach, sizeof(stock_attach), "stock_attach", 24},
124
        {NULL, NULL, NULL, NULL, stock_mail_compose, sizeof(stock_mail_compose), "stock_mail-compose", 24},
125
        {NULL, NULL, NULL, NULL, stock_mail_forward, sizeof(stock_mail_forward), "stock_mail-forward", 24},
126
        {NULL, NULL, NULL, NULL, stock_mail_receive, sizeof(stock_mail_receive), "stock_mail-receive", 24},
127
        {NULL, NULL, NULL, NULL, stock_mail_receive_all, sizeof(stock_mail_receive_all), NULL, 0},
128
        {NULL, NULL, NULL, NULL, stock_mail_reply, sizeof(stock_mail_reply), "stock_mail-reply", 24},
129
        {NULL, NULL, NULL, NULL, stock_mail_reply_to_all, sizeof(stock_mail_reply_to_all), "stock_mail-reply-to-all", 24},
130
        {NULL, NULL, NULL, NULL, stock_mail_send, sizeof(stock_mail_send), "stock_mail-send", 24},
131
        {NULL, NULL, NULL, NULL, stock_mail_send_queue, sizeof(stock_mail_send_queue), NULL, 0},
132
        {NULL, NULL, NULL, NULL, stock_insert_file, sizeof(stock_insert_file), "stock_insert-file", 24},
133
        {NULL, NULL, NULL, NULL, stock_addressbook, sizeof(stock_addressbook), "stock_addressbook", 24},
134
        {NULL, NULL, NULL, NULL, stock_delete, sizeof(stock_delete), GTK_STOCK_DELETE, 24},
135
        {NULL, NULL, NULL, NULL, stock_spam, sizeof(stock_spam), "stock_spam", 24},
136
        {NULL, NULL, NULL, NULL, stock_hand_signed, sizeof(stock_hand_signed), "stock_hand-signed", 24},
137
        {NULL, NULL, NULL, NULL, stock_sylpheed, sizeof(stock_sylpheed), NULL, 0},
138
        {NULL, NULL, NULL, NULL, sylpheed_logo, sizeof(sylpheed_logo), NULL, 0},
139
};
140

    
141
/* return newly constructed GtkPixmap from GdkPixmap */
142
GtkWidget *stock_pixmap_widget(GtkWidget *window, StockPixmap icon)
143
{
144
        GdkPixmap *pixmap;
145
        GdkBitmap *mask;
146

    
147
        g_return_val_if_fail(window != NULL, NULL);
148
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
149

    
150
        stock_pixmap_gdk(window, icon, &pixmap, &mask);
151
        return gtk_pixmap_new(pixmap, mask);
152
}
153

    
154
GtkWidget *stock_pixbuf_widget(GtkWidget *window, StockPixmap icon)
155
{
156
        GdkPixbuf *pixbuf;
157

    
158
        g_return_val_if_fail(window != NULL, NULL);
159
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
160

    
161
        stock_pixbuf_gdk(window, icon, &pixbuf);
162
        return gtk_image_new_from_pixbuf(pixbuf);
163
}
164

    
165
/* create GdkPixmap if it has not created yet */
166
gint stock_pixmap_gdk(GtkWidget *window, StockPixmap icon,
167
                      GdkPixmap **pixmap, GdkBitmap **mask)
168
{
169
        StockPixmapData *pix_d;
170

    
171
        if (pixmap) *pixmap = NULL;
172
        if (mask)   *mask   = NULL;
173

    
174
        g_return_val_if_fail(window != NULL, -1);
175
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
176

    
177
        pix_d = &pixmaps[icon];
178

    
179
        g_return_val_if_fail(pix_d->data != NULL, -1);
180

    
181
        if (!pix_d->pixmap) {
182
                PIXMAP_CREATE(window, pix_d->pixmap, pix_d->mask,
183
                              pix_d->data);
184
        }
185

    
186
        if (pixmap) *pixmap = pix_d->pixmap;
187
        if (mask)   *mask   = pix_d->mask;
188

    
189
        return 0;
190
}
191

    
192
gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
193
{
194
        StockPixmapData *pix_d;
195

    
196
        if (pixbuf)
197
                *pixbuf = NULL;
198

    
199
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
200

    
201
        pix_d = &pixmaps[icon];
202

    
203
        if (!pix_d->pixbuf && pix_d->pixbuf_data)
204
                pix_d->pixbuf = gdk_pixbuf_new_from_inline
205
                        (pix_d->pixbuf_data_len, pix_d->pixbuf_data,
206
                         FALSE, NULL);
207
        if (!pix_d->pixbuf && pix_d->icon_name)
208
                pix_d->pixbuf = gtk_icon_theme_load_icon
209
                        (gtk_icon_theme_get_default(),
210
                         pix_d->icon_name, pix_d->size, 0, NULL);
211
        if (!pix_d->pixbuf && pix_d->data)
212
                pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data
213
                        ((const gchar **)pix_d->data);
214
        if (!pix_d->pixbuf) {
215
                g_warning("can't read image %d\n", icon);
216
                return -1;
217
        }
218

    
219
        if (pixbuf)
220
                *pixbuf = pix_d->pixbuf;
221

    
222
        return 0;
223
}