From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: gtkada evenhandler on_procedure method , how to access children of topwindow in the eventhandler Date: Sat, 2 Nov 2019 12:03:20 +0100 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57442 Date: 2019-11-02T12:03:20+01:00 List-Id: On 2019-11-02 11:22, Alain De Vos wrote: > I have a window with obe button and one label and want to change the text on the label when the button is pressed in the eventhandler, I pass the top window. > > procedure hello is > Top : Gtk.Window.Gtk_Window; > Button : Gtk_Button; > Label : Gtk_Label; > VBox : Gtk_Box; > procedure Create_Window is > begin > Gtk.Window.Gtk_New > (Window => Top, > The_Type => Gtk.Enums.Window_Toplevel); > Gtk.Window.Set_Title (Window => Top, Title => "Hello from ADA"); > Gtk_New(Button); > Button.On_Clicked (Call => On_Button_Click'Access, > Slot => Top); > Gtk_New(Label); > Gtk_New_Vbox(VBox); > Add (VBox,Button); > Add (VBox,Label); > Add (Top,VBox); > Gtk.Window.Show_All (Top); > end Create_Window; > begin > Gtk.Main.Init; > Create_Window; > Gtk.Main.Main; > end hello; > > I pass the topwindow to the eventhandler(slot). > In the eventhandler I need go from the Top to the Vbox to the Label and set the text on the label ... button pressed. I probably need to set a property in the main and query it in the handler and cast the correct type ... > {The label is not directly visible in the handler ...} > > package body buttonhandler is > procedure On_Button_Click (Top : access Glib.Object.GObject_Record'Class) is > begin > Put_line ("Hallo"); > -- I need to go from Top to Vbox to Label and set text ... ???? > end On_Button_Click; > end buttonhandler; It is possible to enumerate children of a container, but that is not the recommended way as it is weakly typed and fragile. A better way is a derived widget. It is very easy to drive customized widgets in GtkAda. E.g. type My_Box_Record is new Gtk_VBox with -- Derive from VBox Button : Gtk_Button; Label : Gtk_Label; end record; type My_Box is access all My_Box_Record; procedure Gtk_New (Box : out My_Box); Creation: procedure Gtk_New (Box : out My_Box) is begin Box := new My_Box_Record; Initialize_Vbox (Box); -- Parent's initialization from Gtk_Box Gtk_New (Box.Button); Box.Add (Box.Button); Gtk_New (Box.Label); Box.Add (Box.Label); -- Connect signal handlers here, pass My_Box to them end Get_New; Put declaration of the custom widget in a separate package. All handlers go into the package body. [This will reduce the inevitable mess GTK imposes on any otherwise cleanly designed Ada application] -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de