Re: Scroll to the end of a TextView

It wasn't intuitive, but scroll to mark doe the trick, the following
func append to a textview (a log actually) and scrolls:

void scacpg_append_runlog(char * msg, ...)
   GtkTextView * eview;
   GtkTextBuffer * ebuf;
   GtkTextIter start, end;
   va_list ap;
   char * buffer = NULL;
   int l, L = 128;
   GtkTextMark* mark;

   va_start(ap, msg);

   do {
      L *= 2;
      debug("realloc of log buffer to size %d", L);
      buffer = realloc(buffer, L);
      l = vsnprintf(buffer, L, msg, ap);
      if (l < 0) return;
   } while (l >= L);

   eview = (GtkTextView* ) lookup_widget(dialog_run,
   ebuf = gtk_text_view_get_buffer (eview);

   debug ("runlog: %s(%d)", buffer, l);
   gtk_text_buffer_get_bounds (ebuf, &start, &end);
   gtk_text_buffer_insert  (ebuf, &end, buffer, l);
   gtk_text_buffer_get_bounds (ebuf, &start, &end);

   mark = gtk_text_buffer_create_mark    (ebuf, NULL, &end, 1);
   gtk_text_view_scroll_to_mark(eview, mark, 0.0, 0, 0.0, 1.0);
   gtk_text_buffer_delete_mark (ebuf, mark);



On Thu, 2004-03-04 at 20:45, Felipe Weckx wrote:
> Hi everyone,
> Here's the deal: the program receives a string and show it on a TextView 
> , that's OK, but I have to scroll the view to end of the text, I tried 
> using gtk_text_buffer_get_end_iter and gtk_text_view_scroll_to_iter, but 
>   it only scrolls to beginning of the text I've just inserted, so if it 
> has more than one line, it doesn't scrolls to the end.
> Does anyone knows how to scroll to the end of the text?
Terje Eggestad <terje eggestad iname com>

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