0
votes

I'm writing some sort of chat in Ada using Gtk+ (technically GtkAda). And I have of problem with some Gtk. My window consists of an Entry, TextView and Button ("Send").

The hard part is in handler On_Button_Send_Clicked (procedure that deals with signal 'clicked' on button). I want to read text form Entry and place it in TextView, but how can I access TextView and Entry from a procedure that has only access to Button, as I connect the signal with a handler in this way:

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

procedure On_Button_Send_Clicked
    (Object : access Gtk_Widget_Record'Class);
...

Handlers.Connect
   (Button, "clicked", Handlers.To_Marshaller (On_Button_Send_Clicked'access);

My question is: are there any methods like Get_Gtk_Entry or Get_Text_View, which would be the simples way? Or is there another way, but still simple?

I have also come across a solution in which I declare a record:

type Widget_Collection_Record is new Glib.Object.GObject_Record with record
    Terminal   : Gtk.GEntry.Gtk_Entry;
    Text_Field : Gtk.Text_View.Gtk_Text_View;
end record;

and make the callback this way:

package Widget_Collection_Cb is new Gtk.Handlers.Callback
    (Widget_Type => Widget_Collection_Record);

procedure On_Button_Send_Clicked
    (Object : access Widget_Collection_Record'Class);

But now I have another question: how do I connect a signal from a Button with a handler, since the widget Button is not a part of my Widget_Collection_Record?

I'm not sure whether I sound clear...

So please, if you know something that may solve my problem, please post - it could be C, C++, Python - I'll try to convert it to Ada ;D

And the summary of my problem is:

How can I write a handler to read from an Entry and write on a Text_View when a Button clicked?

Edit: Question closed. I'm aware that it's not clear what I asked for, and that's way I've chosen the way to pass record of User_Data to callback... and now my new problem is here

1
If you don't get an aswer here, you can try at comp.lang.ada, some knowledgeable GtkAda developers hang out there.Marc C
Preparing an sscce may be helpful, too.trashgod
See also this answer.trashgod
See also this example.trashgod
I updated this answer with a link for glade; the generated Ada source may be useful.trashgod

1 Answers

0
votes

Usually I use this reference : http://www.univ-orleans.fr/sciences/info/ressources/webada/doc/gtkada/gtkada_rm/index.html

You didn't provide much informations about the organization of your project. But if you have a simple procedure where you declare everything then :

procedure foo is
    -- variables
    E : GTk_GEntry;
    T : Gtk_Text_View;
    ...
    procedure On_Button_Send_Clicked (Object : access Gtk_Widget_Record'Class) is
    begin
       S : String := Get_Text (E);
       B : Gtk_Text_Buffer := Get_Buffer (T);
    begin
       Set_Text (B, S);
       ...
    end On_Button_Send_Clicked;
begin
   ...
   Handlers.Connect
      (Button, "clicked", Handlers.To_Marshaller (On_Button_Send_Clicked'access);
   ...
end foo