comp.lang.ada
 help / color / mirror / Atom feed
From: DrPi <314@drpi.fr>
Subject: Re: GtkAda callback and event
Date: Fri, 10 Sep 2021 22:42:19 +0200	[thread overview]
Message-ID: <613bc32d$0$27421$426a74cc@news.free.fr> (raw)
In-Reply-To: <c9395f4d-e1d3-4c33-80f1-ff86c0cdf7fan@googlegroups.com>

Le 10/09/2021 à 08:56, Emmanuel Briot a écrit :
>>> type My_Button is new Gtk.Whatever_Path.Button_Type with record
>>> User_Data : User_Data_Type;
>>> end record;
> 
> This is indeed the recommended approach. In practice, most widgets have a single callback per event type (so one for motion_notify, one for click, and so on). All that's needed is the `Self` parameter which contains all relevant information. At least this was my experience based on the GPS source code, which is a relatively extensive GUI application. I don't remember the stats exactly, but there were just a few cases where this approach did not work. And this is why we implemented the higher-level approach in GtkAda, where there are no possible errors in the type of parameters for callbacks.
> 
> There are a few cases where you want to share the same callback subprogram for multiple events, or multiple types of widgets for instance. In these cases, you might have to fallback to using the generics to connect, along with specifying a user data. As much as possible, I would recommend not using this approach if you can avoid it.
> 
> I do not share Dmitry's distrust of generics, but for GUI applications I 100% agree that an OO approach works much better indeed. The performance cost is negligible in such contexts, and the flexibility is much needed.
> 
>> User data is a property of the event not of the button. E.g. consider a
>> button to save file. The user data would be some Ada object responsible
>> for dealing with the file. What about other buttons? What about
>> life-times of buttons? User data usually have a longer life span etc.
> 
> Presumably you would have one callback procedure to deal with the file, another one to exit the application, another one to ask the user's name and whatever else. For all of these, you do not need user data and the high-level callbacks provided by GtkAda are much easier to use.
> 
> One contrived example where user data might be used is for instance: we have one callback responsible for moving the cursor in an editor, and the user data is used to pass UP, DOWN, LEFT or RIGHT to indicate which direction to move. But even in such a case, I would argue it is better to have four small callbacks that call the same shared procedure, and still use the high-level callbacks of GtkAda.
> 

That's very interesting.
I didn't think I can extend the widget type to add my own parameters.
Thanks all for your help.

Nicolas

  reply	other threads:[~2021-09-10 20:42 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-04 21:39 GtkAda callback and event DrPi
2021-09-04 22:29 ` Dmitry A. Kazakov
2021-09-05 13:50   ` DrPi
2021-09-05 14:48     ` Dmitry A. Kazakov
2021-09-05 14:58       ` DrPi
2021-09-05 15:04         ` DrPi
2021-09-05 15:12           ` Dmitry A. Kazakov
2021-09-05 15:20             ` DrPi
2021-09-05 15:53               ` Dmitry A. Kazakov
2021-09-05 20:49                 ` DrPi
2021-09-09  6:56                   ` Emmanuel Briot
2021-09-09  7:57                     ` DrPi
2021-09-09 18:41                       ` Jere
2021-09-09 19:58                         ` Dmitry A. Kazakov
2021-09-09 21:01                           ` Jere
2021-09-10  6:38                             ` Dmitry A. Kazakov
2021-09-10  6:56                               ` Emmanuel Briot
2021-09-10 20:42                                 ` DrPi [this message]
2021-09-10 20:58                                   ` Dmitry A. Kazakov
2021-09-11  7:38                                     ` Emmanuel Briot
2021-09-11 15:24                                     ` DrPi
2021-09-11 15:56                                       ` Dmitry A. Kazakov
2021-09-12  7:08                                       ` AdaMagica
2021-09-12  8:52                                         ` Dmitry A. Kazakov
2021-09-12 13:00                                           ` DrPi
2021-09-12 13:57                                             ` Dmitry A. Kazakov
2021-09-10 20:46                                 ` Dmitry A. Kazakov
2021-09-11  7:36                                   ` Emmanuel Briot
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox