From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=BAYES_05,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:ad4:55eb:: with SMTP id bu11mr5081439qvb.57.1631221311984; Thu, 09 Sep 2021 14:01:51 -0700 (PDT) X-Received: by 2002:a05:6902:124c:: with SMTP id t12mr6375214ybu.91.1631221311842; Thu, 09 Sep 2021 14:01:51 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 9 Sep 2021 14:01:51 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=98.118.241.166; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 98.118.241.166 References: <6133e791$0$6461$426a74cc@news.free.fr> <6134cb26$0$3697$426a74cc@news.free.fr> <6134db32$0$6461$426a74cc@news.free.fr> <6134dc71$0$3693$426a74cc@news.free.fr> <6134e03d$0$3372$426a74cc@news.free.fr> <61352d42$0$3749$426a74cc@news.free.fr> <944e2cf6-2e24-480e-b7f7-0e0e0f5082e7n@googlegroups.com> <6139be6f$0$12704$426a74cc@news.free.fr> <757da468-7b58-43c2-95e6-917b3212f7b2n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: GtkAda callback and event From: Jere Injection-Date: Thu, 09 Sep 2021 21:01:51 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:62685 List-Id: On Thursday, September 9, 2021 at 3:58:06 PM UTC-4, Dmitry A. Kazakov wrote: > On 2021-09-09 20:41, Jere wrote: > > > I'm not as versed in GtkAda, but it looks like those have 'Class types so if > > it is like most of the other GUI frameworks out there, you typically would > > extend the type that you are doing the handler for and your user data would > > be fields of the new record type. Since the handler uses 'Class you could just > > cast the parameter to your new type and have access to the user data. > > > > Handlers without user data are non-generic and exist for each event > because GtkAda is generated. So, it is possible to generate a > non-generic handler/connect pair for each of hundreds of events per each > widget. This is what Emmanuel suggested: > > Cb_GObject_Gdk_Event_Motion_Boolean > > But, no user data. > > You could not do same and stuff thousands of cases in a single generic > handler package! There is only one for all widgets-events. Okie dokie! After reading this chain I took a look at the GtkAda manual and saw that they had separate high level events for things like button clicks and such and that they used access to 'Class types so I was hoping that meant for the OP that they could, for example do something like: type My_Button is new Gtk.Whatever_Path.Button_Type with record User_Data : User_Data_Type; end record; procedure On_Button_Click(Self : access to Button_Type'Class) is A_Button : My_Button renames My_Button(Self.all); -- forget if this is allowed or not begin -- use A_Button.User_Data.??? end On_Button_Click; and attach that as the handler. But based on what you said it sounds like this is not actually an option. (And of course the OP isn't using buttons, but just an example). > > There is much hatred towards OO design in Ada community which is > possibly was a motive behind this. > > An OO design would be to create an abstract base type for each event > with a primitive operation handle the event. The target widget type > would be fixed class-wide, but since it is practically never used, that > is no problem. This is the design I see most often in GUI frameworks (though usually an interface (if you like OO) or a trait object (if you don't care for OO) instead of an abstract class, but about the same). I was hoping the GtkAda framework offered this as well so the OP could have something to work with.