Re: [gtk-list] How do I scroll from the program



I use this code in one of my programs to append messages to a log window
and have the window scroll to the end.

static GtkText *logwin;
static GtkAdjustment *logadj;

static void
append_to_log(const gchar *prefix, const gchar *msg)
{
    guint pos = gtk_text_get_length(logwin);

    gtk_text_freeze(logwin);
    if (prefix)
	gtk_editable_insert_text(GTK_EDITABLE(logwin), 
				 prefix, strlen(prefix), &pos);
    gtk_editable_insert_text(GTK_EDITABLE(logwin), msg, strlen(msg),
&pos);
    gtk_editable_insert_text(GTK_EDITABLE(logwin), "\n", 1, &pos);
    gtk_text_thaw(logwin);

    gtk_adjustment_set_value(logadj, logadj->upper - logadj->page_size);
}

The following initialises the two static variables.  It depends on glade
produced code, but the idea shoud be clear.

    logwin = GTK_TEXT(lookup_widget(top->window, "top_level_message"));
    scr = GTK_SCROLLED_WINDOW(lookup_widget(top->window,
"scrolledwindow8"));
    logadj = gtk_scrolled_window_get_vadjustment(scr);



-- 
René Seindal (rene@seindal.dk)			http://www.seindal.dk/rene/



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