Re: [gtk-list] Re: entry input verification [Was: Uppercase onlyent



On Wed, 1 Mar 2000, Ralf Corsepius wrote:

> 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

  I posted a message 2 weeks ago with subject 'cursor position handling by
GtkEntry' - I complained about this strange behaviour of GtkEntry. Seems that
even deleting all text in entry (by gtk_entry_set_text(e,"") and returning
current content back won't update cursor position at all). So, cursor handling
is almost broken for GtkEntry. I guess standard hack could help (not tested) -
adding new idle one-shot callback that will position cursor to correct place 
and remove itself from list of iddle callbacks could work, but what will 
happen if used is typing very fast?

  No one replied to that message I've posted.

 Best regards,
  -Vlad



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