[gtkada] Need help with Entry and Signals

Emmanuel Briot briot at gnat.com
Mon Jun 5 12:19:26 CEST 2000


Preben Randhol writes:
 > I'm trying to add a "filter" to a entry widget so that I can filter out
 > those keys that are not allowed to input. That is such as GDK_Left and
 > GDK_Right and more. I also want to use this Handler to check the keys
 > inputted against another string.
[...]
 > Now this works, but when I press the left arrow the Entry Widget looses
 > the Focus. I think this is because as the Entry widget isn't processing
 > the left arrow, the window thinks that it should move the focus to the
 > next widget. Is this right. And how can I prevent this from happening?


Here are a few additional comments that Bobby left out.

The handler for "key_press_event" should return a Boolean (as documented in
gtk-widget.ads).
The development version of Gate/Dgate now will automatically recognize these
handlers, but this has not been released yet. You will have to modify it by
hand.

Thus, you should have something like:


function Check_Pressed_Key (myEntry : access Gtk.Gentry.Gtk_Entry_Record'Class;
                            myEvent : Gdk.Event.Gdk_Event_Key)
                    return Boolean
is
begin
   ....
   return False;
end Check_Pressed_Key;

When you find a key that you know how to handle, you should first stop the
emission of the signal, as Bobby described in his mail, and then return
'True', so that the event is not propagated to its parent (ie the notebook or
whatever container you used).

 > Another thing is there a functions so that one can easily check the Key
 > (in the code above) against a Wide_character? 

No, you can only get a string, with Gdk.Event.Get_String.
GtkAda does not automatically know what is a string and what is a wide-string
(this is expecting since this comes from the C char*, which does not specify
the format).

Emmanuel





More information about the gtkada mailing list