aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/color_dlg.c
blob: e9c103e4e7f8acc95bca229e1e3c5a267cd13bcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
/* color_dlg.c
 * Definitions for dialog boxes for color filters
 *
 * $Id: color_dlg.c,v 1.15 2002/08/02 22:34:53 jmayer Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <gtk/gtk.h>

#include <stdlib.h>
#include <string.h>

#include <errno.h>

#include "gtk/main.h"
#include <epan/packet.h>
#include "colors.h"
#include "color_dlg.h"
#include "file.h"
#include <epan/dfilter/dfilter.h>
#include "simple_dialog.h"
#include "dlg_utils.h"
#include "ui_util.h"
#include "dfilter_expr_dlg.h"


static GtkWidget* colorize_dialog_new(void);
static void add_filter_to_clist(gpointer filter_arg, gpointer clist_arg);
static void color_filter_up_cb(GtkButton *button, gpointer user_data);
static void color_filter_down_cb(GtkButton *button, gpointer user_data);
static void remember_selected_row(GtkCList *clist, gint row, gint column,
				 GdkEvent *event, gpointer user_data);
static void unremember_selected_row(GtkCList *clist, gint row, gint column,
				 GdkEvent *event, gpointer user_data);
static void color_destroy_cb(GtkButton *button, gpointer user_data);
static void destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy);
static void color_new_cb(GtkButton *button, gpointer user_data);
static void color_edit_cb(GtkButton *button, gpointer user_data);
static void color_delete_cb(GtkWidget *widget, gpointer user_data);
static void color_save_cb(GtkButton *button, gpointer user_data);
static void color_ok_cb(GtkButton *button, gpointer user_data);
static void color_cancel_cb(GtkWidget *widget, gpointer user_data);
static void color_apply_cb(GtkButton *button, gpointer user_data);

static void edit_color_filter_dialog_new(GtkWidget *color_filters,
				 GtkWidget **colorize_filter_name,
				 GtkWidget **colorize_filter_text);
static void edit_color_filter_destroy_cb(GtkObject *object,
				 gpointer user_data);
static void edit_color_filter_fg_cb(GtkButton *button, gpointer user_data);
static void edit_color_filter_bg_cb(GtkButton *button, gpointer user_data);
static void edit_color_filter_ok_cb(GtkButton *button, gpointer user_data);
static void edit_color_filter_cancel_cb(GtkObject *object, gpointer user_data);

static GtkWidget* color_sel_win_new(color_filter_t *colorf, gboolean);
static void color_sel_ok_cb(GtkButton *button, gpointer user_data);
static void color_sel_cancel_cb(GtkObject *object, gpointer user_data);

static GtkWidget *colorize_win;
static gint	  num_of_filters;  /* number of filters being displayed */
static gint	  row_selected;	   /* row in color_filters that is selected */

static gchar *titles[2] = { "Name", "Filter String" };

#define COLOR_UP_LB		"color_up_lb"
#define COLOR_DOWN_LB		"color_down_lb"
#define COLOR_EDIT_LB		"color_edit_lb"
#define COLOR_DELETE_LB		"color_delete_lb"
#define COLOR_FILTERS_CL	"color_filters_cl"
#define COLOR_FILTER		"color_filter"
#define COLOR_SELECTION_FG	"color_selection_fg"
#define COLOR_SELECTION_BG	"color_selection_bg"
#define COLOR_SELECTION_PARENT	"color_selection_parent"

static void
filter_expr_cb(GtkWidget *w _U_, gpointer filter_te)
{

        dfilter_expr_dlg_new(GTK_WIDGET(filter_te));
}


/* Callback for the "Display:Colorize Display" menu item. */
void
color_display_cb(GtkWidget *w _U_, gpointer d _U_)
{
  if (colorize_win != NULL) {
    /* There's already a color dialog box active; reactivate it. */
    reactivate_window(colorize_win);
  } else {
    /* Create a new "Colorize Display" dialog. */
    colorize_win = colorize_dialog_new();
  }
}

/* Create the "Add color to protocols" dialog. */
static GtkWidget*
colorize_dialog_new (void)
{
  GtkWidget *color_win;
  GtkWidget *vbox1;
  GtkWidget *hbox1;
  GtkWidget *vbox2;
  GtkWidget *vbox4;
  GtkWidget *color_filter_up;
  GtkWidget *label4;
  GtkWidget *color_filter_down;
  GtkWidget *scrolledwindow1;
  GtkWidget *color_filters;
  GtkWidget *color_new;
  GtkWidget *color_edit;
  GtkWidget *color_delete;
  GtkWidget *color_save;
  GtkWidget *hbox3;
  GtkWidget *color_ok;
  GtkWidget *color_apply;
  GtkWidget *color_cancel;
  GtkTooltips *tooltips;

  row_selected = -1; /* no row selected */
  tooltips = gtk_tooltips_new ();

  color_win = dlg_window_new ("Add color to protocols");
  gtk_object_set_data (GTK_OBJECT (color_win), "color_win", color_win);

  vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_widget_ref (vbox1);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "vbox1", vbox1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox1);
  gtk_container_add (GTK_CONTAINER (color_win), vbox1);

  hbox1 = gtk_hbox_new (FALSE, 0);
  gtk_widget_ref (hbox1);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "hbox1", hbox1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox1);
  gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);

  /* vbox2 holds the Up and Down Buttons and label */
  vbox2 = gtk_vbox_new (TRUE, 0);
  gtk_widget_ref (vbox2);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "vbox2", vbox2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox2);
  gtk_box_pack_start (GTK_BOX (hbox1), vbox2, FALSE, TRUE, 0);
  gtk_widget_set_usize (vbox2, 150, -2);

  color_filter_up = gtk_button_new_with_label (("Up"));
  gtk_widget_ref (color_filter_up);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "color_filter_up", color_filter_up,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_filter_up);
  gtk_box_pack_start (GTK_BOX (vbox2), color_filter_up, FALSE, FALSE, 0);
  gtk_tooltips_set_tip (tooltips, color_filter_up, ("Move filter higher in list"), NULL);
  gtk_widget_set_sensitive (color_filter_up, FALSE);

  label4 = gtk_label_new (("Move filter\nup or down\n[List is processed \n"
			  "in order until\nmatch is found]"));
  gtk_widget_ref (label4);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "label4", label4,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (label4);
  gtk_box_pack_start (GTK_BOX (vbox2), label4, FALSE, FALSE, 0);

  color_filter_down = gtk_button_new_with_label (("Down"));
  gtk_widget_ref (color_filter_down);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "color_filter_down", color_filter_down,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_filter_down);
  gtk_box_pack_start (GTK_BOX (vbox2), color_filter_down, FALSE, FALSE, 0);
  gtk_tooltips_set_tip (tooltips, color_filter_down, ("Move filter lower in list"), NULL);
  gtk_widget_set_sensitive (color_filter_down, FALSE);
  /* End vbox2 */

  /* create the list of filters */
  scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_ref (scrolledwindow1);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "scrolledwindow1", scrolledwindow1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (scrolledwindow1);
  gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow1, TRUE, TRUE, 0);

  color_filters = gtk_clist_new_with_titles(2, titles);

  num_of_filters = 0;
  g_slist_foreach(filter_list, add_filter_to_clist, color_filters);

  gtk_widget_show (color_filters);
  gtk_container_add (GTK_CONTAINER (scrolledwindow1), color_filters);
  gtk_widget_set_usize (color_filters, 300, -2);
  gtk_clist_set_column_width (GTK_CLIST (color_filters), 0, 80);
  gtk_clist_set_column_width (GTK_CLIST (color_filters), 1, 80);
  gtk_clist_column_titles_show (GTK_CLIST (color_filters));
  /* end list of filters */

  /* vbox4 is first button column */
  vbox4 = gtk_vbox_new (FALSE, 0);
  gtk_widget_ref (vbox4);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "vbox4", vbox4,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox4);
  gtk_box_pack_start (GTK_BOX (hbox1), vbox4, TRUE, FALSE, 5);
#if 0
  gtk_widget_set_usize (vbox4, -2, 30);
#endif

  color_new = gtk_button_new_with_label (("New"));
  gtk_widget_ref (color_new);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "color_new", color_new,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_new);
  gtk_box_pack_start (GTK_BOX (vbox4), color_new, FALSE, FALSE, 5);
  gtk_widget_set_usize (color_new, 50, 20);
  gtk_tooltips_set_tip (tooltips, color_new, ("Create a new colorization filter after selected filter"), NULL);

  color_edit = gtk_button_new_with_label (("Edit"));
  gtk_widget_ref (color_edit);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "color_edit", color_edit,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_edit);
  gtk_widget_set_usize(color_edit, 50, 20);
  gtk_box_pack_start (GTK_BOX (vbox4), color_edit, FALSE, FALSE, 5);
  gtk_tooltips_set_tip (tooltips, color_edit, ("Change color of selected filter"), NULL);
  gtk_widget_set_sensitive (color_edit, FALSE);

  color_delete = gtk_button_new_with_label (("Delete"));
  gtk_widget_ref (color_delete);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "color_delete", color_delete,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_delete);
  gtk_box_pack_start (GTK_BOX (vbox4), color_delete, FALSE, FALSE, 5);
  gtk_widget_set_usize (color_delete, 50, 20);
  gtk_tooltips_set_tip (tooltips, color_delete, ("Delete selected colorization filter"), NULL);
  gtk_widget_set_sensitive (color_delete, FALSE);

  color_save = gtk_button_new_with_label (("Save"));
  gtk_widget_ref (color_save);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "color_save", color_save,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_save);
  gtk_box_pack_start (GTK_BOX (vbox4), color_save, FALSE, FALSE, 5);
  gtk_widget_set_usize (color_save, 50, 20);
  gtk_tooltips_set_tip (tooltips, color_save, ("Save all filters to disk"), NULL);

  /* hbox3 is bottom button row */
  hbox3 = gtk_hbox_new (FALSE, 0);
  gtk_widget_ref (hbox3);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "hbox3", hbox3,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox3);
  gtk_box_pack_start (GTK_BOX (vbox1), hbox3, TRUE, FALSE, 5);
  gtk_widget_set_usize (hbox3, 177, 30);

  color_ok = gtk_button_new_with_label (("OK"));
  gtk_widget_ref (color_ok);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "color_ok", color_ok,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_ok);
  gtk_box_pack_start (GTK_BOX (hbox3), color_ok, TRUE, FALSE, 0);
  gtk_widget_set_usize (color_ok, 50, 20);
  gtk_tooltips_set_tip (tooltips, color_ok, ("Accept filter list; apply changes"), NULL);

  color_apply = gtk_button_new_with_label (("Apply"));
  gtk_widget_ref (color_apply);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "color_apply", color_apply,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_apply);
  gtk_box_pack_start (GTK_BOX (hbox3), color_apply, TRUE, FALSE, 0);
  gtk_widget_set_usize (color_apply, 50, 20);
  gtk_tooltips_set_tip (tooltips, color_apply, ("Apply filters in list"), NULL);

  color_cancel = gtk_button_new_with_label (("Cancel"));
  gtk_widget_ref (color_cancel);
  gtk_object_set_data_full (GTK_OBJECT (color_win), "color_cancel", color_cancel,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_cancel);
  gtk_box_pack_start (GTK_BOX (hbox3), color_cancel, TRUE, FALSE, 0);
  gtk_widget_set_usize (color_cancel, 50, 20);
  gtk_tooltips_set_tip (tooltips, color_cancel, ("No more filter changes; don't apply"), NULL);

  gtk_signal_connect (GTK_OBJECT (color_win), "destroy",
                      GTK_SIGNAL_FUNC (color_destroy_cb),
                      NULL);
  gtk_object_set_data(GTK_OBJECT (color_filter_up), COLOR_FILTERS_CL,
                      color_filters);
  gtk_signal_connect (GTK_OBJECT (color_filter_up), "clicked",
                      GTK_SIGNAL_FUNC (color_filter_up_cb),
                      NULL);
  gtk_object_set_data(GTK_OBJECT (color_filter_down), COLOR_FILTERS_CL,
                      color_filters);
  gtk_signal_connect (GTK_OBJECT (color_filter_down), "clicked",
                      GTK_SIGNAL_FUNC (color_filter_down_cb),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (color_filters), "select_row",
                      GTK_SIGNAL_FUNC (remember_selected_row),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (color_filters), "unselect_row",
                      GTK_SIGNAL_FUNC (unremember_selected_row),
                      NULL);
  gtk_object_set_data(GTK_OBJECT (color_filters), COLOR_UP_LB,
                      color_filter_up);
  gtk_object_set_data(GTK_OBJECT (color_filters), COLOR_DOWN_LB,
                      color_filter_down);
  gtk_object_set_data(GTK_OBJECT (color_filters), COLOR_EDIT_LB,
                      color_edit);
  gtk_object_set_data(GTK_OBJECT (color_filters), COLOR_DELETE_LB,
                      color_delete);
  gtk_object_set_data(GTK_OBJECT (color_new), COLOR_FILTERS_CL,
                      color_filters);
  gtk_signal_connect (GTK_OBJECT (color_new), "clicked",
                      GTK_SIGNAL_FUNC (color_new_cb),
                      NULL);
  gtk_object_set_data(GTK_OBJECT (color_edit), COLOR_FILTERS_CL,
                      color_filters);
  gtk_signal_connect (GTK_OBJECT (color_edit), "clicked",
                      GTK_SIGNAL_FUNC (color_edit_cb),
                      NULL);
  gtk_object_set_data(GTK_OBJECT (color_delete), COLOR_EDIT_LB,
                      color_edit);
  gtk_object_set_data(GTK_OBJECT (color_delete), COLOR_FILTERS_CL,
                      color_filters);
  gtk_signal_connect (GTK_OBJECT (color_delete), "clicked",
                      GTK_SIGNAL_FUNC (color_delete_cb),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (color_save), "clicked",
                      GTK_SIGNAL_FUNC (color_save_cb),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (color_ok), "clicked",
                      GTK_SIGNAL_FUNC (color_ok_cb),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (color_apply), "clicked",
                      GTK_SIGNAL_FUNC (color_apply_cb),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (color_cancel), "clicked",
                      GTK_SIGNAL_FUNC (color_cancel_cb),
                      NULL);

  gtk_widget_grab_focus (color_filters);
  gtk_object_set_data (GTK_OBJECT (color_win), "tooltips", tooltips);
  gtk_widget_show (color_win);

  dlg_set_cancel(color_win, color_cancel);

  return color_win;
}

static void
add_filter_to_clist(gpointer filter_arg, gpointer clist_arg)
{
  color_filter_t *colorf = filter_arg;
  GtkWidget *color_filters = clist_arg;
  gchar *data[2];
  gint row;

  data[0] = colorf->filter_name;
  data[1] = colorf->filter_text;
  row = gtk_clist_append(GTK_CLIST(color_filters), data);
  gtk_clist_set_row_data(GTK_CLIST(color_filters), row, colorf);
  gtk_clist_set_foreground(GTK_CLIST(color_filters), row, &colorf->fg_color);
  gtk_clist_set_background(GTK_CLIST(color_filters), row, &colorf->bg_color);
  num_of_filters++;
}

/* Move the selected filter up in the list */
static void
color_filter_up_cb                     (GtkButton       *button,
                                        gpointer         user_data _U_)
{
  gint filter_number;
  GtkWidget *color_filters;
  color_filter_t *colorf;

  filter_number = row_selected;
  g_assert(filter_number > 0);

  color_filters = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(button),
		      COLOR_FILTERS_CL);
  colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
  gtk_clist_swap_rows(GTK_CLIST(color_filters), filter_number, filter_number-1);

  /*
   * That row is still selected, but it's now row N-1.
   */
  remember_selected_row(GTK_CLIST(color_filters), filter_number-1, 0, NULL,
      NULL);

  filter_list = g_slist_remove(filter_list, colorf);
  filter_list = g_slist_insert(filter_list, colorf, filter_number-1);
}

/* Move the selected filter down in the list */
static void
color_filter_down_cb                   (GtkButton       *button,
                                        gpointer         user_data _U_)
{
  gint filter_number;
  GtkWidget *color_filters;
  color_filter_t *colorf;

  filter_number = row_selected;
  g_assert(filter_number < num_of_filters - 1);

  color_filters = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(button),
		      COLOR_FILTERS_CL);
  colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
  gtk_clist_swap_rows(GTK_CLIST(color_filters), filter_number+1, filter_number);

  /*
   * That row is still selected, but it's now row N+1.
   */
  remember_selected_row(GTK_CLIST(color_filters), filter_number+1, 0, NULL,
      NULL);

  filter_list = g_slist_remove(filter_list, colorf);
  filter_list = g_slist_insert(filter_list, colorf, filter_number+1);
}

/* A row was selected; remember its row number */
static void
remember_selected_row                 (GtkCList        *clist,
                                        gint             row,
                                        gint             column _U_,
                                        GdkEvent        *event _U_,
                                        gpointer         user_data _U_)
{
  GtkWidget *button;

  row_selected = row;

  /*
   * A row is selected, so we can move it up *if* it's not at the top
   * and move it down *if* it's not at the bottom.
   */
  button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(clist),
					    COLOR_UP_LB);
  gtk_widget_set_sensitive (button, row > 0);
  button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(clist),
					    COLOR_DOWN_LB);
  gtk_widget_set_sensitive (button, row < num_of_filters - 1);

  /*
   * A row is selected, so we can operate on it.
   */
  button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(clist),
					    COLOR_EDIT_LB);
  gtk_widget_set_sensitive (button, TRUE);
  button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(clist),
					    COLOR_DELETE_LB);
  gtk_widget_set_sensitive (button, TRUE);
}

/* A row was unselected; un-remember its row number */
static void
unremember_selected_row                 (GtkCList        *clist,
                                         gint             row _U_,
                                         gint             column _U_,
                                         GdkEvent        *event _U_,
                                         gpointer         user_data _U_)
{
  GtkWidget *button;

  row_selected = -1;

  /*
   * No row is selected, so we can't do operations that affect the
   * selected row.
   */
  button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(clist),
					    COLOR_UP_LB);
  gtk_widget_set_sensitive (button, FALSE);
  button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(clist),
					    COLOR_DOWN_LB);
  gtk_widget_set_sensitive (button, FALSE);
  button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(clist),
					    COLOR_EDIT_LB);
  gtk_widget_set_sensitive (button, FALSE);
  button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(clist),
					    COLOR_DELETE_LB);
  gtk_widget_set_sensitive (button, FALSE);
}

/* Called when the dialog box is being destroyed; destroy any edit
 * dialogs opened from this dialog, and null out the pointer to this
 * dialog.
 jjj*/
static void
color_destroy_cb                       (GtkButton       *button _U_,
                                        gpointer         user_data _U_)
{
  /* Destroy any edit dialogs we have open. */
  g_slist_foreach(filter_list, destroy_edit_dialog_cb, NULL);

  colorize_win = NULL;
}

static void
destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy _U_)
{
  color_filter_t *colorf = (color_filter_t *)filter_arg;

  if (colorf->edit_dialog != NULL)
    gtk_widget_destroy(colorf->edit_dialog);
}

/* XXX - we don't forbid having more than one "Edit color filter" dialog
   open, so these shouldn't be static. */
static GtkWidget *filt_name_entry;
static GtkWidget *filt_text_entry;

/* Create a new filter in the list, and pop up an "Edit color filter"
   dialog box to edit it. */
static void
color_new_cb                          (GtkButton       *button,
                                       gpointer         user_data _U_)
{
  color_filter_t *colorf;
  GtkWidget *color_filters;
  gchar *data[2];
  gint row;

  colorf = new_color_filter("name", "filter"); /* Adds at end! */

  color_filters = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(button),
		      COLOR_FILTERS_CL);
  data[0] = colorf->filter_name;
  data[1] = colorf->filter_text;
  row = gtk_clist_append(GTK_CLIST(color_filters), data);
  gtk_clist_set_row_data(GTK_CLIST(color_filters), row, colorf);
  num_of_filters++;

  /* select the new row */
  gtk_clist_select_row(GTK_CLIST(color_filters), row, -1);
  edit_color_filter_dialog_new(color_filters, &filt_name_entry,
				&filt_text_entry);
}

/* Pop up an "Edit color filter" dialog box to edit an existing filter. */
static void
color_edit_cb                        (GtkButton       *button,
                                      gpointer         user_data _U_)
{
  GtkWidget *color_filters;

  color_filters = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(button),
		      COLOR_FILTERS_CL);
  g_assert(row_selected != -1);
  edit_color_filter_dialog_new(color_filters, &filt_name_entry,
				&filt_text_entry);
}

/* Delete a color from the list. */
static void
color_delete_cb(GtkWidget *widget, gpointer user_data _U_)
{
  GtkWidget *color_filters;
  color_filter_t *colorf;

  if(row_selected != -1){
  	color_filters = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(widget),
		      COLOR_FILTERS_CL);
  	colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row_selected);

	/* Remove this color filter from the CList displaying the
	   color filters. */
	gtk_clist_remove(GTK_CLIST(color_filters), row_selected);
	num_of_filters--;

	/* Destroy any "Edit color filter" dialog boxes editing it. */
	if (colorf->edit_dialog != NULL)
		gtk_widget_destroy(colorf->edit_dialog);

	/* Remove the color filter from the list of color filters. */
	delete_color_filter(colorf);

	/* Select the previous row, if there is one. */
	if (row_selected > 0) {
		row_selected--;
		gtk_clist_select_row(GTK_CLIST(color_filters), row_selected, 0);
	}
  }
}

/* Save color filters to the color filter file. */
static void
color_save_cb                          (GtkButton       *button _U_,
                                        gpointer         user_data _U_)
{
  if (!write_filters())
	simple_dialog(ESD_TYPE_CRIT, NULL, "Could not open filter file: %s",
	    strerror(errno));

}

/* Exit dialog and apply new list of color filters to the capture. */
static void
color_ok_cb                            (GtkButton       *button _U_,
                                        gpointer         user_data _U_)
{
  /* colorize list */
  colorize_packets(&cfile);

  /* Destroy the dialog box. */
  gtk_widget_destroy(colorize_win);
}

/* Exit dialog without colorizing packets with the new list.
   XXX - should really undo any changes to the list.... */
static void
color_cancel_cb                        (GtkWidget       *widget _U_,
                                        gpointer         user_data _U_)
{
  /* Destroy the dialog box. */
  gtk_widget_destroy(colorize_win);
}

/* Apply new list of color filters to the capture. */
static void
color_apply_cb                         (GtkButton       *button _U_,
                                        gpointer         user_data _U_)
{
  colorize_packets(&cfile);
}

/* Create an "Edit color filter" dialog for a given color filter, and
   associate it with that color filter. */
static void
edit_color_filter_dialog_new (GtkWidget *color_filters,
	GtkWidget **colorize_filter_name,
	GtkWidget **colorize_filter_text)
{
  color_filter_t *colorf;
  GtkWidget *edit_dialog;
  GtkWidget *vbox3;
  GtkWidget *hbox6;
  GtkWidget *color_filter_name;
  GtkWidget *hbox7;
  GtkWidget *add_expression_bt;
  GtkWidget *color_filter_text;
  GtkWidget *hbox5;
  GtkWidget *colorize_filter_fg;
  GtkWidget *colorize_filter_bg;
  GtkWidget *hbox4;
  GtkWidget *edit_color_filter_ok;
  GtkWidget *edit_color_filter_cancel;
  GtkTooltips *tooltips;
  GtkStyle  *style;

  colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row_selected);
  if (colorf->edit_dialog != NULL) {
    /* There's already an edit box open for this filter; reactivate it. */
    reactivate_window(colorf->edit_dialog);
    return;
  }

  tooltips = gtk_tooltips_new ();

  edit_dialog = dlg_window_new ("Edit color filter");
  gtk_object_set_data (GTK_OBJECT (edit_dialog), "edit_dialog", edit_dialog);
  colorf->edit_dialog = edit_dialog;

  vbox3 = gtk_vbox_new (FALSE, 0);
  gtk_widget_ref (vbox3);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "vbox3", vbox3,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox3);
  gtk_container_add (GTK_CONTAINER (edit_dialog), vbox3);

  hbox6 = gtk_hbox_new (FALSE, 0);
  gtk_widget_ref (hbox6);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "hbox6", hbox6,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox6);
  gtk_box_pack_start (GTK_BOX (vbox3), hbox6, TRUE, FALSE, 5);

  color_filter_name = gtk_label_new (("Name: "));
  gtk_widget_ref (color_filter_name);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "color_filter_name", color_filter_name,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_filter_name);
  gtk_box_pack_start (GTK_BOX (hbox6), color_filter_name, FALSE, FALSE, 0);

  *colorize_filter_name = gtk_entry_new ();
  gtk_widget_ref (*colorize_filter_name);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "*colorize_filter_name", *colorize_filter_name,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_entry_set_text(GTK_ENTRY(*colorize_filter_name), colorf->filter_name);

  style = gtk_style_copy(gtk_widget_get_style(*colorize_filter_name));
  style->base[GTK_STATE_NORMAL] = colorf->bg_color;
  style->fg[GTK_STATE_NORMAL]   = colorf->fg_color;
  gtk_widget_set_style(*colorize_filter_name, style);

  gtk_widget_show (*colorize_filter_name);
  gtk_box_pack_start (GTK_BOX (hbox6), *colorize_filter_name, TRUE, TRUE, 0);
  gtk_tooltips_set_tip (tooltips, *colorize_filter_name, ("This is the editable name of the filter. (No @ characters allowed.)"), NULL);

  hbox7 = gtk_hbox_new (FALSE, 0);
  gtk_widget_ref (hbox7);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "hbox7", hbox7,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox7);
  gtk_box_pack_start (GTK_BOX (vbox3), hbox7, TRUE, FALSE, 5);

  color_filter_text = gtk_label_new (("Filter text:"));
  gtk_widget_ref (color_filter_text);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "color_filter_text", color_filter_text,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (color_filter_text);
  gtk_box_pack_start (GTK_BOX (hbox7), color_filter_text, FALSE, FALSE, 0);

  *colorize_filter_text = gtk_entry_new ();
  gtk_widget_ref (*colorize_filter_text);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "*colorize_filter_text", *colorize_filter_text,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_entry_set_text(GTK_ENTRY(*colorize_filter_text), colorf->filter_text);


#if 0
  style = gtk_style_copy(gtk_widget_get_style(*colorize_filter_text));
  style->base[GTK_STATE_NORMAL] = colorf->bg_color;
  style->fg[GTK_STATE_NORMAL]   = colorf->fg_color;
#endif
  gtk_widget_set_style(*colorize_filter_text, style);
  gtk_widget_show (*colorize_filter_text);
  gtk_box_pack_start (GTK_BOX (hbox7), *colorize_filter_text, TRUE, TRUE, 0);
  gtk_tooltips_set_tip (tooltips, *colorize_filter_text, ("This is the editable text of the filter"), NULL);

  /* Create the "Add Expression..." button, to pop up a dialog
  for constructing filter comparison expressions. */
  add_expression_bt = gtk_button_new_with_label("Add Expression...");
  gtk_signal_connect(GTK_OBJECT(add_expression_bt), "clicked",
      GTK_SIGNAL_FUNC(filter_expr_cb), *colorize_filter_text);
  gtk_box_pack_start (GTK_BOX(hbox7), add_expression_bt, FALSE, FALSE, 3);
  gtk_widget_show(add_expression_bt);

  hbox5 = gtk_hbox_new (FALSE, 0);
  gtk_widget_ref (hbox5);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "hbox5", hbox5,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox5);
  gtk_box_pack_start (GTK_BOX (vbox3), hbox5, FALSE, FALSE, 5);
  gtk_widget_set_usize (hbox5, -2, 60);

  colorize_filter_fg = gtk_button_new_with_label (("Choose \nforeground\ncolor"));
  gtk_widget_ref (colorize_filter_fg);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "colorize_filter_fg", colorize_filter_fg,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (colorize_filter_fg);
  gtk_box_pack_start (GTK_BOX (hbox5), colorize_filter_fg, TRUE, FALSE, 0);
  gtk_tooltips_set_tip (tooltips, colorize_filter_fg, ("Select color for data display"), NULL);

  colorize_filter_bg = gtk_button_new_with_label (("Choose\nbackground\ncolor"));
  gtk_widget_ref (colorize_filter_bg);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "colorize_filter_bg", colorize_filter_bg,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (colorize_filter_bg);
  gtk_box_pack_start (GTK_BOX (hbox5), colorize_filter_bg, TRUE, FALSE, 0);
  gtk_tooltips_set_tip (tooltips, colorize_filter_bg, ("Select color for data display"), NULL);

  hbox4 = gtk_hbox_new (FALSE, 0);
  gtk_widget_ref (hbox4);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "hbox4", hbox4,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox4);
  gtk_box_pack_start (GTK_BOX (vbox3), hbox4, TRUE, FALSE, 5);
  gtk_widget_set_usize (hbox4, -2, 30);

  edit_color_filter_ok = gtk_button_new_with_label (("OK"));
  gtk_widget_ref (edit_color_filter_ok);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "edit_color_filter_ok", edit_color_filter_ok,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_set_usize (edit_color_filter_ok, 50, 20);
  gtk_widget_show (edit_color_filter_ok);
  gtk_box_pack_start (GTK_BOX (hbox4), edit_color_filter_ok, TRUE, FALSE, 0);
  gtk_tooltips_set_tip (tooltips, edit_color_filter_ok, ("Accept filter color change"), NULL);

  edit_color_filter_cancel = gtk_button_new_with_label (("Cancel"));
  gtk_widget_ref (edit_color_filter_cancel);
  gtk_object_set_data_full (GTK_OBJECT (edit_dialog), "edit_color_filter_cancel", edit_color_filter_cancel,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_set_usize (edit_color_filter_cancel, 50, 20);
  gtk_widget_show (edit_color_filter_cancel);
  gtk_box_pack_start (GTK_BOX (hbox4), edit_color_filter_cancel, TRUE, FALSE, 0);
  gtk_tooltips_set_tip (tooltips, edit_color_filter_cancel, ("Reject filter color change"), NULL);
  gtk_object_set_data(GTK_OBJECT (edit_dialog), COLOR_FILTER,
                      colorf);
  gtk_signal_connect (GTK_OBJECT (edit_dialog), "destroy",
                      GTK_SIGNAL_FUNC (edit_color_filter_destroy_cb),
                      NULL);
  gtk_object_set_data(GTK_OBJECT (colorize_filter_fg), COLOR_FILTER,
                      colorf);
  gtk_signal_connect (GTK_OBJECT (colorize_filter_fg), "clicked",
                      GTK_SIGNAL_FUNC (edit_color_filter_fg_cb),
                      NULL);
  gtk_object_set_data(GTK_OBJECT (colorize_filter_bg), COLOR_FILTER,
                      colorf);
  gtk_signal_connect (GTK_OBJECT (colorize_filter_bg), "clicked",
                      GTK_SIGNAL_FUNC (edit_color_filter_bg_cb),
                      NULL);
  gtk_object_set_data(GTK_OBJECT (edit_color_filter_ok), COLOR_FILTERS_CL,
                      color_filters);
  gtk_object_set_data(GTK_OBJECT (edit_color_filter_ok), COLOR_FILTER,
                      colorf);
  gtk_signal_connect (GTK_OBJECT (edit_color_filter_ok), "clicked",
                      GTK_SIGNAL_FUNC (edit_color_filter_ok_cb),
                      edit_dialog);
  gtk_signal_connect (GTK_OBJECT (edit_color_filter_cancel), "clicked",
                      GTK_SIGNAL_FUNC (edit_color_filter_cancel_cb),
                      edit_dialog);

  gtk_object_set_data (GTK_OBJECT (edit_dialog), "tooltips", tooltips);

  dlg_set_cancel(edit_dialog, edit_color_filter_cancel);

  gtk_widget_show (edit_dialog);
}

/* Called when the dialog box is being destroyed; destroy any color
   selection dialogs opened from this dialog, and null out the pointer
   to this dialog. */
static void
edit_color_filter_destroy_cb           (GtkObject       *object,
                                        gpointer         user_data _U_)
{
  color_filter_t *colorf;
  GtkWidget *color_sel;

  colorf = (color_filter_t *) gtk_object_get_data(GTK_OBJECT(object),
		      COLOR_FILTER);

  colorf->edit_dialog = NULL;

  /* Destroy any color selection dialogs this dialog had open. */
  color_sel = (GtkWidget *) gtk_object_get_data(object, COLOR_SELECTION_FG);
  if (color_sel != NULL)
    gtk_widget_destroy(color_sel);
  color_sel = (GtkWidget *) gtk_object_get_data(object, COLOR_SELECTION_BG);
  if (color_sel != NULL)
    gtk_widget_destroy(color_sel);
}

/* Pop up a color selection box to choose the foreground color. */
static void
edit_color_filter_fg_cb                (GtkButton       *button,
                                        gpointer         user_data _U_)
{
  color_filter_t *colorf;
  GtkWidget *color_selection_fg;

  colorf = (color_filter_t *) gtk_object_get_data(GTK_OBJECT(button),
		      COLOR_FILTER);
  /* Do we already have one open for this dialog? */
  color_selection_fg = gtk_object_get_data(GTK_OBJECT (colorf->edit_dialog),
      COLOR_SELECTION_FG);
  if (color_selection_fg != NULL) {
    /* Yes.  Just reactivate it. */
    reactivate_window(color_selection_fg);
  } else {
    /* No.  Create a new color selection box, and associate it with
       this dialog. */
    color_selection_fg = color_sel_win_new(colorf, FALSE);
    gtk_object_set_data(GTK_OBJECT (colorf->edit_dialog), COLOR_SELECTION_FG,
                      color_selection_fg);
    gtk_object_set_data(GTK_OBJECT (color_selection_fg),
		COLOR_SELECTION_PARENT, colorf->edit_dialog);
  }
}

/* Pop up a color selection box to choose the background color. */
static void
edit_color_filter_bg_cb                (GtkButton       *button,
                                        gpointer         user_data _U_)
{
  color_filter_t *colorf;
  GtkWidget *color_selection_bg;

  colorf = (color_filter_t *) gtk_object_get_data(GTK_OBJECT(button),
		      COLOR_FILTER);

  /* Do we already have one open for this dialog? */
  color_selection_bg = gtk_object_get_data(GTK_OBJECT (colorf->edit_dialog),
      COLOR_SELECTION_BG);
  if (color_selection_bg != NULL) {
    /* Yes.  Just reactivate it. */
    reactivate_window(color_selection_bg);
  } else {
    /* No.  Create a new color selection box, and associate it with
       this dialog. */
    color_selection_bg = color_sel_win_new(colorf, TRUE);
    gtk_object_set_data(GTK_OBJECT (colorf->edit_dialog), COLOR_SELECTION_BG,
                      color_selection_bg);
    gtk_object_set_data(GTK_OBJECT (color_selection_bg),
		COLOR_SELECTION_PARENT, colorf->edit_dialog);
  }
}

/* accept color (and potential content) change */
static void
edit_color_filter_ok_cb                (GtkButton       *button,
                                        gpointer         user_data)
{
  GtkWidget *dialog;
  GtkStyle *style;
  GdkColor new_fg_color;
  GdkColor new_bg_color;
  gchar *filter_name;
  gchar *filter_text;
  color_filter_t *colorf;
  dfilter_t *compiled_filter;
  GtkWidget *color_filters;

  dialog = (GtkWidget *)user_data;

  style = gtk_widget_get_style(filt_name_entry);
  new_bg_color = style->base[GTK_STATE_NORMAL];
  new_fg_color = style->fg[GTK_STATE_NORMAL];

  filter_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(filt_name_entry)));
  filter_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(filt_text_entry)));

  if(strchr(filter_name,'@') || strchr(filter_text,'@')){
	simple_dialog(ESD_TYPE_CRIT, NULL, "Filter names and strings must not"
	  " use the '@' character. Filter unchanged.");
	g_free(filter_name);
  	g_free(filter_text);
	return;
  }

  if(!dfilter_compile(filter_text, &compiled_filter)) {
	simple_dialog(ESD_TYPE_CRIT, NULL, "Filter \"%s\" did not compile correctly.\n"
		" Please try again. Filter unchanged.\n%s\n", filter_name,
		dfilter_error_msg);
  } else {
	color_filters = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(button),
		      COLOR_FILTERS_CL);
        colorf = (color_filter_t *) gtk_object_get_data(GTK_OBJECT(button),
		      COLOR_FILTER);

	if (colorf->filter_name != NULL)
	    g_free(colorf->filter_name);
	colorf->filter_name = filter_name;
	if (colorf->filter_text != NULL)
	    g_free(colorf->filter_text);
	colorf->filter_text = filter_text;
	colorf->fg_color = new_fg_color;
	colorf->bg_color = new_bg_color;
	gtk_clist_set_foreground(GTK_CLIST(color_filters), row_selected,
	    &new_fg_color);
	gtk_clist_set_background(GTK_CLIST(color_filters), row_selected,
	    &new_bg_color);
	if(colorf->c_colorfilter != NULL)
	    dfilter_free(colorf->c_colorfilter);
	colorf->c_colorfilter = compiled_filter;
	/* gtk_clist_set_text frees old text (if any) and allocates new space */
	gtk_clist_set_text(GTK_CLIST(color_filters), row_selected, 0,
	    filter_name);
	gtk_clist_set_text(GTK_CLIST(color_filters), row_selected, 1,
	    filter_text);

	/* Destroy the dialog box. */
	gtk_widget_destroy(dialog);
  }
}

/* Exit dialog and do not process list */
static void
edit_color_filter_cancel_cb            (GtkObject       *object _U_,
                                        gpointer         user_data)
{
  GtkWidget *dialog;

  dialog = (GtkWidget *)user_data;

  /* Destroy the dialog box. */
  gtk_widget_destroy(dialog);
}

static GtkWidget*
color_sel_win_new(color_filter_t *colorf, gboolean is_bg)
{
  gint title_len;
  gchar *title;
  static const gchar fg_title_format[] = "Choose foreground color for \"%s\"";
  static const gchar bg_title_format[] = "Choose background color for \"%s\"";
  GtkWidget *color_sel_win;
  GdkColor *color;
  GtkWidget *color_sel_ok;
  GtkWidget *color_sel_cancel;
  GtkWidget *color_sel_help;

  if (is_bg) {
    color = &colorf->bg_color;
    title_len = strlen(bg_title_format) + strlen(colorf->filter_name);
    title = g_malloc(title_len + 1);
    sprintf(title, bg_title_format, colorf->filter_name);
  } else {
    color = &colorf->fg_color;
    title_len = strlen(fg_title_format) + strlen(colorf->filter_name);
    title = g_malloc(title_len + 1);
    sprintf(title, fg_title_format, colorf->filter_name);
  }
  color_sel_win = gtk_color_selection_dialog_new(title);
  g_free(title);
  gtk_object_set_data (GTK_OBJECT (color_sel_win), "color_sel_win", color_sel_win);
  gtk_container_set_border_width (GTK_CONTAINER (color_sel_win), 10);

  if (color != NULL) {
    gdouble cols[3];

    cols[0] = (gdouble)color->red / 65536.0;
    cols[1] = (gdouble)color->green / 65536.0;
    cols[2] = (gdouble)color->blue / 65536.0;

    gtk_color_selection_set_color(
		    GTK_COLOR_SELECTION(
			    GTK_COLOR_SELECTION_DIALOG(color_sel_win)->colorsel), cols);
  }

  color_sel_ok = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->ok_button;
  gtk_object_set_data (GTK_OBJECT (color_sel_win), "color_sel_ok", color_sel_ok);
  gtk_widget_show (color_sel_ok);
  GTK_WIDGET_SET_FLAGS (color_sel_ok, GTK_CAN_DEFAULT);

  color_sel_cancel = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->cancel_button;
  gtk_object_set_data (GTK_OBJECT (color_sel_win), "color_sel_cancel", color_sel_cancel);
  gtk_widget_show (color_sel_cancel);
  GTK_WIDGET_SET_FLAGS (color_sel_cancel, GTK_CAN_DEFAULT);


  color_sel_help = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->help_button;
  gtk_object_set_data (GTK_OBJECT (color_sel_win), "color_sel_help", color_sel_help);
  gtk_widget_show (color_sel_help);


  GTK_WIDGET_SET_FLAGS (color_sel_help, GTK_CAN_DEFAULT);
  gtk_signal_connect (GTK_OBJECT (color_sel_win), "destroy",
                      GTK_SIGNAL_FUNC (color_sel_cancel_cb),
                      color_sel_win);

  gtk_signal_connect (GTK_OBJECT (color_sel_ok), "clicked",
                      GTK_SIGNAL_FUNC (color_sel_ok_cb),
                      color_sel_win);
  gtk_signal_connect (GTK_OBJECT (color_sel_cancel), "clicked",
                      GTK_SIGNAL_FUNC (color_sel_cancel_cb),
                      color_sel_win);

  gtk_widget_show(color_sel_win);
  return color_sel_win;
}

static void
color_sel_win_destroy(GtkWidget *sel_win)
{
  GtkWidget *parent;
  GtkWidget *color_selection_fg, *color_selection_bg;

  /* Find the "Edit color filter" dialog box with which this is associated. */
  parent = (GtkWidget *)gtk_object_get_data(GTK_OBJECT (sel_win),
      COLOR_SELECTION_PARENT);

  /* Find that dialog box's foreground and background color selection
     boxes, if any. */
  color_selection_fg = gtk_object_get_data(GTK_OBJECT (parent),
      COLOR_SELECTION_FG);
  color_selection_bg = gtk_object_get_data(GTK_OBJECT (parent),
      COLOR_SELECTION_BG);

  if (sel_win == color_selection_fg) {
    /* This was its foreground color selection box; it isn't, anymore. */
    gtk_object_set_data(GTK_OBJECT (parent), COLOR_SELECTION_FG, NULL);
  }
  if (sel_win == color_selection_bg) {
    /* This was its background color selection box; it isn't, anymore. */
    gtk_object_set_data(GTK_OBJECT (parent), COLOR_SELECTION_BG, NULL);
  }

  /* Now destroy it. */
  gtk_widget_destroy(sel_win);
}

/* Retrieve selected color */
static void
color_sel_ok_cb                        (GtkButton       *button _U_,
                                        gpointer         user_data)
{
  GdkColor new_color; /* Color from color selection dialog */
  gdouble new_colors[3];
  GtkWidget *color_dialog;
  GtkStyle  *style;
  GtkWidget *parent;
  GtkWidget *color_selection_fg, *color_selection_bg;
  gboolean is_bg;

  color_dialog = (GtkWidget *)user_data;

  gtk_color_selection_get_color(GTK_COLOR_SELECTION(
   GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), new_colors);

  new_color.red   = (guint16)(new_colors[0]*65535.0);
  new_color.green = (guint16)(new_colors[1]*65535.0);
  new_color.blue  = (guint16)(new_colors[2]*65535.0);

  if ( ! get_color(&new_color) ){
	simple_dialog(ESD_TYPE_CRIT, NULL, "Could not allocate color.  Try again.");
  } else {
	/* Find the "Edit color filter" dialog box with which this is
	   associated. */
	parent = (GtkWidget *)gtk_object_get_data(GTK_OBJECT (color_dialog),
	      COLOR_SELECTION_PARENT);

	/* Find that dialog box's foreground and background color selection
	   boxes, if any. */
	color_selection_fg = gtk_object_get_data(GTK_OBJECT (parent),
	      COLOR_SELECTION_FG);
	color_selection_bg = gtk_object_get_data(GTK_OBJECT (parent),
	      COLOR_SELECTION_BG);
	is_bg = (color_dialog == color_selection_bg);

	color_sel_win_destroy(color_dialog);

	/* now apply the change to the fore/background */
	
	style = gtk_style_copy(gtk_widget_get_style(filt_name_entry));
	if (is_bg)
	  style->base[GTK_STATE_NORMAL] = new_color;
	else
	  style->fg[GTK_STATE_NORMAL] = new_color;
	gtk_widget_set_style(filt_name_entry, style);
	gtk_widget_set_style(filt_text_entry, style);	
  }
}

/* Don't choose the selected color as the foreground or background
   color for the filter. */
static void
color_sel_cancel_cb                    (GtkObject       *object _U_,
                                        gpointer         user_data)
{
  GtkWidget *color_dialog;
  color_dialog = (GtkWidget *)user_data;
  /* nothing to change here.  Just get rid of the dialog box. */

  color_sel_win_destroy(color_dialog);
}