/* colors.c
* Definitions for color structures and routines
*
- * $Id: colors.c,v 1.24 1999/12/19 10:39:33 guy Exp $
+ * $Id: colors.c,v 1.27 1999/12/20 06:05:07 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
static GtkWidget* colorize_dialog_new(colfilter *filter);
static void add_filter_to_clist(gpointer filter_arg, gpointer clist_arg);
-static void colorize_dialog_destroy(void);
-static void destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy);
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 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);
GtkWidget *color_filters,
GtkWidget **colorize_filter_name,
GtkWidget **colorize_filter_text);
-static void edit_color_filter_dialog_destroy(color_filter_t *colorf);
+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* create_color_sel_win(colfilter *filter, GdkColor *);
+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_FILTER "color_filter"
#define COLOR_SELECTION_FG "color_selection_fg"
#define COLOR_SELECTION_BG "color_selection_bg"
+#define COLOR_SELECTION_PARENT "color_selection_parent"
/* This structure is used to allow you to compile in default colors if
* you wish. They can be later changed by a user.
color_display_cb(GtkWidget *w, gpointer d)
{
if (colorize_win != NULL) {
- /* There's already a color dialog box active; raise it.
- XXX - give it focus, too. Alas, GDK has nothing that
- calls "XSetInputFocus()" on a window.... */
- gdk_window_raise(colorize_win->window);
+ /* 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(cf.colors);
gtk_widget_set_usize (color_cancel, 50, 30);
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_clist_set_background(GTK_CLIST(color_filters), row, &colorf->bg_color);
}
-/* Destroy the "Add color to protocols" dialog, and any "Edit color filter"
- dialogs popped up from it. */
-static void
-colorize_dialog_destroy(void)
-{
- /* Destroy any edit dialogs we have open. */
- g_slist_foreach(filter_list, destroy_edit_dialog_cb, NULL);
-
- /* Delete the dialog box itself. */
- gtk_widget_destroy(colorize_win);
- colorize_win = NULL;
-}
-
-static void
-destroy_edit_dialog_cb(gpointer filter_arg, gpointer dummy)
-{
- edit_color_filter_dialog_destroy((color_filter_t *)filter_arg);
-}
-
/* Move the selected filter up in the list */
static void
color_filter_up_cb (GtkButton *button,
filter->row_selected = row;
}
+/* Called when the dialog box is being destroyed; destroy any edit
+ dialogs opened from this dialog, and null out the pointer to this
+ dialog. */
+static void
+color_destroy_cb (GtkButton *button,
+ gpointer user_data)
+{
+ /* 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)
+{
+ 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;
COLOR_FILTERS_CL);
colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters),
filter->row_selected);
+
+ /* Remove this color filter from the CList displaying the
+ color filters. */
gtk_clist_remove(GTK_CLIST(color_filters), filter->row_selected);
- edit_color_filter_dialog_destroy(colorf);
+
+ /* 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);
filter->num_of_filters--;
if(!filter->num_of_filters){
/* colorize list */
colorize_packets(&cf);
- /* Delete the dialog box. */
- colorize_dialog_destroy();
+ /* Destroy the dialog box. */
+ gtk_widget_destroy(colorize_win);
}
/* Exit dialog without colorizing packets with the new list.
color_cancel_cb (GtkWidget *widget,
gpointer user_data)
{
- /* Delete the dialog box. */
- colorize_dialog_destroy();
+ /* Destroy the dialog box. */
+ gtk_widget_destroy(colorize_win);
}
/* Apply new list of color filters to the capture. */
colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters),
filter->row_selected);
if (colorf->edit_dialog != NULL) {
- /* There's already an edit box open for this filter; raise it.
- XXX - give it focus, too. Alas, GDK has nothing that calls
- "XSetInputFocus()" on a window.... */
- gdk_window_raise(colorf->edit_dialog->window);
+ /* There's already an edit box open for this filter; reactivate it. */
+ reactivate_window(colorf->edit_dialog);
return;
}
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);
-#if 0
+ 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_cancel_cb),
- edit_dialog);
-#endif
+ 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_connect (GTK_OBJECT (edit_color_filter_ok), "clicked",
GTK_SIGNAL_FUNC (edit_color_filter_ok_cb),
edit_dialog);
- gtk_object_set_data(GTK_OBJECT (edit_color_filter_cancel), COLOR_FILTER,
- colorf);
gtk_signal_connect (GTK_OBJECT (edit_color_filter_cancel), "clicked",
GTK_SIGNAL_FUNC (edit_color_filter_cancel_cb),
edit_dialog);
gtk_widget_show (edit_dialog);
}
-/* Destroy an "Edit color filter" dialog for a given color filter, and
- any color selection dialogs popped up from it. */
+/* 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_dialog_destroy(color_filter_t *colorf)
+edit_color_filter_destroy_cb (GtkObject *object,
+ gpointer user_data)
{
- GtkWidget *dialog = colorf->edit_dialog;
+ color_filter_t *colorf;
GtkWidget *color_sel;
- if (dialog != NULL) {
- colorf->edit_dialog = NULL;
-
- /* Destroy any color selection dialogs this dialog had open. */
- color_sel = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(dialog),
- COLOR_SELECTION_FG);
- if (color_sel != NULL)
- gtk_widget_destroy(color_sel);
- color_sel = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(dialog),
- COLOR_SELECTION_BG);
- if (color_sel != NULL)
- gtk_widget_destroy(color_sel);
-
- /* Now destroy the dialog itself. */
- gtk_widget_destroy(dialog);
- }
-}
+ colorf = (color_filter_t *) gtk_object_get_data(GTK_OBJECT(object),
+ COLOR_FILTER);
-/* XXX - we allow more than one color selection box to be open, so
- this shouldn't be static. */
-static gint bg_set_flag; /* 0 -> setting foreground, 1-> setting background */
+ 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
filter = (colfilter *)user_data;
colorf = (color_filter_t *) gtk_object_get_data(GTK_OBJECT(button),
COLOR_FILTER);
- color_selection_fg = create_color_sel_win(filter, &colorf->fg_color);
- gtk_object_set_data(GTK_OBJECT (colorf->edit_dialog), COLOR_SELECTION_FG,
+ /* 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);
- bg_set_flag = 0;
+ 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. */
filter = (colfilter *)user_data;
colorf = (color_filter_t *) gtk_object_get_data(GTK_OBJECT(button),
COLOR_FILTER);
- color_selection_bg = create_color_sel_win(filter, &colorf->bg_color);
- gtk_object_set_data(GTK_OBJECT (colorf->edit_dialog), COLOR_SELECTION_BG,
+
+ /* 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);
- bg_set_flag = 1;
+ gtk_object_set_data(GTK_OBJECT (color_selection_bg),
+ COLOR_SELECTION_PARENT, colorf->edit_dialog);
+ }
}
/* accept color (and potential content) change */
cf.colors->row_selected, 1, filter_text);
/* Destroy the dialog box. */
- edit_color_filter_dialog_destroy(colorf);
+ gtk_widget_destroy(dialog);
}
}
edit_color_filter_cancel_cb (GtkObject *object,
gpointer user_data)
{
-
GtkWidget *dialog;
- color_filter_t *colorf;
dialog = (GtkWidget *)user_data;
- colorf = (color_filter_t *) gtk_object_get_data(GTK_OBJECT(object),
- COLOR_FILTER);
/* Destroy the dialog box. */
- edit_color_filter_dialog_destroy(colorf);
+ gtk_widget_destroy(dialog);
}
static GtkWidget*
-create_color_sel_win (colfilter *filter, GdkColor * color)
+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;
- color_sel_win = gtk_color_selection_dialog_new (("Choose color"));
+ 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);
GTK_WIDGET_SET_FLAGS (color_sel_help, GTK_CAN_DEFAULT);
-#if 0
gtk_signal_connect (GTK_OBJECT (color_sel_win), "destroy",
GTK_SIGNAL_FUNC (color_sel_cancel_cb),
color_sel_win);
-#endif
gtk_signal_connect (GTK_OBJECT (color_sel_ok), "clicked",
GTK_SIGNAL_FUNC (color_sel_ok_cb),
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,
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;
if ( ! get_color(&new_color) ){
simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate color. Try again.");
} else {
- gtk_widget_destroy(color_dialog);
+ /* 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( bg_set_flag)
+ if (is_bg)
style->base[GTK_STATE_NORMAL] = new_color;
else
style->fg[GTK_STATE_NORMAL] = new_color;
color_dialog = (GtkWidget *)user_data;
/* nothing to change here. Just get rid of the dialog box. */
- gtk_widget_destroy(color_dialog);
+ color_sel_win_destroy(color_dialog);
}
static gboolean