RE: GtkAdjustment question
- From: "AZINCOURT, Eric" <eric azincourt freshfields com>
- To: "'gtk-list gnome org'" <gtk-list gnome org>
- Subject: RE: GtkAdjustment question
- Date: Tue, 2 Jul 2002 17:27:12 +0100
unsubscribe
-----Original Message-----
From: Brian Masney [mailto:masneyb ntelos net]
Sent: mardi 2 juillet 2002 12:49
To: gtk-list gnome org
Subject: GtkAdjustment question
I am working on porting an app from gtk 1.2 over to 2.0. I am using the
TextView widget to display log messages to the user, and as new messages
appear, I would automatically like the window to scroll. But, if the user
goes
to scroll up in the text view, I don't want it to scroll down automatically.
The problem that I ran into if I display more than a page full of text in
the
text view before I enter the main loop, it won't automatically scroll. I've
included a test program that inserts text on startup, and then every 1.5
seconds, it will insert more text.
#include <gtk/gtk.h>
#include <stdio.h>
#include <time.h>
GtkAdjustment * logwdw_vadj;
GtkWidget * logwdw;
static void log ( char * message );
static gint insert_text ( gpointer data );
int
main (int argc, char **argv)
{
GtkWidget * window, * sw;
char buf[20];
int i;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (window, 400, 100);
logwdw = gtk_text_view_new ();
gtk_text_view_set_editable (GTK_TEXT_VIEW (logwdw), FALSE);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (logwdw), FALSE);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (logwdw), GTK_WRAP_WORD);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
logwdw_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW
(sw));
gtk_container_add (GTK_CONTAINER (sw), logwdw);
gtk_container_add (GTK_CONTAINER (window), sw);
gtk_widget_show_all (window);
/* Change this to only 1 or 2 iterations, and it will work properly */
for (i=0; i<20; i++)
{
g_snprintf (buf, sizeof (buf), "Message %d\n", i);
log (buf);
}
gtk_timeout_add (1500, insert_text, NULL);
gtk_main ();
return (0);
}
static void
log (char * message)
{
GtkTextBuffer * textbuf;
GtkTextIter iter;
guint len;
int upd;
upd = logwdw_vadj->upper - logwdw_vadj->page_size == logwdw_vadj->value;
printf ("upd %d, lower %.2f, upper %.2f, value %.2f, step_increment %.2f,
page_increment %.2f, page_size %.2f\n", upd, logwdw_vadj->lower,
logwdw_vadj->upper, logwdw_vadj->value, logwdw_vadj->step_increment,
logwdw_vadj->page_increment, logwdw_vadj->page_size);
textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw));
len = gtk_text_buffer_get_char_count (textbuf);
gtk_text_buffer_get_iter_at_offset (textbuf, &iter, len);
gtk_text_buffer_insert (textbuf, &iter, message, -1);
if (upd)
gtk_adjustment_set_value (logwdw_vadj, logwdw_vadj->upper);
}
static gint
insert_text (gpointer data)
{
char buf[20];
int i;
for (i=0; i<5; i++)
{
g_snprintf (buf, sizeof (buf), "Message %d\n", i);
log (buf);
}
gtk_timeout_add (1500, insert_text, NULL);
return (0);
}
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list
This e-mail is confidential and may well also be legally privileged. If you have received it in error, you are on notice of its status. Please notify us immediately by reply e-mail and then delete this message from your system. Please do not copy it or use it for any purposes, or disclose its contents to any other person: to do so could be a breach of confidence. Thank you for your co-operation. Please contact our
IT Helpdesk on +44 (0) 20 7936 4000 Ext.2000 or email ITHelp freshfields com if you need assistance.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]