[gtkada] Gtk_Spin_Button and focus out signal.

Clark, G L g.l.clark at lmco.com
Thu May 9 00:57:30 CEST 2002


Preben Randhol, et al:

   Here's what I found out... (Since I asked the question.)

   It seems the main problem is that the text typed into a Spin_Button entry
field is not reflected in the Spin Button's adjustment until the Focus_Out
event is called. In a user implemented focus_out handler the value typed
into the entry field is not yet available.  At least not until the focus_out
event is propagated up the widget tree (or however that works), which
happens after the user defined focus_out finishes execution.
   The solution is to emit an "activate" signal within the user defined
focus_out even handler.  This will sync the value in the field with the
value of the Spin_Button's adjustment.  It will also force the value into
the correct range as expected.
 
	procedure On_Some_Spin_Button_Focus_Out
	  (Object : access Gtk_Spin_Button_Record'Class) is
	
	begin
        Spin_Button_Callback.Emit_By_Name(Object, "activate");
        -- Do validation or storage or any other necessary operations.
	end On_Some_Spin_Button_Focus_Out;

-George Clark


-----Original Message-----
From: Preben Randhol [mailto:randhol at pvv.org]
Sent: Wednesday, May 08, 2002 10:46 AM
To: gtkada at lists.act-europe.fr
Subject: Re: [gtkada] Gtk_Spin_Button and focus out signal.


"Clark, G L" <g.l.clark at lmco.com> wrote on 08/05/2002 (16:53) :
>
> Hello All,
>
>    In my application I have implemented "focus out" handlers for my
> Spin_Button widgets which validates and stores the data.  However,
> internally "focus out" is used to update the value to a valid range...
they
> no longer do this. The range is left invalid when data is read and it's
> causing all sorts of problems.
>    How do I go about forcing the spin_button to jump into a valid range in
> the "focus out" handler that I've implemented.

   procedure On_Some_Spin_Button_Focus
      (Object : access  Gtk_Spin_Button_Record'Class) is

      Value : GFloat := Get_Value_As_Float (Object);
      Adjustment : Gtk_Adjustment := Get_Adjustment (Object);
   begin

   if Value < Get_Lower (Adjustment) then
      Value := Get_Lower (Adjustment);
   elsif Value > Get_Upper (Adjustment) then
      Value := Get_Upper (Adjustment);
   end if;

   Set_Value (Adjustment, Value);
   Set_Adjustment (Object, Adjustment);

   end On_Some_Spin_Button_Focus;

Note I have not tested this. I have to run now as the shops close in 15
min due. Hope it helps.

--
Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
                 «For me, Ada95 puts back the joy in programming.»

_______________________________________________
gtkada mailing list
gtkada at lists.act-europe.fr
http://lists.act-europe.fr/mailman/listinfo/gtkada




More information about the gtkada mailing list