Re: [gtk-list] RE: entry input verification [Was: Uppercase only ent
- From: Owen Taylor <otaylor redhat com>
- To: gtk-list redhat com
- Cc: Ralf Corsepius <corsepiu faw uni-ulm de>, trog gtk org
- Subject: Re: [gtk-list] RE: entry input verification [Was: Uppercase only ent
- Date: 29 Feb 2000 13:12:18 -0500
Trog <trog@gtk.org> writes:
> On 29-Feb-2000 Ralf Corsepius wrote:
> > On a related subject (It might be an FAQ, but ...):
>
> [NOTE to self] write a FAQ entry for this.
>
> >
> > I am looking for a method to provide input verification on
> > GtkEntry/GtkEditable, e.g. I am looking for an GtkEditable which
> > shall only
> > accept a subset of characters (eg. those that match a regular
> > expression, or
> > integers only) as text input.
> >
> > [Actually, I looking for something similar to Motif's
> > XmNmodifyVerifyCallback
> > for XmTextFieldWidgets]
> >
> > The approach you outline above doesn't seem to work in my case,
> > because the
> > insert_text signal does't seem to allow changing the size of the
> > inserted
> > text.
> > Implementing it with the changed signal seems to be possible, but
> > seems to be
> > rather ineffective and also seems to suffer from the "infinite
> > loop" issue
> > (changed being called because invoking "set_text" ).
>
> Attach to the "key_press_event" event of the entry widget:
>
> gtk_signal_connect(GTK_OBJECT(entry),
> "key_press_event"
> GTK_SIGNAL_FUNC(entry_key_press),
> data);
>
> Then the callback function goes along the lines:
>
> gint entry_key_press (GtkWidget *widget,
> GdkEventKey *event,
> gpointer data)
> {
> switch (event->keyval) {
> case GDK_F1:
> gtk_signal_emit_stop_by_name(GTK_OBJECT(widget),"key_press_event");
> gtk_editable_insert_text( GTK_EDITABLE(widget), "hello",
> 5,>K_EDITABLE(widget)->current_pos);
> return TRUE;
>
> case GDK_F2:
> gtk_signal_emit_stop_by_name(GTK_OBJECT(widget),"key_press_event");
> gtk_editable_insert_text( GTK_EDITABLE(widget), "world",
> 5,>K_EDITABLE(widget)->current_pos);
> return TRUE;
> }
>
> return FALSE;
> }
>
> I think that covers what you need. Well, you should get the idea
> anyway.
This isn't a good approach, because if you do it this way, the
user will be able to cut-and-paste invalid input into the entry,
even if they can't edit it directly.
See the example in the GtkEditable reference docs:
http://developer.gnome.org/doc/API/gtk/gtkeditable.html
For a completion implementation of the method that Havoc has
described.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]