Fix access beyond array bounds
[claws.git] / src / toolbar.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001-2012 Hiroyuki Yamamoto and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifndef __CUSTOM_TOOLBAR_H__
21 #define __CUSTOM_TOOLBAR_H__
22
23 #include "gtk/gtkutils.h"
24
25 #define SEPARATOR_PIXMAP     "---"
26
27 typedef struct _Toolbar Toolbar;
28 typedef struct _ToolbarItem ToolbarItem;
29 typedef struct _ToolbarClawsActions ToolbarClawsActions;
30
31 typedef enum {
32         TOOLBAR_MAIN = 0,       
33         TOOLBAR_COMPOSE,
34         TOOLBAR_MSGVIEW
35 } ToolbarType;
36
37 #define NUM_TOOLBARS    3
38
39 typedef enum 
40 {
41         COMPOSEBUTTON_MAIL,
42         COMPOSEBUTTON_NEWS
43 } ComposeButtonType;
44
45 typedef enum 
46 {
47         LEARN_SPAM,
48         LEARN_HAM
49 } LearnButtonType;
50
51 struct _Toolbar {
52         GtkWidget *toolbar;
53
54         GtkWidget *folders_btn;
55         GtkWidget *get_btn;
56         GtkWidget *getall_btn;
57         GtkWidget *send_btn;
58
59         GtkWidget *compose_mail_btn;
60         GtkWidget *compose_mail_icon;
61         GtkWidget *compose_news_icon;
62
63         GtkWidget *reply_btn;
64         GtkWidget *replysender_btn;
65         GtkWidget *replyall_btn;
66         GtkWidget *replylist_btn;
67
68         GtkWidget *fwd_btn;
69         
70         GtkWidget *trash_btn;
71         GtkWidget *delete_btn;
72         GtkWidget *prev_btn;
73         GtkWidget *next_btn;
74         GtkWidget *exec_btn;
75
76         GtkWidget *separator;
77         GtkWidget *learn_spam_btn;
78         GtkWidget *learn_spam_icon;
79         GtkWidget *learn_ham_icon;
80         
81         GtkWidget *cancel_inc_btn;
82         GtkWidget *cancel_send_btn;
83         GtkWidget *cancel_all_btn;
84         
85         ComposeButtonType compose_btn_type;
86         LearnButtonType learn_btn_type;
87
88         /* compose buttons */
89         GtkWidget *sendl_btn;
90         GtkWidget *draft_btn;
91         GtkWidget *insert_btn;
92         GtkWidget *attach_btn;
93         GtkWidget *sig_btn;
94         GtkWidget *exteditor_btn;
95         GtkWidget *linewrap_current_btn;
96         GtkWidget *linewrap_all_btn;
97         GtkWidget *addrbook_btn;
98
99         GtkWidget *open_mail_btn;
100         GtkWidget *close_window_btn;
101
102         GtkWidget *preferences_btn;
103
104         GSList    *action_list;
105         GSList    *item_list;
106
107 #ifdef USE_ENCHANT
108         GtkWidget *spellcheck_btn;
109 #endif
110 #if !GTK_CHECK_VERSION(2,12,0)
111         GtkTooltips *tooltips;
112 #endif
113 };
114
115 struct _ToolbarItem {
116         gint             index;
117         gchar           *file;
118         gchar           *text;
119         ToolbarType      type;
120         gpointer         parent;
121 };
122
123 #define TOOLBAR_DESTROY_ITEMS(item_list) \
124 { \
125         ToolbarItem *item; \
126         while (item_list != NULL) { \
127                 item = (ToolbarItem*)item_list->data; \
128                 item_list = g_slist_remove(item_list, item); \
129                 if (item->file) \
130                         g_free(item->file); \
131                 if (item->text) \
132                         g_free(item->text); \
133                 g_free(item);\
134         }\
135         g_slist_free(item_list);\
136 }
137
138 #define TOOLBAR_DESTROY_ACTIONS(action_list) \
139 { \
140         ToolbarClawsActions *action; \
141         while (action_list != NULL) { \
142                 action = (ToolbarClawsActions*)action_list->data;\
143                 action_list = \
144                         g_slist_remove(action_list, action);\
145                 if (action->name) \
146                         g_free(action->name); \
147                 g_free(action); \
148         } \
149         g_slist_free(action_list); \
150 }
151
152
153
154
155 /* enum holds available actions for both 
156    Compose Toolbar and Main Toolbar 
157 */
158 enum {
159         /* main toolbar */
160         A_RECEIVE_ALL = 0,
161         A_RECEIVE_CUR,
162         A_SEND_QUEUED,
163         A_COMPOSE_EMAIL,
164         A_COMPOSE_NEWS,
165         A_REPLY_MESSAGE,
166         A_REPLY_SENDER,
167         A_REPLY_ALL,
168         A_REPLY_ML,
169         A_OPEN_MAIL,
170         A_FORWARD,
171         A_TRASH,
172         A_DELETE_REAL,
173         A_EXECUTE,
174         A_GOTO_PREV,
175         A_GOTO_NEXT,
176         A_IGNORE_THREAD,
177         A_WATCH_THREAD,
178         A_PRINT,
179         A_LEARN_SPAM,
180         A_GO_FOLDERS,
181         A_PREFERENCES,
182
183         /* compose toolbar */
184         A_SEND,
185         A_SENDL,
186         A_DRAFT,
187         A_INSERT,
188         A_ATTACH,
189         A_SIG,
190         A_EXTEDITOR,
191         A_LINEWRAP_CURRENT,
192         A_LINEWRAP_ALL,
193         A_ADDRBOOK,
194 #ifdef USE_ENCHANT
195         A_CHECK_SPELLING,
196 #endif
197
198         /* common items */
199         A_CLAWS_ACTIONS,
200         A_CANCEL_INC,
201         A_CANCEL_SEND,
202         A_CANCEL_ALL,
203         A_CLOSE,
204
205         A_SEPARATOR,
206
207         A_CLAWS_PLUGINS,
208
209         N_ACTION_VAL
210 };
211
212 struct _ToolbarClawsActions {
213         GtkWidget *widget;
214         gchar     *name;
215 };
216
217
218 GList   *toolbar_get_action_items       (ToolbarType     source);
219
220 void    toolbar_save_config_file        (ToolbarType     source);
221 void    toolbar_read_config_file        (ToolbarType     source);
222
223 void    toolbar_set_default             (ToolbarType     source);
224 void    toolbar_clear_list              (ToolbarType     source);
225
226 GSList  *toolbar_get_list               (ToolbarType     source);
227 void    toolbar_set_list_item           (ToolbarItem    *t_item, 
228                                          ToolbarType     source);
229
230 gint    toolbar_ret_val_from_descr      (const gchar    *descr);
231 gchar   *toolbar_ret_descr_from_val     (gint            val);
232
233 void    toolbar_main_set_sensitive      (gpointer        data);
234 void    toolbar_comp_set_sensitive      (gpointer        data, 
235                                          gboolean        sensitive);
236
237 /* invoked by mainwindow entries and toolbar actions */
238 void    delete_msgview_cb               (gpointer        data, 
239                                          guint           action, 
240                                          GtkWidget      *widget);
241 void    inc_mail_cb                     (gpointer        data,
242                                          guint           action,
243                                          GtkWidget      *widget);
244 void    inc_all_account_mail_cb         (gpointer        data,
245                                          guint           action,
246                                          GtkWidget      *widget);
247 void    send_queue_cb                   (gpointer        data,
248                                          guint           action,
249                                          GtkWidget      *widget);
250 void    compose_mail_cb                 (gpointer       data, 
251                                          guint           action,
252                                          GtkWidget      *widget);
253 void    compose_news_cb                 (gpointer        data, 
254                                          guint           action,
255                                          GtkWidget      *widget);
256 /* END */
257
258 void    toolbar_toggle                  (guint           action,
259                                          gpointer        data);
260 void    toolbar_update                  (ToolbarType     type, 
261                                         gpointer         data);        
262 Toolbar *toolbar_create                 (ToolbarType     type, 
263                                          GtkWidget      *container,
264                                          gpointer        data);
265 void    toolbar_set_style               (GtkWidget      *toolbar_wid,
266                                          GtkWidget      *handlebox_wid,
267                                          guint           action);
268 void    toolbar_destroy                 (Toolbar        *toolbar);
269 void toolbar_set_learn_button           (Toolbar        *toolbar, 
270                                          LearnButtonType  learn_btn_type);
271 const gchar *toolbar_get_short_text     (int action);
272 int          toolbar_get_icon           (int action);
273 gboolean toolbar_check_action_btns      (ToolbarType    type);
274 #endif /* __CUSTOM_TOOLBAR_H__ */