From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Where do I get my Cairo context from (in GTK3)? Date: Wed, 27 Apr 2016 10:08:11 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <0a9cf35e-45ba-49c1-9d6a-4a0da3457e70@googlegroups.com> <31e4394b-eb85-4d31-bd25-f2bd332c7c9b@googlegroups.com> NNTP-Posting-Host: G7MXAklp0OAVRSdfcmpxRQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:30300 Date: 2016-04-27T10:08:11+02:00 List-Id: On 27/04/2016 09:47, briot.emmanuel@gmail.com wrote: >> I would use On_* procedures if I didn't need user data. Until now no >> success. > > Are you sure you really need that user data ? In my experience, it is often > better to extend the widget type in your application, store whatever information > is needed in that child type, and then use the On_* procedure passing a Slot > object (so that the callback receives your widget type, rather than the widget > on which the action occurred). This works in 95% of the cases. Quite the opposite, this works in only few cases. The problem is that the handler of a signal is practically never the issuer of. So handling own events is very rare, only when the widget is a reusable extension of some other widget and the signal is used internally. End instances of widgets are never like that. The most frequent case is a container widget handling signals from its children. The first parameter of the handler is never ever used, because the identification of the issuer is the handler procedure itself. The user parameter is the container widget, which is the case for the OP, I suppose. > The GNAT Development Studio (GPS), which is about 500_000 lines of code > has almost no use of user data, and those that remain are mostly because > that part of the code hasn't been updated yet. I have several GTK projects with exactly opposite statistics. Callbacks without user data are never used. Though many widgets are extensions as you suggested. The design of handler connecting should have a reverse version "connect-from" in addition to current "connect-to", in a language like Ada without full double dispatch. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de