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