Ethereal-dev: [ethereal-dev] idea for style change of byte view highlighting and sample patch

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Nathan Neulinger <nneul@xxxxxxx>
Date: Mon, 06 Dec 1999 19:03:01 -0600
Note - this patch isn't ready (it works fine, but it's got visual
glitches), but it demonstrates the idea enough for discussion.

This patch highlights the text in the byte view by inverting it, in
addition to boldfacing it. This can be considerably easier to read in
some cases (in particular, looking at the ASCII portion).

Thoughts? 

-- Nathan

------------------------------------------------------------
Nathan Neulinger                       EMail:  nneul@xxxxxxx
University of Missouri - Rolla         Phone: (573) 341-4841
Computing Services                       Fax: (573) 341-4216
Index: gtk/proto_draw.c
===================================================================
RCS file: /cvsroot/ethereal/gtk/proto_draw.c,v
retrieving revision 1.7
diff -u -r1.7 proto_draw.c
--- proto_draw.c	1999/12/03 21:28:58	1.7
+++ proto_draw.c	1999/12/07 01:00:24
@@ -62,9 +62,16 @@
   gint     i = 0, j, k, cur;
   gchar    line[128], hexchars[] = "0123456789abcdef", c = '\0';
   GdkFont *cur_font, *new_font;
+  GdkColor *fg_color = NULL, *bg_color = NULL;
+  GtkStyle *style = NULL;
 
   /* Freeze the text for faster display */
   gtk_text_freeze(bv);
+  style = gtk_widget_get_style(GTK_WIDGET(bv));
+  if ( style ) {
+    fg_color = &style->text[GTK_STATE_NORMAL];
+    bg_color = &style->base[GTK_STATE_NORMAL];
+  }
 
   /* Clear out the text */
   gtk_text_set_point(bv, 0);
@@ -73,7 +80,7 @@
   while (i < len) {
     /* Print the line number */
     sprintf(line, "%04x  ", i);
-    gtk_text_insert(bv, m_r_font, NULL, NULL, line, -1);
+    gtk_text_insert(bv, m_r_font, fg_color, bg_color, line, -1);
     /* Do we start in bold? */
     cur_font = (i >= bstart && i < (bstart + blen)) ? m_b_font : m_r_font;
     j   = i;
@@ -94,13 +101,27 @@
       /* Did we cross a bold/plain boundary? */
       new_font = (i >= bstart && i < (bstart + blen)) ? m_b_font : m_r_font;
       if (cur_font != new_font) {
-        gtk_text_insert(bv, cur_font, NULL, NULL, line, cur);
+		if ( cur_font == m_b_font )
+		{
+        	gtk_text_insert(bv, cur_font, bg_color, fg_color, line, cur);
+		}
+		else
+		{
+        	gtk_text_insert(bv, cur_font, fg_color, bg_color, line, cur);
+		}
         cur_font = new_font;
         cur = 0;
       }
     }
     line[cur++] = ' ';
-    gtk_text_insert(bv, cur_font, NULL, NULL, line, cur);
+	if ( cur_font == m_b_font )
+	{
+    	gtk_text_insert(bv, cur_font, bg_color, fg_color, line, cur);
+	}
+	else
+	{
+    	gtk_text_insert(bv, cur_font, fg_color, bg_color, line, cur);
+	}
 
     cur = 0;
     i = j;
@@ -127,14 +148,28 @@
       /* Did we cross a bold/plain boundary? */
       new_font = (i >= bstart && i < (bstart + blen)) ? m_b_font : m_r_font;
       if (cur_font != new_font) {
-        gtk_text_insert(bv, cur_font, NULL, NULL, line, cur);
+		if ( cur_font == m_b_font )
+		{
+    		gtk_text_insert(bv, cur_font, bg_color, fg_color, line, cur);
+		}
+		else
+		{
+    		gtk_text_insert(bv, cur_font, fg_color, bg_color, line, cur);
+		}
         cur_font = new_font;
         cur = 0;
       }
     }
     line[cur++] = '\n';
     line[cur]   = '\0';
-    gtk_text_insert(bv, cur_font, NULL, NULL, line, -1);
+	if ( cur_font == m_b_font )
+	{
+    	gtk_text_insert(bv, cur_font, bg_color, fg_color, line, -1);
+	}
+	else
+	{
+    	gtk_text_insert(bv, cur_font, fg_color, bg_color, line, -1);
+	}
   }
 
   /* scroll text into position */