Re: [gtk-list] Re: entry input verification [Was: Uppercase only ent
- From: Ralf Corsepius <corsepiu faw uni-ulm de>
- To: gtk-list redhat com
- CC: Havoc Pennington <hp redhat com>, Owen Taylor <otaylor redhat com>
- Subject: Re: [gtk-list] Re: entry input verification [Was: Uppercase only ent
- Date: Wed, 01 Mar 2000 03:16:32 +0100
Owen Taylor wrote:
> 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.
> 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
Thanks for the pointer (I knew I had seen it before :).
What I tried is to implemente a "changed" signal handler in analogy to Havoc's
example (cf. below), but now ...
I don't seem to be able to the get the cursor positioned correctly.
I.e. in the example below (a "changed"-signal handler), when an editable
initially displayed "123<cursor>", after typing in a non-digit from the
keyboard, "123<blank><cursor>" is displayed. When pasting a string of
non-digits, strlen(string) blanks are displayed.
Though the characters seem to be deleted, the cursor seems to show where it
would have been shown, if the text had not been modified.
void
VerifyCB(GtkEditable *editable,
gpointer user_data)
{
int i ;
gchar *text = gtk_editable_get_chars(editable,0,-1);
for (i = 0; (text[i] != 0) && (isdigit(text[i])); i++){}
if ( text[i] != 0 )
{
text[i]=0 ;
gtk_editable_set_position(editable,i);
gtk_signal_handler_block_by_func (GTK_OBJECT (editable),
GTK_SIGNAL_FUNC (VerifyCB), user_data);
gtk_editable_delete_text(editable,i,-1);
gtk_signal_emit_stop_by_name (GTK_OBJECT (editable), "changed");
gtk_signal_handler_unblock_by_func (GTK_OBJECT (editable),
GTK_SIGNAL_FUNC(VerifyCB), user_data);
}
g_free (text);
}
I tend to think that cursor positioning with XXX_set_position from inside
"changed" or "insert_text" signal handler doesn't work or at least is not
allowed, when trying to reduce the size of the text.
Ralf
--
Ralf Corsepius
Forschungsinstitut fuer Anwendungsorientierte Wissensverarbeitung (FAW)
Helmholtzstr. 16, 89081 Ulm, Germany Tel: +49/731/501-8690
mailto:corsepiu@faw.uni-ulm.de FAX: +49/731/501-999
http://www.faw.uni-ulm.de
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]