[gtkada] Need help with Entry and Signals

Preben Randhol randhol at pvv.org
Sun Jun 4 20:36:05 CEST 2000


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.

I have thus done this:

---------------------------------------------------------------------------
[window1_pkg.adb]

   -- Connecting the signal to the  procedure Check_Pressed_Key
   Entry_Cb.Connect
        (Window1.Entry1,
         Name => "key_press_event",
         Marsh => Entry_Cb.To_Marshaller (Check_Pressed_Key'Access),
         After => False);
         
[window1_pkg-callbacks.ads]

   procedure Check_Pressed_Key (myEntry : access 
                                          Gtk.Gentry.Gtk_Entry_Record'Class;
                                myEvent : Gdk.Event.Gdk_Event_Key);

[window1_pkg-callbacks.adb]

   procedure Check_Pressed_Key (myEntry : access 
                                          Gtk.Gentry.Gtk_Entry_Record'Class;
                                myEvent : Gdk.Event.Gdk_Event_Key) is
      Key : Gdk_Key_Type;
   begin
       Key := Get_Key_Val(myEvent);
      
       -- Only for debugging
       -- Ada.Text_IO.Put_Line ("Key: " &Gdk_Key_Type'Image(Key));

      if (Key = GDK_Left ) then
         
         -- I don't want the Entry to get this key so I use
         -- Emit_Stop_By_Name
         Emit_Stop_By_Name(myEntry, "key_press_event");
       end if;

   end Check_Pressed_Key;

[callbacks_touch.ads]

   package Entry_Cb is new 
         Gtk.Handlers.Callback (Widget_Type => Gtk_Entry_Record);

-----------------------------------------------------------------------------

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?

Also if you see som bug/stupidness in this code please tell me.

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

-- 
Preben Randhol -- [randhol at pvv.org] -- <http://www.pvv.org/~randhol/>
         "Det eneste trygge stedet i verden er inne i en fortelling."
                                                      -- Athol Fugard





More information about the gtkada mailing list