diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2006-10-02 00:13:14 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2006-10-02 00:13:14 +0000 |
commit | 589b473e4191323c9c3102691e81b83348662c84 (patch) | |
tree | 2ba3f8c1cad2b417208e0046501d47dbe54b7e9a | |
parent | 2cf4d327f20371b321bdae7545b098cda3f6fcf0 (diff) |
various (huge) code cleanup incl. splitting of the coloring dialog and the actual color rule edit dialog into two files - this makes the things much more clearer now (at least for me)
svn path=/trunk/; revision=19392
-rw-r--r-- | color_filters.h | 7 | ||||
-rw-r--r-- | gtk/Makefile.am | 1 | ||||
-rw-r--r-- | gtk/Makefile.common | 1 | ||||
-rw-r--r-- | gtk/color_dlg.c | 785 | ||||
-rw-r--r-- | gtk/color_edit_dlg.c | 615 | ||||
-rw-r--r-- | gtk/color_edit_dlg.h | 45 |
6 files changed, 788 insertions, 666 deletions
diff --git a/color_filters.h b/color_filters.h index d253517af0..361032fb6b 100644 --- a/color_filters.h +++ b/color_filters.h @@ -74,7 +74,10 @@ gboolean color_filters_import(gchar *path, gpointer arg); */ gboolean color_filters_export(gchar *path, gboolean only_marked); -/** @todo don't what this function is for, please add explanation +/* Prime the epan_dissect_t with all the compiler + * color filters in 'color_filter_list'. + * + * @param the epan dissector details */ void color_filters_prime_edt(epan_dissect_t *edt); @@ -117,7 +120,7 @@ color_filter_t *color_filter_new(const gchar *name, const gchar *filter_string, */ void color_filter_remove(color_filter_t *colorf); -/** Add a color filter. +/** A color filter was added (from import). * * @param colorf the new color filter * @param arg the color filter widget diff --git a/gtk/Makefile.am b/gtk/Makefile.am index d4153da9ed..bd4aa023fb 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -47,6 +47,7 @@ noinst_HEADERS = \ capture_prefs.h \ cfilter_combo_utils.h \ color_dlg.h \ + color_edit_dlg.h \ colors.h \ column_prefs.h \ compat_macros.h \ diff --git a/gtk/Makefile.common b/gtk/Makefile.common index 23058f628d..e12bf92270 100644 --- a/gtk/Makefile.common +++ b/gtk/Makefile.common @@ -50,6 +50,7 @@ WIRESHARK_GTK_SRC = \ capture_prefs.c \ cfilter_combo_utils.c \ color_dlg.c \ + color_edit_dlg.c \ color_utils.c \ colors.c \ column_prefs.c \ diff --git a/gtk/color_dlg.c b/gtk/color_dlg.c index c8a89368c0..48a1a41634 100644 --- a/gtk/color_dlg.c +++ b/gtk/color_dlg.c @@ -49,6 +49,7 @@ #include <epan/prefs.h> #include "help_dlg.h" +#include "color_edit_dlg.h" /* XXX - ugly workaround for bug #699 */ /* the "Up"/"Down" buttons of the GTK2.x version doesn't work properly */ @@ -81,7 +82,7 @@ static void color_destroy_cb(GtkButton *button, gpointer user_data); static void destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy); static void create_new_color_filter(GtkButton *button, const char *filter); static void color_new_cb(GtkButton *button, gpointer user_data); -static void color_props_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); @@ -90,48 +91,22 @@ static void color_apply_cb(GtkButton *button, gpointer user_data); static void color_clear_cb(GtkWidget *button, gpointer user_data); static void color_import_cb(GtkButton *button, gpointer user_data ); -static void edit_color_filter_dialog(GtkWidget *color_filters, - GtkWidget **colorize_filter_name, - GtkWidget **colorize_filter_text, - guchar is_new_filter); - -#if GTK_MAJOR_VERSION < 2 -static void edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data); -#else -static void edit_color_filter_destroy_cb(GObject *object, gpointer user_data); -#endif -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_new_color_filter_cancel_cb(GtkButton *button, 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 */ +gint num_of_filters; /* number of filters being displayed */ +gint row_selected; /* row in color_filters that is selected */ #define COLOR_UP_LB "color_up_lb" #define COLOR_DOWN_LB "color_down_lb" -#define COLOR_PROPS_LB "color_props_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. */ +/* Callback for the "Display:Coloring Rules" menu item. */ void color_display_cb(GtkWidget *w _U_, gpointer d _U_) { @@ -144,7 +119,7 @@ color_display_cb(GtkWidget *w _U_, gpointer d _U_) } } -/* this opens the colorize dialogue and presets the filter string */ +/* this opens the color dialog and presets the filter string */ void color_display_with_filter(char *filter) { @@ -203,7 +178,7 @@ colorize_dialog_new (char *filter) GtkWidget *edit_fr; GtkWidget *edit_vbox; GtkWidget *color_new; - GtkWidget *color_props; + GtkWidget *color_edit; GtkWidget *color_delete; GtkWidget *manage_fr; @@ -265,13 +240,13 @@ colorize_dialog_new (char *filter) gtk_box_pack_start (GTK_BOX (edit_vbox), color_new, FALSE, FALSE, 5); gtk_tooltips_set_tip (tooltips, color_new, ("Create a new filter at the end of the list"), NULL); - color_props = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_EDIT); + color_edit = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_EDIT); #if GTK_MAJOR_VERSION < 2 - WIDGET_SET_SIZE(color_props, BUTTON_SIZE_X, BUTTON_SIZE_Y); + WIDGET_SET_SIZE(color_edit, BUTTON_SIZE_X, BUTTON_SIZE_Y); #endif - gtk_box_pack_start (GTK_BOX (edit_vbox), color_props, FALSE, FALSE, 5); - gtk_tooltips_set_tip (tooltips, color_props, ("Edit the properties of the selected filter"), NULL); - gtk_widget_set_sensitive (color_props, FALSE); + gtk_box_pack_start (GTK_BOX (edit_vbox), color_edit, FALSE, FALSE, 5); + gtk_tooltips_set_tip (tooltips, color_edit, ("Edit the properties of the selected filter"), NULL); + gtk_widget_set_sensitive (color_edit, FALSE); color_delete = BUTTON_NEW_FROM_STOCK(GTK_STOCK_DELETE); gtk_box_pack_start (GTK_BOX (edit_vbox), color_delete, FALSE, FALSE, 5); @@ -446,16 +421,15 @@ colorize_dialog_new (char *filter) #endif OBJECT_SET_DATA(color_filters, COLOR_UP_LB, color_filter_up); OBJECT_SET_DATA(color_filters, COLOR_DOWN_LB, color_filter_down); - OBJECT_SET_DATA(color_filters, COLOR_PROPS_LB, color_props); + OBJECT_SET_DATA(color_filters, COLOR_EDIT_LB, color_edit); OBJECT_SET_DATA(color_filters, COLOR_DELETE_LB, color_delete); OBJECT_SET_DATA(color_new, COLOR_FILTERS_CL, color_filters); SIGNAL_CONNECT(color_new, "clicked", color_new_cb, NULL); - OBJECT_SET_DATA(color_props, COLOR_FILTERS_CL, color_filters); - SIGNAL_CONNECT(color_props, "clicked", color_props_cb, NULL); - OBJECT_SET_DATA(color_delete, COLOR_PROPS_LB, color_props); + OBJECT_SET_DATA(color_edit, COLOR_FILTERS_CL, color_filters); + SIGNAL_CONNECT(color_edit, "clicked", color_edit_cb, NULL); + OBJECT_SET_DATA(color_delete, COLOR_EDIT_LB, color_edit); OBJECT_SET_DATA(color_delete, COLOR_FILTERS_CL, color_filters); SIGNAL_CONNECT(color_delete, "clicked", color_delete_cb, NULL); - SIGNAL_CONNECT(color_save, "clicked", color_save_cb, NULL); SIGNAL_CONNECT(color_export, "clicked", file_color_export_cmd_cb, NULL); OBJECT_SET_DATA(color_import, COLOR_FILTERS_CL, color_filters); SIGNAL_CONNECT(color_import, "clicked", color_import_cb, color_filters); @@ -463,6 +437,7 @@ colorize_dialog_new (char *filter) SIGNAL_CONNECT(color_clear, "clicked", color_clear_cb, NULL); SIGNAL_CONNECT(color_ok, "clicked", color_ok_cb, NULL); SIGNAL_CONNECT(color_apply, "clicked", color_apply_cb, NULL); + SIGNAL_CONNECT(color_save, "clicked", color_save_cb, NULL); SIGNAL_CONNECT(color_win, "delete_event", window_delete_event_cb, NULL); @@ -480,42 +455,7 @@ colorize_dialog_new (char *filter) return color_win; } -static void -add_filter_to_list(gpointer filter_arg, gpointer list_arg) -{ - color_filter_t *colorf = filter_arg; -#if GTK_MAJOR_VERSION < 2 - GtkWidget *color_filters = list_arg; - gchar *data[2]; - gint row; - GdkColor bg, fg; - - data[0] = colorf->filter_name; - data[1] = colorf->filter_text; - row = gtk_clist_append(GTK_CLIST(color_filters), data); - color_t_to_gdkcolor(&fg, &colorf->fg_color); - color_t_to_gdkcolor(&bg, &colorf->bg_color); - gtk_clist_set_row_data(GTK_CLIST(color_filters), row, colorf); - gtk_clist_set_foreground(GTK_CLIST(color_filters), row, &fg); - gtk_clist_set_background(GTK_CLIST(color_filters), row, &bg); -#else - gchar fg_str[14], bg_str[14]; - GtkListStore *store; - GtkTreeIter iter; - - store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list_arg))); - gtk_list_store_append(store, &iter); - g_snprintf(fg_str, 14, "#%04X%04X%04X", - colorf->fg_color.red, colorf->fg_color.green, colorf->fg_color.blue); - g_snprintf(bg_str, 14, "#%04X%04X%04X", - colorf->bg_color.red, colorf->bg_color.green, colorf->bg_color.blue); - gtk_list_store_set(store, &iter, 0, colorf->filter_name, - 1, colorf->filter_text, 2, fg_str, 3, bg_str, - 4, colorf, -1); -#endif - num_of_filters++; -} - +/* move a row in the list +/- one position up/down */ static void move_this_row (GtkWidget *color_filters, gint filter_number, gint amount) /* only tested with +1(down) and -1(up) */ @@ -584,7 +524,7 @@ static void move_this_row (GtkWidget *color_filters, color_filter_list = g_slist_insert(color_filter_list, colorf, filter_number + amount); } -/* Move the selected filters up in the list */ +/* User pressed the "Up" button: Move the selected filters up in the list */ static void color_filter_up_cb(GtkButton *button, gpointer user_data _U_) { @@ -625,7 +565,7 @@ color_filter_up_cb(GtkButton *button, gpointer user_data _U_) } } -/* Move the selected filters down in the list */ +/* User pressed the "Down" button: Move the selected filters down in the list */ static void color_filter_down_cb(GtkButton *button, gpointer user_data _U_) { @@ -688,7 +628,7 @@ remember_selected_row(GtkCList *clist, gint row, gint column _U_, /* * A row is selected, so we can operate on it. */ - button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_PROPS_LB); + button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_EDIT_LB); gtk_widget_set_sensitive (button, TRUE); button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DELETE_LB); gtk_widget_set_sensitive(button, TRUE); @@ -759,7 +699,7 @@ remember_selected_row(GtkTreeSelection *sel, gpointer color_filters) */ /* We can only edit if there is exactly one filter selected */ - button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_PROPS_LB); + button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_EDIT_LB); gtk_widget_set_sensitive (button, data.count == 1); /* We can delete any number of filters */ @@ -786,7 +726,7 @@ remember_selected_row(GtkTreeSelection *sel, gpointer color_filters) gtk_widget_set_sensitive (button, FALSE); button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DOWN_LB); gtk_widget_set_sensitive (button, FALSE); - button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_PROPS_LB); + button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_EDIT_LB); gtk_widget_set_sensitive (button, FALSE); button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DELETE_LB); gtk_widget_set_sensitive (button, FALSE); @@ -821,7 +761,7 @@ unremember_selected_row (GtkCList *clist, gtk_widget_set_sensitive (button, FALSE); button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DOWN_LB); gtk_widget_set_sensitive (button, FALSE); - button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_PROPS_LB); + button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_EDIT_LB); gtk_widget_set_sensitive (button, FALSE); button = (GtkWidget *)OBJECT_GET_DATA(clist, COLOR_DELETE_LB); gtk_widget_set_sensitive(button, FALSE); @@ -829,10 +769,20 @@ unremember_selected_row (GtkCList *clist, } #endif +/* destroy a single color edit dialog */ +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) + window_destroy(colorf->edit_dialog); +} + /* 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_) @@ -843,20 +793,44 @@ color_destroy_cb (GtkButton *button _U_, colorize_win = NULL; } +/* add a single color filter to the list */ static void -destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy _U_) +add_filter_to_list(gpointer filter_arg, gpointer list_arg) { - color_filter_t *colorf = (color_filter_t *)filter_arg; + color_filter_t *colorf = filter_arg; +#if GTK_MAJOR_VERSION < 2 + GtkWidget *color_filters = list_arg; + gchar *data[2]; + gint row; + GdkColor bg, fg; - if (colorf->edit_dialog != NULL) - window_destroy(colorf->edit_dialog); -} + data[0] = colorf->filter_name; + data[1] = colorf->filter_text; + row = gtk_clist_append(GTK_CLIST(color_filters), data); + color_t_to_gdkcolor(&fg, &colorf->fg_color); + color_t_to_gdkcolor(&bg, &colorf->bg_color); + gtk_clist_set_row_data(GTK_CLIST(color_filters), row, colorf); + gtk_clist_set_foreground(GTK_CLIST(color_filters), row, &fg); + gtk_clist_set_background(GTK_CLIST(color_filters), row, &bg); +#else + gchar fg_str[14], bg_str[14]; + GtkListStore *store; + GtkTreeIter iter; -/* 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; + store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list_arg))); + gtk_list_store_append(store, &iter); + g_snprintf(fg_str, 14, "#%04X%04X%04X", + colorf->fg_color.red, colorf->fg_color.green, colorf->fg_color.blue); + g_snprintf(bg_str, 14, "#%04X%04X%04X", + colorf->bg_color.red, colorf->bg_color.green, colorf->bg_color.blue); + gtk_list_store_set(store, &iter, 0, colorf->filter_name, + 1, colorf->filter_text, 2, fg_str, 3, bg_str, + 4, colorf, -1); +#endif + num_of_filters++; +} +/* add a new filter to the list and select it */ static void color_add_colorf(GtkWidget *color_filters, color_filter_t *colorf) { @@ -871,7 +845,6 @@ color_add_colorf(GtkWidget *color_filters, color_filter_t *colorf) add_filter_to_list(colorf, color_filters); #if GTK_MAJOR_VERSION < 2 - /* select the new row */ gtk_clist_select_row(GTK_CLIST(color_filters), num_of_filters - 1, -1); #else @@ -884,6 +857,7 @@ color_add_colorf(GtkWidget *color_filters, color_filter_t *colorf) #endif } +/* a new color filter was read in from the filter file */ void color_filter_add_cb(color_filter_t *colorf, gpointer arg) { @@ -895,29 +869,8 @@ color_filter_add_cb(color_filter_t *colorf, gpointer arg) #endif } -/* Pop up an "Export color filter" dialog box. */ -static void -color_import_cb(GtkButton *button, gpointer user_data ) -{ - GtkWidget *color_filters; -#if GTK_MAJOR_VERSION >= 2 - GtkTreeSelection *sel; -#endif - - color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL); - -#if GTK_MAJOR_VERSION >= 2 - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters)); - gtk_tree_selection_unselect_all (sel); -#else - gtk_clist_unselect_all (GTK_CLIST(color_filters)); -#endif - - file_color_import_cmd_cb(GTK_WIDGET(button), user_data); -} - -/* Create a new filter in the list, and pop up an "Edit color filter" - dialog box to edit it. */ +/* Create a new filter, add it to the list, and pop up an + "Edit color filter" dialog box to edit it. */ static void create_new_color_filter(GtkButton *button, const char *filter) { @@ -946,40 +899,36 @@ create_new_color_filter(GtkButton *button, const char *filter) color_add_colorf(color_filters, colorf); - edit_color_filter_dialog(color_filters, &filt_name_entry, &filt_text_entry, TRUE); + edit_color_filter_dialog(color_filters, TRUE); - /* Show the (in)validity of the default filter string */ - filter_te_syntax_check_cb(filt_text_entry); - - - #if GTK_MAJOR_VERSION >= 2 gtk_widget_grab_focus(color_filters); #endif } -/* Create a new filter in the list, and pop up an "Edit color filter" - dialog box to edit it. */ +/* User pressed the "New" button: 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_) { create_new_color_filter(button, "filter"); } -/* Pop up an "Edit color filter" dialog box to edit an existing filter. */ +/* User pressed the "Edit" button: Pop up an "Edit color filter" dialog box + to edit an existing filter. */ static void -color_props_cb(GtkButton *button, gpointer user_data _U_) +color_edit_cb(GtkButton *button, gpointer user_data _U_) { GtkWidget *color_filters; color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL); g_assert(row_selected != -1); - edit_color_filter_dialog(color_filters, &filt_name_entry, &filt_text_entry, FALSE); + edit_color_filter_dialog(color_filters, FALSE); } -/* Delete a color from the list. */ -static void -color_delete(gint row, GtkWidget *color_filters) +/* Delete a single color filter from the list. */ +void +color_delete(gint row, GtkWidget *color_filters) { color_filter_t *colorf; @@ -1024,7 +973,8 @@ color_delete(gint row, GtkWidget *color_filters) #endif } -/* Delete the selected color from the list.*/ + +/* User pressed the "Delete" button: Delete the selected color from the list.*/ static void color_delete_cb(GtkWidget *widget, gpointer user_data _U_) { @@ -1062,16 +1012,29 @@ color_delete_cb(GtkWidget *widget, gpointer user_data _U_) } } -/* Save color filters to the color filter file. */ +/* User pressed "Import": Pop up an "Import color filter" dialog box. */ static void -color_save_cb(GtkButton *button _U_, gpointer user_data _U_) +color_import_cb(GtkButton *button, gpointer user_data ) { - if (!color_filters_write()) - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not open filter file: %s", strerror(errno)); + GtkWidget *color_filters; +#if GTK_MAJOR_VERSION >= 2 + GtkTreeSelection *sel; +#endif + + color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL); + +#if GTK_MAJOR_VERSION >= 2 + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters)); + gtk_tree_selection_unselect_all (sel); +#else + gtk_clist_unselect_all (GTK_CLIST(color_filters)); +#endif + + file_color_import_cmd_cb(GTK_WIDGET(button), user_data); } -/* Remove all user defined color filters and revert to the global file. */ +/* User confirmed the clear operation: Remove all user defined color filters and + revert to the global file. */ static void color_clear_cmd(GtkWidget *widget) { @@ -1096,7 +1059,7 @@ color_clear_cmd(GtkWidget *widget) window_destroy(colorize_win); } -/* clear button: user responded to question */ +/* Clear button: user responded to question */ static void color_clear_answered_cb(gpointer dialog _U_, gint btn, gpointer data) { switch(btn) { @@ -1110,7 +1073,7 @@ static void color_clear_answered_cb(gpointer dialog _U_, gint btn, gpointer data } } -/* clear button: ask user before really doing it */ +/* User pressed "clear" button: ask user before really doing it */ void color_clear_cb(GtkWidget *widget, gpointer data _U_) { gpointer dialog; @@ -1124,7 +1087,8 @@ color_clear_cb(GtkWidget *widget, gpointer data _U_) { simple_dialog_set_cb(dialog, color_clear_answered_cb, widget); } -/* Exit dialog and apply new list of color filters to the capture. */ +/* User pressed "Ok" button: Exit dialog and apply new list of + color filters to the capture. */ static void color_ok_cb(GtkButton *button _U_, gpointer user_data _U_) { @@ -1135,538 +1099,31 @@ color_ok_cb(GtkButton *button _U_, gpointer user_data _U_) window_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. */ - window_destroy(colorize_win); -} - -/* Apply new list of color filters to the capture. */ +/* User pressed "Apply" button: apply the new list of color filters + to the capture. */ static void color_apply_cb(GtkButton *button _U_, gpointer user_data _U_) { cf_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(GtkWidget *color_filters, - GtkWidget **colorize_filter_name, - GtkWidget **colorize_filter_text, - guchar is_new_filter) -{ - color_filter_t *colorf; - GtkWidget *edit_dialog; - GtkWidget *dialog_vbox; - GtkTooltips *tooltips; - GtkStyle *style; - - GtkWidget *filter_fr; - GtkWidget *filter_fr_vbox; - GtkWidget *filter_name_hbox; - GtkWidget *color_filter_name; - GtkWidget *filter_string_hbox; - GtkWidget *add_expression_bt; - GtkWidget *color_filter_text; - - GtkWidget *colorize_fr; - GtkWidget *colorize_hbox; - GtkWidget *colorize_filter_fg; - GtkWidget *colorize_filter_bg; - - GtkWidget *bbox; - GtkWidget *edit_color_filter_ok; - GtkWidget *edit_color_filter_cancel; - -#if GTK_MAJOR_VERSION >= 2 - GtkTreeModel *model; - GtkTreeIter iter; -#endif - -#if GTK_MAJOR_VERSION >= 2 - model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters)); - - gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected); - gtk_tree_model_get(model, &iter, 4, &colorf, -1); - -#else - colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row_selected); -#endif - 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 (); - - /* dialog window */ - edit_dialog = dlg_window_new ("Wireshark: Edit Color Filter"); - gtk_window_set_default_size(GTK_WINDOW(edit_dialog), 500, -1); - OBJECT_SET_DATA(edit_dialog, "edit_dialog", edit_dialog); - colorf->edit_dialog = edit_dialog; - - dialog_vbox = gtk_vbox_new (FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5); - gtk_container_add (GTK_CONTAINER (edit_dialog), dialog_vbox); - - /* Filter frame */ - filter_fr = gtk_frame_new("Filter"); - gtk_box_pack_start (GTK_BOX (dialog_vbox), filter_fr, FALSE, FALSE, 0); - - filter_fr_vbox = gtk_vbox_new (FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (filter_fr_vbox), 5); - gtk_container_add(GTK_CONTAINER(filter_fr), filter_fr_vbox); - - /* filter name hbox */ - filter_name_hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (filter_fr_vbox), filter_name_hbox, TRUE, FALSE, 3); - - color_filter_name = gtk_label_new (("Name: ")); - gtk_box_pack_start (GTK_BOX (filter_name_hbox), color_filter_name, FALSE, FALSE, 0); - - *colorize_filter_name = gtk_entry_new (); - gtk_entry_set_text(GTK_ENTRY(*colorize_filter_name), colorf->filter_name); - - style = gtk_style_copy(gtk_widget_get_style(*colorize_filter_name)); - color_t_to_gdkcolor(&style->base[GTK_STATE_NORMAL], &colorf->bg_color); -#if GTK_MAJOR_VERSION < 2 - color_t_to_gdkcolor(&style->fg[GTK_STATE_NORMAL], &colorf->fg_color); -#else - color_t_to_gdkcolor(&style->text[GTK_STATE_NORMAL], &colorf->fg_color); -#endif - gtk_widget_set_style(*colorize_filter_name, style); - - gtk_box_pack_start (GTK_BOX (filter_name_hbox), *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); - - - /* filter string hbox */ - filter_string_hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (filter_fr_vbox), filter_string_hbox, TRUE, FALSE, 3); - - color_filter_text = gtk_label_new (("String: ")); - gtk_box_pack_start (GTK_BOX (filter_string_hbox), color_filter_text, FALSE, FALSE, 0); - - *colorize_filter_text = gtk_entry_new (); - SIGNAL_CONNECT(*colorize_filter_text, "changed", filter_te_syntax_check_cb, NULL); - 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_style_unref(style); - gtk_box_pack_start (GTK_BOX (filter_string_hbox), *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 = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_ADD_EXPRESSION); - SIGNAL_CONNECT(add_expression_bt, "clicked", filter_expr_cb, *colorize_filter_text); - gtk_box_pack_start (GTK_BOX(filter_string_hbox), add_expression_bt, FALSE, FALSE, 3); - gtk_tooltips_set_tip (tooltips, add_expression_bt, ("Add an expression to the filter string"), NULL); - - - /* choose color frame */ - colorize_fr = gtk_frame_new("Display Colors"); - gtk_box_pack_start (GTK_BOX (dialog_vbox), colorize_fr, FALSE, FALSE, 0); - - colorize_hbox = gtk_hbox_new (FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (colorize_hbox), 5); - gtk_container_add(GTK_CONTAINER(colorize_fr), colorize_hbox); - - colorize_filter_fg = gtk_button_new_with_label (("Foreground Color...")); - gtk_box_pack_start (GTK_BOX (colorize_hbox), colorize_filter_fg, TRUE, FALSE, 0); - gtk_tooltips_set_tip (tooltips, colorize_filter_fg, ("Select foreground color for data display"), NULL); - - colorize_filter_bg = gtk_button_new_with_label (("Background Color...")); - gtk_box_pack_start (GTK_BOX (colorize_hbox), colorize_filter_bg, TRUE, FALSE, 0); - gtk_tooltips_set_tip (tooltips, colorize_filter_bg, ("Select background color for data display"), NULL); - - - /* button box */ - bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL); - gtk_box_pack_start(GTK_BOX(dialog_vbox), bbox, FALSE, FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (bbox), 0); - - edit_color_filter_ok = OBJECT_GET_DATA(bbox, GTK_STOCK_OK); - gtk_tooltips_set_tip (tooltips, edit_color_filter_ok, ("Accept filter color change"), NULL); - - edit_color_filter_cancel = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL); - gtk_tooltips_set_tip (tooltips, edit_color_filter_cancel, ("Reject filter color change"), NULL); - - gtk_widget_grab_default(edit_color_filter_ok); - - /* signals and such */ - OBJECT_SET_DATA(edit_dialog, COLOR_FILTER, colorf); - SIGNAL_CONNECT(edit_dialog, "destroy", edit_color_filter_destroy_cb, NULL); - OBJECT_SET_DATA(colorize_filter_fg, COLOR_FILTER, colorf); - SIGNAL_CONNECT(colorize_filter_fg, "clicked", edit_color_filter_fg_cb, NULL); - OBJECT_SET_DATA(colorize_filter_bg, COLOR_FILTER, colorf); - SIGNAL_CONNECT(colorize_filter_bg, "clicked", edit_color_filter_bg_cb, NULL); - OBJECT_SET_DATA(edit_color_filter_ok, COLOR_FILTERS_CL, color_filters); - OBJECT_SET_DATA(edit_color_filter_ok, COLOR_FILTER, colorf); - SIGNAL_CONNECT(edit_color_filter_ok, "clicked", edit_color_filter_ok_cb, edit_dialog); - - /* set callback to delete new filters if cancel chosen */ - if (is_new_filter) - { - OBJECT_SET_DATA(edit_color_filter_cancel, COLOR_FILTERS_CL, color_filters); - SIGNAL_CONNECT(edit_color_filter_cancel, "clicked", - edit_new_color_filter_cancel_cb, edit_dialog); - } - /* escape will select cancel */ - window_set_cancel_button(edit_dialog, edit_color_filter_cancel, window_cancel_button_cb); - - SIGNAL_CONNECT(edit_dialog, "delete_event", window_delete_event_cb, NULL); - - gtk_widget_show_all(edit_dialog); - window_present(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. */ -#if GTK_MAJOR_VERSION < 2 -static void -edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data _U_) -#else -static void -edit_color_filter_destroy_cb(GObject *object, gpointer user_data _U_) -#endif -{ - color_filter_t *colorf; - GtkWidget *color_sel; - - colorf = (color_filter_t *)OBJECT_GET_DATA(object, COLOR_FILTER); - colorf->edit_dialog = NULL; - - /* Destroy any color selection dialogs this dialog had open. */ - color_sel = (GtkWidget *)OBJECT_GET_DATA(object, COLOR_SELECTION_FG); - if (color_sel != NULL) - window_destroy(color_sel); - color_sel = (GtkWidget *)OBJECT_GET_DATA(object, COLOR_SELECTION_BG); - if (color_sel != NULL) - window_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 *)OBJECT_GET_DATA(button, COLOR_FILTER); - /* Do we already have one open for this dialog? */ - color_selection_fg = OBJECT_GET_DATA(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); - OBJECT_SET_DATA(colorf->edit_dialog, COLOR_SELECTION_FG, color_selection_fg); - OBJECT_SET_DATA(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 *)OBJECT_GET_DATA(button, COLOR_FILTER); - /* Do we already have one open for this dialog? */ - color_selection_bg = OBJECT_GET_DATA(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); - OBJECT_SET_DATA(colorf->edit_dialog, COLOR_SELECTION_BG, color_selection_bg); - OBJECT_SET_DATA(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; -#if GTK_MAJOR_VERSION >= 2 - GtkTreeModel *model; - GtkTreeIter iter; - gchar fg_str[14], bg_str[14]; -#endif - - dialog = (GtkWidget *)user_data; - - style = gtk_widget_get_style(filt_name_entry); - new_bg_color = style->base[GTK_STATE_NORMAL]; -#if GTK_MAJOR_VERSION < 2 - new_fg_color = style->fg[GTK_STATE_NORMAL]; -#else - new_fg_color = style->text[GTK_STATE_NORMAL]; -#endif - - 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_ERROR, ESD_BTN_OK, - "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_ERROR, ESD_BTN_OK, - "Filter \"%s\" didn't compile correctly.\n" - " Please try again. Filter unchanged.\n%s\n", filter_name, - dfilter_error_msg); - } else { - color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL); - colorf = (color_filter_t *)OBJECT_GET_DATA(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; - gdkcolor_to_color_t(&colorf->fg_color, &new_fg_color); - gdkcolor_to_color_t(&colorf->bg_color, &new_bg_color); -#if GTK_MAJOR_VERSION < 2 - 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); -#else - g_snprintf(fg_str, 14, "#%04X%04X%04X", - new_fg_color.red, new_fg_color.green, new_fg_color.blue); - g_snprintf(bg_str, 14, "#%04X%04X%04X", - new_bg_color.red, new_bg_color.green, new_bg_color.blue); - model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters)); - gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, filter_name, - 1, filter_text, 2, fg_str, 3, bg_str, -1); -#endif - if(colorf->c_colorfilter != NULL) - dfilter_free(colorf->c_colorfilter); - colorf->c_colorfilter = compiled_filter; -#if GTK_MAJOR_VERSION < 2 - /* 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); -#endif - - /* Destroy the dialog box. */ - window_destroy(dialog); - } -} - -/* reject new color filter addition */ -static void -edit_new_color_filter_cancel_cb(GtkButton *button, gpointer user_data _U_) -{ - /* Delete the entry. N.B. this already destroys the edit_dialog window. */ - color_delete(num_of_filters-1, (GtkWidget*)OBJECT_GET_DATA(button, COLOR_FILTERS_CL)); -} - -static GtkWidget* -color_sel_win_new(color_filter_t *colorf, gboolean is_bg) -{ - gchar *title; - GtkWidget *color_sel_win; - color_t *color; -#if GTK_MAJOR_VERSION >= 2 - GdkColor gcolor; -#endif - GtkWidget *color_sel_ok; - GtkWidget *color_sel_cancel; - GtkWidget *color_sel_help; - - if (is_bg) { - color = &colorf->bg_color; - title = g_strdup_printf("Wireshark: Choose background color for \"%s\"", - colorf->filter_name); - } else { - color = &colorf->fg_color; - title = g_strdup_printf("Wireshark: Choose foreground color for \"%s\"", - colorf->filter_name); - } - color_sel_win = gtk_color_selection_dialog_new(title); - g_free(title); - OBJECT_SET_DATA(color_sel_win, "color_sel_win", color_sel_win); - gtk_container_set_border_width (GTK_CONTAINER (color_sel_win), 10); - - if (color != NULL) { -#if GTK_MAJOR_VERSION < 2 - 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); -#else - color_t_to_gdkcolor(&gcolor, color); - gtk_color_selection_set_current_color( - GTK_COLOR_SELECTION( - GTK_COLOR_SELECTION_DIALOG(color_sel_win)->colorsel), &gcolor); -#endif - } - - color_sel_ok = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->ok_button; - OBJECT_SET_DATA(color_sel_win, "color_sel_ok", 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; - OBJECT_SET_DATA(color_sel_win, "color_sel_cancel", 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; - OBJECT_SET_DATA(color_sel_win, "color_sel_help", color_sel_help); - - - GTK_WIDGET_SET_FLAGS (color_sel_help, GTK_CAN_DEFAULT); - - SIGNAL_CONNECT(color_sel_ok, "clicked", color_sel_ok_cb, color_sel_win); - SIGNAL_CONNECT(color_sel_cancel, "clicked", color_sel_cancel_cb, color_sel_win); - - gtk_widget_show_all(color_sel_win); - return color_sel_win; -} - +/* User pressed the "Save" button: save the color filters to the + color filter file. */ 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 *)OBJECT_GET_DATA(sel_win, COLOR_SELECTION_PARENT); - - /* Find that dialog box's foreground and background color selection - boxes, if any. */ - color_selection_fg = OBJECT_GET_DATA(parent, COLOR_SELECTION_FG); - color_selection_bg = OBJECT_GET_DATA(parent, COLOR_SELECTION_BG); - - if (sel_win == color_selection_fg) { - /* This was its foreground color selection box; it isn't, anymore. */ - OBJECT_SET_DATA(parent, COLOR_SELECTION_FG, NULL); - } - if (sel_win == color_selection_bg) { - /* This was its background color selection box; it isn't, anymore. */ - OBJECT_SET_DATA(parent, COLOR_SELECTION_BG, NULL); - } - - /* Now destroy it. */ - window_destroy(sel_win); -} - -/* Retrieve selected color */ -static void -color_sel_ok_cb (GtkButton *button _U_, - gpointer user_data) +color_save_cb(GtkButton *button _U_, gpointer user_data _U_) { - GdkColor new_color; /* Color from color selection dialog */ -#if GTK_MAJOR_VERSION < 2 - gdouble new_colors[3]; -#endif - GtkWidget *color_dialog; - GtkStyle *style; - GtkWidget *parent; - GtkWidget *color_selection_fg, *color_selection_bg; - gboolean is_bg; - - color_dialog = (GtkWidget *)user_data; - -#if GTK_MAJOR_VERSION < 2 - 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); -#else - gtk_color_selection_get_current_color(GTK_COLOR_SELECTION( - GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &new_color); -#endif - - if ( ! get_color(&new_color) ){ + if (!color_filters_write()) simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not allocate color. Try again."); - } else { - /* Find the "Edit color filter" dialog box with which this is - associated. */ - parent = (GtkWidget *)OBJECT_GET_DATA(color_dialog, COLOR_SELECTION_PARENT); - - /* Find that dialog box's foreground and background color selection - boxes, if any. */ - color_selection_fg = OBJECT_GET_DATA(parent, COLOR_SELECTION_FG); - color_selection_bg = OBJECT_GET_DATA(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; -#if GTK_MAJOR_VERSION < 2 - else - style->fg[GTK_STATE_NORMAL] = new_color; -#else - else - style->text[GTK_STATE_NORMAL] = new_color; -#endif - gtk_widget_set_style(filt_name_entry, style); - gtk_widget_set_style(filt_text_entry, style); - gtk_style_unref(style); - } + "Could not open filter file: %s", strerror(errno)); } -/* Don't choose the selected color as the foreground or background - color for the filter. */ +/* User pressed "Cancel" button (or "ESC" or the 'X'): + Exit dialog without colorizing packets with the new list. + XXX - should really undo any changes to the list.... */ static void -color_sel_cancel_cb (GtkObject *object _U_, - gpointer user_data) +color_cancel_cb(GtkWidget *widget _U_, gpointer user_data _U_) { - 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); + /* Destroy the dialog box. */ + window_destroy(colorize_win); } + diff --git a/gtk/color_edit_dlg.c b/gtk/color_edit_dlg.c new file mode 100644 index 0000000000..1bb3ff8138 --- /dev/null +++ b/gtk/color_edit_dlg.c @@ -0,0 +1,615 @@ +/* color_dlg.c + * Definitions for dialog boxes for color filters + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * 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 <epan/packet.h> +#include "color.h" +#include "colors.h" +#include "color_filters.h" + +#include "dlg_utils.h" +#include "gui_utils.h" +#include "compat_macros.h" +#include "filter_dlg.h" +#include "dfilter_expr_dlg.h" +#include "simple_dialog.h" + +#include "color_edit_dlg.h" + +/* XXX - ugly workaround for bug #699 */ +/* the "Up"/"Down" buttons of the GTK2.x version doesn't work properly */ +/* simply use the GTK1.x version of this dialog for now ... */ +#if GTK_MAJOR_VERSION >= 2 +#undef GTK_MAJOR_VERSION +#define GTK_MAJOR_VERSION 1 +#define BUTTON_SIZE_X -1 +#define BUTTON_SIZE_Y -1 +#else +#define BUTTON_SIZE_X 50 +#define BUTTON_SIZE_Y 20 +#endif +/* XXX - ugly workaround for bug #699 */ + + +#if GTK_MAJOR_VERSION < 2 +static void edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data); +#else +static void edit_color_filter_destroy_cb(GObject *object, gpointer user_data); +#endif +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_new_color_filter_cancel_cb(GtkButton *button, 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); + + +#define COLOR_FILTERS_CL "color_filters_cl" +#define COLOR_FILTER "color_filter" +#define COLOR_FILTER_NAME_TE "color_filter_name_te" +#define COLOR_FILTER_TEXT_TE "color_filter_text_te" +#define COLOR_SELECTION_FG "color_selection_fg" +#define COLOR_SELECTION_BG "color_selection_bg" +#define COLOR_SELECTION_PARENT "color_selection_parent" + +/* XXX - we don't forbid having more than one "Edit color filter" dialog + open, so these shouldn't be global. */ +static GtkWidget *filt_name_entry; +static GtkWidget *filt_text_entry; + + +static void +filter_expr_cb(GtkWidget *w _U_, gpointer filter_te) +{ + + dfilter_expr_dlg_new(GTK_WIDGET(filter_te)); +} + + +/* Create an "Edit Color Filter" dialog for a given color filter, and + associate it with that color filter. */ +void +edit_color_filter_dialog(GtkWidget *color_filters, + gboolean is_new_filter) +{ + color_filter_t *colorf; + GtkWidget *edit_dialog; + GtkWidget *dialog_vbox; + GtkTooltips *tooltips; + GtkStyle *style; + + GtkWidget *filter_fr; + GtkWidget *filter_fr_vbox; + GtkWidget *filter_name_hbox; + GtkWidget *color_filter_name; + GtkWidget *filter_string_hbox; + GtkWidget *add_expression_bt; + GtkWidget *color_filter_text; + + GtkWidget *colorize_fr; + GtkWidget *colorize_hbox; + GtkWidget *colorize_filter_fg; + GtkWidget *colorize_filter_bg; + + GtkWidget *bbox; + GtkWidget *edit_color_filter_ok; + GtkWidget *edit_color_filter_cancel; + +#if GTK_MAJOR_VERSION >= 2 + GtkTreeModel *model; + GtkTreeIter iter; +#endif + +#if GTK_MAJOR_VERSION >= 2 + model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters)); + + gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected); + gtk_tree_model_get(model, &iter, 4, &colorf, -1); + +#else + colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row_selected); +#endif + 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 (); + + /* dialog window */ + edit_dialog = dlg_window_new ("Wireshark: Edit Color Filter"); + gtk_window_set_default_size(GTK_WINDOW(edit_dialog), 500, -1); + OBJECT_SET_DATA(edit_dialog, "edit_dialog", edit_dialog); + colorf->edit_dialog = edit_dialog; + + dialog_vbox = gtk_vbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5); + gtk_container_add (GTK_CONTAINER (edit_dialog), dialog_vbox); + + /* Filter frame */ + filter_fr = gtk_frame_new("Filter"); + gtk_box_pack_start (GTK_BOX (dialog_vbox), filter_fr, FALSE, FALSE, 0); + + filter_fr_vbox = gtk_vbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (filter_fr_vbox), 5); + gtk_container_add(GTK_CONTAINER(filter_fr), filter_fr_vbox); + + /* filter name hbox */ + filter_name_hbox = gtk_hbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (filter_fr_vbox), filter_name_hbox, TRUE, FALSE, 3); + + color_filter_name = gtk_label_new (("Name: ")); + gtk_box_pack_start (GTK_BOX (filter_name_hbox), color_filter_name, FALSE, FALSE, 0); + + filt_name_entry = gtk_entry_new (); + gtk_entry_set_text(GTK_ENTRY(filt_name_entry), colorf->filter_name); + + style = gtk_style_copy(gtk_widget_get_style(filt_name_entry)); + color_t_to_gdkcolor(&style->base[GTK_STATE_NORMAL], &colorf->bg_color); +#if GTK_MAJOR_VERSION < 2 + color_t_to_gdkcolor(&style->fg[GTK_STATE_NORMAL], &colorf->fg_color); +#else + color_t_to_gdkcolor(&style->text[GTK_STATE_NORMAL], &colorf->fg_color); +#endif + gtk_widget_set_style(filt_name_entry, style); + + gtk_box_pack_start (GTK_BOX (filter_name_hbox), filt_name_entry, TRUE, TRUE, 0); + gtk_tooltips_set_tip (tooltips, filt_name_entry, ("This is the editable name of the filter. (No @ characters allowed.)"), NULL); + + + /* filter string hbox */ + filter_string_hbox = gtk_hbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (filter_fr_vbox), filter_string_hbox, TRUE, FALSE, 3); + + color_filter_text = gtk_label_new (("String: ")); + gtk_box_pack_start (GTK_BOX (filter_string_hbox), color_filter_text, FALSE, FALSE, 0); + + filt_text_entry = gtk_entry_new (); + SIGNAL_CONNECT(filt_text_entry, "changed", filter_te_syntax_check_cb, NULL); + gtk_entry_set_text(GTK_ENTRY(filt_text_entry), colorf->filter_text); + +#if 0 + style = gtk_style_copy(gtk_widget_get_style(filt_text_entry)); + style->base[GTK_STATE_NORMAL] = colorf->bg_color; + style->fg[GTK_STATE_NORMAL] = colorf->fg_color; +#endif + gtk_widget_set_style(filt_text_entry, style); + gtk_style_unref(style); + gtk_box_pack_start (GTK_BOX (filter_string_hbox), filt_text_entry, TRUE, TRUE, 0); + gtk_tooltips_set_tip (tooltips, filt_text_entry, ("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 = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_ADD_EXPRESSION); + SIGNAL_CONNECT(add_expression_bt, "clicked", filter_expr_cb, filt_text_entry); + gtk_box_pack_start (GTK_BOX(filter_string_hbox), add_expression_bt, FALSE, FALSE, 3); + gtk_tooltips_set_tip (tooltips, add_expression_bt, ("Add an expression to the filter string"), NULL); + + /* Show the (in)validity of the default filter string */ + filter_te_syntax_check_cb(filt_text_entry); + + /* choose color frame */ + colorize_fr = gtk_frame_new("Display Colors"); + gtk_box_pack_start (GTK_BOX (dialog_vbox), colorize_fr, FALSE, FALSE, 0); + + colorize_hbox = gtk_hbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (colorize_hbox), 5); + gtk_container_add(GTK_CONTAINER(colorize_fr), colorize_hbox); + + colorize_filter_fg = gtk_button_new_with_label (("Foreground Color...")); + gtk_box_pack_start (GTK_BOX (colorize_hbox), colorize_filter_fg, TRUE, FALSE, 0); + gtk_tooltips_set_tip (tooltips, colorize_filter_fg, ("Select foreground color for data display"), NULL); + + colorize_filter_bg = gtk_button_new_with_label (("Background Color...")); + gtk_box_pack_start (GTK_BOX (colorize_hbox), colorize_filter_bg, TRUE, FALSE, 0); + gtk_tooltips_set_tip (tooltips, colorize_filter_bg, ("Select background color for data display"), NULL); + + + /* button box */ + bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL); + gtk_box_pack_start(GTK_BOX(dialog_vbox), bbox, FALSE, FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (bbox), 0); + + edit_color_filter_ok = OBJECT_GET_DATA(bbox, GTK_STOCK_OK); + gtk_tooltips_set_tip (tooltips, edit_color_filter_ok, ("Accept filter color change"), NULL); + + edit_color_filter_cancel = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL); + gtk_tooltips_set_tip (tooltips, edit_color_filter_cancel, ("Reject filter color change"), NULL); + + gtk_widget_grab_default(edit_color_filter_ok); + + /* signals and such */ + OBJECT_SET_DATA(edit_dialog, COLOR_FILTER, colorf); + SIGNAL_CONNECT(edit_dialog, "destroy", edit_color_filter_destroy_cb, NULL); + OBJECT_SET_DATA(colorize_filter_fg, COLOR_FILTER, colorf); + SIGNAL_CONNECT(colorize_filter_fg, "clicked", edit_color_filter_fg_cb, NULL); + OBJECT_SET_DATA(colorize_filter_bg, COLOR_FILTER, colorf); + SIGNAL_CONNECT(colorize_filter_bg, "clicked", edit_color_filter_bg_cb, NULL); + OBJECT_SET_DATA(edit_color_filter_ok, COLOR_FILTERS_CL, color_filters); + OBJECT_SET_DATA(edit_color_filter_ok, COLOR_FILTER, colorf); + SIGNAL_CONNECT(edit_color_filter_ok, "clicked", edit_color_filter_ok_cb, edit_dialog); + + /* set callback to delete new filters if cancel chosen */ + if (is_new_filter) + { + OBJECT_SET_DATA(edit_color_filter_cancel, COLOR_FILTERS_CL, color_filters); + SIGNAL_CONNECT(edit_color_filter_cancel, "clicked", + edit_new_color_filter_cancel_cb, edit_dialog); + } + /* escape will select cancel */ + window_set_cancel_button(edit_dialog, edit_color_filter_cancel, window_cancel_button_cb); + + SIGNAL_CONNECT(edit_dialog, "delete_event", window_delete_event_cb, NULL); + + gtk_widget_show_all(edit_dialog); + window_present(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. */ +#if GTK_MAJOR_VERSION < 2 +static void +edit_color_filter_destroy_cb(GtkObject *object, gpointer user_data _U_) +#else +static void +edit_color_filter_destroy_cb(GObject *object, gpointer user_data _U_) +#endif +{ + color_filter_t *colorf; + GtkWidget *color_sel; + + colorf = (color_filter_t *)OBJECT_GET_DATA(object, COLOR_FILTER); + colorf->edit_dialog = NULL; + + /* Destroy any color selection dialogs this dialog had open. */ + color_sel = (GtkWidget *)OBJECT_GET_DATA(object, COLOR_SELECTION_FG); + if (color_sel != NULL) + window_destroy(color_sel); + color_sel = (GtkWidget *)OBJECT_GET_DATA(object, COLOR_SELECTION_BG); + if (color_sel != NULL) + window_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 *)OBJECT_GET_DATA(button, COLOR_FILTER); + /* Do we already have one open for this dialog? */ + color_selection_fg = OBJECT_GET_DATA(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); + OBJECT_SET_DATA(colorf->edit_dialog, COLOR_SELECTION_FG, color_selection_fg); + OBJECT_SET_DATA(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 *)OBJECT_GET_DATA(button, COLOR_FILTER); + /* Do we already have one open for this dialog? */ + color_selection_bg = OBJECT_GET_DATA(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); + OBJECT_SET_DATA(colorf->edit_dialog, COLOR_SELECTION_BG, color_selection_bg); + OBJECT_SET_DATA(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; +#if GTK_MAJOR_VERSION >= 2 + GtkTreeModel *model; + GtkTreeIter iter; + gchar fg_str[14], bg_str[14]; +#endif + + dialog = (GtkWidget *)user_data; + + style = gtk_widget_get_style(filt_name_entry); + new_bg_color = style->base[GTK_STATE_NORMAL]; +#if GTK_MAJOR_VERSION < 2 + new_fg_color = style->fg[GTK_STATE_NORMAL]; +#else + new_fg_color = style->text[GTK_STATE_NORMAL]; +#endif + + 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_ERROR, ESD_BTN_OK, + "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_ERROR, ESD_BTN_OK, + "Filter \"%s\" didn't compile correctly.\n" + " Please try again. Filter unchanged.\n%s\n", filter_name, + dfilter_error_msg); + } else { + color_filters = (GtkWidget *)OBJECT_GET_DATA(button, COLOR_FILTERS_CL); + colorf = (color_filter_t *)OBJECT_GET_DATA(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; + gdkcolor_to_color_t(&colorf->fg_color, &new_fg_color); + gdkcolor_to_color_t(&colorf->bg_color, &new_bg_color); +#if GTK_MAJOR_VERSION < 2 + 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); +#else + g_snprintf(fg_str, 14, "#%04X%04X%04X", + new_fg_color.red, new_fg_color.green, new_fg_color.blue); + g_snprintf(bg_str, 14, "#%04X%04X%04X", + new_bg_color.red, new_bg_color.green, new_bg_color.blue); + model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters)); + gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, filter_name, + 1, filter_text, 2, fg_str, 3, bg_str, -1); +#endif + if(colorf->c_colorfilter != NULL) + dfilter_free(colorf->c_colorfilter); + colorf->c_colorfilter = compiled_filter; +#if GTK_MAJOR_VERSION < 2 + /* 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); +#endif + + /* Destroy the dialog box. */ + window_destroy(dialog); + } +} + +/* reject new color filter addition */ +static void +edit_new_color_filter_cancel_cb(GtkButton *button, gpointer user_data _U_) +{ + /* Delete the entry. As a side effect this destroys the edit_dialog window. */ + color_delete(num_of_filters-1, (GtkWidget*)OBJECT_GET_DATA(button, COLOR_FILTERS_CL)); +} + +static GtkWidget* +color_sel_win_new(color_filter_t *colorf, gboolean is_bg) +{ + gchar *title; + GtkWidget *color_sel_win; + color_t *color; +#if GTK_MAJOR_VERSION >= 2 + GdkColor gcolor; +#endif + GtkWidget *color_sel_ok; + GtkWidget *color_sel_cancel; + GtkWidget *color_sel_help; + + if (is_bg) { + color = &colorf->bg_color; + title = g_strdup_printf("Wireshark: Choose background color for \"%s\"", + colorf->filter_name); + } else { + color = &colorf->fg_color; + title = g_strdup_printf("Wireshark: Choose foreground color for \"%s\"", + colorf->filter_name); + } + color_sel_win = gtk_color_selection_dialog_new(title); + g_free(title); + OBJECT_SET_DATA(color_sel_win, "color_sel_win", color_sel_win); + gtk_container_set_border_width (GTK_CONTAINER (color_sel_win), 10); + + if (color != NULL) { +#if GTK_MAJOR_VERSION < 2 + 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); +#else + color_t_to_gdkcolor(&gcolor, color); + gtk_color_selection_set_current_color( + GTK_COLOR_SELECTION( + GTK_COLOR_SELECTION_DIALOG(color_sel_win)->colorsel), &gcolor); +#endif + } + + color_sel_ok = GTK_COLOR_SELECTION_DIALOG (color_sel_win)->ok_button; + OBJECT_SET_DATA(color_sel_win, "color_sel_ok", 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; + OBJECT_SET_DATA(color_sel_win, "color_sel_cancel", 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; + OBJECT_SET_DATA(color_sel_win, "color_sel_help", color_sel_help); + + + GTK_WIDGET_SET_FLAGS (color_sel_help, GTK_CAN_DEFAULT); + + SIGNAL_CONNECT(color_sel_ok, "clicked", color_sel_ok_cb, color_sel_win); + SIGNAL_CONNECT(color_sel_cancel, "clicked", color_sel_cancel_cb, color_sel_win); + + gtk_widget_show_all(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 *)OBJECT_GET_DATA(sel_win, COLOR_SELECTION_PARENT); + + /* Find that dialog box's foreground and background color selection + boxes, if any. */ + color_selection_fg = OBJECT_GET_DATA(parent, COLOR_SELECTION_FG); + color_selection_bg = OBJECT_GET_DATA(parent, COLOR_SELECTION_BG); + + if (sel_win == color_selection_fg) { + /* This was its foreground color selection box; it isn't, anymore. */ + OBJECT_SET_DATA(parent, COLOR_SELECTION_FG, NULL); + } + if (sel_win == color_selection_bg) { + /* This was its background color selection box; it isn't, anymore. */ + OBJECT_SET_DATA(parent, COLOR_SELECTION_BG, NULL); + } + + /* Now destroy it. */ + window_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 */ +#if GTK_MAJOR_VERSION < 2 + gdouble new_colors[3]; +#endif + GtkWidget *color_dialog; + GtkStyle *style; + GtkWidget *parent; + GtkWidget *color_selection_fg, *color_selection_bg; + gboolean is_bg; + + color_dialog = (GtkWidget *)user_data; + +#if GTK_MAJOR_VERSION < 2 + 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); +#else + gtk_color_selection_get_current_color(GTK_COLOR_SELECTION( + GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &new_color); +#endif + + if ( ! get_color(&new_color) ){ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Could not allocate color. Try again."); + } else { + /* Find the "Edit color filter" dialog box with which this is + associated. */ + parent = (GtkWidget *)OBJECT_GET_DATA(color_dialog, COLOR_SELECTION_PARENT); + + /* Find that dialog box's foreground and background color selection + boxes, if any. */ + color_selection_fg = OBJECT_GET_DATA(parent, COLOR_SELECTION_FG); + color_selection_bg = OBJECT_GET_DATA(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; +#if GTK_MAJOR_VERSION < 2 + else + style->fg[GTK_STATE_NORMAL] = new_color; +#else + else + style->text[GTK_STATE_NORMAL] = new_color; +#endif + gtk_widget_set_style(filt_name_entry, style); + gtk_widget_set_style(filt_text_entry, style); + gtk_style_unref(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); +} diff --git a/gtk/color_edit_dlg.h b/gtk/color_edit_dlg.h new file mode 100644 index 0000000000..9f633f5251 --- /dev/null +++ b/gtk/color_edit_dlg.h @@ -0,0 +1,45 @@ +/* color_edit_dlg.h + * Definitions for dialog boxes for color filters + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * 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. + */ + +#ifndef __COLOR_EDIT_DLG_H__ +#define __COLOR_EDIT_DLG_H__ + +/** @file + * "Colorize Edit Display" dialog box. + * @ingroup dialog_group + */ + +extern gint num_of_filters; /* number of filters being displayed */ +extern gint row_selected; /* row in color_filters that is selected */ + +/* new color filter edit dialog */ +extern void +edit_color_filter_dialog(GtkWidget *color_filters, + gboolean is_new_filter); + +/* edit dialog wants to destroy itself */ +extern void +color_delete(gint row, GtkWidget *color_filters); + +#endif /* color_edit_dlg.h */ |