Groups | Search | Server Info | Login | Register


Groups > comp.lang.ada > #49465

Re: GtkAda callback and event

From "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups comp.lang.ada
Subject Re: GtkAda callback and event
Date 2021-09-09 21:58 +0200
Organization Aioe.org NNTP Server
Message-ID <shdp09$87k$1@gioia.aioe.org> (permalink)
References (8 earlier) <sh2p61$1dll$1@gioia.aioe.org> <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>

Show all headers | View raw


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

Back to comp.lang.ada | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-04 23:39 +0200
  Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-05 00:29 +0200
    Re: GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-05 15:50 +0200
      Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-05 16:48 +0200
        Re: GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-05 16:58 +0200
          Re: GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-05 17:04 +0200
            Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-05 17:12 +0200
              Re: GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-05 17:20 +0200
                Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-05 17:53 +0200
                Re: GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-05 22:49 +0200
                Re: GtkAda callback and event Emmanuel Briot <briot.emmanuel@gmail.com> - 2021-09-08 23:56 -0700
                Re: GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-09 09:57 +0200
                Re: GtkAda callback and event Jere <jhb.chat@gmail.com> - 2021-09-09 11:41 -0700
                Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-09 21:58 +0200
                Re: GtkAda callback and event Jere <jhb.chat@gmail.com> - 2021-09-09 14:01 -0700
                Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-10 08:38 +0200
                Re: GtkAda callback and event Emmanuel Briot <briot.emmanuel@gmail.com> - 2021-09-09 23:56 -0700
                Re: GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-10 22:42 +0200
                Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-10 22:58 +0200
                Re: GtkAda callback and event Emmanuel Briot <briot.emmanuel@gmail.com> - 2021-09-11 00:38 -0700
                Re: GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-11 17:24 +0200
                Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-11 17:56 +0200
                Re: GtkAda callback and event AdaMagica <christ-usch.grein@t-online.de> - 2021-09-12 00:08 -0700
                Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-12 10:52 +0200
                Re: GtkAda callback and event DrPi <314@drpi.fr> - 2021-09-12 15:00 +0200
                Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-12 15:57 +0200
                Re: GtkAda callback and event "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-09-10 22:46 +0200
                Re: GtkAda callback and event Emmanuel Briot <briot.emmanuel@gmail.com> - 2021-09-11 00:36 -0700

csiph-web