0.99.7 Entry (editable?) bug




The Entry widget seems to have a problem handling the insertion of
some characters in the character set.

The code below illustrates the problem. Hitting F1 will insert a
character with code /244 (a kind of square with a diagonal line off of
each corner). Hitting F2 inserts an 'h'.

To see the problem, hit F2 a couple of times, and then use backspace
to delete the h's. Do the same with F1 and you will see that all the
text in the entry since the first F1 gets deleted with one backspace
key press.

You can see this more vividly by pressing F1, and then typing some
text into the entry and hitting backspace - all the text disappears.

Cheers

Tony

PS. Why, you may ask, would I want to insert such characters in the
first place. I use them in my irc client to allow the user to mark
the start/end of a region of bold text, for example.

But, this could also conceivably happen using cut and paste.
--
E-Mail: Tony Gale <gale@daedalus.dera.gov.uk>
There's nothing remarkable about it.  All one has to do is hit the
right
keys at the right time and the instrument plays itself.
                -- J.S. Bach

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.
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>

gint entry_key_press (GtkWidget *widget, GdkEventKey *event, GtkEntry *entry)
{

  if (event->keyval == GDK_F1) {
	gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
        gtk_entry_append_text( GTK_ENTRY(widget), "\244");
        return TRUE;
  } else if (event->keyval == GDK_F2) {
	gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
        gtk_entry_append_text( GTK_ENTRY(widget), "h");
        return TRUE;
  }
  return(FALSE);
}

int main (int argc, char *argv[])
{

    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *entry;
    GtkWidget *button;

    gtk_init (&argc, &argv);

    /* create a new window */
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);
    gtk_window_set_title(GTK_WINDOW (window), "GTK Entry");
    gtk_signal_connect(GTK_OBJECT (window), "delete_event",
                       (GtkSignalFunc) gtk_exit, NULL);

    vbox = gtk_vbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), vbox);
    gtk_widget_show (vbox);

    entry = gtk_entry_new_with_max_length (50);
    gtk_signal_connect (GTK_OBJECT(entry), "key_press_event",
                        GTK_SIGNAL_FUNC(entry_key_press), entry);
  
    gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
    gtk_widget_show (entry);
                               
    button = gtk_button_new_with_label ("Close");
    gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
			       GTK_SIGNAL_FUNC(gtk_exit),
			       GTK_OBJECT (window));
    gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
    gtk_widget_show (button);
    
    gtk_widget_show(window);

    gtk_main();
    return(0);
}


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