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"
40 #include <epan/dfilter/dfilter.h>
41 #include "simple_dialog.h"
42 #include "dlg_utils.h"
44 #include "dfilter_expr_dlg.h"
45 #include "compat_macros.h"
46 #include "filter_dlg.h"
48 #include "gtkglobals.h"
51 static GtkWidget* colorize_dialog_new(char *filter);
52 static void add_filter_to_list(gpointer filter_arg, gpointer list_arg);
53 static void color_filter_up_cb(GtkButton *button, gpointer user_data);
54 static void color_filter_down_cb(GtkButton *button, gpointer user_data);
55 #if GTK_MAJOR_VERSION < 2
56 static void remember_selected_row(GtkCList *clist, gint row, gint column,
57 GdkEvent *event, gpointer user_data);
58 static void unremember_selected_row(GtkCList *clist, gint row, gint column,
59 GdkEvent *event, gpointer user_data);
61 static void remember_selected_row(GtkTreeSelection *sel, gpointer list);
63 static void color_destroy_cb(GtkButton *button, gpointer user_data);
64 static void destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy);
65 static void create_new_color_filter(GtkButton *button, char *filter);
66 static void color_new_cb(GtkButton *button, gpointer user_data);
67 static void color_props_cb(GtkButton *button, gpointer user_data);
68 static void color_delete_cb(GtkWidget *widget, gpointer user_data);
69 static void color_save_cb(GtkButton *button, gpointer user_data);
70 static void color_ok_cb(GtkButton *button, gpointer user_data);
71 static void color_cancel_cb(GtkWidget *widget, gpointer user_data);
72 static void color_apply_cb(GtkButton *button, gpointer user_data);
73 static void color_clear_cb(GtkWidget *button, gpointer user_data);
74 static void color_import_cb(GtkButton *button, gpointer user_data );
76 static void edit_color_filter_dialog(GtkWidget *color_filters,
77 GtkWidget **colorize_filter_name,
78 GtkWidget **colorize_filter_text,
79 guchar is_new_filter);
81 #if GTK_MAJOR_VERSION < 2
82 static void edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data);
84 static void edit_color_filter_destroy_cb(GObject *object, gpointer user_data);
86 static void edit_color_filter_fg_cb(GtkButton *button, gpointer user_data);
87 static void edit_color_filter_bg_cb(GtkButton *button, gpointer user_data);
88 static void edit_color_filter_ok_cb(GtkButton *button, gpointer user_data);
89 static void edit_new_color_filter_cancel_cb(GtkButton *button, gpointer user_data);
91 static GtkWidget* color_sel_win_new(color_filter_t *colorf, gboolean);
92 static void color_sel_ok_cb(GtkButton *button, gpointer user_data);
93 static void color_sel_cancel_cb(GtkObject *object, gpointer user_data);
95 static GtkWidget *colorize_win;
96 static gint num_of_filters; /* number of filters being displayed */
97 static gint row_selected; /* row in color_filters that is selected */
99 #define COLOR_UP_LB "color_up_lb"
100 #define COLOR_DOWN_LB "color_down_lb"
101 #define COLOR_PROPS_LB "color_props_lb"
102 #define COLOR_DELETE_LB "color_delete_lb"
103 #define COLOR_FILTERS_CL "color_filters_cl"
104 #define COLOR_FILTER "color_filter"
105 #define COLOR_SELECTION_FG "color_selection_fg"
106 #define COLOR_SELECTION_BG "color_selection_bg"
107 #define COLOR_SELECTION_PARENT "color_selection_parent"
110 filter_expr_cb(GtkWidget *w _U_, gpointer filter_te)
113 dfilter_expr_dlg_new(GTK_WIDGET(filter_te));
117 /* Callback for the "Display:Colorize Display" menu item. */
119 color_display_cb(GtkWidget *w _U_, gpointer d _U_)
121 if (colorize_win != NULL) {
122 /* There's already a color dialog box active; reactivate it. */
123 reactivate_window(colorize_win);
125 /* Create a new "Colorize Display" dialog. */
126 colorize_win = colorize_dialog_new(NULL);
130 /* this opens the colorize dialogue and presets the filter string */
132 color_display_with_filter(char *filter)
134 if (colorize_win != NULL) {
135 /* There's already a color dialog box active; reactivate it. */
136 reactivate_window(colorize_win);
138 /* Create a new "Colorize Display" dialog. */
139 colorize_win = colorize_dialog_new(filter);
143 /* if this filter is marked count it in the given int* */
145 count_this_mark(gpointer filter_arg, gpointer counter_arg)
147 color_filter_t *colorf = filter_arg;
148 int * cnt = counter_arg;
154 /* TODO: implement count of selected filters. Plug in to file_dlg update of "export selected" checkbox. */
155 int color_marked_count(void)
159 g_slist_foreach(filter_list, count_this_mark, &count);
164 /* Create the "Coloring Rules" dialog. */
166 colorize_dialog_new (char *filter)
168 GtkWidget *color_win;
170 GtkWidget *main_hbox;
171 GtkWidget *ctrl_vbox;
172 GtkTooltips *tooltips;
175 GtkWidget *order_vbox;
176 GtkWidget *color_filter_up;
177 GtkWidget *order_move_label;
178 GtkWidget *color_filter_down;
181 GtkWidget *list_vbox;
182 GtkWidget *scrolledwindow1;
183 GtkWidget *color_filters;
184 GtkWidget *list_label;
187 GtkWidget *edit_vbox;
188 GtkWidget *color_new;
189 GtkWidget *color_props;
190 GtkWidget *color_delete;
192 GtkWidget *manage_fr;
193 GtkWidget *manage_vbox;
194 GtkWidget *color_export;
195 GtkWidget *color_import;
196 GtkWidget *color_clear;
198 GtkWidget *button_ok_hbox;
200 GtkWidget *color_apply;
201 GtkWidget *color_save;
202 GtkWidget *color_cancel;
204 #if GTK_MAJOR_VERSION >= 2
206 GtkCellRenderer *renderer;
207 GtkTreeViewColumn *column;
208 GtkTreeSelection *selection;
210 gchar *titles[] = { "Name", "String" };
213 row_selected = -1; /* no row selected */
214 tooltips = gtk_tooltips_new ();
216 /* Resizing of the dialog window is now reasonably done.
217 * Default size is set so that it should fit into every usual screen resolution.
218 * All other widgets are always packed depending on the current window size. */
219 color_win = dlg_window_new ("Ethereal: Coloring Rules");
220 OBJECT_SET_DATA(color_win, "color_win", color_win);
221 gtk_window_set_default_size(GTK_WINDOW(color_win), DEF_WIDTH, DEF_HEIGHT * 2/3);
222 dlg_vbox = gtk_vbox_new (FALSE, 0);
223 gtk_container_set_border_width (GTK_CONTAINER (dlg_vbox), 5);
224 gtk_container_add (GTK_CONTAINER (color_win), dlg_vbox);
226 main_hbox = gtk_hbox_new (FALSE, 0);
227 gtk_box_pack_start (GTK_BOX (dlg_vbox), main_hbox, TRUE, TRUE, 0);
229 ctrl_vbox = gtk_vbox_new (FALSE, 0);
230 gtk_box_pack_start (GTK_BOX (main_hbox), ctrl_vbox, FALSE, FALSE, 0);
233 /* edit buttons frame */
234 edit_fr = gtk_frame_new("Edit");
235 gtk_box_pack_start (GTK_BOX (ctrl_vbox), edit_fr, TRUE, TRUE, 0);
237 /* edit_vbox is first button column (containing: new, edit and such) */
238 edit_vbox = gtk_vbutton_box_new();
239 gtk_button_box_set_child_size(GTK_BUTTON_BOX(edit_vbox), 50, 20);
240 gtk_container_set_border_width (GTK_CONTAINER (edit_vbox), 5);
241 gtk_container_add(GTK_CONTAINER(edit_fr), edit_vbox);
243 color_new = BUTTON_NEW_FROM_STOCK(GTK_STOCK_NEW);
244 #if GTK_MAJOR_VERSION < 2
245 WIDGET_SET_SIZE(color_new, 50, 20);
247 gtk_box_pack_start (GTK_BOX (edit_vbox), color_new, FALSE, FALSE, 5);
248 gtk_tooltips_set_tip (tooltips, color_new, ("Create a new filter at the end of the list"), NULL);
250 color_props = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_EDIT);
251 #if GTK_MAJOR_VERSION < 2
252 WIDGET_SET_SIZE(color_props, 50, 20);
254 gtk_box_pack_start (GTK_BOX (edit_vbox), color_props, FALSE, FALSE, 5);
255 gtk_tooltips_set_tip (tooltips, color_props, ("Edit the properties of the selected filter"), NULL);
256 gtk_widget_set_sensitive (color_props, FALSE);
258 color_delete = BUTTON_NEW_FROM_STOCK(GTK_STOCK_DELETE);
259 gtk_box_pack_start (GTK_BOX (edit_vbox), color_delete, FALSE, FALSE, 5);
260 #if GTK_MAJOR_VERSION < 2
261 WIDGET_SET_SIZE(color_delete, 50, 20);
263 gtk_tooltips_set_tip (tooltips, color_delete, ("Delete the selected filter"), NULL);
264 gtk_widget_set_sensitive (color_delete, FALSE);
265 /* End edit buttons frame */
268 /* manage buttons frame */
269 manage_fr = gtk_frame_new("Manage");
270 gtk_box_pack_start (GTK_BOX (ctrl_vbox), manage_fr, FALSE, FALSE, 0);
272 manage_vbox = gtk_vbox_new (FALSE, 0);
273 gtk_container_set_border_width (GTK_CONTAINER (manage_vbox), 5);
274 gtk_container_add(GTK_CONTAINER(manage_fr), manage_vbox);
276 color_export = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_EXPORT);
277 gtk_box_pack_start (GTK_BOX (manage_vbox), color_export, FALSE, FALSE, 5);
278 #if GTK_MAJOR_VERSION < 2
279 WIDGET_SET_SIZE(color_export, 50, 20);
281 gtk_tooltips_set_tip(tooltips, color_export, ("Save all/marked filters to a file"), NULL);
283 color_import = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_IMPORT);
284 gtk_box_pack_start (GTK_BOX (manage_vbox), color_import, FALSE, FALSE, 5);
285 #if GTK_MAJOR_VERSION < 2
286 WIDGET_SET_SIZE(color_import, 50, 20);
288 gtk_tooltips_set_tip(tooltips, color_import, ("Load filters from a file"), NULL);
290 color_clear = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLEAR);
291 gtk_box_pack_start(GTK_BOX (manage_vbox), color_clear, FALSE, FALSE, 5);
292 #if GTK_MAJOR_VERSION < 2
293 WIDGET_SET_SIZE(color_clear, 50, 20);
295 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);
298 /* filter list frame */
299 list_fr = gtk_frame_new("Filter");
300 gtk_box_pack_start (GTK_BOX (main_hbox), list_fr, TRUE, TRUE, 0);
302 list_vbox = gtk_vbox_new (FALSE, 0);
303 gtk_container_set_border_width (GTK_CONTAINER (list_vbox), 5);
304 gtk_container_add(GTK_CONTAINER(list_fr), list_vbox);
306 list_label = gtk_label_new (("[List is processed in order until match is found]"));
307 gtk_box_pack_start (GTK_BOX (list_vbox), list_label, FALSE, FALSE, 0);
309 /* create the list of filters */
310 scrolledwindow1 = scrolled_window_new(NULL, NULL);
311 #if GTK_MAJOR_VERSION >= 2
312 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow1),
315 gtk_box_pack_start (GTK_BOX (list_vbox), scrolledwindow1, TRUE, TRUE, 0);
317 #if GTK_MAJOR_VERSION < 2
318 color_filters = gtk_clist_new_with_titles(2, titles);
320 /* the list store contains : filter name, filter string, foreground
321 * color, background color, pointer to color filter */
322 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING,
323 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
324 color_filters = tree_view_new(GTK_TREE_MODEL(store));
325 g_object_unref(store);
326 renderer = gtk_cell_renderer_text_new();
327 column = gtk_tree_view_column_new_with_attributes(titles[0], renderer, "text",
329 "background", 3, NULL);
330 gtk_tree_view_column_set_fixed_width(column, 80);
331 gtk_tree_view_append_column(GTK_TREE_VIEW(color_filters), column);
332 renderer = gtk_cell_renderer_text_new();
333 column = gtk_tree_view_column_new_with_attributes(titles[1], renderer, "text",
335 "background", 3, NULL);
336 gtk_tree_view_column_set_fixed_width(column, 300);
337 gtk_tree_view_append_column(GTK_TREE_VIEW(color_filters), column);
338 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(color_filters), TRUE);
339 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(color_filters), FALSE);
343 g_slist_foreach(filter_list, add_filter_to_list, color_filters);
345 #if GTK_MAJOR_VERSION < 2
346 gtk_clist_set_selection_mode (GTK_CLIST (color_filters),GTK_SELECTION_EXTENDED);
348 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
349 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
352 gtk_container_add (GTK_CONTAINER (scrolledwindow1), color_filters);
353 #if GTK_MAJOR_VERSION < 2
354 gtk_clist_set_column_width (GTK_CLIST (color_filters), 0, 80);
355 gtk_clist_set_column_width (GTK_CLIST (color_filters), 1, 300);
356 gtk_clist_column_titles_show (GTK_CLIST (color_filters));
361 order_fr = gtk_frame_new("Order");
362 gtk_box_pack_start (GTK_BOX (main_hbox), order_fr, FALSE, FALSE, 0);
364 order_vbox = gtk_vbox_new (TRUE, 0);
365 gtk_container_set_border_width (GTK_CONTAINER (order_vbox), 5);
366 gtk_container_add(GTK_CONTAINER(order_fr), order_vbox);
368 color_filter_up = BUTTON_NEW_FROM_STOCK(GTK_STOCK_GO_UP);
369 #if GTK_MAJOR_VERSION < 2
370 WIDGET_SET_SIZE(color_filter_up, 50, 20);
372 gtk_box_pack_start (GTK_BOX (order_vbox), color_filter_up, FALSE, FALSE, 0);
373 gtk_tooltips_set_tip (tooltips, color_filter_up, ("Move filter higher in list"), NULL);
374 gtk_widget_set_sensitive (color_filter_up, FALSE);
376 order_move_label = gtk_label_new (("Move\nselected filter\nup or down"));
377 gtk_box_pack_start (GTK_BOX (order_vbox), order_move_label, FALSE, FALSE, 0);
379 color_filter_down = BUTTON_NEW_FROM_STOCK(GTK_STOCK_GO_DOWN);
380 #if GTK_MAJOR_VERSION < 2
381 WIDGET_SET_SIZE(color_filter_down, 50, 20);
383 gtk_box_pack_start (GTK_BOX (order_vbox), color_filter_down, FALSE, FALSE, 0);
384 gtk_tooltips_set_tip (tooltips, color_filter_down, ("Move filter lower in list"), NULL);
385 gtk_widget_set_sensitive (color_filter_down, FALSE);
388 /* Button row: OK and cancel buttons */
389 button_ok_hbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_SAVE, GTK_STOCK_CLOSE/*, GTK_STOCK_CANCEL*/, NULL);
390 gtk_box_pack_start (GTK_BOX (dlg_vbox), button_ok_hbox, FALSE, FALSE, 5);
392 color_ok = OBJECT_GET_DATA(button_ok_hbox, GTK_STOCK_OK);
393 gtk_tooltips_set_tip (tooltips, color_ok, ("Apply the color filters to the display and close this dialog"), NULL);
395 color_apply = OBJECT_GET_DATA(button_ok_hbox, GTK_STOCK_APPLY);
396 gtk_tooltips_set_tip (tooltips, color_apply, ("Apply the color filters to the display but keep this dialog open"), NULL);
398 color_save = OBJECT_GET_DATA(button_ok_hbox, GTK_STOCK_SAVE);
399 gtk_tooltips_set_tip (tooltips, color_save, ("Save the color filters permanently and keep this dialog open"), NULL);
401 color_cancel = OBJECT_GET_DATA(button_ok_hbox, GTK_STOCK_CLOSE);
402 window_set_cancel_button(color_win, color_cancel, color_cancel_cb);
403 gtk_tooltips_set_tip (tooltips, color_cancel, ("Close this dialog but don't apply the color filter changes to the display"), NULL);
405 gtk_widget_grab_default(color_ok);
407 /* signals and such */
408 SIGNAL_CONNECT(color_win, "destroy", color_destroy_cb, NULL);
409 OBJECT_SET_DATA(color_filter_up, COLOR_FILTERS_CL, color_filters);
410 SIGNAL_CONNECT(color_filter_up, "clicked", color_filter_up_cb, NULL);
411 OBJECT_SET_DATA(color_filter_down, COLOR_FILTERS_CL, color_filters);
412 SIGNAL_CONNECT(color_filter_down, "clicked", color_filter_down_cb, NULL);
413 #if GTK_MAJOR_VERSION < 2
414 SIGNAL_CONNECT(color_filters, "select_row", remember_selected_row, NULL);
415 SIGNAL_CONNECT(color_filters, "unselect_row", unremember_selected_row, NULL);
417 SIGNAL_CONNECT(selection, "changed", remember_selected_row, color_filters);
419 OBJECT_SET_DATA(color_filters, COLOR_UP_LB, color_filter_up);
420 OBJECT_SET_DATA(color_filters, COLOR_DOWN_LB, color_filter_down);
421 OBJECT_SET_DATA(color_filters, COLOR_PROPS_LB, color_props);
422 OBJECT_SET_DATA(color_filters, COLOR_DELETE_LB, color_delete);
423 OBJECT_SET_DATA(color_new, COLOR_FILTERS_CL, color_filters);
424 SIGNAL_CONNECT(color_new, "clicked", color_new_cb, NULL);
425 OBJECT_SET_DATA(color_props, COLOR_FILTERS_CL, color_filters);
426 SIGNAL_CONNECT(color_props, "clicked", color_props_cb, NULL);
427 OBJECT_SET_DATA(color_delete, COLOR_PROPS_LB, color_props);
428 OBJECT_SET_DATA(color_delete, COLOR_FILTERS_CL, color_filters);
429 SIGNAL_CONNECT(color_delete, "clicked", color_delete_cb, NULL);
430 SIGNAL_CONNECT(color_save, "clicked", color_save_cb, NULL);
431 SIGNAL_CONNECT(color_export, "clicked", file_color_export_cmd_cb, NULL);
432 OBJECT_SET_DATA(color_import, COLOR_FILTERS_CL, color_filters);
433 SIGNAL_CONNECT(color_import, "clicked", color_import_cb, color_filters);
434 OBJECT_SET_DATA(color_clear, COLOR_FILTERS_CL, color_filters);
435 SIGNAL_CONNECT(color_clear, "clicked", color_clear_cb, NULL);
436 SIGNAL_CONNECT(color_ok, "clicked", color_ok_cb, NULL);
437 SIGNAL_CONNECT(color_apply, "clicked", color_apply_cb, NULL);
439 SIGNAL_CONNECT(color_win, "delete_event", window_delete_event_cb, NULL);
441 gtk_widget_grab_focus(color_filters);
443 gtk_widget_show_all(color_win);
444 window_present(color_win);
447 /* if we specified a preset filter string, open the new dialog and
449 create_new_color_filter(GTK_BUTTON(color_new), filter);
456 add_filter_to_list(gpointer filter_arg, gpointer list_arg)
458 color_filter_t *colorf = filter_arg;
459 #if GTK_MAJOR_VERSION < 2
460 GtkWidget *color_filters = list_arg;
465 data[0] = colorf->filter_name;
466 data[1] = colorf->filter_text;
467 row = gtk_clist_append(GTK_CLIST(color_filters), data);
468 color_t_to_gdkcolor(&fg, &colorf->fg_color);
469 color_t_to_gdkcolor(&bg, &colorf->bg_color);
470 gtk_clist_set_row_data(GTK_CLIST(color_filters), row, colorf);
471 gtk_clist_set_foreground(GTK_CLIST(color_filters), row, &fg);
472 gtk_clist_set_background(GTK_CLIST(color_filters), row, &bg);
474 gchar fg_str[14], bg_str[14];
478 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list_arg)));
479 gtk_list_store_append(store, &iter);
480 g_snprintf(fg_str, 14, "#%04X%04X%04X",
481 colorf->fg_color.red, colorf->fg_color.green, colorf->fg_color.blue);
482 g_snprintf(bg_str, 14, "#%04X%04X%04X",
483 colorf->bg_color.red, colorf->bg_color.green, colorf->bg_color.blue);
484 gtk_list_store_set(store, &iter, 0, colorf->filter_name,
485 1, colorf->filter_text, 2, fg_str, 3, bg_str,
491 void move_this_row (GtkWidget *color_filters,
493 gint amount) /* only tested with +1(down) and -1(up) */
495 color_filter_t *colorf;
496 #if GTK_MAJOR_VERSION < 2
500 GtkTreeIter iter1, iter2;
501 gchar *name, *string, *fg_str, *bg_str;
504 g_assert(amount == +1 || amount == -1);
505 g_assert(amount == +1 || filter_number > 0);
506 g_assert(amount == -1 || filter_number < num_of_filters - 1);
508 #if GTK_MAJOR_VERSION < 2
511 lower = filter_number;
512 higher = filter_number + amount;
516 higher = filter_number;
517 lower = filter_number + amount;
520 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
521 gtk_clist_swap_rows(GTK_CLIST(color_filters), higher, lower);
524 * That row is still selected, but it's now moved.
526 remember_selected_row(GTK_CLIST(color_filters), filter_number + amount, 0, NULL, NULL);
529 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
530 gtk_tree_model_iter_nth_child(model, &iter1, NULL, filter_number);
531 gtk_tree_model_iter_nth_child(model, &iter2, NULL, filter_number + amount);
533 gtk_tree_model_get(model, &iter1, 0, &name, 1, &string,
534 2, &fg_str, 3, &bg_str, 4, &colorf, -1);
535 gtk_list_store_remove(GTK_LIST_STORE(model), &iter1);
537 gtk_list_store_insert_before(GTK_LIST_STORE(model), &iter1, &iter2);
539 gtk_list_store_insert_after(GTK_LIST_STORE(model), &iter1, &iter2);
540 gtk_list_store_set(GTK_LIST_STORE(model), &iter1, 0, name, 1, string,
541 2, fg_str, 3, bg_str, 4, colorf, -1);
548 * re-select the initial row
550 gtk_widget_grab_focus(color_filters);
551 gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters)), &iter1);
555 filter_list = g_slist_remove(filter_list, colorf);
556 filter_list = g_slist_insert(filter_list, colorf, filter_number + amount);
559 /* Move the selected filters up in the list */
561 color_filter_up_cb(GtkButton *button, gpointer user_data _U_)
565 GtkWidget * color_filters;
566 color_filter_t *colorf;
567 #if GTK_MAJOR_VERSION < 2
571 GtkTreeSelection *sel;
575 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
577 #if GTK_MAJOR_VERSION < 2
578 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), 0);
583 for (filter_number = 0; filter_number < num_of_filters; filter_number++)
585 #if GTK_MAJOR_VERSION < 2
586 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
588 move_this_row (color_filters, filter_number, amount);
590 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
591 gtk_tree_model_iter_nth_child(model, &iter, NULL, filter_number);
592 gtk_tree_model_get(model, &iter, 4, &colorf, -1);
593 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
594 if (gtk_tree_selection_iter_is_selected(sel, &iter))
595 move_this_row (color_filters, filter_number, amount);
600 /* Move the selected filters down in the list */
602 color_filter_down_cb(GtkButton *button, gpointer user_data _U_)
606 GtkWidget * color_filters;
607 color_filter_t *colorf;
608 #if GTK_MAJOR_VERSION < 2
615 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
617 #if GTK_MAJOR_VERSION < 2
618 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), num_of_filters - 1);
623 for (filter_number = num_of_filters - 1; filter_number >= 0; filter_number--)
625 #if GTK_MAJOR_VERSION < 2
626 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
628 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
629 gtk_tree_model_iter_nth_child(model, &iter, NULL, filter_number);
630 gtk_tree_model_get(model, &iter, 4, &colorf, -1);
633 move_this_row (color_filters, filter_number, amount);
637 /* A row was selected; remember its row number */
638 #if GTK_MAJOR_VERSION < 2
640 remember_selected_row(GtkCList *clist, gint row, gint column _U_,
641 GdkEvent *event _U_, gpointer user_data _U_)
644 color_filter_t *colorf;
648 colorf = gtk_clist_get_row_data(clist, row);
649 colorf->marked = TRUE;
652 * A row is selected, so we can move it up *if* it's not at the top
653 * and move it down *if* it's not at the bottom.
655 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_UP_LB);
656 gtk_widget_set_sensitive (button, row > 0);
657 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DOWN_LB);
658 gtk_widget_set_sensitive(button, row < num_of_filters - 1);
661 * A row is selected, so we can operate on it.
663 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_PROPS_LB);
664 gtk_widget_set_sensitive (button, TRUE);
665 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DELETE_LB);
666 gtk_widget_set_sensitive(button, TRUE);
673 gint count; /* count of selected filters */
674 gboolean first_marked; /* true if the first filter in the list is marked */
675 gboolean last_marked; /* true if the last filter in the list is marked */
676 gpointer color_filters;
678 /* called for each selected row in the tree.
680 void remember_this_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer arg)
683 color_filter_t *colorf;
684 struct remember_data *data = arg;
686 gtk_tree_model_get(model, iter, 4, &colorf, -1);
687 colorf->marked = TRUE;
689 path_index = gtk_tree_path_get_indices(path); /* not to be freed */
690 if (path_index == NULL) /* can return NULL according to API doc.*/
694 row_selected = path_index[0];
696 if (row_selected == 0)
697 data->first_marked = TRUE;
698 if (row_selected == num_of_filters - 1)
699 data->last_marked = TRUE;
704 /* clear the mark on this filter */
706 clear_mark(gpointer filter_arg, gpointer arg _U_)
708 color_filter_t *colorf = filter_arg;
710 colorf->marked = FALSE;
713 /* The gtk+2.0 version gets called for, (maybe multiple,) changes in the selection. */
715 remember_selected_row(GtkTreeSelection *sel, gpointer color_filters)
718 struct remember_data data;
720 data.first_marked = data.last_marked = FALSE;
722 data.color_filters = color_filters;
724 g_slist_foreach(filter_list, clear_mark, NULL);
725 gtk_tree_selection_selected_foreach(sel,remember_this_row, &data);
730 * One or more rows are selected, so we can operate on them.
733 /* We can only edit if there is exactly one filter selected */
734 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_PROPS_LB);
735 gtk_widget_set_sensitive (button, data.count == 1);
737 /* We can delete any number of filters */
738 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DELETE_LB);
739 gtk_widget_set_sensitive (button, TRUE);
741 * We can move them up *if* one of them isn't the top row,
742 * and move them down *if* one of them isn't the bottom row.
744 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_UP_LB);
745 gtk_widget_set_sensitive(button, !data.first_marked);
746 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DOWN_LB);
747 gtk_widget_set_sensitive(button, !data.last_marked);
754 * No row is selected, so we can't do operations that affect the
757 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_UP_LB);
758 gtk_widget_set_sensitive (button, FALSE);
759 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DOWN_LB);
760 gtk_widget_set_sensitive (button, FALSE);
761 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_PROPS_LB);
762 gtk_widget_set_sensitive (button, FALSE);
763 button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DELETE_LB);
764 gtk_widget_set_sensitive (button, FALSE);
769 #if GTK_MAJOR_VERSION < 2
770 /* A row was unselected; un-remember its row number */
772 unremember_selected_row (GtkCList *clist,
776 gpointer user_data _U_)
779 color_filter_t *colorf;
783 colorf = gtk_clist_get_row_data(clist, row);
784 colorf->marked = FALSE;
786 if (color_marked_count() == 0)
789 * No row is selected, so we can't do operations that affect the
792 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_UP_LB);
793 gtk_widget_set_sensitive (button, FALSE);
794 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DOWN_LB);
795 gtk_widget_set_sensitive (button, FALSE);
796 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_PROPS_LB);
797 gtk_widget_set_sensitive (button, FALSE);
798 button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DELETE_LB);
799 gtk_widget_set_sensitive(button, FALSE);
804 /* Called when the dialog box is being destroyed; destroy any edit
805 * dialogs opened from this dialog, and null out the pointer to this
809 color_destroy_cb (GtkButton *button _U_,
810 gpointer user_data _U_)
812 /* Destroy any edit dialogs we have open. */
813 g_slist_foreach(filter_list, destroy_edit_dialog_cb, NULL);
819 destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy _U_)
821 color_filter_t *colorf = (color_filter_t *)filter_arg;
823 if (colorf->edit_dialog != NULL)
824 window_destroy(colorf->edit_dialog);
827 /* XXX - we don't forbid having more than one "Edit color filter" dialog
828 open, so these shouldn't be static. */
829 static GtkWidget *filt_name_entry;
830 static GtkWidget *filt_text_entry;
833 color_add_colorf(GtkWidget *color_filters, color_filter_t *colorf)
835 #if GTK_MAJOR_VERSION < 2
840 GtkTreeSelection *sel;
843 add_filter_to_list(colorf, color_filters);
845 #if GTK_MAJOR_VERSION < 2
847 /* select the new row */
848 gtk_clist_select_row(GTK_CLIST(color_filters), num_of_filters - 1, -1);
850 /* select the new row */
851 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
852 num_filters = gtk_tree_model_iter_n_children(model, NULL);
853 gtk_tree_model_iter_nth_child(model, &iter, NULL, num_filters - 1);
854 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
855 gtk_tree_selection_select_iter(sel, &iter);
860 color_add_filter_cb (color_filter_t *colorf, gpointer arg)
862 GtkWidget *color_filters = arg;
864 color_add_colorf(color_filters, colorf);
865 #if GTK_MAJOR_VERSION >= 2
866 gtk_widget_grab_focus(color_filters);
870 /* Pop up an "Export color filter" dialog box. */
872 color_import_cb(GtkButton *button, gpointer user_data )
874 GtkWidget *color_filters;
875 #if GTK_MAJOR_VERSION >= 2
876 GtkTreeSelection *sel;
879 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
881 #if GTK_MAJOR_VERSION >= 2
882 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
883 gtk_tree_selection_unselect_all (sel);
885 gtk_clist_unselect_all (GTK_CLIST(color_filters));
888 file_color_import_cmd_cb(GTK_WIDGET(button), user_data);
891 /* Create a new filter in the list, and pop up an "Edit color filter"
892 dialog box to edit it. */
894 create_new_color_filter(GtkButton *button, char *filter)
896 color_filter_t *colorf;
898 color_t bg_color, fg_color;
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 gdkcolor_to_color_t(&bg_color, &style->base[GTK_STATE_NORMAL]);
916 gdkcolor_to_color_t(&fg_color, &style->text[GTK_STATE_NORMAL]);
917 colorf = new_color_filter("name", filter, &bg_color, &fg_color); /* Adds at end! */
919 color_add_colorf(color_filters, colorf);
921 edit_color_filter_dialog(color_filters, &filt_name_entry, &filt_text_entry, TRUE);
923 /* Show the (in)validity of the default filter string */
924 filter_te_syntax_check_cb(filt_text_entry);
928 #if GTK_MAJOR_VERSION >= 2
929 gtk_widget_grab_focus(color_filters);
933 /* Create a new filter in the list, and pop up an "Edit color filter"
934 dialog box to edit it. */
936 color_new_cb(GtkButton *button, gpointer user_data _U_)
938 create_new_color_filter(button, "filter");
941 /* Pop up an "Edit color filter" dialog box to edit an existing filter. */
943 color_props_cb(GtkButton *button, gpointer user_data _U_)
945 GtkWidget *color_filters;
947 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
948 g_assert(row_selected != -1);
949 edit_color_filter_dialog(color_filters, &filt_name_entry, &filt_text_entry, FALSE);
952 /* Delete a color from the list. */
954 color_delete(gint row, GtkWidget *color_filters)
956 color_filter_t *colorf;
958 #if GTK_MAJOR_VERSION >= 2
963 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
964 gtk_tree_model_iter_nth_child(model, &iter, NULL, row);
965 gtk_tree_model_get(model, &iter, 4, &colorf, -1);
967 /* Remove this color filter from the CList displaying the
969 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
972 /* Destroy any "Edit color filter" dialog boxes editing it. */
973 if (colorf->edit_dialog != NULL)
974 window_destroy(colorf->edit_dialog);
976 /* Remove the color filter from the list of color filters. */
977 remove_color_filter(colorf);
979 /* If we grab the focus after updating the selection, the first
980 * row is always selected, so we do it before */
981 gtk_widget_grab_focus(color_filters);
983 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row);
985 /* Remove this color filter from the CList displaying the
987 gtk_clist_remove(GTK_CLIST(color_filters), row);
990 /* Destroy any "Edit color filter" dialog boxes editing it. */
991 if (colorf->edit_dialog != NULL)
992 window_destroy(colorf->edit_dialog);
994 /* Remove the color filter from the list of color filters. */
995 remove_color_filter(colorf);
999 /* Delete the selected color from the list.*/
1001 color_delete_cb(GtkWidget *widget, gpointer user_data _U_)
1003 GtkWidget *color_filters;
1004 gint row, num_filters;
1005 #if GTK_MAJOR_VERSION < 2
1006 color_filter_t *colorf;
1008 GtkTreeModel *model;
1010 GtkTreeSelection *sel;
1013 color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
1015 #if GTK_MAJOR_VERSION < 2
1016 num_filters = num_of_filters;
1018 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
1019 num_filters = gtk_tree_model_iter_n_children(model, NULL);
1020 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
1023 for (row = num_filters - 1; row >= 0; row--)
1025 #if GTK_MAJOR_VERSION < 2
1026 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row);
1028 color_delete (row, color_filters);
1030 gtk_tree_model_iter_nth_child(model, &iter, NULL, row);
1031 if (gtk_tree_selection_iter_is_selected(sel, &iter))
1032 color_delete (row, color_filters);
1037 /* Save color filters to the color filter file. */
1039 color_save_cb(GtkButton *button _U_, gpointer user_data _U_)
1041 if (!write_filters())
1042 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1043 "Could not open filter file: %s", strerror(errno));
1046 /* Remove all user defined color filters and revert to the global file. */
1048 color_clear_cmd(GtkWidget *widget)
1050 GtkWidget * color_filters;
1052 color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
1054 while (num_of_filters > 0)
1056 color_delete (num_of_filters-1, color_filters);
1059 if (!revert_filters())
1060 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1061 "Could not delete filter file: %s", strerror(errno));
1064 colorize_packets(&cfile);
1066 /* Destroy the dialog box. */
1067 /* XXX: is this useful? user might want to continue with editing new colors */
1068 window_destroy(colorize_win);
1071 /* clear button: user responded to question */
1072 void color_clear_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
1075 case(ESD_BTN_CLEAR):
1076 color_clear_cmd(data);
1078 case(ESD_BTN_CANCEL):
1081 g_assert_not_reached();
1085 /* clear button: ask user before really doing it */
1087 color_clear_cb(GtkWidget *widget, gpointer data _U_) {
1090 /* ask user, if he/she is really sure */
1091 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTN_CLEAR | ESD_BTN_CANCEL,
1092 PRIMARY_TEXT_START "Remove all your personal color settings?" PRIMARY_TEXT_END "\n\n"
1093 "This will revert the color settings to global defaults.\n\n"
1094 "Are you really sure?");
1096 simple_dialog_set_cb(dialog, color_clear_answered_cb, widget);
1099 /* Exit dialog and apply new list of color filters to the capture. */
1101 color_ok_cb(GtkButton *button _U_, gpointer user_data _U_)
1104 colorize_packets(&cfile);
1106 /* Destroy the dialog box. */
1107 window_destroy(colorize_win);
1110 /* Exit dialog without colorizing packets with the new list.
1111 XXX - should really undo any changes to the list.... */
1113 color_cancel_cb(GtkWidget *widget _U_, gpointer user_data _U_)
1115 /* Destroy the dialog box. */
1116 window_destroy(colorize_win);
1119 /* Apply new list of color filters to the capture. */
1121 color_apply_cb(GtkButton *button _U_, gpointer user_data _U_)
1123 colorize_packets(&cfile);
1126 /* Create an "Edit Color Filter" dialog for a given color filter, and
1127 associate it with that color filter. */
1129 edit_color_filter_dialog(GtkWidget *color_filters,
1130 GtkWidget **colorize_filter_name,
1131 GtkWidget **colorize_filter_text,
1132 guchar is_new_filter)
1134 color_filter_t *colorf;
1135 GtkWidget *edit_dialog;
1136 GtkWidget *dialog_vbox;
1137 GtkTooltips *tooltips;
1140 GtkWidget *filter_fr;
1141 GtkWidget *filter_fr_vbox;
1142 GtkWidget *filter_name_hbox;
1143 GtkWidget *color_filter_name;
1144 GtkWidget *filter_string_hbox;
1145 GtkWidget *add_expression_bt;
1146 GtkWidget *color_filter_text;
1148 GtkWidget *colorize_fr;
1149 GtkWidget *colorize_hbox;
1150 GtkWidget *colorize_filter_fg;
1151 GtkWidget *colorize_filter_bg;
1154 GtkWidget *edit_color_filter_ok;
1155 GtkWidget *edit_color_filter_cancel;
1157 #if GTK_MAJOR_VERSION >= 2
1158 GtkTreeModel *model;
1162 #if GTK_MAJOR_VERSION >= 2
1163 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
1165 gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected);
1166 gtk_tree_model_get(model, &iter, 4, &colorf, -1);
1169 colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row_selected);
1171 if (colorf->edit_dialog != NULL) {
1172 /* There's already an edit box open for this filter; reactivate it. */
1173 reactivate_window(colorf->edit_dialog);
1177 tooltips = gtk_tooltips_new ();
1180 edit_dialog = dlg_window_new ("Ethereal: Edit Color Filter");
1181 gtk_window_set_default_size(GTK_WINDOW(edit_dialog), 500, -1);
1182 OBJECT_SET_DATA(edit_dialog, "edit_dialog", edit_dialog);
1183 colorf->edit_dialog = edit_dialog;
1185 dialog_vbox = gtk_vbox_new (FALSE, 0);
1186 gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
1187 gtk_container_add (GTK_CONTAINER (edit_dialog), dialog_vbox);
1190 filter_fr = gtk_frame_new("Filter");
1191 gtk_box_pack_start (GTK_BOX (dialog_vbox), filter_fr, FALSE, FALSE, 0);
1193 filter_fr_vbox = gtk_vbox_new (FALSE, 0);
1194 gtk_container_set_border_width (GTK_CONTAINER (filter_fr_vbox), 5);
1195 gtk_container_add(GTK_CONTAINER(filter_fr), filter_fr_vbox);
1197 /* filter name hbox */
1198 filter_name_hbox = gtk_hbox_new (FALSE, 0);
1199 gtk_box_pack_start (GTK_BOX (filter_fr_vbox), filter_name_hbox, TRUE, FALSE, 3);
1201 color_filter_name = gtk_label_new (("Name: "));
1202 gtk_box_pack_start (GTK_BOX (filter_name_hbox), color_filter_name, FALSE, FALSE, 0);
1204 *colorize_filter_name = gtk_entry_new ();
1205 gtk_entry_set_text(GTK_ENTRY(*colorize_filter_name), colorf->filter_name);
1207 style = gtk_style_copy(gtk_widget_get_style(*colorize_filter_name));
1208 color_t_to_gdkcolor(&style->base[GTK_STATE_NORMAL], &colorf->bg_color);
1209 #if GTK_MAJOR_VERSION < 2
1210 color_t_to_gdkcolor(&style->fg[GTK_STATE_NORMAL], &colorf->fg_color);
1212 color_t_to_gdkcolor(&style->text[GTK_STATE_NORMAL], &colorf->fg_color);
1214 gtk_widget_set_style(*colorize_filter_name, style);
1216 gtk_box_pack_start (GTK_BOX (filter_name_hbox), *colorize_filter_name, TRUE, TRUE, 0);
1217 gtk_tooltips_set_tip (tooltips, *colorize_filter_name, ("This is the editable name of the filter. (No @ characters allowed.)"), NULL);
1220 /* filter string hbox */
1221 filter_string_hbox = gtk_hbox_new (FALSE, 0);
1222 gtk_box_pack_start (GTK_BOX (filter_fr_vbox), filter_string_hbox, TRUE, FALSE, 3);
1224 color_filter_text = gtk_label_new (("String: "));
1225 gtk_box_pack_start (GTK_BOX (filter_string_hbox), color_filter_text, FALSE, FALSE, 0);
1227 *colorize_filter_text = gtk_entry_new ();
1228 SIGNAL_CONNECT(*colorize_filter_text, "changed", filter_te_syntax_check_cb, NULL);
1229 gtk_entry_set_text(GTK_ENTRY(*colorize_filter_text), colorf->filter_text);
1232 style = gtk_style_copy(gtk_widget_get_style(*colorize_filter_text));
1233 style->base[GTK_STATE_NORMAL] = colorf->bg_color;
1234 style->fg[GTK_STATE_NORMAL] = colorf->fg_color;
1236 gtk_widget_set_style(*colorize_filter_text, style);
1237 gtk_box_pack_start (GTK_BOX (filter_string_hbox), *colorize_filter_text, TRUE, TRUE, 0);
1238 gtk_tooltips_set_tip (tooltips, *colorize_filter_text, ("This is the editable text of the filter"), NULL);
1240 /* Create the "Add Expression..." button, to pop up a dialog
1241 for constructing filter comparison expressions. */
1242 add_expression_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_ADD_EXPRESSION);
1243 SIGNAL_CONNECT(add_expression_bt, "clicked", filter_expr_cb, *colorize_filter_text);
1244 gtk_box_pack_start (GTK_BOX(filter_string_hbox), add_expression_bt, FALSE, FALSE, 3);
1245 gtk_tooltips_set_tip (tooltips, add_expression_bt, ("Add an expression to the filter string"), NULL);
1248 /* choose color frame */
1249 colorize_fr = gtk_frame_new("Display Colors");
1250 gtk_box_pack_start (GTK_BOX (dialog_vbox), colorize_fr, FALSE, FALSE, 0);
1252 colorize_hbox = gtk_hbox_new (FALSE, 0);
1253 gtk_container_set_border_width (GTK_CONTAINER (colorize_hbox), 5);
1254 gtk_container_add(GTK_CONTAINER(colorize_fr), colorize_hbox);
1256 colorize_filter_fg = gtk_button_new_with_label (("Foreground Color..."));
1257 gtk_box_pack_start (GTK_BOX (colorize_hbox), colorize_filter_fg, TRUE, FALSE, 0);
1258 gtk_tooltips_set_tip (tooltips, colorize_filter_fg, ("Select foreground color for data display"), NULL);
1260 colorize_filter_bg = gtk_button_new_with_label (("Background Color..."));
1261 gtk_box_pack_start (GTK_BOX (colorize_hbox), colorize_filter_bg, TRUE, FALSE, 0);
1262 gtk_tooltips_set_tip (tooltips, colorize_filter_bg, ("Select background color for data display"), NULL);
1266 bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1267 gtk_box_pack_start(GTK_BOX(dialog_vbox), bbox, FALSE, FALSE, 0);
1268 gtk_container_set_border_width (GTK_CONTAINER (bbox), 0);
1270 edit_color_filter_ok = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
1271 gtk_tooltips_set_tip (tooltips, edit_color_filter_ok, ("Accept filter color change"), NULL);
1273 edit_color_filter_cancel = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
1274 gtk_tooltips_set_tip (tooltips, edit_color_filter_cancel, ("Reject filter color change"), NULL);
1276 gtk_widget_grab_default(edit_color_filter_ok);
1278 /* signals and such */
1279 OBJECT_SET_DATA(edit_dialog, COLOR_FILTER, colorf);
1280 SIGNAL_CONNECT(edit_dialog, "destroy", edit_color_filter_destroy_cb, NULL);
1281 OBJECT_SET_DATA(colorize_filter_fg, COLOR_FILTER, colorf);
1282 SIGNAL_CONNECT(colorize_filter_fg, "clicked", edit_color_filter_fg_cb, NULL);
1283 OBJECT_SET_DATA(colorize_filter_bg, COLOR_FILTER, colorf);
1284 SIGNAL_CONNECT(colorize_filter_bg, "clicked", edit_color_filter_bg_cb, NULL);
1285 OBJECT_SET_DATA(edit_color_filter_ok, COLOR_FILTERS_CL, color_filters);
1286 OBJECT_SET_DATA(edit_color_filter_ok, COLOR_FILTER, colorf);
1287 SIGNAL_CONNECT(edit_color_filter_ok, "clicked", edit_color_filter_ok_cb, edit_dialog);
1289 /* set callback to delete new filters if cancel chosen */
1292 OBJECT_SET_DATA(edit_color_filter_cancel, COLOR_FILTERS_CL, color_filters);
1293 SIGNAL_CONNECT(edit_color_filter_cancel, "clicked",
1294 edit_new_color_filter_cancel_cb, edit_dialog);
1296 /* escape will select cancel */
1297 window_set_cancel_button(edit_dialog, edit_color_filter_cancel, window_cancel_button_cb);
1299 SIGNAL_CONNECT(edit_dialog, "delete_event", window_delete_event_cb, NULL);
1301 gtk_widget_show_all(edit_dialog);
1302 window_present(edit_dialog);
1305 /* Called when the dialog box is being destroyed; destroy any color
1306 selection dialogs opened from this dialog, and null out the pointer
1308 #if GTK_MAJOR_VERSION < 2
1310 edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data _U_)
1313 edit_color_filter_destroy_cb(GObject *object, gpointer user_data _U_)
1316 color_filter_t *colorf;
1317 GtkWidget *color_sel;
1319 colorf = (color_filter_t *)OBJECT_GET_DATA(object, COLOR_FILTER);
1320 colorf->edit_dialog = NULL;
1322 /* Destroy any color selection dialogs this dialog had open. */
1323 color_sel = (GtkWidget *)OBJECT_GET_DATA(object, COLOR_SELECTION_FG);
1324 if (color_sel != NULL)
1325 window_destroy(color_sel);
1326 color_sel = (GtkWidget *)OBJECT_GET_DATA(object, COLOR_SELECTION_BG);
1327 if (color_sel != NULL)
1328 window_destroy(color_sel);
1331 /* Pop up a color selection box to choose the foreground color. */
1333 edit_color_filter_fg_cb(GtkButton *button, gpointer user_data _U_)
1335 color_filter_t *colorf;
1336 GtkWidget *color_selection_fg;
1338 colorf = (color_filter_t *)OBJECT_GET_DATA(button, COLOR_FILTER);
1339 /* Do we already have one open for this dialog? */
1340 color_selection_fg = OBJECT_GET_DATA(colorf->edit_dialog, COLOR_SELECTION_FG);
1341 if (color_selection_fg != NULL) {
1342 /* Yes. Just reactivate it. */
1343 reactivate_window(color_selection_fg);
1345 /* No. Create a new color selection box, and associate it with
1347 color_selection_fg = color_sel_win_new(colorf, FALSE);
1348 OBJECT_SET_DATA(colorf->edit_dialog, COLOR_SELECTION_FG, color_selection_fg);
1349 OBJECT_SET_DATA(color_selection_fg, COLOR_SELECTION_PARENT, colorf->edit_dialog);
1353 /* Pop up a color selection box to choose the background color. */
1355 edit_color_filter_bg_cb (GtkButton *button,
1356 gpointer user_data _U_)
1358 color_filter_t *colorf;
1359 GtkWidget *color_selection_bg;
1361 colorf = (color_filter_t *)OBJECT_GET_DATA(button, COLOR_FILTER);
1362 /* Do we already have one open for this dialog? */
1363 color_selection_bg = OBJECT_GET_DATA(colorf->edit_dialog, COLOR_SELECTION_BG);
1364 if (color_selection_bg != NULL) {
1365 /* Yes. Just reactivate it. */
1366 reactivate_window(color_selection_bg);
1368 /* No. Create a new color selection box, and associate it with
1370 color_selection_bg = color_sel_win_new(colorf, TRUE);
1371 OBJECT_SET_DATA(colorf->edit_dialog, COLOR_SELECTION_BG, color_selection_bg);
1372 OBJECT_SET_DATA(color_selection_bg, COLOR_SELECTION_PARENT, colorf->edit_dialog);
1376 /* accept color (and potential content) change */
1378 edit_color_filter_ok_cb (GtkButton *button,
1383 GdkColor new_fg_color;
1384 GdkColor new_bg_color;
1387 color_filter_t *colorf;
1388 dfilter_t *compiled_filter;
1389 GtkWidget *color_filters;
1390 #if GTK_MAJOR_VERSION >= 2
1391 GtkTreeModel *model;
1393 gchar fg_str[14], bg_str[14];
1396 dialog = (GtkWidget *)user_data;
1398 style = gtk_widget_get_style(filt_name_entry);
1399 new_bg_color = style->base[GTK_STATE_NORMAL];
1400 #if GTK_MAJOR_VERSION < 2
1401 new_fg_color = style->fg[GTK_STATE_NORMAL];
1403 new_fg_color = style->text[GTK_STATE_NORMAL];
1406 filter_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(filt_name_entry)));
1407 filter_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(filt_text_entry)));
1409 if(strchr(filter_name,'@') || strchr(filter_text,'@')){
1410 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1411 "Filter names and strings must not"
1412 " use the '@' character. Filter unchanged.");
1413 g_free(filter_name);
1414 g_free(filter_text);
1418 if(!dfilter_compile(filter_text, &compiled_filter)) {
1419 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1420 "Filter \"%s\" did not compile correctly.\n"
1421 " Please try again. Filter unchanged.\n%s\n", filter_name,
1424 color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
1425 colorf = (color_filter_t *)OBJECT_GET_DATA(button, COLOR_FILTER);
1427 if (colorf->filter_name != NULL)
1428 g_free(colorf->filter_name);
1429 colorf->filter_name = filter_name;
1430 if (colorf->filter_text != NULL)
1431 g_free(colorf->filter_text);
1432 colorf->filter_text = filter_text;
1433 gdkcolor_to_color_t(&colorf->fg_color, &new_fg_color);
1434 gdkcolor_to_color_t(&colorf->bg_color, &new_bg_color);
1435 #if GTK_MAJOR_VERSION < 2
1436 gtk_clist_set_foreground(GTK_CLIST(color_filters), row_selected,
1438 gtk_clist_set_background(GTK_CLIST(color_filters), row_selected,
1441 g_snprintf(fg_str, 14, "#%04X%04X%04X",
1442 new_fg_color.red, new_fg_color.green, new_fg_color.blue);
1443 g_snprintf(bg_str, 14, "#%04X%04X%04X",
1444 new_bg_color.red, new_bg_color.green, new_bg_color.blue);
1445 model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
1446 gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected);
1447 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, filter_name,
1448 1, filter_text, 2, fg_str, 3, bg_str, -1);
1450 if(colorf->c_colorfilter != NULL)
1451 dfilter_free(colorf->c_colorfilter);
1452 colorf->c_colorfilter = compiled_filter;
1453 #if GTK_MAJOR_VERSION < 2
1454 /* gtk_clist_set_text frees old text (if any) and allocates new space */
1455 gtk_clist_set_text(GTK_CLIST(color_filters), row_selected, 0,
1457 gtk_clist_set_text(GTK_CLIST(color_filters), row_selected, 1,
1461 /* Destroy the dialog box. */
1462 window_destroy(dialog);
1466 /* reject new color filter addition */
1468 edit_new_color_filter_cancel_cb(GtkButton *button, gpointer user_data _U_)
1470 /* Delete the entry. N.B. this already destroys the edit_dialog window. */
1471 color_delete(num_of_filters-1, (GtkWidget*)OBJECT_GET_DATA(button, COLOR_FILTERS_CL));
1475 color_sel_win_new(color_filter_t *colorf, gboolean is_bg)
1478 GtkWidget *color_sel_win;
1480 #if GTK_MAJOR_VERSION >= 2
1483 GtkWidget *color_sel_ok;
1484 GtkWidget *color_sel_cancel;
1485 GtkWidget *color_sel_help;
1488 color = &colorf->bg_color;
1489 title = g_strdup_printf("Ethereal: Choose background color for \"%s\"",
1490 colorf->filter_name);
1492 color = &colorf->fg_color;
1493 title = g_strdup_printf("Ethereal: Choose foreground color for \"%s\"",
1494 colorf->filter_name);
1496 color_sel_win = gtk_color_selection_dialog_new(title);
1498 OBJECT_SET_DATA(color_sel_win, "color_sel_win", color_sel_win);
1499 gtk_container_set_border_width (GTK_CONTAINER (color_sel_win), 10);
1501 if (color != NULL) {
1502 #if GTK_MAJOR_VERSION < 2
1505 cols[0] = (gdouble)color->red / 65536.0;
1506 cols[1] = (gdouble)color->green / 65536.0;
1507 cols[2] = (gdouble)color->blue / 65536.0;
1509 gtk_color_selection_set_color(
1510 GTK_COLOR_SELECTION(
1511 GTK_COLOR_SELECTION_DIALOG(color_sel_win)->colorsel), cols);
1513 color_t_to_gdkcolor(&gcolor, color);
1514 gtk_color_selection_set_current_color(
1515 GTK_COLOR_SELECTION(
1516 GTK_COLOR_SELECTION_DIALOG(color_sel_win)->colorsel), &gcolor);
1520 color_sel_ok = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->ok_button;
1521 OBJECT_SET_DATA(color_sel_win, "color_sel_ok", color_sel_ok);
1522 GTK_WIDGET_SET_FLAGS (color_sel_ok, GTK_CAN_DEFAULT);
1524 color_sel_cancel = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->cancel_button;
1525 OBJECT_SET_DATA(color_sel_win, "color_sel_cancel", color_sel_cancel);
1526 GTK_WIDGET_SET_FLAGS (color_sel_cancel, GTK_CAN_DEFAULT);
1529 color_sel_help = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->help_button;
1530 OBJECT_SET_DATA(color_sel_win, "color_sel_help", color_sel_help);
1533 GTK_WIDGET_SET_FLAGS (color_sel_help, GTK_CAN_DEFAULT);
1535 SIGNAL_CONNECT(color_sel_ok, "clicked", color_sel_ok_cb, color_sel_win);
1536 SIGNAL_CONNECT(color_sel_cancel, "clicked", color_sel_cancel_cb, color_sel_win);
1538 gtk_widget_show_all(color_sel_win);
1539 return color_sel_win;
1543 color_sel_win_destroy(GtkWidget *sel_win)
1546 GtkWidget *color_selection_fg, *color_selection_bg;
1548 /* Find the "Edit color filter" dialog box with which this is associated. */
1549 parent = (GtkWidget *)OBJECT_GET_DATA(sel_win, COLOR_SELECTION_PARENT);
1551 /* Find that dialog box's foreground and background color selection
1553 color_selection_fg = OBJECT_GET_DATA(parent, COLOR_SELECTION_FG);
1554 color_selection_bg = OBJECT_GET_DATA(parent, COLOR_SELECTION_BG);
1556 if (sel_win == color_selection_fg) {
1557 /* This was its foreground color selection box; it isn't, anymore. */
1558 OBJECT_SET_DATA(parent, COLOR_SELECTION_FG, NULL);
1560 if (sel_win == color_selection_bg) {
1561 /* This was its background color selection box; it isn't, anymore. */
1562 OBJECT_SET_DATA(parent, COLOR_SELECTION_BG, NULL);
1565 /* Now destroy it. */
1566 window_destroy(sel_win);
1569 /* Retrieve selected color */
1571 color_sel_ok_cb (GtkButton *button _U_,
1574 GdkColor new_color; /* Color from color selection dialog */
1575 #if GTK_MAJOR_VERSION < 2
1576 gdouble new_colors[3];
1578 GtkWidget *color_dialog;
1581 GtkWidget *color_selection_fg, *color_selection_bg;
1584 color_dialog = (GtkWidget *)user_data;
1586 #if GTK_MAJOR_VERSION < 2
1587 gtk_color_selection_get_color(GTK_COLOR_SELECTION(
1588 GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), new_colors);
1590 new_color.red = (guint16)(new_colors[0]*65535.0);
1591 new_color.green = (guint16)(new_colors[1]*65535.0);
1592 new_color.blue = (guint16)(new_colors[2]*65535.0);
1594 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(
1595 GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &new_color);
1598 if ( ! get_color(&new_color) ){
1599 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1600 "Could not allocate color. Try again.");
1602 /* Find the "Edit color filter" dialog box with which this is
1604 parent = (GtkWidget *)OBJECT_GET_DATA(color_dialog, COLOR_SELECTION_PARENT);
1606 /* Find that dialog box's foreground and background color selection
1608 color_selection_fg = OBJECT_GET_DATA(parent, COLOR_SELECTION_FG);
1609 color_selection_bg = OBJECT_GET_DATA(parent, COLOR_SELECTION_BG);
1610 is_bg = (color_dialog == color_selection_bg);
1612 color_sel_win_destroy(color_dialog);
1614 /* now apply the change to the fore/background */
1616 style = gtk_style_copy(gtk_widget_get_style(filt_name_entry));
1618 style->base[GTK_STATE_NORMAL] = new_color;
1619 #if GTK_MAJOR_VERSION < 2
1621 style->fg[GTK_STATE_NORMAL] = new_color;
1624 style->text[GTK_STATE_NORMAL] = new_color;
1626 gtk_widget_set_style(filt_name_entry, style);
1627 gtk_widget_set_style(filt_text_entry, style);
1631 /* Don't choose the selected color as the foreground or background
1632 color for the filter. */
1634 color_sel_cancel_cb (GtkObject *object _U_,
1637 GtkWidget *color_dialog;
1638 color_dialog = (GtkWidget *)user_data;
1639 /* nothing to change here. Just get rid of the dialog box. */
1641 color_sel_win_destroy(color_dialog);