Ethereal-dev: [ethereal-dev] colors.c and .h patches
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Phil Techau <phil_t@xxxxxxxxxxxxx>
Date: Thu, 07 Oct 1999 11:08:11 -0400
Please find attached the output from "diff -u" against colors.c and colors.h. If we can't allocate a (now read-only) color from the system colormap, then we get our best color mode from gtk and allocate a new colormap. This seems to work with OpenView, and no nasty colors have been seen yet from using this method. The one thing that is nagging me is to maybe save off the colors that we've chosen so far, so that if we roll over to a private colormap we can reallocate those colors. Comments? If someone could check these changes in, I'd appreciate it. A couple of notes: - one of the list's suggestions was to run OpenView with a private colormap; I did a quick check and didn't find a well-documented option to do this - another suggestion was to use gdk_color_black; gdk.h in GTK+ 1.2.4 has this function marked as "Deprecated" - I made and tested these changes under Solaris; however, my CVS/Internet access is via Win98/WinCvs with a little Linux thrown in for the "diff -u", and I have to re-do the edits by hand a second time; hopefully everything survived the wild ride. Regards, Phil Techau
--- original/colors.c Thu Oct 7 10:20:46 1999 +++ ./colors.c Thu Oct 7 10:10:34 1999 @@ -50,6 +50,7 @@ GdkColor proto_colors[MAXCOLORS]; GdkColormap* sys_cmap; +GdkColormap* our_cmap = NULL; static gchar *titles[2] = { "Name", "Filter String" }; GdkColor WHITE = { 0, 65535, 65535, 65535 }; @@ -86,14 +87,10 @@ sys_cmap = gdk_colormap_get_system(); /* Allocate "constant" colors. */ - if( !gdk_colormap_alloc_color(sys_cmap, &WHITE, TRUE, TRUE)){ + if( !get_color(&WHITE) || + !get_color(&BLACK)){ /* oops */ - simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate color white."); - } - - if( !gdk_colormap_alloc_color(sys_cmap, &BLACK, TRUE, TRUE)){ - /* oops */ - simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate color black."); + simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate basic colors."); } #ifdef READ_DEFAULT_COLOR_LIST @@ -101,7 +98,7 @@ for (i = 0 ; i < sizeof default_colors/sizeof (struct _default_colors); i++){ gdk_color_parse(default_colors[i].color, &color); - if( !gdk_colormap_alloc_color(sys_cmap, &color, TRUE, TRUE)){ + if( !get_color(&color)){ /* oops */ simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate color %s.", default_colors[i].color); @@ -257,32 +254,32 @@ bg_color.red = bg_r; bg_color.green = bg_g; bg_color.blue = bg_b; - if( !gdk_colormap_alloc_color(sys_cmap, &fg_color, TRUE, TRUE)){ - /* oops */ - simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate fg color specified" - "in input file for %s.", name); + if( !get_color(&fg_color)){ + /* oops */ + simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate fg color specified" + "in input file for %s.", name); - i++; - continue; + i++; + continue; } - if( !gdk_colormap_alloc_color(sys_cmap, &bg_color, TRUE, TRUE)){ - /* oops */ - simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate bg color specified" - "in input file for %s.", name); - i++; - continue; + if( !get_color(&bg_color)){ + /* oops */ + simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate bg color specified" + "in input file for %s.", name); + i++; + continue; } - color_filter(cf,i)->bg_color = bg_color; - color_filter(cf,i)->fg_color = fg_color; - gtk_clist_set_foreground(GTK_CLIST(cf->colors->color_filters), + color_filter(cf,i)->bg_color = bg_color; + color_filter(cf,i)->fg_color = fg_color; + gtk_clist_set_foreground(GTK_CLIST(cf->colors->color_filters), i,&fg_color); - gtk_clist_set_background(GTK_CLIST(cf->colors->color_filters), + gtk_clist_set_background(GTK_CLIST(cf->colors->color_filters), i,&bg_color); i++; } /* if sscanf */ - } while( !feof(f)); + } while( !feof(f)); return TRUE; } @@ -639,7 +636,7 @@ new_color.green = (guint16)(new_colors[1]*65535.0); new_color.blue = (guint16)(new_colors[2]*65535.0); - if ( ! gdk_colormap_alloc_color(sys_cmap, &new_color, TRUE, TRUE) ){ + if ( ! get_color(&new_color) ){ simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate color. Try again."); } else { gtk_widget_destroy(color_dialog); @@ -1110,3 +1107,18 @@ return color_sel_win; } +gboolean +get_color ( GdkColor *new_color) { + + GdkVisual *pv; + + if (!our_cmap) { + if ( !gdk_colormap_alloc_color (sys_cmap, new_color, FALSE, TRUE)) { + pv = gdk_visual_get_best(); + if ( !(our_cmap = gdk_colormap_new(pv, TRUE))) + simple_dialog(ESD_TYPE_WARN, NULL, "Could not create new colormap"); + } else + return (TRUE); + } + return ( gdk_colormap_alloc_color ( our_cmap, new_color, FALSE, TRUE) ); +}
--- original/colors.h Thu Oct 7 10:20:46 1999 +++ ./colors.h Thu Oct 7 10:16:36 1999 @@ -149,6 +149,9 @@ color_sel_ok_cb (GtkButton *button, gpointer user_data); +gboolean +get_color (GdkColor *new_color); + GtkWidget* create_color_win (cap_file *cf); GtkWidget* create_colorize_win (cap_file *cf, GtkWidget **colorize_filter_name,
- Follow-Ups:
- Re: [ethereal-dev] colors.c and .h patches
- From: Guy Harris
- Re: [ethereal-dev] colors.c and .h patches
- From: Guy Harris
- Re: [ethereal-dev] colors.c and .h patches
- Prev by Date: [ethereal-dev] More press
- Next by Date: Re: [ethereal-dev] More press
- Previous by thread: Re: [ethereal-dev] More press
- Next by thread: Re: [ethereal-dev] colors.c and .h patches
- Index(es):