2 * Definitions for dialog boxes for color filters
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/packet.h>
37 #include "color_filters.h"
38 #include "color_dlg.h"
39 #include "color_utils.h"
41 #include <epan/dfilter/dfilter.h>
42 #include "simple_dialog.h"
43 #include "dlg_utils.h"
45 #include "dfilter_expr_dlg.h"
46 #include "compat_macros.h"
47 #include "filter_dlg.h"
49 #include "gtkglobals.h"
52 static GtkWidget* colorize_dialog_new(char *filter);
53 static void add_filter_to_list(gpointer filter_arg, gpointer list_arg);
54 static void color_filter_up_cb(GtkButton *button, gpointer user_data);
55 static void color_filter_down_cb(GtkButton *button, gpointer user_data);
56 #if GTK_MAJOR_VERSION < 2
57 static void remember_selected_row(GtkCList *clist, gint row, gint column,
58 GdkEvent *event, gpointer user_data);
59 static void unremember_selected_row(GtkCList *clist, gint row, gint column,
60 GdkEvent *event, gpointer user_data);
62 static void remember_selected_row(GtkTreeSelection *sel, gpointer list);
64 static void color_destroy_cb(GtkButton *button, gpointer user_data);
65 static void destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy);
66 static void create_new_color_filter(GtkButton *button, char *filter);
67 static void color_new_cb(GtkButton *button, gpointer user_data);
68 static void color_props_cb(GtkButton *button, gpointer user_data);
69 static void color_delete_cb(GtkWidget *widget, gpointer user_data);
70 static void color_save_cb(GtkButton *button, gpointer user_data);
71 static void color_ok_cb(GtkButton *button, gpointer user_data);
72 static void color_cancel_cb(GtkWidget *widget, gpointer user_data);
73 static void color_apply_cb(GtkButton *button, gpointer user_data);
74 static void color_clear_cb(GtkWidget *button, gpointer user_data);
75 static void color_import_cb(GtkButton *button, gpointer user_data );
77 static void edit_color_filter_dialog(GtkWidget *color_filters,
78 GtkWidget **colorize_filter_name,
79 GtkWidget **colorize_filter_text,
80 guchar is_new_filter);
82 #if GTK_MAJOR_VERSION < 2
83 static void edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data);
85 static void edit_color_filter_destroy_cb(GObject *object, gpointer user_data);
87 static void edit_color_filter_fg_cb(GtkButton *button, gpointer user_data);
88 static void edit_color_filter_bg_cb(GtkButton *button, gpointer user_data);
89 static void edit_color_filter_ok_cb(GtkButton *button, gpointer user_data);
90 static void edit_new_color_filter_cancel_cb(GtkButton *button, gpointer user_data);
92 static GtkWidget* color_sel_win_new(color_filter_t *colorf, gboolean);
93 static void color_sel_ok_cb(GtkButton *button, gpointer user_data);
94 static void color_sel_cancel_cb(GtkObject *object, gpointer user_data);
96 static GtkWidget *colorize_win;
97 static gint num_of_filters; /* number of filters being displayed */
98 static gint row_selected; /* row in color_filters that is selected */
100 #define COLOR_UP_LB "color_up_lb"
101 #define COLOR_DOWN_LB "color_down_lb"
102 #define COLOR_PROPS_LB "color_props_lb"
103 #define COLOR_DELETE_LB "color_delete_lb"
104 #define COLOR_FILTERS_CL "color_filters_cl"
105 #define COLOR_FILTER "color_filter"
106 #define COLOR_SELECTION_FG "color_selection_fg"
107 #define COLOR_SELECTION_BG "color_selection_bg"
108 #define COLOR_SELECTION_PARENT "color_selection_parent"
111 filter_expr_cb(GtkWidget *w _U_, gpointer filter_te)
114 dfilter_expr_dlg_new(GTK_WIDGET(filter_te));
118 /* Callback for the "Display:Colorize Display" menu item. */
120 color_display_cb(GtkWidget *w _U_, gpointer d _U_)
122 if (colorize_win != NULL) {
123 /* There's already a color dialog box active; reactivate it. */
124 reactivate_window(colorize_win);
126 /* Create a new "Colorize Display" dialog. */
127 colorize_win = colorize_dialog_new(NULL);
131 /* this opens the colorize dialogue and presets the filter string */
133 color_display_with_filter(char *filter)
135 if (colorize_win != NULL) {
136 /* There's already a color dialog box active; reactivate it. */
137 reactivate_window(colorize_win);
139 /* Create a new "Colorize Display" dialog. */
140 colorize_win = colorize_dialog_new(filter);
144 /* if this filter is marked count it in the given int* */
146 count_this_mark(gpointer filter_arg, gpointer counter_arg)
148 color_filter_t *colorf = filter_arg;
149 int * cnt = counter_arg;
155 /* TODO: implement count of selected filters. Plug in to file_dlg update of "export selected" checkbox. */
156 int color_marked_count(void)
160 g_slist_foreach(filter_list, count_this_mark, &count);
165 /* Create the "Coloring Rules" dialog. */
167 colorize_dialog_new (char *filter)
169 GtkWidget *color_win;
171 GtkWidget *main_hbox;
172 GtkWidget *ctrl_vbox;
173 GtkTooltips *tooltips;
176 GtkWidget *order_vbox;
177 GtkWidget *color_filter_up;
178 GtkWidget *order_move_label;
179 GtkWidget *color_filter_down;
182 GtkWidget *list_vbox;
183 GtkWidget *scrolledwindow1;
184 GtkWidget *color_filters;
185 GtkWidget *list_label;
188 GtkWidget *edit_vbox;
189 GtkWidget *color_new;
190 GtkWidget *color_props;
191 GtkWidget *color_delete;
193 GtkWidget *manage_fr;
194 GtkWidget *manage_vbox;
195 GtkWidget *color_export;
196 GtkWidget *color_import;
197 GtkWidget *color_clear;
199 GtkWidget *button_ok_hbox;
201 GtkWidget *color_apply;
202 GtkWidget *color_save;
203 GtkWidget *color_cancel;
205 #if GTK_MAJOR_VERSION >= 2
207 GtkCellRenderer *renderer;
208 GtkTreeViewColumn *column;
209 GtkTreeSelection *selection;
211 gchar *titles[] = { "Name", "String" };
214 row_selected = -1; /* no row selected */
215 tooltips = gtk_tooltips_new ();
217 /* Resizing of the dialog window is now reasonably done.
218 * Default size is set so that it should fit into every usual screen resolution.
219 * All other widgets are always packed depending on the current window size. */
220 color_win = dlg_window_new ("Ethereal: Coloring Rules");
221 OBJECT_SET_DATA(color_win, "color_win", color_win);
222 gtk_window_set_default_size(GTK_WINDOW(color_win), DEF_WIDTH, DEF_HEIGHT * 2/3);
223 dlg_vbox = gtk_vbox_new (FALSE, 0);
224 gtk_container_set_border_width (GTK_CONTAINER (dlg_vbox), 5);
225 gtk_container_add (GTK_CONTAINER (color_win), dlg_vbox);
227 main_hbox = gtk_hbox_new (FALSE, 0);
228 gtk_box_pack_start (GTK_BOX (dlg_vbox), main_hbox, TRUE, TRUE, 0);
230 ctrl_vbox = gtk_vbox_new (FALSE, 0);
231 gtk_box_pack_start (GTK_BOX (main_hbox), ctrl_vbox, FALSE, FALSE, 0);
234 /* edit buttons frame */
235 edit_fr = gtk_frame_new("Edit");
236 gtk_box_pack_start (GTK_BOX (ctrl_vbox), edit_fr, TRUE, TRUE, 0);
238 /* edit_vbox is first button column (containing: new, edit and such) */
239 edit_vbox = gtk_vbutton_box_new();
240 gtk_button_box_set_child_size(GTK_BUTTON_BOX(edit_vbox), 50, 20);
241 gtk_container_set_border_width (GTK_CONTAINER (edit_vbox), 5);
242 gtk_container_add(GTK_CONTAINER(edit_fr), edit_vbox);
244 color_new = BUTTON_NEW_FROM_STOCK(GTK_STOCK_NEW);
245 #if GTK_MAJOR_VERSION < 2
246 WIDGET_SET_SIZE(color_new, 50, 20);
248 gtk_box_pack_start (GTK_BOX (edit_vbox), color_new, FALSE, FALSE, 5);
249 gtk_tooltips_set_tip (tooltips, color_new, ("Create a new filter at the end of the list"), NULL);
251 color_props = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_EDIT);
252 #if GTK_MAJOR_VERSION < 2
253 WIDGET_SET_SIZE(color_props, 50, 20);
255 gtk_box_pack_start (GTK_BOX (edit_vbox), color_props, FALSE, FALSE, 5);
256 gtk_tooltips_set_tip (tooltips, color_props, ("Edit the properties of the selected filter"), NULL);
257 gtk_widget_set_sensitive (color_props, FALSE);
259 color_delete = BUTTON_NEW_FROM_STOCK(GTK_STOCK_DELETE);
260 gtk_box_pack_start (GTK_BOX (edit_vbox), color_delete, FALSE, FALSE, 5);
261 #if GTK_MAJOR_VERSION < 2
262 WIDGET_SET_SIZE(color_delete, 50, 20);
264 gtk_tooltips_set_tip (tooltips, color_delete, ("Delete the selected filter"), NULL);
265 gtk_widget_set_sensitive (color_delete, FALSE);
266 /* End edit buttons frame */
269 /* manage buttons frame */
270 manage_fr = gtk_frame_new("Manage");
271 gtk_box_pack_start (GTK_BOX (ctrl_vbox), manage_fr, FALSE, FALSE, 0);
273 manage_vbox = gtk_vbox_new (FALSE, 0);
274 gtk_container_set_border_width (GTK_CONTAINER (manage_vbox), 5);
275 gtk_container_add(GTK_CONTAINER(manage_fr), manage_vbox);
277 color_export = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_EXPORT);
278 gtk_box_pack_start (GTK_BOX (manage_vbox), color_export, FALSE, FALSE, 5);
279 #if GTK_MAJOR_VERSION < 2
280 WIDGET_SET_SIZE(color_export, 50, 20);
282 gtk_tooltips_set_tip(tooltips, color_export, ("Save all/marked filters to a file"), NULL);
284 color_import = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_IMPORT);
285 gtk_box_pack_start (GTK_BOX (manage_vbox), color_import, FALSE, FALSE, 5);
286 #if GTK_MAJOR_VERSION < 2
287 WIDGET_SET_SIZE(color_import, 50, 20);
289 gtk_tooltips_set_tip(tooltips, color_import, ("Load filters from a file"), NULL);
291 color_clear = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLEAR);
292 gtk_box_pack_start(GTK_BOX (manage_vbox), color_clear, FALSE, FALSE, 5);
293 #if GTK_MAJOR_VERSION < 2
294 WIDGET_SET_SIZE(color_clear, 50, 20);
296 gtk_tooltips_set_tip(tooltips, color_clear, ("Clear all filters in the user's colorfilters file and revert to system-wide default filter set"), NULL);
299 /* filter list frame */
300 list_fr = gtk_frame_new("Filter");
301 gtk_box_pack_start (GTK_BOX (main_hbox), list_fr, TRUE, TRUE, 0);
303 list_vbox = gtk_vbox_new (FALSE, 0);
304 gtk_container_set_border_width (GTK_CONTAINER (list_vbox), 5);
305 gtk_container_add(GTK_CONTAINER(list_fr), list_vbox);
307 list_label = gtk_label_new (("[List is processed in order until match is found]"));
308 gtk_box_pack_start (GTK_BOX (list_vbox), list_label, FALSE, FALSE, 0);
310 /* create the list of filters */
311 scrolledwindow1 = scrolled_window_new(NULL, NULL);
312 #if GTK_MAJOR_VERSION >= 2
313 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow1),
316 gtk_box_pack_start (GTK_BOX (list_vbox), scrolledwindow1, TRUE, TRUE, 0);
318 #if GTK_MAJOR_VERSION < 2
319 color_filters = gtk_clist_new_with_titles(2, titles);
321 /* the list store contains : filter name, filter string, foreground
322 * color, background color, pointer to color filter */
323 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING,
324 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
325 color_filters = tree_view_new(GTK_TREE_MODEL(store));
326 g_object_unref(store);
327 renderer = gtk_cell_renderer_text_new();
328 column = gtk_tree_view_column_new_with_attributes(titles[0], renderer, "text",
330 "background", 3, NULL);
331 gtk_tree_view_column_set_fixed_width(column, 80);
332 gtk_tree_view_append_column(GTK_TREE_VIEW(color_filters), column);
333 renderer = gtk_cell_renderer_text_new();
334 column = gtk_tree_view_column_new_with_attributes(titles[1], renderer, "text",
336 "background", 3, NULL);
337 gtk_tree_view_column_set_fixed_width(column, 300);
338 gtk_tree_view_append_column(GTK_TREE_VIEW(color_filters), column);
339 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(color_filters), TRUE);
340 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(color_filters), FALSE);
344 g_slist_foreach(filter_list, add_filter_to_list, color_filters);
346 #if GTK_MAJOR_VERSION < 2
347 gtk_clist_set_selection_mode (GTK_CLIST (color_filters),GTK_SELECTION_EXTENDED);
349 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
350 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
353 gtk_container_add (GTK_CONTAINER (scrolledwindow1), color_filters);
354 #if GTK_MAJOR_VERSION < 2
355 gtk_clist_set_column_width (GTK_CLIST (color_filters), 0, 80);
356 gtk_clist_set_column_width (GTK_CLIST (color_filters), 1, 300);
357 gtk_clist_column_titles_show (GTK_CLIST (color_filters));
362 order_fr = gtk_frame_new("Order");
363 gtk_box_pack_start (GTK_BOX (main_hbox), order_fr, FALSE, FALSE, 0);
365 order_vbox = gtk_vbox_new (TRUE, 0);
366 gtk_container_set_border_width (GTK_CONTAINER (order_vbox), 5);
367 gtk_container_add(GTK_CONTAINER(order_fr), order_vbox);
369 color_filter_up = BUTTON_NEW_FROM_STOCK(GTK_STOCK_GO_UP);
370 #if GTK_MAJOR_VERSION < 2
371 WIDGET_SET_SIZE(color_filter_up, 50, 20);
373 gtk_box_pack_start (GTK_BOX (order_vbox), color_filter_up, FALSE, FALSE, 0);
374 gtk_tooltips_set_tip (tooltips, color_filter_up, ("Move filter higher in list"), NULL);
375 gtk_widget_set_sensitive (color_filter_up, FALSE);
377 order_move_label = gtk_label_new (("Move\nselected filter\nup or down"));
378 gtk_box_pack_start (GTK_BOX (order_vbox), order_move_label, FALSE, FALSE, 0);
380 color_filter_down = BUTTON_NEW_FROM_STOCK(GTK_STOCK_GO_DOWN);
381 #if GTK_MAJOR_VERSION < 2
382 WIDGET_SET_SIZE(color_filter_down, 50, 20);
384 gtk_box_pack_start (GTK_BOX (order_vbox), color_filter_down, FALSE, FALSE, 0);
385 gtk_tooltips_set_tip (tooltips, color_filter_down, ("Move filter lower in list"), NULL);
386 gtk_widget_set_sensitive (color_filter_down, FALSE);
389 /* Button row: OK and cancel buttons */
390 button_ok_hbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_SAVE, GTK_STOCK_CLOSE/*, GTK_STOCK_CANCEL*/, NULL);
391 gtk_box_pack_start (GTK_BOX (dlg_vbox), button_ok_hbox, FALSE, FALSE, 5);
393 color_ok = OBJECT_GET_DATA(button_ok_hbox, GTK_STOCK_OK);
394 gtk_tooltips_set_tip (tooltips, color_ok, ("Apply the color filters to the display and close this dialog"), NULL);
396 color_apply = OBJECT_GET_DATA(button_ok_hbox, GTK_STOCK_APPLY);
397 gtk_tooltips_set_tip (tooltips, color_apply, ("Apply the color filters to the display but keep this dialog open"), NULL);
399 color_save = OBJECT_GET_DATA(button_ok_hbox, GTK_STOCK_SAVE);
400 gtk_tooltips_set_tip (tooltips, color_save, ("Save the color filters permanently and keep this dialog open"), NULL);
402 color_cancel = OBJECT_GET_DATA(button_ok_hbox, GTK_STOCK_CLOSE);
403 window_set_cancel_button(color_win, color_cancel, color_cancel_cb);
404 gtk_tooltips_set_tip (tooltips, color_cancel, ("Close this dialog but don't apply the color filter changes to the display"), NULL);
406 gtk_widget_grab_default(color_ok);
408 /* signals and such */
409 SIGNAL_CONNECT(color_win, "destroy", color_destroy_cb, NULL);
410 OBJECT_SET_DATA(color_filter_up, COLOR_FILTERS_CL, color_filters);
411 SIGNAL_CONNECT(color_filter_up, "clicked", color_filter_up_cb, NULL);
412 OBJECT_SET_DATA(color_filter_down, COLOR_FILTERS_CL, color_filters);
413 SIGNAL_CONNECT(color_filter_down, "clicked", color_filter_down_cb, NULL);
414 #if GTK_MAJOR_VERSION < 2
415 SIGNAL_CONNECT(color_filters, "select_row", remember_selected_row, NULL);
416 SIGNAL_CONNECT(color_filters, "unselect_row", unremember_selected_row, NULL);
418 SIGNAL_CONNECT(selection, "changed", remember_selected_row, color_filters);
420 OBJECT_SET_DATA(color_filters, COLOR_UP_LB, color_filter_up);
421 OBJECT_SET_DATA(color_filters, COLOR_DOWN_LB, color_filter_down);
422 OBJECT_SET_DATA(color_filters, COLOR_PROPS_LB, color_props);
423 OBJECT_SET_DATA(color_filters, COLOR_DELETE_LB, color_delete);
424 OBJECT_SET_DATA(color_new, COLOR_FILTERS_CL, color_filters);
425 SIGNAL_CONNECT(color_new, "clicked", color_new_cb, NULL);
426 OBJECT_SET_DATA(color_props, COLOR_FILTERS_CL, color_filters);
427 SIGNAL_CONNECT(color_props, "clicked", color_props_cb, NULL);
428 OBJECT_SET_DATA(color_delete, COLOR_PROPS_LB, color_props);
429 OBJECT_SET_DATA(color_delete, COLOR_FILTERS_CL, color_filters);
430 SIGNAL_CONNECT(color_delete, "clicked", color_delete_cb, NULL);
431 SIGNAL_CONNECT(color_save, "clicked", color_save_cb, NULL);
432 SIGNAL_CONNECT(color_export, "clicked", file_color_export_cmd_cb, NULL);
433 OBJECT_SET_DATA(color_import, COLOR_FILTERS_CL, color_filters);
434 SIGNAL_CONNECT(color_import, "clicked", color_import_cb, color_filters);
435 OBJECT_SET_DATA(color_clear, COLOR_FILTERS_CL, color_filters);
436 SIGNAL_CONNECT(color_clear, "clicked", color_clear_cb, NULL);
437 SIGNAL_CONNECT(color_ok, "clicked", color_ok_cb, NULL);
438 SIGNAL_CONNECT(color_apply, "clicked", color_apply_cb, NULL);
440 SIGNAL_CONNECT(color_win, "delete_event", window_delete_event_cb, NULL);
442 gtk_widget_grab_focus(color_filters);
444 gtk_widget_show_all(color_win);
445 window_present(color_win);
448 /* if we specified a preset filter string, open the new dialog and
450 create_new_color_filter(GTK_BUTTON(color_new), filter);
457 add_filter_to_list(gpointer filter_arg, gpointer list_arg)
459 color_filter_t *colorf = filter_arg;
460 #if GTK_MAJOR_VERSION < 2
461 GtkWidget *color_filters = list_arg;
466 data[0] = colorf->filter_name;
467 data[1] = colorf->filter_text;
468 row = gtk_clist_append(GTK_CLIST(color_filters), data);
469 color_t_to_gdkcolor(&fg, &colorf->fg_color);
470 color_t_to_gdkcolor(&bg, &colorf->bg_color);
471 gtk_clist_set_row_data(GTK_CLIST(color_filters), row, colorf);
472 gtk_clist_set_foreground(GTK_CLIST(color_filters), row, &fg);
473 gtk_clist_set_background(GTK_CLIST(color_filters), row, &bg);
475 gchar fg_str[14], bg_str[14];
479 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list_arg)));
480 gtk_list_store_append(store, &iter);
481 g_snprintf(fg_str, 14, "#%04X%04X%04X",
482 colorf->fg_color.red, colorf->fg_color.green, colorf->fg_color.blue);
483 g_snprintf(bg_str, 14, "#%04X%04X%04X",
484 colorf->bg_color.red, colorf->bg_color.green, colorf->bg_color.blue);
485 gtk_list_store_set(store, &iter, 0, colorf->filter_name,
486 1, colorf->filter_text, 2, fg_str, 3, bg_str,
492 void move_this_row (GtkWidget *color_filters,
494 gint amount) /* only tested with +1(down) and -1(up) */
496 color_filter_t *colorf;
497 #if GTK_MAJOR_VERSION < 2
501 GtkTreeIter iter1, iter2;
502 gchar *name, *string, *fg_str, *bg_str;
505 g_assert(amount == +1 || amount == -1);
506 g_assert(amount == +1 || filter_number > 0);
507 g_assert(amount == -1 || filter_number < num_of_filters - 1);
509 #if GTK_MAJOR_VERSION < 2
512 lower = filter_number;
513 higher = filter_number + amount;
517 higher = filter_number;
518 lower = filter_number + amount;
521 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
522 gtk_clist_swap_rows(GTK_CLIST(color_filters), higher, lower);
525 * That row is still selected, but it's now moved.
527 remember_selected_row(GTK_CLIST(color_filters), filter_number + amount, 0, NULL, NULL);
530 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
531 gtk_tree_model_iter_nth_child(model, &iter1, NULL, filter_number);
532 gtk_tree_model_iter_nth_child(model, &iter2, NULL, filter_number + amount);
534 gtk_tree_model_get(model, &iter1, 0, &name, 1, &string,
535 2, &fg_str, 3, &bg_str, 4, &colorf, -1);
536 gtk_list_store_remove(GTK_LIST_STORE(model), &iter1);
538 gtk_list_store_insert_before(GTK_LIST_STORE(model), &iter1, &iter2);
540 gtk_list_store_insert_after(GTK_LIST_STORE(model), &iter1, &iter2);
541 gtk_list_store_set(GTK_LIST_STORE(model), &iter1, 0, name, 1, string,
542 2, fg_str, 3, bg_str, 4, colorf, -1);
549 * re-select the initial row
551 gtk_widget_grab_focus(color_filters);
552 gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters)), &iter1);
556 filter_list = g_slist_remove(filter_list, colorf);
557 filter_list = g_slist_insert(filter_list, colorf, filter_number + amount);
560 /* Move the selected filters up in the list */
562 color_filter_up_cb(GtkButton *button, gpointer user_data _U_)
566 GtkWidget * color_filters;
567 color_filter_t *colorf;
568 #if GTK_MAJOR_VERSION < 2
572 GtkTreeSelection *sel;
576 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
578 #if GTK_MAJOR_VERSION < 2
579 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), 0);
584 for (filter_number = 0; filter_number < num_of_filters; filter_number++)
586 #if GTK_MAJOR_VERSION < 2
587 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
589 move_this_row (color_filters, filter_number, amount);
591 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
592 gtk_tree_model_iter_nth_child(model, &iter, NULL, filter_number);
593 gtk_tree_model_get(model, &iter, 4, &colorf, -1);
594 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
595 if (gtk_tree_selection_iter_is_selected(sel, &iter))
596 move_this_row (color_filters, filter_number, amount);
601 /* Move the selected filters down in the list */
603 color_filter_down_cb(GtkButton *button, gpointer user_data _U_)
607 GtkWidget * color_filters;
608 color_filter_t *colorf;
609 #if GTK_MAJOR_VERSION < 2
616 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
618 #if GTK_MAJOR_VERSION < 2
619 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), num_of_filters - 1);
624 for (filter_number = num_of_filters - 1; filter_number >= 0; filter_number--)
626 #if GTK_MAJOR_VERSION < 2
627 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
629 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
630 gtk_tree_model_iter_nth_child(model, &iter, NULL, filter_number);
631 gtk_tree_model_get(model, &iter, 4, &colorf, -1);
634 move_this_row (color_filters, filter_number, amount);
638 /* A row was selected; remember its row number */
639 #if GTK_MAJOR_VERSION < 2
641 remember_selected_row(GtkCList *clist, gint row, gint column _U_,
642 GdkEvent *event _U_, gpointer user_data _U_)
645 color_filter_t *colorf;
649 colorf = gtk_clist_get_row_data(clist, row);
650 colorf->marked = TRUE;
653 * A row is selected, so we can move it up *if* it's not at the top
654 * and move it down *if* it's not at the bottom.
656 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_UP_LB);
657 gtk_widget_set_sensitive (button, row > 0);
658 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DOWN_LB);
659 gtk_widget_set_sensitive(button, row < num_of_filters - 1);
662 * A row is selected, so we can operate on it.
664 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_PROPS_LB);
665 gtk_widget_set_sensitive (button, TRUE);
666 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DELETE_LB);
667 gtk_widget_set_sensitive(button, TRUE);
674 gint count; /* count of selected filters */
675 gboolean first_marked; /* true if the first filter in the list is marked */
676 gboolean last_marked; /* true if the last filter in the list is marked */
677 gpointer color_filters;
679 /* called for each selected row in the tree.
681 void remember_this_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer arg)
684 color_filter_t *colorf;
685 struct remember_data *data = arg;
687 gtk_tree_model_get(model, iter, 4, &colorf, -1);
688 colorf->marked = TRUE;
690 path_index = gtk_tree_path_get_indices(path); /* not to be freed */
691 if (path_index == NULL) /* can return NULL according to API doc.*/
695 row_selected = path_index[0];
697 if (row_selected == 0)
698 data->first_marked = TRUE;
699 if (row_selected == num_of_filters - 1)
700 data->last_marked = TRUE;
705 /* clear the mark on this filter */
707 clear_mark(gpointer filter_arg, gpointer arg _U_)
709 color_filter_t *colorf = filter_arg;
711 colorf->marked = FALSE;
714 /* The gtk+2.0 version gets called for, (maybe multiple,) changes in the selection. */
716 remember_selected_row(GtkTreeSelection *sel, gpointer color_filters)
719 struct remember_data data;
721 data.first_marked = data.last_marked = FALSE;
723 data.color_filters = color_filters;
725 g_slist_foreach(filter_list, clear_mark, NULL);
726 gtk_tree_selection_selected_foreach(sel,remember_this_row, &data);
731 * One or more rows are selected, so we can operate on them.
734 /* We can only edit if there is exactly one filter selected */
735 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_PROPS_LB);
736 gtk_widget_set_sensitive (button, data.count == 1);
738 /* We can delete any number of filters */
739 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DELETE_LB);
740 gtk_widget_set_sensitive (button, TRUE);
742 * We can move them up *if* one of them isn't the top row,
743 * and move them down *if* one of them isn't the bottom row.
745 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_UP_LB);
746 gtk_widget_set_sensitive(button, !data.first_marked);
747 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DOWN_LB);
748 gtk_widget_set_sensitive(button, !data.last_marked);
755 * No row is selected, so we can't do operations that affect the
758 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_UP_LB);
759 gtk_widget_set_sensitive (button, FALSE);
760 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DOWN_LB);
761 gtk_widget_set_sensitive (button, FALSE);
762 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_PROPS_LB);
763 gtk_widget_set_sensitive (button, FALSE);
764 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DELETE_LB);
765 gtk_widget_set_sensitive (button, FALSE);
770 #if GTK_MAJOR_VERSION < 2
771 /* A row was unselected; un-remember its row number */
773 unremember_selected_row (GtkCList *clist,
777 gpointer user_data _U_)
780 color_filter_t *colorf;
784 colorf = gtk_clist_get_row_data(clist, row);
785 colorf->marked = FALSE;
787 if (color_marked_count() == 0)
790 * No row is selected, so we can't do operations that affect the
793 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_UP_LB);
794 gtk_widget_set_sensitive (button, FALSE);
795 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DOWN_LB);
796 gtk_widget_set_sensitive (button, FALSE);
797 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_PROPS_LB);
798 gtk_widget_set_sensitive (button, FALSE);
799 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DELETE_LB);
800 gtk_widget_set_sensitive(button, FALSE);
805 /* Called when the dialog box is being destroyed; destroy any edit
806 * dialogs opened from this dialog, and null out the pointer to this
810 color_destroy_cb (GtkButton *button _U_,
811 gpointer user_data _U_)
813 /* Destroy any edit dialogs we have open. */
814 g_slist_foreach(filter_list, destroy_edit_dialog_cb, NULL);
820 destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy _U_)
822 color_filter_t *colorf = (color_filter_t *)filter_arg;
824 if (colorf->edit_dialog != NULL)
825 window_destroy(colorf->edit_dialog);
828 /* XXX - we don't forbid having more than one "Edit color filter" dialog
829 open, so these shouldn't be static. */
830 static GtkWidget *filt_name_entry;
831 static GtkWidget *filt_text_entry;
834 color_add_colorf(GtkWidget *color_filters, color_filter_t *colorf)
836 #if GTK_MAJOR_VERSION < 2
841 GtkTreeSelection *sel;
844 add_filter_to_list(colorf, color_filters);
846 #if GTK_MAJOR_VERSION < 2
848 /* select the new row */
849 gtk_clist_select_row(GTK_CLIST(color_filters), num_of_filters - 1, -1);
851 /* select the new row */
852 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
853 num_filters = gtk_tree_model_iter_n_children(model, NULL);
854 gtk_tree_model_iter_nth_child(model, &iter, NULL, num_filters - 1);
855 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
856 gtk_tree_selection_select_iter(sel, &iter);
861 color_add_filter_cb (color_filter_t *colorf, gpointer arg)
863 GtkWidget *color_filters = arg;
865 color_add_colorf(color_filters, colorf);
866 #if GTK_MAJOR_VERSION >= 2
867 gtk_widget_grab_focus(color_filters);
871 /* Pop up an "Export color filter" dialog box. */
873 color_import_cb(GtkButton *button, gpointer user_data )
875 GtkWidget *color_filters;
876 #if GTK_MAJOR_VERSION >= 2
877 GtkTreeSelection *sel;
880 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
882 #if GTK_MAJOR_VERSION >= 2
883 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
884 gtk_tree_selection_unselect_all (sel);
886 gtk_clist_unselect_all (GTK_CLIST(color_filters));
889 file_color_import_cmd_cb(GTK_WIDGET(button), user_data);
892 /* Create a new filter in the list, and pop up an "Edit color filter"
893 dialog box to edit it. */
895 create_new_color_filter(GtkButton *button, char *filter)
897 color_filter_t *colorf;
899 GtkWidget *color_filters;
900 #if GTK_MAJOR_VERSION >= 2
901 GtkTreeSelection *sel;
904 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
906 #if GTK_MAJOR_VERSION >= 2
907 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
908 gtk_tree_selection_unselect_all (sel);
910 gtk_clist_unselect_all (GTK_CLIST(color_filters));
913 /* Use the default background and foreground colors as the colors. */
914 style = gtk_widget_get_style(packet_list);
915 colorf = new_color_filter("name", filter, &style->base[GTK_STATE_NORMAL],
916 &style->text[GTK_STATE_NORMAL]); /* Adds at end! */
918 color_add_colorf(color_filters, colorf);
920 edit_color_filter_dialog(color_filters, &filt_name_entry, &filt_text_entry, TRUE);
922 /* Show the (in)validity of the default filter string */
923 filter_te_syntax_check_cb(filt_text_entry);
927 #if GTK_MAJOR_VERSION >= 2
928 gtk_widget_grab_focus(color_filters);
932 /* Create a new filter in the list, and pop up an "Edit color filter"
933 dialog box to edit it. */
935 color_new_cb(GtkButton *button, gpointer user_data _U_)
937 create_new_color_filter(button, "filter");
940 /* Pop up an "Edit color filter" dialog box to edit an existing filter. */
942 color_props_cb(GtkButton *button, gpointer user_data _U_)
944 GtkWidget *color_filters;
946 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
947 g_assert(row_selected != -1);
948 edit_color_filter_dialog(color_filters, &filt_name_entry, &filt_text_entry, FALSE);
951 /* Delete a color from the list. */
953 color_delete(gint row, GtkWidget *color_filters)
955 color_filter_t *colorf;
957 #if GTK_MAJOR_VERSION >= 2
962 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
963 gtk_tree_model_iter_nth_child(model, &iter, NULL, row);
964 gtk_tree_model_get(model, &iter, 4, &colorf, -1);
966 /* Remove this color filter from the CList displaying the
968 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
971 /* Destroy any "Edit color filter" dialog boxes editing it. */
972 if (colorf->edit_dialog != NULL)
973 window_destroy(colorf->edit_dialog);
975 /* Remove the color filter from the list of color filters. */
976 remove_color_filter(colorf);
978 /* If we grab the focus after updating the selection, the first
979 * row is always selected, so we do it before */
980 gtk_widget_grab_focus(color_filters);
982 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row);
984 /* Remove this color filter from the CList displaying the
986 gtk_clist_remove(GTK_CLIST(color_filters), row);
989 /* Destroy any "Edit color filter" dialog boxes editing it. */
990 if (colorf->edit_dialog != NULL)
991 window_destroy(colorf->edit_dialog);
993 /* Remove the color filter from the list of color filters. */
994 remove_color_filter(colorf);
998 /* Delete the selected color from the list.*/
1000 color_delete_cb(GtkWidget *widget, gpointer user_data _U_)
1002 GtkWidget *color_filters;
1003 gint row, num_filters;
1004 #if GTK_MAJOR_VERSION < 2
1005 color_filter_t *colorf;
1007 GtkTreeModel *model;
1009 GtkTreeSelection *sel;
1012 color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
1014 #if GTK_MAJOR_VERSION < 2
1015 num_filters = num_of_filters;
1017 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
1018 num_filters = gtk_tree_model_iter_n_children(model, NULL);
1019 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
1022 for (row = num_filters - 1; row >= 0; row--)
1024 #if GTK_MAJOR_VERSION < 2
1025 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row);
1027 color_delete (row, color_filters);
1029 gtk_tree_model_iter_nth_child(model, &iter, NULL, row);
1030 if (gtk_tree_selection_iter_is_selected(sel, &iter))
1031 color_delete (row, color_filters);
1036 /* Save color filters to the color filter file. */
1038 color_save_cb(GtkButton *button _U_, gpointer user_data _U_)
1040 if (!write_filters())
1041 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1042 "Could not open filter file: %s", strerror(errno));
1045 /* Remove all user defined color filters and revert to the global file. */
1047 color_clear_cmd(GtkWidget *widget)
1049 GtkWidget * color_filters;
1051 color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
1053 while (num_of_filters > 0)
1055 color_delete (num_of_filters-1, color_filters);
1058 if (!revert_filters())
1059 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1060 "Could not delete filter file: %s", strerror(errno));
1063 colorize_packets(&cfile);
1065 /* Destroy the dialog box. */
1066 /* XXX: is this useful? user might want to continue with editing new colors */
1067 window_destroy(colorize_win);
1070 /* clear button: user responded to question */
1071 void color_clear_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
1074 case(ESD_BTN_CLEAR):
1075 color_clear_cmd(data);
1077 case(ESD_BTN_CANCEL):
1080 g_assert_not_reached();
1084 /* clear button: ask user before really doing it */
1086 color_clear_cb(GtkWidget *widget, gpointer data _U_) {
1089 /* ask user, if he/she is really sure */
1090 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTN_CLEAR | ESD_BTN_CANCEL,
1091 PRIMARY_TEXT_START "Remove all your personal color settings?" PRIMARY_TEXT_END "\n\n"
1092 "This will revert the color settings to global defaults.\n\n"
1093 "Are you really sure?");
1095 simple_dialog_set_cb(dialog, color_clear_answered_cb, widget);
1098 /* Exit dialog and apply new list of color filters to the capture. */
1100 color_ok_cb(GtkButton *button _U_, gpointer user_data _U_)
1103 colorize_packets(&cfile);
1105 /* Destroy the dialog box. */
1106 window_destroy(colorize_win);
1109 /* Exit dialog without colorizing packets with the new list.
1110 XXX - should really undo any changes to the list.... */
1112 color_cancel_cb(GtkWidget *widget _U_, gpointer user_data _U_)
1114 /* Destroy the dialog box. */
1115 window_destroy(colorize_win);
1118 /* Apply new list of color filters to the capture. */
1120 color_apply_cb(GtkButton *button _U_, gpointer user_data _U_)
1122 colorize_packets(&cfile);
1125 /* Create an "Edit Color Filter" dialog for a given color filter, and
1126 associate it with that color filter. */
1128 edit_color_filter_dialog(GtkWidget *color_filters,
1129 GtkWidget **colorize_filter_name,
1130 GtkWidget **colorize_filter_text,
1131 guchar is_new_filter)
1133 color_filter_t *colorf;
1134 GtkWidget *edit_dialog;
1135 GtkWidget *dialog_vbox;
1136 GtkTooltips *tooltips;
1139 GtkWidget *filter_fr;
1140 GtkWidget *filter_fr_vbox;
1141 GtkWidget *filter_name_hbox;
1142 GtkWidget *color_filter_name;
1143 GtkWidget *filter_string_hbox;
1144 GtkWidget *add_expression_bt;
1145 GtkWidget *color_filter_text;
1147 GtkWidget *colorize_fr;
1148 GtkWidget *colorize_hbox;
1149 GtkWidget *colorize_filter_fg;
1150 GtkWidget *colorize_filter_bg;
1153 GtkWidget *edit_color_filter_ok;
1154 GtkWidget *edit_color_filter_cancel;
1156 #if GTK_MAJOR_VERSION >= 2
1157 GtkTreeModel *model;
1161 #if GTK_MAJOR_VERSION >= 2
1162 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
1164 gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected);
1165 gtk_tree_model_get(model, &iter, 4, &colorf, -1);
1168 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row_selected);
1170 if (colorf->edit_dialog != NULL) {
1171 /* There's already an edit box open for this filter; reactivate it. */
1172 reactivate_window(colorf->edit_dialog);
1176 tooltips = gtk_tooltips_new ();
1179 edit_dialog = dlg_window_new ("Ethereal: Edit Color Filter");
1180 gtk_window_set_default_size(GTK_WINDOW(edit_dialog), 500, -1);
1181 OBJECT_SET_DATA(edit_dialog, "edit_dialog", edit_dialog);
1182 colorf->edit_dialog = edit_dialog;
1184 dialog_vbox = gtk_vbox_new (FALSE, 0);
1185 gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
1186 gtk_container_add (GTK_CONTAINER (edit_dialog), dialog_vbox);
1189 filter_fr = gtk_frame_new("Filter");
1190 gtk_box_pack_start (GTK_BOX (dialog_vbox), filter_fr, FALSE, FALSE, 0);
1192 filter_fr_vbox = gtk_vbox_new (FALSE, 0);
1193 gtk_container_set_border_width (GTK_CONTAINER (filter_fr_vbox), 5);
1194 gtk_container_add(GTK_CONTAINER(filter_fr), filter_fr_vbox);
1196 /* filter name hbox */
1197 filter_name_hbox = gtk_hbox_new (FALSE, 0);
1198 gtk_box_pack_start (GTK_BOX (filter_fr_vbox), filter_name_hbox, TRUE, FALSE, 3);
1200 color_filter_name = gtk_label_new (("Name: "));
1201 gtk_box_pack_start (GTK_BOX (filter_name_hbox), color_filter_name, FALSE, FALSE, 0);
1203 *colorize_filter_name = gtk_entry_new ();
1204 gtk_entry_set_text(GTK_ENTRY(*colorize_filter_name), colorf->filter_name);
1206 style = gtk_style_copy(gtk_widget_get_style(*colorize_filter_name));
1207 color_t_to_gdkcolor(&style->base[GTK_STATE_NORMAL], &colorf->bg_color);
1208 #if GTK_MAJOR_VERSION < 2
1209 color_t_to_gdkcolor(&style->fg[GTK_STATE_NORMAL], &colorf->fg_color);
1211 color_t_to_gdkcolor(&style->text[GTK_STATE_NORMAL], &colorf->fg_color);
1213 gtk_widget_set_style(*colorize_filter_name, style);
1215 gtk_box_pack_start (GTK_BOX (filter_name_hbox), *colorize_filter_name, TRUE, TRUE, 0);
1216 gtk_tooltips_set_tip (tooltips, *colorize_filter_name, ("This is the editable name of the filter. (No @ characters allowed.)"), NULL);
1219 /* filter string hbox */
1220 filter_string_hbox = gtk_hbox_new (FALSE, 0);
1221 gtk_box_pack_start (GTK_BOX (filter_fr_vbox), filter_string_hbox, TRUE, FALSE, 3);
1223 color_filter_text = gtk_label_new (("String: "));
1224 gtk_box_pack_start (GTK_BOX (filter_string_hbox), color_filter_text, FALSE, FALSE, 0);
1226 *colorize_filter_text = gtk_entry_new ();
1227 SIGNAL_CONNECT(*colorize_filter_text, "changed", filter_te_syntax_check_cb, NULL);
1228 gtk_entry_set_text(GTK_ENTRY(*colorize_filter_text), colorf->filter_text);
1231 style = gtk_style_copy(gtk_widget_get_style(*colorize_filter_text));
1232 style->base[GTK_STATE_NORMAL] = colorf->bg_color;
1233 style->fg[GTK_STATE_NORMAL] = colorf->fg_color;
1235 gtk_widget_set_style(*colorize_filter_text, style);
1236 gtk_box_pack_start (GTK_BOX (filter_string_hbox), *colorize_filter_text, TRUE, TRUE, 0);
1237 gtk_tooltips_set_tip (tooltips, *colorize_filter_text, ("This is the editable text of the filter"), NULL);
1239 /* Create the "Add Expression..." button, to pop up a dialog
1240 for constructing filter comparison expressions. */
1241 add_expression_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_ADD_EXPRESSION);
1242 SIGNAL_CONNECT(add_expression_bt, "clicked", filter_expr_cb, *colorize_filter_text);
1243 gtk_box_pack_start (GTK_BOX(filter_string_hbox), add_expression_bt, FALSE, FALSE, 3);
1244 gtk_tooltips_set_tip (tooltips, add_expression_bt, ("Add an expression to the filter string"), NULL);
1247 /* choose color frame */
1248 colorize_fr = gtk_frame_new("Display Colors");
1249 gtk_box_pack_start (GTK_BOX (dialog_vbox), colorize_fr, FALSE, FALSE, 0);
1251 colorize_hbox = gtk_hbox_new (FALSE, 0);
1252 gtk_container_set_border_width (GTK_CONTAINER (colorize_hbox), 5);
1253 gtk_container_add(GTK_CONTAINER(colorize_fr), colorize_hbox);
1255 colorize_filter_fg = gtk_button_new_with_label (("Foreground Color..."));
1256 gtk_box_pack_start (GTK_BOX (colorize_hbox), colorize_filter_fg, TRUE, FALSE, 0);
1257 gtk_tooltips_set_tip (tooltips, colorize_filter_fg, ("Select foreground color for data display"), NULL);
1259 colorize_filter_bg = gtk_button_new_with_label (("Background Color..."));
1260 gtk_box_pack_start (GTK_BOX (colorize_hbox), colorize_filter_bg, TRUE, FALSE, 0);
1261 gtk_tooltips_set_tip (tooltips, colorize_filter_bg, ("Select background color for data display"), NULL);
1265 bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1266 gtk_box_pack_start(GTK_BOX(dialog_vbox), bbox, FALSE, FALSE, 0);
1267 gtk_container_set_border_width (GTK_CONTAINER (bbox), 0);
1269 edit_color_filter_ok = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
1270 gtk_tooltips_set_tip (tooltips, edit_color_filter_ok, ("Accept filter color change"), NULL);
1272 edit_color_filter_cancel = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
1273 gtk_tooltips_set_tip (tooltips, edit_color_filter_cancel, ("Reject filter color change"), NULL);
1275 gtk_widget_grab_default(edit_color_filter_ok);
1277 /* signals and such */
1278 OBJECT_SET_DATA(edit_dialog, COLOR_FILTER, colorf);
1279 SIGNAL_CONNECT(edit_dialog, "destroy", edit_color_filter_destroy_cb, NULL);
1280 OBJECT_SET_DATA(colorize_filter_fg, COLOR_FILTER, colorf);
1281 SIGNAL_CONNECT(colorize_filter_fg, "clicked", edit_color_filter_fg_cb, NULL);
1282 OBJECT_SET_DATA(colorize_filter_bg, COLOR_FILTER, colorf);
1283 SIGNAL_CONNECT(colorize_filter_bg, "clicked", edit_color_filter_bg_cb, NULL);
1284 OBJECT_SET_DATA(edit_color_filter_ok, COLOR_FILTERS_CL, color_filters);
1285 OBJECT_SET_DATA(edit_color_filter_ok, COLOR_FILTER, colorf);
1286 SIGNAL_CONNECT(edit_color_filter_ok, "clicked", edit_color_filter_ok_cb, edit_dialog);
1288 /* set callback to delete new filters if cancel chosen */
1291 OBJECT_SET_DATA(edit_color_filter_cancel, COLOR_FILTERS_CL, color_filters);
1292 SIGNAL_CONNECT(edit_color_filter_cancel, "clicked",
1293 edit_new_color_filter_cancel_cb, edit_dialog);
1295 /* escape will select cancel */
1296 window_set_cancel_button(edit_dialog, edit_color_filter_cancel, window_cancel_button_cb);
1298 SIGNAL_CONNECT(edit_dialog, "delete_event", window_delete_event_cb, NULL);
1300 gtk_widget_show_all(edit_dialog);
1301 window_present(edit_dialog);
1304 /* Called when the dialog box is being destroyed; destroy any color
1305 selection dialogs opened from this dialog, and null out the pointer
1307 #if GTK_MAJOR_VERSION < 2
1309 edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data _U_)
1312 edit_color_filter_destroy_cb(GObject *object, gpointer user_data _U_)
1315 color_filter_t *colorf;
1316 GtkWidget *color_sel;
1318 colorf = (color_filter_t *)OBJECT_GET_DATA(object, COLOR_FILTER);
1319 colorf->edit_dialog = NULL;
1321 /* Destroy any color selection dialogs this dialog had open. */
1322 color_sel = (GtkWidget *)OBJECT_GET_DATA(object, COLOR_SELECTION_FG);
1323 if (color_sel != NULL)
1324 window_destroy(color_sel);
1325 color_sel = (GtkWidget *)OBJECT_GET_DATA(object, COLOR_SELECTION_BG);
1326 if (color_sel != NULL)
1327 window_destroy(color_sel);
1330 /* Pop up a color selection box to choose the foreground color. */
1332 edit_color_filter_fg_cb(GtkButton *button, gpointer user_data _U_)
1334 color_filter_t *colorf;
1335 GtkWidget *color_selection_fg;
1337 colorf = (color_filter_t *)OBJECT_GET_DATA(button, COLOR_FILTER);
1338 /* Do we already have one open for this dialog? */
1339 color_selection_fg = OBJECT_GET_DATA(colorf->edit_dialog, COLOR_SELECTION_FG);
1340 if (color_selection_fg != NULL) {
1341 /* Yes. Just reactivate it. */
1342 reactivate_window(color_selection_fg);
1344 /* No. Create a new color selection box, and associate it with
1346 color_selection_fg = color_sel_win_new(colorf, FALSE);
1347 OBJECT_SET_DATA(colorf->edit_dialog, COLOR_SELECTION_FG, color_selection_fg);
1348 OBJECT_SET_DATA(color_selection_fg, COLOR_SELECTION_PARENT, colorf->edit_dialog);
1352 /* Pop up a color selection box to choose the background color. */
1354 edit_color_filter_bg_cb (GtkButton *button,
1355 gpointer user_data _U_)
1357 color_filter_t *colorf;
1358 GtkWidget *color_selection_bg;
1360 colorf = (color_filter_t *)OBJECT_GET_DATA(button, COLOR_FILTER);
1361 /* Do we already have one open for this dialog? */
1362 color_selection_bg = OBJECT_GET_DATA(colorf->edit_dialog, COLOR_SELECTION_BG);
1363 if (color_selection_bg != NULL) {
1364 /* Yes. Just reactivate it. */
1365 reactivate_window(color_selection_bg);
1367 /* No. Create a new color selection box, and associate it with
1369 color_selection_bg = color_sel_win_new(colorf, TRUE);
1370 OBJECT_SET_DATA(colorf->edit_dialog, COLOR_SELECTION_BG, color_selection_bg);
1371 OBJECT_SET_DATA(color_selection_bg, COLOR_SELECTION_PARENT, colorf->edit_dialog);
1375 /* accept color (and potential content) change */
1377 edit_color_filter_ok_cb (GtkButton *button,
1382 GdkColor new_fg_color;
1383 GdkColor new_bg_color;
1386 color_filter_t *colorf;
1387 dfilter_t *compiled_filter;
1388 GtkWidget *color_filters;
1389 #if GTK_MAJOR_VERSION >= 2
1390 GtkTreeModel *model;
1392 gchar fg_str[14], bg_str[14];
1395 dialog = (GtkWidget *)user_data;
1397 style = gtk_widget_get_style(filt_name_entry);
1398 new_bg_color = style->base[GTK_STATE_NORMAL];
1399 #if GTK_MAJOR_VERSION < 2
1400 new_fg_color = style->fg[GTK_STATE_NORMAL];
1402 new_fg_color = style->text[GTK_STATE_NORMAL];
1405 filter_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(filt_name_entry)));
1406 filter_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(filt_text_entry)));
1408 if(strchr(filter_name,'@') || strchr(filter_text,'@')){
1409 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1410 "Filter names and strings must not"
1411 " use the '@' character. Filter unchanged.");
1412 g_free(filter_name);
1413 g_free(filter_text);
1417 if(!dfilter_compile(filter_text, &compiled_filter)) {
1418 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1419 "Filter \"%s\" did not compile correctly.\n"
1420 " Please try again. Filter unchanged.\n%s\n", filter_name,
1423 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
1424 colorf = (color_filter_t *)OBJECT_GET_DATA(button, COLOR_FILTER);
1426 if (colorf->filter_name != NULL)
1427 g_free(colorf->filter_name);
1428 colorf->filter_name = filter_name;
1429 if (colorf->filter_text != NULL)
1430 g_free(colorf->filter_text);
1431 colorf->filter_text = filter_text;
1432 gdkcolor_to_color_t(&colorf->fg_color, &new_fg_color);
1433 gdkcolor_to_color_t(&colorf->bg_color, &new_bg_color);
1434 #if GTK_MAJOR_VERSION < 2
1435 gtk_clist_set_foreground(GTK_CLIST(color_filters), row_selected,
1437 gtk_clist_set_background(GTK_CLIST(color_filters), row_selected,
1440 g_snprintf(fg_str, 14, "#%04X%04X%04X",
1441 new_fg_color.red, new_fg_color.green, new_fg_color.blue);
1442 g_snprintf(bg_str, 14, "#%04X%04X%04X",
1443 new_bg_color.red, new_bg_color.green, new_bg_color.blue);
1444 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
1445 gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected);
1446 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, filter_name,
1447 1, filter_text, 2, fg_str, 3, bg_str, -1);
1449 if(colorf->c_colorfilter != NULL)
1450 dfilter_free(colorf->c_colorfilter);
1451 colorf->c_colorfilter = compiled_filter;
1452 #if GTK_MAJOR_VERSION < 2
1453 /* gtk_clist_set_text frees old text (if any) and allocates new space */
1454 gtk_clist_set_text(GTK_CLIST(color_filters), row_selected, 0,
1456 gtk_clist_set_text(GTK_CLIST(color_filters), row_selected, 1,
1460 /* Destroy the dialog box. */
1461 window_destroy(dialog);
1465 /* reject new color filter addition */
1467 edit_new_color_filter_cancel_cb(GtkButton *button, gpointer user_data _U_)
1469 /* Delete the entry. N.B. this already destroys the edit_dialog window. */
1470 color_delete(num_of_filters-1, (GtkWidget*)OBJECT_GET_DATA(button, COLOR_FILTERS_CL));
1474 color_sel_win_new(color_filter_t *colorf, gboolean is_bg)
1477 GtkWidget *color_sel_win;
1479 #if GTK_MAJOR_VERSION >= 2
1482 GtkWidget *color_sel_ok;
1483 GtkWidget *color_sel_cancel;
1484 GtkWidget *color_sel_help;
1487 color = &colorf->bg_color;
1488 title = g_strdup_printf("Ethereal: Choose background color for \"%s\"",
1489 colorf->filter_name);
1491 color = &colorf->fg_color;
1492 title = g_strdup_printf("Ethereal: Choose foreground color for \"%s\"",
1493 colorf->filter_name);
1495 color_sel_win = gtk_color_selection_dialog_new(title);
1497 OBJECT_SET_DATA(color_sel_win, "color_sel_win", color_sel_win);
1498 gtk_container_set_border_width (GTK_CONTAINER (color_sel_win), 10);
1500 if (color != NULL) {
1501 #if GTK_MAJOR_VERSION < 2
1504 cols[0] = (gdouble)color->red / 65536.0;
1505 cols[1] = (gdouble)color->green / 65536.0;
1506 cols[2] = (gdouble)color->blue / 65536.0;
1508 gtk_color_selection_set_color(
1509 GTK_COLOR_SELECTION(
1510 GTK_COLOR_SELECTION_DIALOG(color_sel_win)->colorsel), cols);
1512 color_t_to_gdkcolor(&gcolor, color);
1513 gtk_color_selection_set_current_color(
1514 GTK_COLOR_SELECTION(
1515 GTK_COLOR_SELECTION_DIALOG(color_sel_win)->colorsel), &gcolor);
1519 color_sel_ok = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->ok_button;
1520 OBJECT_SET_DATA(color_sel_win, "color_sel_ok", color_sel_ok);
1521 GTK_WIDGET_SET_FLAGS (color_sel_ok, GTK_CAN_DEFAULT);
1523 color_sel_cancel = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->cancel_button;
1524 OBJECT_SET_DATA(color_sel_win, "color_sel_cancel", color_sel_cancel);
1525 GTK_WIDGET_SET_FLAGS (color_sel_cancel, GTK_CAN_DEFAULT);
1528 color_sel_help = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->help_button;
1529 OBJECT_SET_DATA(color_sel_win, "color_sel_help", color_sel_help);
1532 GTK_WIDGET_SET_FLAGS (color_sel_help, GTK_CAN_DEFAULT);
1534 SIGNAL_CONNECT(color_sel_ok, "clicked", color_sel_ok_cb, color_sel_win);
1535 SIGNAL_CONNECT(color_sel_cancel, "clicked", color_sel_cancel_cb, color_sel_win);
1537 gtk_widget_show_all(color_sel_win);
1538 return color_sel_win;
1542 color_sel_win_destroy(GtkWidget *sel_win)
1545 GtkWidget *color_selection_fg, *color_selection_bg;
1547 /* Find the "Edit color filter" dialog box with which this is associated. */
1548 parent = (GtkWidget *)OBJECT_GET_DATA(sel_win, COLOR_SELECTION_PARENT);
1550 /* Find that dialog box's foreground and background color selection
1552 color_selection_fg = OBJECT_GET_DATA(parent, COLOR_SELECTION_FG);
1553 color_selection_bg = OBJECT_GET_DATA(parent, COLOR_SELECTION_BG);
1555 if (sel_win == color_selection_fg) {
1556 /* This was its foreground color selection box; it isn't, anymore. */
1557 OBJECT_SET_DATA(parent, COLOR_SELECTION_FG, NULL);
1559 if (sel_win == color_selection_bg) {
1560 /* This was its background color selection box; it isn't, anymore. */
1561 OBJECT_SET_DATA(parent, COLOR_SELECTION_BG, NULL);
1564 /* Now destroy it. */
1565 window_destroy(sel_win);
1568 /* Retrieve selected color */
1570 color_sel_ok_cb (GtkButton *button _U_,
1573 GdkColor new_color; /* Color from color selection dialog */
1574 #if GTK_MAJOR_VERSION < 2
1575 gdouble new_colors[3];
1577 GtkWidget *color_dialog;
1580 GtkWidget *color_selection_fg, *color_selection_bg;
1583 color_dialog = (GtkWidget *)user_data;
1585 #if GTK_MAJOR_VERSION < 2
1586 gtk_color_selection_get_color(GTK_COLOR_SELECTION(
1587 GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), new_colors);
1589 new_color.red = (guint16)(new_colors[0]*65535.0);
1590 new_color.green = (guint16)(new_colors[1]*65535.0);
1591 new_color.blue = (guint16)(new_colors[2]*65535.0);
1593 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(
1594 GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &new_color);
1597 if ( ! get_color(&new_color) ){
1598 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1599 "Could not allocate color. Try again.");
1601 /* Find the "Edit color filter" dialog box with which this is
1603 parent = (GtkWidget *)OBJECT_GET_DATA(color_dialog, COLOR_SELECTION_PARENT);
1605 /* Find that dialog box's foreground and background color selection
1607 color_selection_fg = OBJECT_GET_DATA(parent, COLOR_SELECTION_FG);
1608 color_selection_bg = OBJECT_GET_DATA(parent, COLOR_SELECTION_BG);
1609 is_bg = (color_dialog == color_selection_bg);
1611 color_sel_win_destroy(color_dialog);
1613 /* now apply the change to the fore/background */
1615 style = gtk_style_copy(gtk_widget_get_style(filt_name_entry));
1617 style->base[GTK_STATE_NORMAL] = new_color;
1618 #if GTK_MAJOR_VERSION < 2
1620 style->fg[GTK_STATE_NORMAL] = new_color;
1623 style->text[GTK_STATE_NORMAL] = new_color;
1625 gtk_widget_set_style(filt_name_entry, style);
1626 gtk_widget_set_style(filt_text_entry, style);
1630 /* Don't choose the selected color as the foreground or background
1631 color for the filter. */
1633 color_sel_cancel_cb (GtkObject *object _U_,
1636 GtkWidget *color_dialog;
1637 color_dialog = (GtkWidget *)user_data;
1638 /* nothing to change here. Just get rid of the dialog box. */
1640 color_sel_win_destroy(color_dialog);