Ethereal-dev: [ethereal-dev] patch to have ethereal scroll bold text into view

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, 15 Nov 1999 13:06:28 -0600
Does anyone know how to set the scroll position of a GtkText while it is 
frozen? That is the core of the problem - normally doing the inserts will 
scroll the cursor into position. I tried doing various things with 
setting the adjustment value, but it seems that this just causes crashes, 
so I'm probably not doing it right. 

Logic of the code:
	remember first bold line
	at end of that first bold line, get current insertion point
	at end of data
		thaw
		insert a blank
		delete the blank
		move to saved point
		insert a blank
		delete the blank
		freeze

This isn't the best way of doing it, but it does cause ethereal to have 
much more reasonable positioning of the highlighted text.

Note - This patch introduces a very slight flicker to the text box due to
it scrolling to the end and then back to the beginning. The reason I
scroll to the end first is to avoid the situation where a very short
portion of the bold area is visible at the end of the text box. This
causes much more of the text to be visible. 

-- Nathan

------------------------------------------------------------
Nathan Neulinger                       EMail:  nneul@xxxxxxx
University of Missouri - Rolla         Phone: (573) 341-4841
Computing Services                       Fax: (573) 341-4216
? gtk/.proto_draw.c.swp
Index: gtk/proto_draw.c
===================================================================
RCS file: /cvsroot/ethereal/gtk/proto_draw.c,v
retrieving revision 1.3
diff -u -r1.3 proto_draw.c
--- proto_draw.c	1999/09/12 20:23:43	1.3
+++ proto_draw.c	1999/11/15 18:59:34
@@ -59,9 +59,12 @@
 packet_hex_print(GtkText *bv, guint8 *pd, gint len, gint bstart, gint blen) {
   gint     i = 0, j, k, cur;
   gchar    line[128], hexchars[] = "0123456789abcdef";
+  gint     savepoint = 0, firstboldline = 0;
   GdkFont *cur_font, *new_font;
+  gint     scrolled = 0;
   
   while (i < len) {
+    firstboldline = 0;
     /* Print the line number */
     sprintf(line, "%04x  ", i);
     gtk_text_insert(bv, m_r_font, NULL, NULL, line, -1);
@@ -85,6 +88,11 @@
       /* 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) {
+	if ( !scrolled && new_font == m_b_font )
+	{
+		firstboldline = 1;
+		scrolled = 1;
+	}
         gtk_text_insert(bv, cur_font, NULL, NULL, line, cur);
         cur_font = new_font;
         cur = 0;
@@ -113,9 +121,27 @@
         cur = 0;
       }
     }
+    /* if this was the first bold line, find the insertion point at the end
+       of the line. Doing this at the end of the line so that it doesn't
+       need to redraw/shift all of that line's text. */
+    if ( firstboldline ) {
+      savepoint = gtk_text_get_point(bv);
+    }
     line[cur++] = '\n';
     line[cur]   = '\0';
     gtk_text_insert(bv, cur_font, NULL, NULL, line, -1);
+  }
+
+  /* scroll text into position */
+  if ( savepoint != 0 )
+  {
+    gtk_text_thaw(bv);
+    gtk_text_insert(bv,cur_font,NULL,NULL," ",1);
+    gtk_text_backward_delete(bv,1);
+    gtk_text_set_point(bv, savepoint);
+    gtk_text_insert(bv,cur_font,NULL,NULL," ",1);
+    gtk_text_backward_delete(bv,1);
+    gtk_text_freeze(bv);
   }
 }