Re: ANNOUNCE: gtkentrymask - gtkentry with masks and types

Santiago Capel escribió:

> Havoc Pennington escribió:
> > Santiago Capel <bluefish ono com> writes:
> > > Hello, I am proud to announce a new gtk entry widget that allows to add
> > > type and mask (with internationalization, I hope ;-) ) to gtkentry. It
> > > is at:
> > >
> > >
> >
> > This looks like a useful widget, it may even work in to the validation
> > feature for GtkEntry. See
> >  We also need to
> > research APIs for this in Java/Swing, Qt, and System.WinForms from the
> > .NET platform to see what ideas can be gathered.
> Ok, I have read the discussion, and this is my approach:
> In relation to focus, I have suffered a great deal with the focus_in and
> focus_out events, but not only with GTK but also with Windows (Visual
> Basic 5). This is an annoying problem very difficult to solve just with
> the events activate, focus_in and focus_out. I think that what we need
> is a validate event, that would work in the following way:
> - Add to GtkWidget a 'validate' event
>     gint (* validate_event ) (GtkWidget *widget, GdkEventFocus *event);
> - Add to GtkWidget a 'causes_validation' flag/property/bit
> - The validate callback function could be like this:
>     gint my_widget_validate_event_cb(GtkWidget *widget, GdkEventFocus
> *event)
>     {
>             return my_widget_is_valid();
>     }
> - Behavior.
>     When my_widget loses its focus, the GTK focus handling routine
> should do:
>     new_focused_widget = find the new focused widget
>     if new_focused_widget belongs to my dialog/window/form/application
> then
>         if new_focused_widget->causes_validation = true then
>             emit validate signal on my_widget
>             if validate returned false then
>                   grab the focus again to my_widget,
>                            assuring that neither the validate nor
> focus_in nor focus_out event
>                            are emitted neither on new_focused_widget nor
> on my_widget
>            endif
>         endif
>     endif
> With this approach, a typical form with the buttons OK and Cancel would
> have the Cancel->causes_validation=false
> and the rest of widgets (including the OK button) with
> causes_validation=true.
> Each time a widget loses its focus, the validate event is called on that
> widget. If the validation is correct it returns true and the normal
> behavior of focus_out is done, it the validation is incorrect, the
> validate event (application programmer) can show a message (very
> troublesome because of the focus_in and outs caused by the message
> window) and return false, in which case, the focus is given back to that
> widget. If the user press the Cancel button, there is no validation and
> the window closes.

Well, I have been hacking a bit in the gtk+-1.2.10 code to implement this
behavior and the result is very successful.

I have uploaded a version of gtk+-1.2.10 called gtk+-1.2.10-with-validation
and you can find it at:

To test it, execute the test program called 'testgtk' and press the button
'entry'. In the window appear a entry box, a combo box, three checkbuttons and
a button.
Place the cursor over the first widget (the entry widget). Its text is Hello
world. Then, try to click one of the checkbuttons or the button or the combo.
You'll see a dialog appear (this can be a message dialog) and when you close
it, the focus is back to the entry.

If you write a text in the entry starting with 'a', you'll be able to go to
the other controls, as the entry is valid.

For a explanation of the code, I'm going to create right now a new thread of
posts to this list, called 'GtkWidgets validation'

        Santiago Capel Torres

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