text widget with adjustment



Hi all,

This is with the current CVS snapshot. I am trying to change the
viewing position of a text widget with a vertical scrollbar,
using an adjustment. However, when I try and change the value of the
adjustment, to change the view port, it crashes.

I don't really know if the way I am attempting to do this is supposed
to work - but I need to be able to do this. Basically I want to be
able to insert some text at the bottom of a text widget, and for that
to be in the visible part of the text widget.

Anyway, here is the code. It dies in the call
to gtk_adjustment_set_value. Any help appreciated.

Tony
----------------------------------

#include <gtk/gtk.h>

void quit_callback (GtkWidget *widget, gpointer data)
{
  g_print ("%s\n", (char *) data);
  gtk_exit(0);
}  

int main(int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *hbox;
  GtkWidget *text;
  GtkWidget *vscrollbar;
  GtkObject *adjustment;

  char buff[1000];
  int i;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_signal_connect(GTK_OBJECT(window), "destroy",
                     GTK_SIGNAL_FUNC(quit_callback),
                     "WM destroy");
  gtk_signal_connect (GTK_OBJECT(window), "delete_event",
                      GTK_SIGNAL_FUNC(quit_callback),
                       "Delete");

  hbox = gtk_hbox_new(FALSE, 1);
  gtk_container_border_width(GTK_CONTAINER(hbox), 1);
  gtk_container_add(GTK_CONTAINER(window), hbox);
  gtk_widget_show(hbox);

  adjustment = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 10.0);

  text = gtk_text_new(NULL, GTK_ADJUSTMENT(adjustment));
  gtk_text_set_editable(GTK_TEXT(text), FALSE);
  gtk_box_pack_start(GTK_BOX(hbox), text, TRUE, TRUE, 2);
  gtk_widget_show (text);

  vscrollbar = gtk_vscrollbar_new (GTK_TEXT(text)->vadj);
  gtk_range_set_update_policy (GTK_RANGE (vscrollbar),
                               GTK_UPDATE_CONTINUOUS);
  gtk_box_pack_start(GTK_BOX(hbox), vscrollbar, FALSE, TRUE, 0);
  gtk_widget_show (vscrollbar);           
  gtk_widget_show(window);

  gtk_text_freeze( GTK_TEXT(text) );
  for (i=0; i < 100; i++) {
    sprintf(buff, "Text line %d\n");
    gtk_text_insert( GTK_TEXT(text), NULL, NULL, NULL, buff, -1);
  }

  /* Dies here */
  gtk_adjustment_set_value( GTK_ADJUSTMENT(adjustment), 100.0);

  gtk_text_thaw( GTK_TEXT(text) );
  gtk_main();

  return(0);
}                  

--
E-Mail: Tony Gale <gale@minotaur.dra.hmg.gb>
Marriage is a ghastly public confession of a strictly private
intention.

The views expressed above are entirely those of the writer
and do not represent the views, policy or understanding of
any other person or official body.



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