Statistics
| Revision:

root / src / stock_pixmap.c @ 3285

History | View | Annotate | Download (10.7 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2013 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
#include "utils.h"
29

    
30
#include "icons/address.xpm"
31
#include "icons/category.xpm"
32
#include "icons/clip.xpm"
33
#include "icons/complete.xpm"
34
#include "icons/continue.xpm"
35
#include "icons/deleted.xpm"
36
#include "icons/error.xpm"
37
#include "icons/forwarded.xpm"
38
#include "icons/interface.xpm"
39
#include "icons/jpilot.xpm"
40
#include "icons/ldap.xpm"
41
#include "icons/linewrap.xpm"
42
#include "icons/mark.xpm"
43
#include "icons/new.xpm"
44
#include "icons/replied.xpm"
45
#include "icons/unread.xpm"
46
#include "icons/vcard.xpm"
47
#include "icons/online.xpm"
48
#include "icons/offline.xpm"
49
#include "icons/mail.xpm"
50
#include "icons/stock_inbox.h"
51
#include "icons/stock_outbox.h"
52
#include "icons/stock_mail.h"
53
#include "icons/stock_attach.h"
54
#include "icons/stock_mail-compose.h"
55
#include "icons/stock_mail-compose_16.h"
56
#include "icons/stock_mail-forward.h"
57
#include "icons/stock_mail-receive.h"
58
#include "icons/stock_mail_receive_all.h"
59
#include "icons/stock_mail-reply.h"
60
#include "icons/stock_mail-reply-to-all.h"
61
#include "icons/stock_mail-send.h"
62
#include "icons/stock_mail_send_queue.h"
63
#include "icons/stock_insert-file.h"
64
#include "icons/stock_addressbook.h"
65
#include "icons/stock_delete.h"
66
#include "icons/stock_delete_16.h"
67
#include "icons/stock_spam.h"
68
#include "icons/stock_spam_16.h"
69
#include "icons/stock_notspam.h"
70
#include "icons/stock_hand-signed.h"
71
#include "icons/stock_sylpheed.h"
72
#include "icons/stock_sylpheed_16.h"
73
#include "icons/stock_sylpheed_32.h"
74
#include "icons/stock_sylpheed_newmail.h"
75
#include "icons/stock_sylpheed_newmail_16.h"
76
#include "icons/sylpheed-logo.h"
77
#include "icons/stock_person.h"
78
#include "icons/stock_book.h"
79
#include "icons/folder-close.h"
80
#include "icons/folder-open.h"
81
#include "icons/folder-noselect.h"
82
#include "icons/folder-search.h"
83
#include "icons/group.h"
84
#include "icons/html.h"
85

    
86
typedef struct _StockPixmapData        StockPixmapData;
87

    
88
struct _StockPixmapData
89
{
90
        gchar **data;
91
        GdkPixmap *pixmap;
92
        GdkBitmap *mask;
93

    
94
        GdkPixbuf *pixbuf;
95
        const guint8 *pixbuf_data;
96
        gint pixbuf_data_len;
97

    
98
        gchar *icon_name;
99
        gint size;
100

    
101
        gchar *icon_file;
102
};
103

    
104
static StockPixmapData pixmaps[] =
105
{
106
        {address_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "address.png"},
107
        {NULL, NULL, NULL, NULL, stock_book, sizeof(stock_book), "stock_book", 16, "stock_book.png"},
108
        {category_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "category.png"},
109
        {clip_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "clip.png"},
110
        {complete_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "complete.png"},
111
        {continue_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "continue.png"},
112
        {deleted_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "deleted.png"},
113
        {NULL, NULL, NULL, NULL, folder_close, sizeof(folder_close), "folder-close", 0, "folder-close.png"},
114
        {NULL, NULL, NULL, NULL, folder_open, sizeof(folder_open), "folder-open", 0, "folder-open.png"},
115
        {NULL, NULL, NULL, NULL, folder_noselect, sizeof(folder_noselect), "folder-noselect", 0, "folder-noselect.png"},
116
        {error_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "error.png"},
117
        {forwarded_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "forwarded.png"},
118
        {NULL, NULL, NULL, NULL, group, sizeof(group), "group", 0, "group.png"},
119
        {NULL, NULL, NULL, NULL, html, sizeof(html), "html", 0, "html.png"},
120
        {interface_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "interface.png"},
121
        {jpilot_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "jpilot.png"},
122
        {ldap_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "ldap.png"},
123
        {linewrap_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "linewrap.png"},
124
        {mark_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "mark.png"},
125
        {new_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "new.png"},
126
        {replied_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "replied.png"},
127
        {unread_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "unread.png"},
128
        {vcard_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "vcard.png"},
129
        {online_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "online.png"},
130
        {offline_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "offline.png"},
131
        {mail_xpm         , NULL, NULL, NULL, NULL, 0, NULL, 0, "mail.png"},
132

    
133
        {NULL, NULL, NULL, NULL, stock_inbox, sizeof(stock_inbox), "stock_inbox", 16, "stock_inbox.png"},
134
        {NULL, NULL, NULL, NULL, stock_outbox, sizeof(stock_outbox), "stock_outbox", 16, "stock_outbox.png"},
135
        {NULL, NULL, NULL, NULL, stock_mail_compose_16, sizeof(stock_mail_compose_16), "stock_mail-compose", 16, "stock_mail-compose_16.png"},
136
        {NULL, NULL, NULL, NULL, stock_delete_16, sizeof(stock_delete_16), GTK_STOCK_DELETE, 16, "stock_delete_16.png"},
137
        {NULL, NULL, NULL, NULL, stock_mail, sizeof(stock_mail), "stock_mail", 24, "stock_mail.png"},
138
        {NULL, NULL, NULL, NULL, stock_attach, sizeof(stock_attach), "stock_attach", 24, "stock_attach.png"},
139
        {NULL, NULL, NULL, NULL, stock_mail_compose, sizeof(stock_mail_compose), "stock_mail-compose", 24, "stock_mail-compose.png"},
140
        {NULL, NULL, NULL, NULL, stock_mail_forward, sizeof(stock_mail_forward), "stock_mail-forward", 24, "stock_mail-forward.png"},
141
        {NULL, NULL, NULL, NULL, stock_mail_receive, sizeof(stock_mail_receive), "stock_mail-receive", 24, "stock_mail-receive.png"},
142
        {NULL, NULL, NULL, NULL, stock_mail_receive_all, sizeof(stock_mail_receive_all), NULL, 0, "stock_mail_receive_all.png"},
143
        {NULL, NULL, NULL, NULL, stock_mail_reply, sizeof(stock_mail_reply), "stock_mail-reply", 24, "stock_mail-reply.png"},
144
        {NULL, NULL, NULL, NULL, stock_mail_reply_to_all, sizeof(stock_mail_reply_to_all), "stock_mail-reply-to-all", 24, "stock_mail-reply-to-all.png"},
145
        {NULL, NULL, NULL, NULL, stock_mail_send, sizeof(stock_mail_send), "stock_mail-send", 24, "stock_mail-send.png"},
146
        {NULL, NULL, NULL, NULL, stock_mail_send_queue, sizeof(stock_mail_send_queue), NULL, 0, "stock_mail_send_queue.png"},
147
        {NULL, NULL, NULL, NULL, stock_insert_file, sizeof(stock_insert_file), "stock_insert-file", 24, "stock_insert-file.png"},
148
        {NULL, NULL, NULL, NULL, stock_addressbook, sizeof(stock_addressbook), "stock_addressbook", 24, "stock_addressbook.png"},
149
        {NULL, NULL, NULL, NULL, stock_delete, sizeof(stock_delete), GTK_STOCK_DELETE, 24, "stock_delete.png"},
150
        {NULL, NULL, NULL, NULL, stock_spam, sizeof(stock_spam), "stock_spam", 24, "stock_spam.png"},
151
        {NULL, NULL, NULL, NULL, stock_notspam, sizeof(stock_notspam), "stock_notspam", 24, "stock_notspam.png"},
152
        {NULL, NULL, NULL, NULL, stock_hand_signed, sizeof(stock_hand_signed), "stock_hand-signed", 24, "stock_hand-signed.png"},
153
        {NULL, NULL, NULL, NULL, stock_sylpheed, sizeof(stock_sylpheed), NULL, 0, "stock_sylpheed.png"},
154
        {NULL, NULL, NULL, NULL, stock_sylpheed_16, sizeof(stock_sylpheed_16), NULL, 0, "stock_sylpheed_16.png"},
155
        {NULL, NULL, NULL, NULL, stock_sylpheed_32, sizeof(stock_sylpheed_32), NULL, 0, "stock_sylpheed_32.png"},
156
        {NULL, NULL, NULL, NULL, stock_sylpheed_newmail, sizeof(stock_sylpheed_newmail), NULL, 0, "stock_sylpheed_newmail.png"},
157
        {NULL, NULL, NULL, NULL, stock_sylpheed_newmail_16, sizeof(stock_sylpheed_newmail_16), NULL, 0, "stock_sylpheed_newmail_16.png"},
158
        {NULL, NULL, NULL, NULL, sylpheed_logo, sizeof(sylpheed_logo), NULL, 0, "sylpheed-logo.png"},
159
        {NULL, NULL, NULL, NULL, stock_person, sizeof(stock_person), "stock_person", 16, "stock_person.png"},
160
        {NULL, NULL, NULL, NULL, folder_search, sizeof(folder_search), "folder-search", 0, "folder-search.png"},
161
        {NULL, NULL, NULL, NULL, stock_spam_16, sizeof(stock_spam_16), "stock_spam", 16, "stock_spam_16.png"},
162
};
163

    
164
static gchar *theme_dir = NULL;
165

    
166

    
167
GtkWidget *stock_pixbuf_widget(GtkWidget *window, StockPixmap icon)
168
{
169
        GdkPixbuf *pixbuf;
170

    
171
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
172

    
173
        stock_pixbuf_gdk(window, icon, &pixbuf);
174
        return gtk_image_new_from_pixbuf(pixbuf);
175
}
176

    
177
GtkWidget *stock_pixbuf_widget_scale(GtkWidget *window, StockPixmap icon,
178
                                     gint width, gint height)
179
{
180
        GdkPixbuf *pixbuf;
181
        GdkPixbuf *scaled_pixbuf;
182
        GtkWidget *image;
183

    
184
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
185

    
186
        stock_pixbuf_gdk(window, icon, &pixbuf);
187
        scaled_pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height,
188
                                                GDK_INTERP_HYPER);
189
        image = gtk_image_new_from_pixbuf(scaled_pixbuf);
190
        g_object_unref(scaled_pixbuf);
191

    
192
        return image;
193
}
194

    
195
/* create GdkPixmap if it has not created yet */
196
gint stock_pixmap_gdk(GtkWidget *window, StockPixmap icon,
197
                      GdkPixmap **pixmap, GdkBitmap **mask)
198
{
199
        StockPixmapData *pix_d;
200

    
201
        if (pixmap) *pixmap = NULL;
202
        if (mask)   *mask   = NULL;
203

    
204
        g_return_val_if_fail(window != NULL, -1);
205
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
206

    
207
        pix_d = &pixmaps[icon];
208

    
209
        g_return_val_if_fail(pix_d->data != NULL, -1);
210

    
211
        if (!pix_d->pixmap) {
212
                PIXMAP_CREATE(window, pix_d->pixmap, pix_d->mask,
213
                              pix_d->data);
214
        }
215

    
216
        if (pixmap) *pixmap = pix_d->pixmap;
217
        if (mask)   *mask   = pix_d->mask;
218

    
219
        return 0;
220
}
221

    
222
gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
223
{
224
        StockPixmapData *pix_d;
225

    
226
        if (pixbuf)
227
                *pixbuf = NULL;
228

    
229
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
230

    
231
        pix_d = &pixmaps[icon];
232

    
233
        if (!pix_d->pixbuf && pix_d->icon_file && theme_dir) {
234
                gchar *path;
235

    
236
                path = g_strconcat(theme_dir, G_DIR_SEPARATOR_S,
237
                                   pix_d->icon_file, NULL);
238
                if (is_file_exist(path)) {
239
                        debug_print("stock_pixbuf_gdk: loading theme icon: %s\n", path);
240
                        pix_d->pixbuf = gdk_pixbuf_new_from_file(path, NULL);
241
                }
242
                g_free(path);
243
        }
244

    
245
        if (!pix_d->pixbuf && pix_d->pixbuf_data)
246
                pix_d->pixbuf = gdk_pixbuf_new_from_inline
247
                        (pix_d->pixbuf_data_len, pix_d->pixbuf_data,
248
                         FALSE, NULL);
249
        if (!pix_d->pixbuf && pix_d->icon_name)
250
                pix_d->pixbuf = gtk_icon_theme_load_icon
251
                        (gtk_icon_theme_get_default(),
252
                         pix_d->icon_name, pix_d->size, 0, NULL);
253
        if (!pix_d->pixbuf && pix_d->data)
254
                pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data
255
                        ((const gchar **)pix_d->data);
256
        if (!pix_d->pixbuf) {
257
                g_warning("can't read image %d\n", icon);
258
                return -1;
259
        }
260

    
261
        if (pixbuf)
262
                *pixbuf = pix_d->pixbuf;
263

    
264
        return 0;
265
}
266

    
267
gint stock_pixbuf_set_theme_dir(const gchar *dir)
268
{
269
        g_free(theme_dir);
270
        theme_dir = g_strdup(dir);
271

    
272
        return 0;
273
}