I'm writing a program using gtkada to display a window with a Text_View (within a Scrolled_Window) which will be updated from a GEntry.
I've got it working almost as I want it to be, with the exception of scroll.
As input is processed from the GEntry and inserted into the Text_View I want it to scroll automatically, so the most recent entry is visible at the bottom.
If I understand it correctly, doing a Scroll_To_Iter after inserting text won't work. An idle handler needs to be used to take care of the scrolling.
I just need pointers on how to call it.
The procedure to insert text from the GEntry looks like this:
procedure Insert_Text (S_Out: String) is
Iter : Gtk_Text_Iter;
Scroll_Okay : Boolean;
begin
Get_End_Iter (TextBuffer, Iter);
Insert (TextBuffer, Iter, "You entered:" & ASCII.LF);
Get_End_Iter (TextBuffer, Iter);
Insert (TextBuffer, Iter, S_Out & ASCII.LF);
Get_End_Iter (TextBuffer, Iter);
Scroll_Okay := Scroll_To_Iter
(TextView, Iter, 0.0, True, 1.0, 1.0);
end Insert_Text;
The Scroll_To_Iter call I've included there just for illustration; I know that doesn't do the job.
I have a separate procedure in the same package:
procedure Idle_Scroll (Object : access Gtk_Widget_Record'Class) is
Iter : Gtk_Text_Iter;
Scroll_Okay : Boolean;
begin
Get_End_Iter (TextBuffer, Iter);
Scroll_Okay := Scroll_To_Iter
(TextView, Iter, 0.0, True, 1.0, 1.0);
end Idle_Scroll;
So I'd just like to know how to set up the appropriate idle handler. Any help gratefully received.
Further to the answer below (thanks) I've since tried modifying the code, changing the procedure to a function, and it seems to be progressing in the right direction. I still get stuck when trying to call the Idle_Scroll callback, I get the error '... expected type "G_Source_Func" defined at glib-main.ads ... found type access to function "Idle_Scroll" ...' I tried to set the parameter passed to Idle_Scroll of type G_Source_Func after reading its entry in glibmain.h but I seem to be going round in circles. The full code I've uploaded to sourceforge here: https://sourceforge.net/projects/test-textview/files/