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=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: GtkAda callback and event Date: Thu, 9 Sep 2021 21:58:03 +0200 Organization: Aioe.org NNTP Server Message-ID: 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> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="8436"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:62684 List-Id: 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