comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: GtkAda callback and event
Date: Thu, 9 Sep 2021 14:01:51 -0700 (PDT)	[thread overview]
Message-ID: <f4291006-ea19-4896-b7bc-96ce3c102955n@googlegroups.com> (raw)
In-Reply-To: <shdp09$87k$1@gioia.aioe.org>

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.
>
> <SNIPPED>
> 
> 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.

  reply	other threads:[~2021-09-09 21:01 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 [this message]
2021-09-10  6:38                             ` Dmitry A. Kazakov
2021-09-10  6:56                               ` Emmanuel Briot
2021-09-10 20:42                                 ` DrPi
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