Text widget delete bug example
- From: Tony Gale <gale daedalus dra hmg gb>
- To: gtk-list redhat com
- Subject: Text widget delete bug example
- Date: Wed, 25 Feb 1998 14:42:35 -0000 (GMT)
As requested by Owen :-) here is a piece of example code that
illustrates the Text Widget delete bug.
Just keep hitting the 'add line' button, and when it reaches more
than 10 lines, which is when it starts deleting text, the bug will
become clear - the number should continue to increase.
BTW, I seem to remember that the testgtk text example had a similar
bug when deleting text in editable mode, using the delete key, but
that one seems to be fixed.
Cheers
Tony
--------------------------------------
#include <gtk/gtk.h>
#include <gtk/gtktext.h>
GtkObject *adjustment;
GtkWidget *text;
int numlines = 0;
void quit_callback (GtkWidget *widget, gpointer data)
{
g_print ("%s\n", (char *) data);
gtk_exit(0);
}
void addline_callback(GtkWidget *widget, gpointer data)
{
int numchars=0;
char buff[1024];
gtk_text_freeze(GTK_TEXT(text));
sprintf(buff, "This is line %d\n", numlines);
gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, buff, -1);
gtk_text_thaw(GTK_TEXT(text));
numlines++;
if (numlines > 10) {
gtk_text_freeze(GTK_TEXT(text));
while( GTK_TEXT(text)->text[numchars] &&
(GTK_TEXT(text)->text[numchars] != '\n') ) {
numchars++;
}
if ( GTK_TEXT(text)->text[numchars] ) {
gtk_text_set_point( GTK_TEXT(text), 0);
gtk_text_forward_delete( GTK_TEXT(text), numchars+1);
gtk_text_set_point( GTK_TEXT(text),
gtk_text_get_length( GTK_TEXT(text)));
numlines--;
}
gtk_text_thaw(GTK_TEXT(text));
}
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *vscrollbar;
GtkWidget *button;
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");
gtk_widget_set_usize(GTK_WIDGET (window), 300, 300);
vbox = gtk_vbox_new(FALSE, 1);
gtk_container_border_width(GTK_CONTAINER(vbox), 1);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show(vbox);
hbox = gtk_hbox_new(FALSE, 1);
gtk_container_border_width(GTK_CONTAINER(hbox), 1);
gtk_container_add(GTK_CONTAINER(vbox), 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);
button = gtk_button_new_with_label ("add line");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(addline_callback),
GTK_OBJECT (window));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_show(button);
gtk_main();
return(0);
}
--
E-Mail: Tony Gale <gale@daedalus.dra.hmg.gb>
The best laid plans of mice and men are usually about equal.
-- Blair
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]