06abbd3d5c89064064c610fafd393b92ada31b80
[obnox/wireshark/wip.git] / gtk / toolbar.c
1 /* toolbar.c
2  * The main toolbar
3  * Copyright 2003, Ulf Lamping <ulf.lamping@web.de>
4  *
5  * $Id$
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 /*
27  * This file implements a "main" toolbar for Ethereal (suitable for gtk1 and
28  * gtk2).
29  *
30  * As it is desirable to have the same toolbar implementation for gtk1 and gtk2 
31  * in Ethereal, only those library calls available in the gtk1 libraries 
32  * are used inside this file.
33  *
34  * Hint: gtk2 in comparison to gtk1 has a better way to handle with "common"
35  * icons; gtk2 calls this kind of icons "stock-icons"
36  * (stock-icons including: icons for "open", "save", "print", ...).
37  * The gtk2 version of this code uses them.
38  */
39
40 #ifdef HAVE_CONFIG_H
41 #include "config.h"
42 #endif
43
44 #include <gtk/gtk.h>
45
46 #ifdef HAVE_LIBPCAP
47 #include "capture_dlg.h"
48 #endif /* HAVE_LIBPCAP */
49 #include "filter_dlg.h"
50 #include "file_dlg.h"
51 #include "find_dlg.h"
52 #include "goto_dlg.h"
53 #include "color.h"
54 #include "color_dlg.h"
55 #include <epan/prefs.h>
56 #include "prefs_dlg.h"
57 #include "main.h"
58 #include "help_dlg.h"
59 #include "gtkglobals.h"
60 #include "toolbar.h"
61 #include "keys.h"
62 #include "compat_macros.h"
63 #include "recent.h"
64 #include "packet_history.h"
65 #include "packet_list.h"
66 #include "color_filters.h"
67 #include "menu.h"
68
69 /* Most of the icons used here are coming (or are derived) from GTK2 stock icons.
70  * They were converted using "The Gimp" with standard conversion from png to xpm.
71  * All stock icons can be (currently) found at: 
72  * "ftp://ftp.gtk.org/pub/gtk/v2.0/gtk+-2.0.6.tar.bz2"
73  * in the directory "gtk+-2.0.6\gtk\stock-icons" */
74
75 /* The base for the new capture icons were GNOME system tools: Connection-Ethernet.png 
76  * see http://cvs.gnome.org/viewcvs/gnome-system-tools/pixmaps/ and it's 16x16 counterpart, 
77  * which are released under the GPL (or LGPL?). These icons were 
78  * merged together with some icons of the tremendous ximian icon collection (>1200!)
79  * for  OpenOffice? (LGPL'ed), which can be found at:
80  * http://www.novell.com/coolsolutions/feature/1637.html
81  */
82
83 #if GTK_MAJOR_VERSION < 2
84 #include "../image/toolbar/stock_save_as_24.xpm"
85 #include "../image/toolbar/stock_close_24.xpm"
86 #include "../image/toolbar/stock_refresh_24.xpm"
87 #include "../image/toolbar/stock_print_24.xpm"
88 #include "../image/toolbar/stock_search_24.xpm"
89 #include "../image/toolbar/stock_left_arrow_24.xpm"
90 #include "../image/toolbar/stock_right_arrow_24.xpm"
91 #include "../image/toolbar/stock_jump_to_24.xpm"
92 #include "../image/toolbar/stock_top_24.xpm"
93 #include "../image/toolbar/stock_bottom_24.xpm"
94 #include "../image/toolbar/stock_zoom_in_24.xpm"
95 #include "../image/toolbar/stock_zoom_out_24.xpm"
96 #include "../image/toolbar/stock_zoom_1_24.xpm"
97 #include "../image/toolbar/stock_colorselector_24.xpm"
98 #include "../image/toolbar/stock_help_24.xpm"
99 #endif /* GTK_MAJOR_VERSION */
100
101 /* these icons are derived from the original stock icons */
102 #ifdef HAVE_LIBPCAP
103 #include "../image/toolbar/capture_interfaces_24.xpm"
104 #include "../image/toolbar/capture_options_24.xpm"
105 #include "../image/toolbar/capture_start_24.xpm"
106 #include "../image/toolbar/capture_stop_24.xpm"
107 #include "../image/toolbar/capture_restart_24.xpm"
108 #include "../image/toolbar/capture_filter_24.xpm"
109 #endif /* HAVE_LIBPCAP */
110 #include "../image/toolbar/display_filter_24.xpm"
111 /* these icons are standard stock icons, but used for ethereal specific stock icon labels */
112 #if GTK_MAJOR_VERSION >= 2
113 #include "../image/toolbar/stock_add_24.xpm"
114 #endif
115 #include "../image/toolbar/stock_open_24.xpm"
116 #if GTK_MAJOR_VERSION >= 2
117 #include "../image/toolbar/stock_ok_20.xpm"
118 #endif
119 #include "../image/toolbar/stock_save_24.xpm"
120 #include "../image/toolbar/stock_preferences_24.xpm"
121 #if GTK_MAJOR_VERSION >= 2
122 #include "../image/toolbar/stock_properties_24.xpm"
123 #endif
124 #include "../image/eicon3d16.xpm"
125 #include "../image/toolbar/colorize_24.xpm"
126 #include "../image/toolbar/autoscroll_24.xpm"
127 #include "../image/toolbar/resize_columns_24.xpm"
128 #include "../image/toolbar/time_24.xpm"
129 #include "../image/toolbar/internet_24.xpm"
130 #include "../image/toolbar/web_support_24.xpm"
131 #include "../image/toolbar/wiki_24.xpm"
132 #include "../image/toolbar/conversations_16.xpm"
133 #include "../image/toolbar/endpoints_16.xpm"
134 #include "../image/toolbar/graphs_16.xpm"
135 #include "../image/toolbar/telephony_16.xpm"
136 #include "../image/toolbar/decode_as_16.xpm"
137 #include "../image/toolbar/checkbox_16.xpm"
138 #include "../image/toolbar/file_set_list_16.xpm"
139 #include "../image/toolbar/file_set_next_16.xpm"
140 #include "../image/toolbar/file_set_previous_16.xpm"
141
142
143 /* XXX: add this key to some .h file, as it adds a key to the top level Widget? */
144 #define E_TB_MAIN_KEY             "toolbar_main"
145
146
147 static gboolean toolbar_init = FALSE;
148
149 #ifdef HAVE_LIBPCAP
150 static GtkWidget *capture_options_button, *new_button, *stop_button, *clear_button, *if_button;
151 static GtkWidget *capture_filter_button;
152 #endif /* HAVE_LIBPCAP */
153 static GtkWidget *open_button, *save_button, *save_as_button, *close_button, *reload_button;
154 static GtkWidget *print_button, *find_button, *history_forward_button, *history_back_button;
155 static GtkWidget *go_to_button, *go_to_top_button, *go_to_bottom_button;
156 static GtkWidget *display_filter_button;
157 static GtkWidget *zoom_in_button, *zoom_out_button, *zoom_100_button, *colorize_button, *autoscroll_button, *resize_columns_button;
158 static GtkWidget *color_display_button, *prefs_button, *help_button;
159
160 #if GTK_MAJOR_VERSION >= 2
161 typedef struct stock_pixmap_tag{
162     const char *    name;
163     char **         xpm_data;
164 } stock_pixmap_t;
165
166 /* generate application specific stock items */
167 static void ethereal_stock_icons(void) {
168     GtkIconFactory * factory;
169     gint32 i;
170
171
172     /* register non-standard pixmaps with the gtk-stock engine */
173     static const GtkStockItem stock_items[] = {
174 #ifdef HAVE_LIBPCAP
175         { ETHEREAL_STOCK_CAPTURE_INTERFACES,    ETHEREAL_STOCK_LABEL_CAPTURE_INTERFACES,    0, 0, NULL },
176         { ETHEREAL_STOCK_CAPTURE_OPTIONS,       ETHEREAL_STOCK_LABEL_CAPTURE_OPTIONS,       0, 0, NULL },
177         { ETHEREAL_STOCK_CAPTURE_START,         ETHEREAL_STOCK_LABEL_CAPTURE_START,         0, 0, NULL },
178         { ETHEREAL_STOCK_CAPTURE_STOP,          ETHEREAL_STOCK_LABEL_CAPTURE_STOP,          0, 0, NULL },
179         { ETHEREAL_STOCK_CAPTURE_RESTART,       ETHEREAL_STOCK_LABEL_CAPTURE_RESTART,       0, 0, NULL },
180         { ETHEREAL_STOCK_CAPTURE_FILTER,        ETHEREAL_STOCK_LABEL_CAPTURE_FILTER,        0, 0, NULL },
181         { ETHEREAL_STOCK_CAPTURE_FILTER_ENTRY,  ETHEREAL_STOCK_LABEL_CAPTURE_FILTER_ENTRY,  0, 0, NULL },
182 #endif
183         { ETHEREAL_STOCK_DISPLAY_FILTER,        ETHEREAL_STOCK_LABEL_DISPLAY_FILTER,        0, 0, NULL },
184         { ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY,  ETHEREAL_STOCK_LABEL_DISPLAY_FILTER_ENTRY,  0, 0, NULL },
185         { ETHEREAL_STOCK_PREFS,                 ETHEREAL_STOCK_LABEL_PREFS,                 0, 0, NULL },
186         { ETHEREAL_STOCK_BROWSE,                ETHEREAL_STOCK_LABEL_BROWSE,                0, 0, NULL },
187         { ETHEREAL_STOCK_CREATE_STAT,           ETHEREAL_STOCK_LABEL_CREATE_STAT,           0, 0, NULL },
188         { ETHEREAL_STOCK_EXPORT,                ETHEREAL_STOCK_LABEL_EXPORT,                0, 0, NULL },
189         { ETHEREAL_STOCK_IMPORT,                ETHEREAL_STOCK_LABEL_IMPORT,                0, 0, NULL },
190         { ETHEREAL_STOCK_EDIT,                  ETHEREAL_STOCK_LABEL_EDIT,                  0, 0, NULL },
191         { ETHEREAL_STOCK_ADD_EXPRESSION,        ETHEREAL_STOCK_LABEL_ADD_EXPRESSION,        0, 0, NULL },
192         { ETHEREAL_STOCK_DONT_SAVE,             ETHEREAL_STOCK_LABEL_DONT_SAVE,             0, 0, NULL },
193         { ETHEREAL_STOCK_ABOUT,                 ETHEREAL_STOCK_LABEL_ABOUT,                 0, 0, NULL },
194         { ETHEREAL_STOCK_COLORIZE,              ETHEREAL_STOCK_LABEL_COLORIZE,              0, 0, NULL },
195         { ETHEREAL_STOCK_AUTOSCROLL,            ETHEREAL_STOCK_LABEL_AUTOSCROLL,            0, 0, NULL },
196         { ETHEREAL_STOCK_RESIZE_COLUMNS,        ETHEREAL_STOCK_LABEL_RESIZE_COLUMNS,        0, 0, NULL },
197         { ETHEREAL_STOCK_TIME,                  ETHEREAL_STOCK_LABEL_TIME,                  0, 0, NULL },
198         { ETHEREAL_STOCK_INTERNET,              ETHEREAL_STOCK_LABEL_INTERNET,              0, 0, NULL },
199         { ETHEREAL_STOCK_WEB_SUPPORT,           ETHEREAL_STOCK_LABEL_WEB_SUPPORT,           0, 0, NULL },
200         { ETHEREAL_STOCK_WIKI,                  ETHEREAL_STOCK_LABEL_WIKI,                  0, 0, NULL },
201         { ETHEREAL_STOCK_CONVERSATIONS,         ETHEREAL_STOCK_LABEL_CONVERSATIONS,         0, 0, NULL },
202         { ETHEREAL_STOCK_ENDPOINTS,             ETHEREAL_STOCK_LABEL_ENDPOINTS,             0, 0, NULL },
203         { ETHEREAL_STOCK_GRAPHS,                ETHEREAL_STOCK_LABEL_GRAPHS,                0, 0, NULL },
204         { ETHEREAL_STOCK_TELEPHONY,             ETHEREAL_STOCK_LABEL_TELEPHONY,             0, 0, NULL },
205         { ETHEREAL_STOCK_DECODE_AS,             ETHEREAL_STOCK_LABEL_DECODE_AS,             0, 0, NULL },
206         { ETHEREAL_STOCK_CHECKBOX,              ETHEREAL_STOCK_LABEL_CHECKBOX,              0, 0, NULL },
207         { ETHEREAL_STOCK_FILE_SET_LIST,         ETHEREAL_STOCK_LABEL_FILE_SET_LIST,         0, 0, NULL },
208         { ETHEREAL_STOCK_FILE_SET_NEXT,         ETHEREAL_STOCK_LABEL_FILE_SET_NEXT,         0, 0, NULL },
209         { ETHEREAL_STOCK_FILE_SET_PREVIOUS,     ETHEREAL_STOCK_LABEL_FILE_SET_PREVIOUS,     0, 0, NULL }
210     };
211
212     static const stock_pixmap_t pixmaps[] = {
213 #ifdef HAVE_LIBPCAP
214         { ETHEREAL_STOCK_CAPTURE_INTERFACES,    capture_interfaces_24_xpm },
215         { ETHEREAL_STOCK_CAPTURE_OPTIONS,       capture_options_24_xpm },
216         { ETHEREAL_STOCK_CAPTURE_START,         capture_start_24_xpm },
217         { ETHEREAL_STOCK_CAPTURE_STOP,          capture_stop_24_xpm },
218         { ETHEREAL_STOCK_CAPTURE_RESTART,       capture_restart_24_xpm },
219         { ETHEREAL_STOCK_CAPTURE_FILTER,        capture_filter_24_xpm },
220         { ETHEREAL_STOCK_CAPTURE_FILTER_ENTRY,  capture_filter_24_xpm },
221 #endif
222         { ETHEREAL_STOCK_DISPLAY_FILTER,        display_filter_24_xpm },
223         { ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY,  display_filter_24_xpm },
224         { ETHEREAL_STOCK_PREFS,                 stock_preferences_24_xpm },
225         { ETHEREAL_STOCK_BROWSE,                stock_open_24_xpm },
226         { ETHEREAL_STOCK_CREATE_STAT,           stock_ok_20_xpm },
227         { ETHEREAL_STOCK_EXPORT,                stock_save_24_xpm },    /* XXX: needs a better icon */
228         { ETHEREAL_STOCK_IMPORT,                stock_save_24_xpm },    /* XXX: needs a better icon */
229         { ETHEREAL_STOCK_EDIT,                  stock_properties_24_xpm },
230         { ETHEREAL_STOCK_ADD_EXPRESSION,        stock_add_24_xpm },
231         { ETHEREAL_STOCK_ABOUT,                 eicon3d16_xpm },
232         { ETHEREAL_STOCK_COLORIZE,              colorize_24_xpm },
233         { ETHEREAL_STOCK_AUTOSCROLL,            autoscroll_24_xpm },
234         { ETHEREAL_STOCK_RESIZE_COLUMNS,        resize_columns_24_xpm},
235         { ETHEREAL_STOCK_TIME,                  time_24_xpm},
236         { ETHEREAL_STOCK_INTERNET,              internet_24_xpm},
237         { ETHEREAL_STOCK_WEB_SUPPORT,           web_support_24_xpm},
238         { ETHEREAL_STOCK_WIKI,                  wiki_24_xpm},
239         { ETHEREAL_STOCK_CONVERSATIONS,         conversations_16_xpm},
240         { ETHEREAL_STOCK_ENDPOINTS,             endpoints_16_xpm},
241         { ETHEREAL_STOCK_GRAPHS,                graphs_16_xpm},
242         { ETHEREAL_STOCK_TELEPHONY,             telephony_16_xpm},
243         { ETHEREAL_STOCK_DECODE_AS,             decode_as_16_xpm},
244         { ETHEREAL_STOCK_CHECKBOX,              checkbox_16_xpm},
245         { ETHEREAL_STOCK_FILE_SET_LIST,         file_set_list_16_xpm},
246         { ETHEREAL_STOCK_FILE_SET_NEXT,         file_set_next_16_xpm},
247         { ETHEREAL_STOCK_FILE_SET_PREVIOUS,     file_set_previous_16_xpm},
248         { NULL, NULL }
249     };
250
251     /* Register our stock items */
252     gtk_stock_add (stock_items, G_N_ELEMENTS (stock_items));
253
254     /* Add our custom icon factory to the list of defaults */
255     factory = gtk_icon_factory_new();
256     gtk_icon_factory_add_default(factory);
257
258     /* Create the stock items to add into our icon factory */
259     for (i = 0; pixmaps[i].name != NULL; i++) {
260         GdkPixbuf * pixbuf;
261         GtkIconSet *icon_set;
262
263         pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) (pixmaps[i].xpm_data));
264         g_assert(pixbuf);
265         icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
266         gtk_icon_factory_add (factory, pixmaps[i].name, icon_set);
267         gtk_icon_set_unref (icon_set);
268         g_object_unref (G_OBJECT (pixbuf));
269     }
270
271     /* Drop our reference to the factory, GTK will hold a reference.*/
272     g_object_unref (G_OBJECT (factory));
273 }
274 #endif
275
276
277 /*
278  * Redraw all toolbars (currently only the main toolbar)
279  */
280 void
281 toolbar_redraw_all(void)
282 {
283     GtkWidget     *main_tb;
284
285     main_tb = OBJECT_GET_DATA(top_level, E_TB_MAIN_KEY);
286
287     gtk_toolbar_set_style(GTK_TOOLBAR(main_tb),
288                           prefs.gui_toolbar_main_style);
289
290 #if GTK_MAJOR_VERSION < 2
291     /* In GTK+ 1.2[.x], the toolbar takes the maximum vertical size it ever
292      * had, even if you change the style in such a way as to reduce its
293      * height, unless we queue a resize (which resizes ALL elements in the
294      * top-level container).
295      *
296      * In GTK+ 2.x, this isn't necessary - it does the right thing. */
297     gtk_container_queue_resize(GTK_CONTAINER(top_level));
298 #endif /* GTK_MAJOR_VERSION */
299 }
300
301 /* Enable or disable toolbar items based on whether you have a capture file
302    you've finished reading. */
303 void set_toolbar_for_capture_file(gboolean have_capture_file) {
304     if (toolbar_init) {
305         gtk_widget_set_sensitive(save_button, have_capture_file);
306         gtk_widget_set_sensitive(save_as_button, have_capture_file);
307         gtk_widget_set_sensitive(close_button, have_capture_file);
308         gtk_widget_set_sensitive(reload_button, have_capture_file);
309     }
310 }
311
312 /* Enable or disable menu items based on whether you have an unsaved
313    capture file you've finished reading. */
314 void set_toolbar_for_unsaved_capture_file(gboolean have_unsaved_capture_file) {
315     if (toolbar_init) {
316         if(have_unsaved_capture_file) {
317             gtk_widget_hide(save_as_button);
318             gtk_widget_show(save_button);
319         } else {
320             gtk_widget_show(save_as_button);
321             gtk_widget_hide(save_button);
322         }
323         /*gtk_widget_set_sensitive(save_button, have_unsaved_capture_file);
324         gtk_widget_set_sensitive(save_as_button, !have_unsaved_capture_file);*/
325     }
326 }
327
328
329 /** The packet history has changed, we need to update the menu.
330  *
331  * @param back_history some back history entries available
332  * @param forward_history some forward history entries available
333  */
334 void set_toolbar_for_packet_history(gboolean back_history, gboolean forward_history) {
335     gtk_widget_set_sensitive(history_back_button, back_history);
336     gtk_widget_set_sensitive(history_forward_button, forward_history);
337 }
338
339
340 /* XXX - this is a quick and dirty hack to get the current state of capturing.
341  * this has to be improved, and should be reside somewhere in the capture engine. */
342 gboolean g_is_capture_in_progress = FALSE;
343
344 gboolean
345 is_capture_in_progress(void)
346 {
347     return g_is_capture_in_progress;
348 }
349
350 /* set toolbar state "have a capture in progress" */
351 void set_toolbar_for_capture_in_progress(gboolean capture_in_progress) {
352
353     g_is_capture_in_progress = capture_in_progress;
354
355     if (toolbar_init) {
356 #ifdef HAVE_LIBPCAP
357         gtk_widget_set_sensitive(capture_options_button, !capture_in_progress);
358         gtk_widget_set_sensitive(new_button, !capture_in_progress);
359         gtk_widget_set_sensitive(stop_button, capture_in_progress);
360         gtk_widget_set_sensitive(clear_button, capture_in_progress);
361         /*if (capture_in_progress) {
362             gtk_widget_hide(new_button);
363             gtk_widget_show(stop_button);
364         } else {
365             gtk_widget_show(new_button);
366             gtk_widget_hide(stop_button);
367         }*/
368 #endif /* HAVE_LIBPCAP */
369         gtk_widget_set_sensitive(open_button, !capture_in_progress);
370     }
371 }
372
373 /* set toolbar state "have packets captured" */
374 void set_toolbar_for_captured_packets(gboolean have_captured_packets) {
375
376     if (toolbar_init) {
377         gtk_widget_set_sensitive(print_button, have_captured_packets);
378         gtk_widget_set_sensitive(find_button, have_captured_packets);
379         gtk_widget_set_sensitive(history_back_button, have_captured_packets);
380         gtk_widget_set_sensitive(history_forward_button, have_captured_packets);
381         gtk_widget_set_sensitive(go_to_button, have_captured_packets);
382         gtk_widget_set_sensitive(go_to_top_button, have_captured_packets);
383         gtk_widget_set_sensitive(go_to_bottom_button, have_captured_packets);
384         gtk_widget_set_sensitive(zoom_in_button, have_captured_packets);
385         gtk_widget_set_sensitive(zoom_out_button, have_captured_packets);
386         gtk_widget_set_sensitive(zoom_100_button, have_captured_packets);        
387         gtk_widget_set_sensitive(resize_columns_button, have_captured_packets);
388         /* XXX - I don't see a reason why this should be done (as it is in the
389          * menus) */
390         /* gtk_widget_set_sensitive(color_display_button, have_captured_packets);*/
391     }
392 }
393
394
395 /* helper function: add a separator to the toolbar */
396 static void toolbar_append_separator(GtkWidget *toolbar) {
397 #if GTK_MAJOR_VERSION < 2
398     /* the usage of a gtk_separator doesn't seem to work for a toolbar.
399      * (at least in the win32 port of gtk 1.3)
400      * So simply add a few spaces */
401     gtk_toolbar_append_space(GTK_TOOLBAR(toolbar)); /* space after item */
402     gtk_toolbar_append_space(GTK_TOOLBAR(toolbar)); /* space after item */
403 #else
404     /* GTK 2 uses (as it should be) a seperator when adding this space */
405     gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
406 #endif /* GTK_MAJOR_VERSION */
407 }
408
409
410
411 #if GTK_MAJOR_VERSION < 2
412 #define toolbar_item(new_item, window, toolbar, stock, tooltip, xpm, callback, user_data) { \
413     icon = gdk_pixmap_create_from_xpm_d(window->window, &mask, &window->style->white, xpm); \
414     iconw = gtk_pixmap_new(icon, mask); \
415     new_item = gtk_toolbar_append_item(GTK_TOOLBAR (toolbar), \
416         stock, tooltip, "Private", iconw, GTK_SIGNAL_FUNC(callback), user_data);\
417     }
418 #else
419 #define toolbar_item(new_item, window, toolbar, stock, tooltip, xpm, callback, user_data) { \
420     new_item = gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), \
421         stock, tooltip, "Private", G_CALLBACK(callback), user_data, -1);\
422     }
423 #endif /* GTK_MAJOR_VERSION */
424
425
426 #define toolbar_icon(new_icon, window, xpm) { \
427     icon = gdk_pixmap_create_from_xpm_d(window->window, &mask, &window->style->white, xpm); \
428     new_icon = gtk_pixmap_new(icon, mask); \
429     }
430
431
432 #define toolbar_toggle_button(new_item, window, toolbar, stock, tooltip, xpm, callback, user_data) {\
433     toolbar_icon(iconw, window, xpm); \
434     new_item = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), \
435         GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, \
436         stock, tooltip, "Private", iconw, GTK_SIGNAL_FUNC(callback), user_data);\
437     }
438
439
440
441 static void
442 colorize_toggle_cb(GtkWidget *toggle_button, gpointer user_data _U_) {
443     menu_colorize_changed(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button)));
444 }
445
446 void
447 toolbar_colorize_changed(gboolean packet_list_colorize) {
448     if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(colorize_button)) != packet_list_colorize) {
449         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(colorize_button), packet_list_colorize);
450     }
451 }
452
453
454 #ifdef HAVE_LIBPCAP
455 static void
456 auto_scroll_live_toggle_cb(GtkWidget *autoscroll_button, gpointer user_data _U_) {
457     menu_auto_scroll_live_changed(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(autoscroll_button)));
458 }
459
460 void
461 toolbar_auto_scroll_live_changed(gboolean auto_scroll_live) {
462     if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(autoscroll_button)) != auto_scroll_live) {
463         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autoscroll_button), auto_scroll_live);
464     }
465 }
466 #endif
467
468 /*
469  * Create all toolbars (currently only the main toolbar)
470  */
471 GtkWidget *
472 toolbar_new(void)
473 {
474     GtkWidget *main_tb;
475     GtkWidget *window = top_level;
476 #if GTK_MAJOR_VERSION < 2
477 #endif /* GTK_MAJOR_VERSION */
478     GdkPixmap *icon;
479     GdkBitmap * mask;
480     GtkWidget *iconw;
481
482     
483 #if GTK_MAJOR_VERSION >= 2
484     /* create application specific stock icons */
485     ethereal_stock_icons();
486 #endif
487
488     /* this function should be only called once! */
489     g_assert(!toolbar_init);
490
491     /* we need to realize the window because we use pixmaps for 
492      * items on the toolbar in the context of it */
493     /* (coming from the gtk example, please don't ask me why ;-) */
494     gtk_widget_realize(window);
495
496     /* toolbar will be horizontal, with both icons and text (as default here) */
497     /* (this will usually be overwritten by the preferences setting) */
498 #if GTK_MAJOR_VERSION < 2
499     main_tb = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
500                                GTK_TOOLBAR_BOTH);
501     gtk_toolbar_set_space_size(GTK_TOOLBAR(main_tb), 3);
502     /* the "space lines" in GTK1 looks ugly, so don't use them */
503     /* gtk_toolbar_set_space_style(GTK_TOOLBAR(main_tb), GTK_TOOLBAR_SPACE_LINE); */
504 #else
505     main_tb = gtk_toolbar_new();
506     gtk_toolbar_set_orientation(GTK_TOOLBAR(main_tb),
507                                 GTK_ORIENTATION_HORIZONTAL);
508 #endif /* GTK_MAJOR_VERSION */
509
510     OBJECT_SET_DATA(top_level, E_TB_MAIN_KEY, main_tb);
511
512
513 #ifdef HAVE_LIBPCAP
514     toolbar_item(if_button, window, main_tb, 
515         ETHEREAL_STOCK_CAPTURE_INTERFACES, "List the available capture interfaces...", capture_interfaces_24_xpm, capture_if_cb, NULL);
516     toolbar_item(capture_options_button, window, main_tb, 
517         ETHEREAL_STOCK_CAPTURE_OPTIONS, "Show the capture options...", capture_options_24_xpm, capture_prep_cb, NULL);
518     toolbar_item(new_button, window, main_tb, 
519         ETHEREAL_STOCK_CAPTURE_START, "Start a new live capture", capture_start_24_xpm, capture_start_cb, NULL);
520     toolbar_item(stop_button, window, main_tb, 
521         ETHEREAL_STOCK_CAPTURE_STOP, "Stop the running live capture", capture_stop_24_xpm, capture_stop_cb, NULL);
522     toolbar_item(clear_button, window, main_tb, 
523         ETHEREAL_STOCK_CAPTURE_RESTART, "Restart the running live capture", capture_restart_24_xpm, capture_restart_cb, NULL);
524     toolbar_append_separator(main_tb);
525 #endif /* HAVE_LIBPCAP */
526
527     toolbar_item(open_button, window, main_tb, 
528         GTK_STOCK_OPEN, "Open a capture file...", stock_open_24_xpm, file_open_cmd_cb, NULL);
529     toolbar_item(save_button, window, main_tb, 
530         GTK_STOCK_SAVE, "Save this capture file...", stock_save_24_xpm, file_save_cmd_cb, NULL);
531     toolbar_item(save_as_button, window, main_tb, 
532         GTK_STOCK_SAVE_AS, "Save this capture file as...", stock_save_as_24_xpm, file_save_as_cmd_cb, NULL);
533     toolbar_item(close_button, window, main_tb, 
534         GTK_STOCK_CLOSE, "Close this capture file", stock_close_24_xpm, file_close_cmd_cb, NULL);
535     toolbar_item(reload_button, window, main_tb, 
536         GTK_STOCK_REFRESH, "Reload this capture file", stock_refresh_24_xpm, file_reload_cmd_cb, NULL);
537     toolbar_item(print_button, window, main_tb, 
538         GTK_STOCK_PRINT, "Print packet(s)...", stock_print_24_xpm, file_print_cmd_cb, NULL);
539     toolbar_append_separator(main_tb);
540
541     toolbar_item(find_button, window, main_tb, 
542         GTK_STOCK_FIND, "Find a packet...", stock_search_24_xpm, find_frame_cb, NULL);
543     toolbar_item(history_back_button, window, main_tb, 
544         GTK_STOCK_GO_BACK, "Go back in packet history", stock_left_arrow_24_xpm, history_back_cb, NULL);
545     toolbar_item(history_forward_button, window, main_tb, 
546         GTK_STOCK_GO_FORWARD, "Go forward in packet history", stock_right_arrow_24_xpm, history_forward_cb, NULL);
547     toolbar_item(go_to_button, window, main_tb, 
548         GTK_STOCK_JUMP_TO, "Go to the packet with number...", stock_jump_to_24_xpm, goto_frame_cb, NULL);
549     toolbar_item(go_to_top_button, window, main_tb, 
550         GTK_STOCK_GOTO_TOP, "Go to the first packet", stock_top_24_xpm, goto_top_frame_cb, NULL);
551     toolbar_item(go_to_bottom_button, window, main_tb, 
552         GTK_STOCK_GOTO_BOTTOM, "Go to the last packet", stock_bottom_24_xpm, goto_bottom_frame_cb, NULL);
553     toolbar_append_separator(main_tb);
554
555     toolbar_toggle_button(colorize_button, window, main_tb, 
556         "Colorize"/*ETHEREAL_STOCK_COLORIZE*/, "Colorize Packet List", colorize_24_xpm, colorize_toggle_cb, NULL);
557 #ifdef HAVE_LIBPCAP
558     toolbar_toggle_button(autoscroll_button, window, main_tb, 
559         "Auto Scroll" /*ETHEREAL_STOCK_AUTOSCROLL*/, "Auto Scroll Packet List in Live Capture", autoscroll_24_xpm, auto_scroll_live_toggle_cb, NULL);
560 #endif
561     toolbar_append_separator(main_tb);
562
563     toolbar_item(zoom_in_button, window, main_tb, 
564         GTK_STOCK_ZOOM_IN, "Zoom in", stock_zoom_in_24_xpm, view_zoom_in_cb, NULL);
565     toolbar_item(zoom_out_button, window, main_tb, 
566         GTK_STOCK_ZOOM_OUT, "Zoom out", stock_zoom_out_24_xpm, view_zoom_out_cb, NULL);
567     toolbar_item(zoom_100_button, window, main_tb, 
568         GTK_STOCK_ZOOM_100, "Zoom 100%", stock_zoom_1_24_xpm, view_zoom_100_cb, NULL);
569     toolbar_item(resize_columns_button, window, main_tb, 
570         ETHEREAL_STOCK_RESIZE_COLUMNS, "Resize All Columns", resize_columns_24_xpm, packet_list_resize_columns_cb, NULL);
571     toolbar_append_separator(main_tb);
572     
573 #ifdef HAVE_LIBPCAP
574     toolbar_item(capture_filter_button, window, main_tb, 
575         ETHEREAL_STOCK_CAPTURE_FILTER, "Edit capture filter...", capture_filter_24_xpm, cfilter_dialog_cb, NULL);
576 #endif /* HAVE_LIBPCAP */
577     toolbar_item(display_filter_button, window, main_tb, 
578         ETHEREAL_STOCK_DISPLAY_FILTER, "Edit/apply display filter...", display_filter_24_xpm, dfilter_dialog_cb, NULL);
579     toolbar_item(color_display_button, window, main_tb, 
580         GTK_STOCK_SELECT_COLOR, "Edit coloring rules...", stock_colorselector_24_xpm, color_display_cb, NULL);
581     /* the preference button uses it's own Stock icon label "Prefs", as "Preferences" is too long */
582     toolbar_item(prefs_button, window, main_tb, 
583         ETHEREAL_STOCK_PREFS, "Edit preferences...", stock_preferences_24_xpm, prefs_cb, NULL);
584     toolbar_append_separator(main_tb);
585
586     toolbar_item(help_button, window, main_tb, 
587         GTK_STOCK_HELP, "Show some help...", stock_help_24_xpm, topic_cb, GINT_TO_POINTER(HELP_CONTENT));
588
589     /* disable all "sensitive" items by default */
590     toolbar_init = TRUE;
591     set_toolbar_for_unsaved_capture_file(FALSE);
592     set_toolbar_for_captured_packets(FALSE);
593     set_toolbar_for_capture_file(FALSE);
594 #ifdef HAVE_LIBPCAP
595     set_toolbar_for_capture_in_progress(FALSE);
596 #endif /* HAVE_LIBPCAP */
597
598     /* make current preferences effective */
599     toolbar_redraw_all();
600
601     return main_tb;
602 }
603
604 void
605 set_toolbar_object_data(gchar *key, gpointer data)
606 {
607     OBJECT_SET_DATA(open_button, key, data);
608     OBJECT_SET_DATA(reload_button, key, data);
609 }