comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: GtkAda callback and event
Date: Thu, 9 Sep 2021 21:58:03 +0200	[thread overview]
Message-ID: <shdp09$87k$1@gioia.aioe.org> (raw)
In-Reply-To: 757da468-7b58-43c2-95e6-917b3212f7b2n@googlegroups.com

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.

The problem is that GtkAda uses generics instead of tagged types. And, 
as I frequently say, generics are lousy.

Here is the design, very simplified:

    generic
       type Widget_Type is new Glib.Object.GObject_Record with private; -
       type User_Type (<>) is private;
    package User_Callback is
       type Int_Handler is access procedure
            (  Widget    : access Widget_Type'Class;
               Param     : GInt;
               User_Data : User_Type
            );
       procedure Connect
                 (  ...,
                    Int_Handler
                    ...
                 );
       type GUInt_Handler is access procedure
            (  Widget    : access Widget_Type'Class;
               Param     : GUInt;
               User_Data : User_Type
            );
       procedure Connect
                 (  ...,
                    Int_Handler
                    ...
                 );
       ... -- An so on for each parameter type

In reality it is much messier because handlers are created per generic 
instances. But you see the problem. For each combination of parameters 
you need a handler type and a connect procedure.

Furthermore, observe, that this is inherently type unsafe as you could 
attach any handler from a generic instance to any event regardless the 
parameters of the event.

Welcome to generics, enjoy.

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.

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.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2021-09-09 19:58 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 [this message]
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
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