GtkText bug-fix



Hi,
I do understand that GtkText is long obsolete and you may not be
interested in feature-requests and bug-reports.
However, I have been using GtkText on Gtk+-1.2 mainly because I 
find GtkTextView (and more generaly Gtk+-2.2) too slow for my purpose.

The only problem I have with GtkText is that all the functions that move
the cursor scroll the window from its initial position to a position where
the new cursor is visible, which is much too slow if I want to jump from
line 0 to line 10000!
Thus, I implemented the gtk_text_move_to_row function (already present
but empty) to jump directly to a given row (by row,, I mean a \n
terminated sequence of characters, which can be displayed on several lines
due to line-wrapping). Whith this change, goto-line and search features
can be easily implemented by an application by using the already existing
"move-to-row" action signal.

Lastly, I changed slightly draw_line so that the blank between the last
character of a line and the right border of the widget is filled with the
backgound color assotiated with the \n character (or the hilight color if
the \n character is selected), as I find this much nicer.


As this patch is very small, I put it here:


-------------- cut here ------------------------
--- gtk+-1.2.10/gtk/gtktext.c Thu Mar 15 21:15:12 2001
+++ gtk+-1.2.10-patched/gtk/gtktext.c   Mon May 12 14:36:29 2003
@@ -4182,6 +4182,74 @@
 gtk_text_move_to_row (GtkEditable *editable,
                      gint         row)
 {
+  /* jump directly to row without scrolling through each line */
+
+  GtkText *text;
+  GList* line, *last;
+  guint height = 0;
+  
+  text = GTK_TEXT (editable);
+ 
+  if (text->line_start_cache == NULL) 
+    return;
+
+  /* undraw selection */
+
+  gtk_text_set_selection (editable,
+                         text->cursor_mark.index,
+                         text->cursor_mark.index);
+
+  /* special case */
+  
+  if (row < 0) 
+    {
+      move_cursor_buffer_ver (text, +1);
+      return;
+    }
+
+  
+  /* go up to to index 0 */
+
+  last = text->line_start_cache;
+
+  while (CACHE_DATA(text->line_start_cache).start.index != 0) {
+
+    if (!text->line_start_cache->prev)
+      fetch_lines_backward (text);
+
+    text->line_start_cache = text->line_start_cache->prev;
+  }
+
+  /* now, go down to row row */
+
+  fetch_lines_forward (text, row);
+
+  for (line = text->line_start_cache; line && row > 0; line = line->next)
+    {
+      height += LINE_HEIGHT(CACHE_DATA(line));
+      
+      if (!text->line_wrap || !CACHE_DATA(line).wraps)
+       row -= 1;
+      
+      if (!line->next)
+       fetch_lines_forward (text, row);
+    }
+
+  text->line_start_cache = last;
+
+  /* set cursor & scroll bar */
+
+  undraw_cursor (text, FALSE);
+
+  text->vadj->value = height - text->vadj->page_size / 2;
+  text->vadj->value = MIN (text->vadj->value, 
+                          text->vadj->upper - text->vadj->page_size);
+  text->vadj->value = MAX (text->vadj->value, 0.0);  
+  gtk_signal_emit_by_name (GTK_OBJECT (text->vadj), "value_changed");
+
+  text->cursor_mark = CACHE_DATA(line).start;
+  find_cursor (text, TRUE);
+  draw_cursor (text, FALSE);
 }
 
 static void 
@@ -5123,6 +5191,13 @@
        buffer.ch += len;
       chars -= len;
     }
+
+  /* The blank between the end of a line and the right border of the widget
+     has the background color associated to the \n character, and has the
+     background selection color when the \n is selected, which is nice. */
+  draw_bg_rect (text, &mark, running_offset, pixel_start_height,
+               GTK_WIDGET(text)->allocation.width-running_offset, 
+               LINE_HEIGHT (*lp), TRUE);
 }
 
 static void
-------------- cut here ------------------------


Hope this helps,
-
Antoine





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]