Statistics
| Revision:

root / src / stock_pixmap.c @ 3281

History | View | Annotate | Download (8.65 KB)

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

    
85
typedef struct _StockPixmapData        StockPixmapData;
86

    
87
struct _StockPixmapData
88
{
89
        gchar **data;
90
        GdkPixmap *pixmap;
91
        GdkBitmap *mask;
92
        GdkPixbuf *pixbuf;
93
        const guint8 *pixbuf_data;
94
        gint pixbuf_data_len;
95
        gchar *icon_name;
96
        gint size;
97
};
98

    
99
static StockPixmapData pixmaps[] =
100
{
101
        {address_xpm         , NULL, NULL},
102
        {NULL, NULL, NULL, NULL, stock_book, sizeof(stock_book), "stock_book", 16},
103
        {category_xpm         , NULL, NULL},
104
        {clip_xpm         , NULL, NULL},
105
        {complete_xpm         , NULL, NULL},
106
        {continue_xpm         , NULL, NULL},
107
        {deleted_xpm         , NULL, NULL},
108
        {NULL, NULL, NULL, NULL, folder_close, sizeof(folder_close), "folder-close", 0},
109
        {NULL, NULL, NULL, NULL, folder_open, sizeof(folder_open), "folder-open", 0},
110
        {NULL, NULL, NULL, NULL, folder_noselect, sizeof(folder_noselect), "folder-noselect", 0},
111
        {error_xpm         , NULL, NULL},
112
        {forwarded_xpm         , NULL, NULL},
113
        {NULL, NULL, NULL, NULL, group, sizeof(group), "group", 0},
114
        {NULL, NULL, NULL, NULL, html, sizeof(html), "html", 0},
115
        {interface_xpm         , NULL, NULL},
116
        {jpilot_xpm         , NULL, NULL},
117
        {ldap_xpm         , NULL, NULL},
118
        {linewrap_xpm         , NULL, NULL},
119
        {mark_xpm         , NULL, NULL},
120
        {new_xpm         , NULL, NULL},
121
        {replied_xpm         , NULL, NULL},
122
        {unread_xpm         , NULL, NULL},
123
        {vcard_xpm         , NULL, NULL},
124
        {online_xpm         , NULL, NULL},
125
        {offline_xpm         , NULL, NULL},
126
        {mail_xpm         , NULL, NULL},
127

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

    
159

    
160
GtkWidget *stock_pixbuf_widget(GtkWidget *window, StockPixmap icon)
161
{
162
        GdkPixbuf *pixbuf;
163

    
164
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
165

    
166
        stock_pixbuf_gdk(window, icon, &pixbuf);
167
        return gtk_image_new_from_pixbuf(pixbuf);
168
}
169

    
170
GtkWidget *stock_pixbuf_widget_scale(GtkWidget *window, StockPixmap icon,
171
                                     gint width, gint height)
172
{
173
        GdkPixbuf *pixbuf;
174
        GdkPixbuf *scaled_pixbuf;
175
        GtkWidget *image;
176

    
177
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
178

    
179
        stock_pixbuf_gdk(window, icon, &pixbuf);
180
        scaled_pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height,
181
                                                GDK_INTERP_HYPER);
182
        image = gtk_image_new_from_pixbuf(scaled_pixbuf);
183
        g_object_unref(scaled_pixbuf);
184

    
185
        return image;
186
}
187

    
188
/* create GdkPixmap if it has not created yet */
189
gint stock_pixmap_gdk(GtkWidget *window, StockPixmap icon,
190
                      GdkPixmap **pixmap, GdkBitmap **mask)
191
{
192
        StockPixmapData *pix_d;
193

    
194
        if (pixmap) *pixmap = NULL;
195
        if (mask)   *mask   = NULL;
196

    
197
        g_return_val_if_fail(window != NULL, -1);
198
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
199

    
200
        pix_d = &pixmaps[icon];
201

    
202
        g_return_val_if_fail(pix_d->data != NULL, -1);
203

    
204
        if (!pix_d->pixmap) {
205
                PIXMAP_CREATE(window, pix_d->pixmap, pix_d->mask,
206
                              pix_d->data);
207
        }
208

    
209
        if (pixmap) *pixmap = pix_d->pixmap;
210
        if (mask)   *mask   = pix_d->mask;
211

    
212
        return 0;
213
}
214

    
215
gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
216
{
217
        StockPixmapData *pix_d;
218

    
219
        if (pixbuf)
220
                *pixbuf = NULL;
221

    
222
        g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
223

    
224
        pix_d = &pixmaps[icon];
225

    
226
        if (!pix_d->pixbuf && pix_d->pixbuf_data)
227
                pix_d->pixbuf = gdk_pixbuf_new_from_inline
228
                        (pix_d->pixbuf_data_len, pix_d->pixbuf_data,
229
                         FALSE, NULL);
230
        if (!pix_d->pixbuf && pix_d->icon_name)
231
                pix_d->pixbuf = gtk_icon_theme_load_icon
232
                        (gtk_icon_theme_get_default(),
233
                         pix_d->icon_name, pix_d->size, 0, NULL);
234
        if (!pix_d->pixbuf && pix_d->data)
235
                pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data
236
                        ((const gchar **)pix_d->data);
237
        if (!pix_d->pixbuf) {
238
                g_warning("can't read image %d\n", icon);
239
                return -1;
240
        }
241

    
242
        if (pixbuf)
243
                *pixbuf = pix_d->pixbuf;
244

    
245
        return 0;
246
}