renamed filter_prefs to filter_dlg, as the filter settings are (well, for a long...
[obnox/wireshark/wip.git] / gtk / color_dlg.c
1 /* color_dlg.c
2  * Definitions for dialog boxes for color filters
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <gtk/gtk.h>
30
31 #include <string.h>
32
33 #include "gtk/main.h"
34 #include <epan/packet.h>
35 #include "color.h"
36 #include "colors.h"
37 #include "color_filters.h"
38 #include "color_dlg.h"
39 #include "color_utils.h"
40 #include "file.h"
41 #include <epan/dfilter/dfilter.h>
42 #include "simple_dialog.h"
43 #include "dlg_utils.h"
44 #include "ui_util.h"
45 #include "dfilter_expr_dlg.h"
46 #include "compat_macros.h"
47 #include "filter_dlg.h"
48 #include "file_dlg.h"
49 #include "gtkglobals.h"
50 #include "prefs.h"
51
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);
61 #else
62 static void remember_selected_row(GtkTreeSelection *sel, gpointer list);
63 #endif
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 );
76
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);
81
82 #if GTK_MAJOR_VERSION < 2
83 static void edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data);
84 #else
85 static void edit_color_filter_destroy_cb(GObject *object, gpointer user_data);
86 #endif
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);
91
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);
95
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 */
99
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"
109
110 static void
111 filter_expr_cb(GtkWidget *w _U_, gpointer filter_te)
112 {
113
114         dfilter_expr_dlg_new(GTK_WIDGET(filter_te));
115 }
116
117
118 /* Callback for the "Display:Colorize Display" menu item. */
119 void
120 color_display_cb(GtkWidget *w _U_, gpointer d _U_)
121 {
122   if (colorize_win != NULL) {
123     /* There's already a color dialog box active; reactivate it. */
124     reactivate_window(colorize_win);
125   } else {
126     /* Create a new "Colorize Display" dialog. */
127     colorize_win = colorize_dialog_new(NULL);
128   }
129 }
130
131 /* this opens the colorize dialogue and presets the filter string */
132 void
133 color_display_with_filter(char *filter)
134 {
135   if (colorize_win != NULL) {
136     /* There's already a color dialog box active; reactivate it. */
137     reactivate_window(colorize_win);
138   } else {
139     /* Create a new "Colorize Display" dialog. */
140     colorize_win = colorize_dialog_new(filter);
141   }
142 }
143
144 /* if this filter is marked count it in the given int* */
145 static void
146 count_this_mark(gpointer filter_arg, gpointer counter_arg)
147 {
148   color_filter_t *colorf = filter_arg;
149   int * cnt = counter_arg;
150
151   if (colorf->marked)
152     (*cnt)++;
153 }
154
155 /* TODO: implement count of selected filters. Plug in to file_dlg update of "export selected" checkbox. */
156 int color_marked_count(void)
157 {
158   int count = 0;
159
160   g_slist_foreach(filter_list, count_this_mark, &count);
161
162   return count;
163 }
164
165 /* Create the "Coloring Rules" dialog. */
166 static GtkWidget*
167 colorize_dialog_new (char *filter)
168 {
169   GtkWidget *color_win;
170   GtkWidget *dlg_vbox;
171   GtkWidget *main_hbox;
172   GtkWidget *ctrl_vbox;
173   GtkTooltips *tooltips;
174
175   GtkWidget *order_fr;
176   GtkWidget *order_vbox;
177   GtkWidget *color_filter_up;
178   GtkWidget *order_move_label;
179   GtkWidget *color_filter_down;
180
181   GtkWidget *list_fr;
182   GtkWidget *list_vbox;
183   GtkWidget *scrolledwindow1;
184   GtkWidget *color_filters;
185   GtkWidget *list_label;
186
187   GtkWidget *edit_fr;
188   GtkWidget *edit_vbox;
189   GtkWidget *color_new;
190   GtkWidget *color_props;
191   GtkWidget *color_delete;
192
193   GtkWidget *manage_fr;
194   GtkWidget *manage_vbox;
195   GtkWidget *color_export;
196   GtkWidget *color_import;
197   GtkWidget *color_clear;
198
199   GtkWidget *button_ok_hbox;
200   GtkWidget *color_ok;
201   GtkWidget *color_apply;
202   GtkWidget *color_save;
203   GtkWidget *color_cancel;
204
205 #if GTK_MAJOR_VERSION >= 2
206   GtkListStore      *store;
207   GtkCellRenderer   *renderer;
208   GtkTreeViewColumn *column;
209   GtkTreeSelection  *selection;
210 #endif
211   gchar *titles[] = { "Name", "String" };
212
213
214   row_selected = -1; /* no row selected */
215   tooltips = gtk_tooltips_new ();
216
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);
226
227   main_hbox = gtk_hbox_new (FALSE, 0);
228   gtk_box_pack_start (GTK_BOX (dlg_vbox), main_hbox, TRUE, TRUE, 0);
229
230   ctrl_vbox = gtk_vbox_new (FALSE, 0);
231   gtk_box_pack_start (GTK_BOX (main_hbox), ctrl_vbox, FALSE, FALSE, 0);
232
233
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);
237
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);
243
244   color_new = BUTTON_NEW_FROM_STOCK(GTK_STOCK_NEW);
245 #if GTK_MAJOR_VERSION < 2
246   WIDGET_SET_SIZE(color_new, 50, 20);
247 #endif
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);
250
251   color_props = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_EDIT);
252 #if GTK_MAJOR_VERSION < 2
253   WIDGET_SET_SIZE(color_props, 50, 20);
254 #endif
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);
258
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);
263 #endif
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 */
267
268
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);
272   
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);
276
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);
281 #endif
282   gtk_tooltips_set_tip(tooltips, color_export, ("Save all/marked filters to a file"), NULL);
283
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);
288 #endif
289   gtk_tooltips_set_tip(tooltips, color_import, ("Load filters from a file"), NULL);
290
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);
295 #endif
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);
297
298
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);
302
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);
306
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);
309
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), 
314                                    GTK_SHADOW_IN);
315 #endif
316   gtk_box_pack_start (GTK_BOX (list_vbox), scrolledwindow1, TRUE, TRUE, 0);
317
318 #if GTK_MAJOR_VERSION < 2
319   color_filters = gtk_clist_new_with_titles(2, titles);
320 #else
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",
329                                                     0, "foreground", 2,
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",
335                                                     1, "foreground", 2,
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);
341 #endif
342
343   num_of_filters = 0;
344   g_slist_foreach(filter_list, add_filter_to_list, color_filters);
345
346 #if GTK_MAJOR_VERSION < 2
347   gtk_clist_set_selection_mode    (GTK_CLIST (color_filters),GTK_SELECTION_EXTENDED);
348 #else
349   selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
350   gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
351 #endif
352
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));
358 #endif
359
360
361   /* order frame */
362   order_fr = gtk_frame_new("Order");
363   gtk_box_pack_start (GTK_BOX (main_hbox), order_fr, FALSE, FALSE, 0);
364
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);
368
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);
372 #endif
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);
376
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);
379
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);
383 #endif
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);
387
388
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);
392
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);
395
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);
398
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);
401
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);
405
406   gtk_widget_grab_default(color_ok);
407
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);
417 #else
418   SIGNAL_CONNECT(selection, "changed", remember_selected_row, color_filters);
419 #endif
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);
439
440   SIGNAL_CONNECT(color_win, "delete_event", window_delete_event_cb, NULL);
441
442   gtk_widget_grab_focus(color_filters);
443
444   gtk_widget_show_all(color_win);
445   window_present(color_win);
446
447   if(filter){
448     /* if we specified a preset filter string, open the new dialog and
449        set the filter */
450     create_new_color_filter(GTK_BUTTON(color_new), filter);
451   }
452
453   return color_win;
454 }
455
456 static void
457 add_filter_to_list(gpointer filter_arg, gpointer list_arg)
458 {
459   color_filter_t *colorf = filter_arg;
460 #if GTK_MAJOR_VERSION < 2
461   GtkWidget      *color_filters = list_arg;
462   gchar          *data[2];
463   gint            row;
464   GdkColor        bg, fg;
465
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);
474 #else
475   gchar           fg_str[14], bg_str[14];
476   GtkListStore   *store;
477   GtkTreeIter     iter;
478
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,
487                      4, colorf, -1);
488 #endif
489   num_of_filters++;
490 }
491
492 void move_this_row (GtkWidget   *color_filters, 
493                      gint         filter_number,
494                      gint         amount)            /* only tested with +1(down) and -1(up) */
495 {
496   color_filter_t *colorf;
497 #if GTK_MAJOR_VERSION < 2
498   gint            lower, higher;
499 #else
500   GtkTreeModel   *model;
501   GtkTreeIter     iter1, iter2;
502   gchar          *name, *string, *fg_str, *bg_str;
503 #endif
504
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);
508
509 #if GTK_MAJOR_VERSION < 2
510   if (amount > 0)
511   {
512     lower = filter_number;
513     higher = filter_number + amount;
514   }
515   else
516   {
517     higher = filter_number;
518     lower = filter_number + amount;
519   }
520
521   colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
522   gtk_clist_swap_rows(GTK_CLIST(color_filters), higher, lower);
523
524   /*
525    * That row is still selected, but it's now moved.
526    */
527   remember_selected_row(GTK_CLIST(color_filters), filter_number + amount, 0, NULL, NULL);
528 #else
529
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);
533   
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);
537   if (amount < 0)
538     gtk_list_store_insert_before(GTK_LIST_STORE(model), &iter1, &iter2);
539   else
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);
543   g_free(name);
544   g_free(string);
545   g_free(fg_str);
546   g_free(bg_str);
547
548   /*
549    * re-select the initial row
550    */
551   gtk_widget_grab_focus(color_filters);
552   gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters)), &iter1);
553   
554 #endif
555
556   filter_list = g_slist_remove(filter_list, colorf);
557   filter_list = g_slist_insert(filter_list, colorf, filter_number + amount);
558 }
559
560 /* Move the selected filters up in the list */
561 static void
562 color_filter_up_cb(GtkButton *button, gpointer user_data _U_)
563 {
564   gint amount;
565   gint filter_number;
566   GtkWidget * color_filters;
567   color_filter_t *colorf;
568 #if GTK_MAJOR_VERSION < 2
569 #else
570   GtkTreeIter       iter;
571   GtkTreeModel     *model;
572   GtkTreeSelection *sel;
573 #endif
574
575   amount = -1;
576   color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
577
578 #if GTK_MAJOR_VERSION < 2
579   colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), 0);
580   if (colorf->marked)
581     return;
582 #endif
583
584   for (filter_number = 0; filter_number < num_of_filters; filter_number++)
585   {
586 #if GTK_MAJOR_VERSION < 2
587     colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
588     if (colorf->marked)
589       move_this_row (color_filters, filter_number, amount);
590 #else
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);
597 #endif
598   }
599 }
600
601 /* Move the selected filters down in the list */
602 static void
603 color_filter_down_cb(GtkButton *button, gpointer user_data _U_)
604 {
605   gint amount;
606   gint filter_number;
607   GtkWidget * color_filters;
608   color_filter_t *colorf;
609 #if GTK_MAJOR_VERSION < 2
610 #else
611   GtkTreeIter     iter;
612   GtkTreeModel   *model;
613 #endif
614
615   amount = +1;
616   color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
617
618 #if GTK_MAJOR_VERSION < 2
619     colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), num_of_filters - 1);
620     if (colorf->marked)
621       return;
622 #endif
623
624   for (filter_number = num_of_filters - 1; filter_number >= 0; filter_number--)
625   {
626 #if GTK_MAJOR_VERSION < 2
627     colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
628 #else
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);
632 #endif
633     if (colorf->marked)
634       move_this_row (color_filters, filter_number, amount);
635   }
636 }
637  
638 /* A row was selected; remember its row number */
639 #if GTK_MAJOR_VERSION < 2
640 static void
641 remember_selected_row(GtkCList *clist, gint row, gint column _U_,
642                       GdkEvent *event _U_, gpointer user_data _U_)
643 {
644     GtkWidget    *button;
645     color_filter_t *colorf;
646
647     row_selected = row;
648
649     colorf = gtk_clist_get_row_data(clist, row);
650     colorf->marked = TRUE;
651     
652     /*
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.
655      */
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);
660
661     /*
662      * A row is selected, so we can operate on it.
663      */
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);
668     
669 }
670 #else
671
672 struct remember_data
673 {
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;
678 };
679 /* called for each selected row in the tree.
680 */
681 void remember_this_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer arg)
682 {
683     gint         *path_index;
684     color_filter_t *colorf;
685     struct remember_data *data = arg;
686     
687     gtk_tree_model_get(model, iter, 4, &colorf, -1);
688     colorf->marked = TRUE;
689         
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.*/
692     {
693       return;
694     }
695     row_selected = path_index[0];
696
697     if (row_selected == 0)
698       data->first_marked = TRUE;
699     if (row_selected == num_of_filters - 1)
700       data->last_marked = TRUE;
701
702     data->count++;
703 }
704
705 /* clear the mark on this filter */
706 static void
707 clear_mark(gpointer filter_arg, gpointer arg _U_)
708 {
709   color_filter_t *colorf = filter_arg;
710
711   colorf->marked = FALSE;
712 }
713
714 /* The gtk+2.0 version gets called for, (maybe multiple,) changes in the selection. */
715 static void
716 remember_selected_row(GtkTreeSelection *sel, gpointer color_filters)
717 {
718     GtkWidget    *button;
719     struct remember_data data;
720
721     data.first_marked = data.last_marked = FALSE;
722     data.count = 0; 
723     data.color_filters = color_filters;
724
725     g_slist_foreach(filter_list, clear_mark, NULL);
726     gtk_tree_selection_selected_foreach(sel,remember_this_row, &data);
727                                       
728     if (data.count > 0)
729     {
730       /*
731        * One or more rows are selected, so we can operate on them.
732       */
733        
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);
737       
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);
741       /*
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.
744       */
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);
749     }
750     else
751     {
752       row_selected = -1;
753
754       /*
755        * No row is selected, so we can't do operations that affect the
756        * selected row.
757       */
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);
766     }
767 }
768 #endif
769
770 #if GTK_MAJOR_VERSION < 2
771 /* A row was unselected; un-remember its row number */
772 static void
773 unremember_selected_row                 (GtkCList        *clist,
774                                          gint             row _U_,
775                                          gint             column _U_,
776                                          GdkEvent        *event _U_,
777                                          gpointer         user_data _U_)
778 {
779   GtkWidget *button;
780   color_filter_t *colorf;
781
782   row_selected = -1;
783
784   colorf = gtk_clist_get_row_data(clist, row);
785   colorf->marked = FALSE;
786
787   if (color_marked_count() == 0)
788   {
789     /*
790      * No row is selected, so we can't do operations that affect the
791      * selected row.
792      */
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);
801   }
802 }
803 #endif
804
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
807  * dialog.
808  jjj*/
809 static void
810 color_destroy_cb                       (GtkButton       *button _U_,
811                                         gpointer         user_data _U_)
812 {
813   /* Destroy any edit dialogs we have open. */
814   g_slist_foreach(filter_list, destroy_edit_dialog_cb, NULL);
815
816   colorize_win = NULL;
817 }
818
819 static void
820 destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy _U_)
821 {
822   color_filter_t *colorf = (color_filter_t *)filter_arg;
823
824   if (colorf->edit_dialog != NULL)
825     window_destroy(colorf->edit_dialog);
826 }
827
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;
832
833 static void
834 color_add_colorf(GtkWidget *color_filters, color_filter_t *colorf)
835 {
836 #if GTK_MAJOR_VERSION < 2
837 #else
838   GtkTreeModel     *model;
839   gint              num_filters;
840   GtkTreeIter       iter;
841   GtkTreeSelection *sel;
842 #endif
843
844   add_filter_to_list(colorf, color_filters);
845
846 #if GTK_MAJOR_VERSION < 2
847
848   /* select the new row */
849   gtk_clist_select_row(GTK_CLIST(color_filters), num_of_filters - 1, -1);
850 #else
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);
857 #endif
858 }
859
860 void
861 color_add_filter_cb (color_filter_t *colorf, gpointer arg)
862 {
863   GtkWidget        *color_filters = arg;
864
865   color_add_colorf(color_filters, colorf);
866 #if GTK_MAJOR_VERSION >= 2
867   gtk_widget_grab_focus(color_filters);
868 #endif
869 }
870
871 /* Pop up an "Export color filter" dialog box. */
872 static void
873 color_import_cb(GtkButton *button, gpointer user_data )
874 {
875   GtkWidget        *color_filters;
876 #if GTK_MAJOR_VERSION >= 2
877   GtkTreeSelection *sel;
878 #endif
879
880   color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
881
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);
885 #else
886   gtk_clist_unselect_all (GTK_CLIST(color_filters));
887 #endif
888
889   file_color_import_cmd_cb(GTK_WIDGET(button), user_data);
890 }
891
892 /* Create a new filter in the list, and pop up an "Edit color filter"
893    dialog box to edit it. */
894 static void
895 create_new_color_filter(GtkButton *button, char *filter)
896 {
897   color_filter_t   *colorf;
898   GtkStyle         *style;
899   GtkWidget        *color_filters;
900 #if GTK_MAJOR_VERSION >= 2
901   GtkTreeSelection *sel;
902 #endif
903
904   color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
905
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);
909 #else
910   gtk_clist_unselect_all (GTK_CLIST(color_filters));
911 #endif
912
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! */
917
918   color_add_colorf(color_filters, colorf);
919
920   edit_color_filter_dialog(color_filters, &filt_name_entry, &filt_text_entry, TRUE);
921   
922   /* Show the (in)validity of the default filter string */
923   filter_te_syntax_check_cb(filt_text_entry);
924
925
926
927 #if GTK_MAJOR_VERSION >= 2
928   gtk_widget_grab_focus(color_filters);
929 #endif
930 }
931
932 /* Create a new filter in the list, and pop up an "Edit color filter"
933    dialog box to edit it. */
934 static void
935 color_new_cb(GtkButton *button, gpointer user_data _U_)
936 {
937   create_new_color_filter(button, "filter");
938 }
939
940 /* Pop up an "Edit color filter" dialog box to edit an existing filter. */
941 static void
942 color_props_cb(GtkButton *button, gpointer user_data _U_)
943 {
944   GtkWidget *color_filters;
945
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);
949 }
950
951 /* Delete a color from the list. */
952 static void
953 color_delete(gint row, GtkWidget  *color_filters)
954 {
955     color_filter_t *colorf;
956     
957 #if GTK_MAJOR_VERSION >= 2
958     GtkTreeModel     *model;
959     GtkTreeIter       iter;
960
961     
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);
965     
966     /* Remove this color filter from the CList displaying the
967     color filters. */
968     gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
969     num_of_filters--;
970     
971     /* Destroy any "Edit color filter" dialog boxes editing it. */
972     if (colorf->edit_dialog != NULL)
973     window_destroy(colorf->edit_dialog);
974     
975     /* Remove the color filter from the list of color filters. */
976     remove_color_filter(colorf);
977     
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);
981 #else
982     colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row);
983
984     /* Remove this color filter from the CList displaying the
985        color filters. */
986     gtk_clist_remove(GTK_CLIST(color_filters), row);
987     num_of_filters--;
988
989     /* Destroy any "Edit color filter" dialog boxes editing it. */
990     if (colorf->edit_dialog != NULL)
991         window_destroy(colorf->edit_dialog);
992
993     /* Remove the color filter from the list of color filters. */
994     remove_color_filter(colorf);
995
996 #endif
997 }
998 /* Delete the selected color from the list.*/
999 static void
1000 color_delete_cb(GtkWidget *widget, gpointer user_data _U_)
1001 {
1002   GtkWidget  *color_filters;
1003   gint row, num_filters;
1004 #if GTK_MAJOR_VERSION < 2
1005   color_filter_t *colorf;
1006 #else
1007     GtkTreeModel     *model;
1008     GtkTreeIter       iter;
1009     GtkTreeSelection *sel;
1010 #endif
1011
1012   color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
1013     
1014 #if GTK_MAJOR_VERSION < 2
1015   num_filters = num_of_filters;
1016 #else
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));
1020 #endif
1021
1022   for (row = num_filters - 1; row >= 0; row--)
1023   {
1024 #if GTK_MAJOR_VERSION < 2
1025     colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row);
1026     if (colorf->marked)
1027       color_delete (row, color_filters);
1028 #else
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);
1032 #endif
1033   }
1034 }
1035
1036 /* Save color filters to the color filter file. */
1037 static void
1038 color_save_cb(GtkButton *button _U_, gpointer user_data _U_)
1039 {
1040   if (!write_filters())
1041         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1042             "Could not open filter file: %s", strerror(errno));
1043 }
1044
1045 /* Remove all user defined color filters and revert to the global file. */
1046 static void
1047 color_clear_cmd(GtkWidget *widget)
1048 {
1049     GtkWidget * color_filters;
1050     
1051     color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
1052     
1053     while (num_of_filters > 0)
1054     {
1055         color_delete (num_of_filters-1, color_filters);
1056     }
1057
1058     if (!revert_filters())
1059         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1060             "Could not delete filter file: %s", strerror(errno));
1061
1062     /* colorize list */
1063     colorize_packets(&cfile);
1064
1065     /* Destroy the dialog box. */
1066     /* XXX: is this useful? user might want to continue with editing new colors */
1067     window_destroy(colorize_win);
1068 }
1069
1070 /* clear button: user responded to question */
1071 void color_clear_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
1072 {
1073     switch(btn) {
1074     case(ESD_BTN_CLEAR):
1075         color_clear_cmd(data);
1076         break;
1077     case(ESD_BTN_CANCEL):
1078         break;
1079     default:
1080         g_assert_not_reached();
1081     }
1082 }
1083
1084 /* clear button: ask user before really doing it */
1085 void
1086 color_clear_cb(GtkWidget *widget, gpointer data _U_) {
1087     gpointer  dialog;
1088
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?");
1094
1095     simple_dialog_set_cb(dialog, color_clear_answered_cb, widget);
1096 }
1097
1098 /* Exit dialog and apply new list of color filters to the capture. */
1099 static void
1100 color_ok_cb(GtkButton *button _U_, gpointer user_data _U_)
1101 {
1102   /* colorize list */
1103   colorize_packets(&cfile);
1104
1105   /* Destroy the dialog box. */
1106   window_destroy(colorize_win);
1107 }
1108
1109 /* Exit dialog without colorizing packets with the new list.
1110    XXX - should really undo any changes to the list.... */
1111 static void
1112 color_cancel_cb(GtkWidget *widget _U_, gpointer user_data _U_)
1113 {
1114   /* Destroy the dialog box. */
1115   window_destroy(colorize_win);
1116 }
1117
1118 /* Apply new list of color filters to the capture. */
1119 static void
1120 color_apply_cb(GtkButton *button _U_, gpointer user_data _U_)
1121 {
1122   colorize_packets(&cfile);
1123 }
1124
1125 /* Create an "Edit Color Filter" dialog for a given color filter, and
1126    associate it with that color filter. */
1127 static void
1128 edit_color_filter_dialog(GtkWidget *color_filters,
1129                          GtkWidget **colorize_filter_name,
1130                          GtkWidget **colorize_filter_text,
1131                          guchar is_new_filter)
1132 {
1133     color_filter_t *colorf;
1134     GtkWidget      *edit_dialog;
1135     GtkWidget      *dialog_vbox;
1136     GtkTooltips    *tooltips;
1137     GtkStyle       *style;
1138
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;
1146
1147     GtkWidget *colorize_fr;
1148     GtkWidget *colorize_hbox;
1149     GtkWidget *colorize_filter_fg;
1150     GtkWidget *colorize_filter_bg;
1151
1152     GtkWidget *bbox;
1153     GtkWidget *edit_color_filter_ok;
1154     GtkWidget *edit_color_filter_cancel;
1155
1156 #if GTK_MAJOR_VERSION >= 2
1157     GtkTreeModel     *model;
1158     GtkTreeIter       iter;
1159 #endif
1160
1161 #if GTK_MAJOR_VERSION >= 2
1162     model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
1163
1164     gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected);
1165     gtk_tree_model_get(model, &iter, 4, &colorf, -1);
1166
1167 #else
1168     colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row_selected);
1169 #endif
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);
1173         return;
1174     }
1175
1176     tooltips = gtk_tooltips_new ();
1177
1178     /* dialog window */
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;
1183
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);
1187
1188     /* Filter frame */
1189     filter_fr = gtk_frame_new("Filter");
1190     gtk_box_pack_start (GTK_BOX (dialog_vbox), filter_fr, FALSE, FALSE, 0);
1191
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);
1195
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);
1199
1200     color_filter_name = gtk_label_new (("Name: "));
1201     gtk_box_pack_start (GTK_BOX (filter_name_hbox), color_filter_name, FALSE, FALSE, 0);
1202
1203     *colorize_filter_name = gtk_entry_new ();
1204     gtk_entry_set_text(GTK_ENTRY(*colorize_filter_name), colorf->filter_name);
1205
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);
1210 #else
1211     color_t_to_gdkcolor(&style->text[GTK_STATE_NORMAL], &colorf->fg_color);
1212 #endif
1213     gtk_widget_set_style(*colorize_filter_name, style);
1214
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);
1217
1218
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);
1222
1223     color_filter_text = gtk_label_new (("String: "));
1224     gtk_box_pack_start (GTK_BOX (filter_string_hbox), color_filter_text, FALSE, FALSE, 0);
1225
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);
1229
1230 #if 0
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;
1234 #endif
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);
1238
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);
1245
1246
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);
1250
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);
1254
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);
1258
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);
1262
1263
1264     /* button box */
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);
1268
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);
1271
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);
1274
1275     gtk_widget_grab_default(edit_color_filter_ok);
1276
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);
1287
1288     /* set callback to delete new filters if cancel chosen */
1289     if (is_new_filter)
1290     {
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);
1294     }
1295     /* escape will select cancel */
1296     window_set_cancel_button(edit_dialog, edit_color_filter_cancel, window_cancel_button_cb);
1297
1298     SIGNAL_CONNECT(edit_dialog, "delete_event", window_delete_event_cb, NULL);
1299
1300     gtk_widget_show_all(edit_dialog);
1301     window_present(edit_dialog);
1302 }
1303
1304 /* Called when the dialog box is being destroyed; destroy any color
1305    selection dialogs opened from this dialog, and null out the pointer
1306    to this dialog. */
1307 #if GTK_MAJOR_VERSION < 2
1308 static void
1309 edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data _U_)
1310 #else
1311 static void
1312 edit_color_filter_destroy_cb(GObject *object, gpointer user_data _U_)
1313 #endif
1314 {
1315   color_filter_t *colorf;
1316   GtkWidget *color_sel;
1317
1318   colorf = (color_filter_t *)OBJECT_GET_DATA(object, COLOR_FILTER);
1319   colorf->edit_dialog = NULL;
1320
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);
1328 }
1329
1330 /* Pop up a color selection box to choose the foreground color. */
1331 static void
1332 edit_color_filter_fg_cb(GtkButton *button, gpointer user_data _U_)
1333 {
1334   color_filter_t *colorf;
1335   GtkWidget *color_selection_fg;
1336
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);
1343   } else {
1344     /* No.  Create a new color selection box, and associate it with
1345        this dialog. */
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);
1349   }
1350 }
1351
1352 /* Pop up a color selection box to choose the background color. */
1353 static void
1354 edit_color_filter_bg_cb                (GtkButton       *button,
1355                                         gpointer         user_data _U_)
1356 {
1357   color_filter_t *colorf;
1358   GtkWidget *color_selection_bg;
1359
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);
1366   } else {
1367     /* No.  Create a new color selection box, and associate it with
1368        this dialog. */
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);
1372   }
1373 }
1374
1375 /* accept color (and potential content) change */
1376 static void
1377 edit_color_filter_ok_cb                (GtkButton       *button,
1378                                         gpointer         user_data)
1379 {
1380     GtkWidget      *dialog;
1381     GtkStyle       *style;
1382     GdkColor        new_fg_color;
1383     GdkColor        new_bg_color;
1384     gchar          *filter_name;
1385     gchar          *filter_text;
1386     color_filter_t *colorf;
1387     dfilter_t      *compiled_filter;
1388     GtkWidget      *color_filters;
1389 #if GTK_MAJOR_VERSION >= 2
1390     GtkTreeModel   *model;
1391     GtkTreeIter     iter;
1392     gchar           fg_str[14], bg_str[14];
1393 #endif
1394
1395     dialog = (GtkWidget *)user_data;
1396
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];
1401 #else
1402     new_fg_color = style->text[GTK_STATE_NORMAL];
1403 #endif
1404
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)));
1407
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);
1414         return;
1415     }
1416
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,
1421                       dfilter_error_msg);
1422     } else {
1423         color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL);
1424         colorf = (color_filter_t *)OBJECT_GET_DATA(button, COLOR_FILTER);
1425
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,
1436                                  &new_fg_color);
1437         gtk_clist_set_background(GTK_CLIST(color_filters), row_selected,
1438                                  &new_bg_color);
1439 #else
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);
1448 #endif
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,
1455                            filter_name);
1456         gtk_clist_set_text(GTK_CLIST(color_filters), row_selected, 1,
1457                            filter_text);
1458 #endif
1459
1460         /* Destroy the dialog box. */
1461         window_destroy(dialog);
1462     }
1463 }
1464
1465 /* reject new color filter addition */
1466 static void
1467 edit_new_color_filter_cancel_cb(GtkButton *button, gpointer user_data _U_)
1468 {
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));
1471 }
1472
1473 static GtkWidget*
1474 color_sel_win_new(color_filter_t *colorf, gboolean is_bg)
1475 {
1476   gchar *title;
1477   GtkWidget *color_sel_win;
1478   color_t   *color;
1479 #if GTK_MAJOR_VERSION >= 2
1480   GdkColor   gcolor;
1481 #endif
1482   GtkWidget *color_sel_ok;
1483   GtkWidget *color_sel_cancel;
1484   GtkWidget *color_sel_help;
1485
1486   if (is_bg) {
1487     color = &colorf->bg_color;
1488     title = g_strdup_printf("Ethereal: Choose background color for \"%s\"",
1489         colorf->filter_name);
1490   } else {
1491     color = &colorf->fg_color;
1492     title = g_strdup_printf("Ethereal: Choose foreground color for \"%s\"", 
1493         colorf->filter_name);
1494   }
1495   color_sel_win = gtk_color_selection_dialog_new(title);
1496   g_free(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);
1499
1500   if (color != NULL) {
1501 #if GTK_MAJOR_VERSION < 2
1502     gdouble cols[3];
1503
1504     cols[0] = (gdouble)color->red / 65536.0;
1505     cols[1] = (gdouble)color->green / 65536.0;
1506     cols[2] = (gdouble)color->blue / 65536.0;
1507
1508     gtk_color_selection_set_color(
1509                     GTK_COLOR_SELECTION(
1510                             GTK_COLOR_SELECTION_DIALOG(color_sel_win)->colorsel), cols);
1511 #else
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);
1516 #endif
1517   }
1518
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);
1522
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);
1526
1527
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);
1530
1531
1532   GTK_WIDGET_SET_FLAGS (color_sel_help, GTK_CAN_DEFAULT);
1533
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);
1536
1537   gtk_widget_show_all(color_sel_win);
1538   return color_sel_win;
1539 }
1540
1541 static void
1542 color_sel_win_destroy(GtkWidget *sel_win)
1543 {
1544   GtkWidget *parent;
1545   GtkWidget *color_selection_fg, *color_selection_bg;
1546
1547   /* Find the "Edit color filter" dialog box with which this is associated. */
1548   parent = (GtkWidget *)OBJECT_GET_DATA(sel_win, COLOR_SELECTION_PARENT);
1549
1550   /* Find that dialog box's foreground and background color selection
1551      boxes, if any. */
1552   color_selection_fg = OBJECT_GET_DATA(parent, COLOR_SELECTION_FG);
1553   color_selection_bg = OBJECT_GET_DATA(parent, COLOR_SELECTION_BG);
1554
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);
1558   }
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);
1562   }
1563
1564   /* Now destroy it. */
1565   window_destroy(sel_win);
1566 }
1567
1568 /* Retrieve selected color */
1569 static void
1570 color_sel_ok_cb                        (GtkButton       *button _U_,
1571                                         gpointer         user_data)
1572 {
1573   GdkColor new_color; /* Color from color selection dialog */
1574 #if GTK_MAJOR_VERSION < 2
1575   gdouble new_colors[3];
1576 #endif
1577   GtkWidget *color_dialog;
1578   GtkStyle  *style;
1579   GtkWidget *parent;
1580   GtkWidget *color_selection_fg, *color_selection_bg;
1581   gboolean is_bg;
1582
1583   color_dialog = (GtkWidget *)user_data;
1584
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);
1588
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);
1592 #else
1593   gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(
1594    GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &new_color);
1595 #endif
1596
1597   if ( ! get_color(&new_color) ){
1598         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1599                       "Could not allocate color.  Try again.");
1600   } else {
1601         /* Find the "Edit color filter" dialog box with which this is
1602            associated. */
1603         parent = (GtkWidget *)OBJECT_GET_DATA(color_dialog, COLOR_SELECTION_PARENT);
1604
1605         /* Find that dialog box's foreground and background color selection
1606            boxes, if any. */
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);
1610
1611         color_sel_win_destroy(color_dialog);
1612
1613         /* now apply the change to the fore/background */
1614
1615         style = gtk_style_copy(gtk_widget_get_style(filt_name_entry));
1616         if (is_bg)
1617           style->base[GTK_STATE_NORMAL] = new_color;
1618 #if GTK_MAJOR_VERSION < 2
1619         else
1620           style->fg[GTK_STATE_NORMAL] = new_color;
1621 #else
1622         else
1623           style->text[GTK_STATE_NORMAL] = new_color;
1624 #endif
1625         gtk_widget_set_style(filt_name_entry, style);
1626         gtk_widget_set_style(filt_text_entry, style);
1627   }
1628 }
1629
1630 /* Don't choose the selected color as the foreground or background
1631    color for the filter. */
1632 static void
1633 color_sel_cancel_cb                    (GtkObject       *object _U_,
1634                                         gpointer         user_data)
1635 {
1636   GtkWidget *color_dialog;
1637   color_dialog = (GtkWidget *)user_data;
1638   /* nothing to change here.  Just get rid of the dialog box. */
1639
1640   color_sel_win_destroy(color_dialog);
1641 }