Groups | Search | Server Info | Login | Register
Groups > comp.lang.ada > #49412
| From | "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> |
|---|---|
| Newsgroups | comp.lang.ada |
| Subject | Re: GtkAda callback and event |
| Date | 2021-09-05 00:29 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <sh0s15$1ha4$1@gioia.aioe.org> (permalink) |
| References | <6133e791$0$6461$426a74cc@news.free.fr> |
On 2021-09-04 23:39, DrPi wrote:
> I use an event callback with user data.
>
> I first declare a package :
> package Handler_Motion_Notify is new
> Gtk.Handlers.User_Return_Callback (Widget_Type =>
> Gtk.Text_View.Gtk_Text_View_Record,
>
> Return_Type => Boolean,
>
> User_Type => t_Debug_Panel);
>
> The function callback is declared like this :
> function On_Motion_Notify (TextView : access
> Gtk.Text_View.Gtk_Text_View_Record'Class;
> DebugPanel : t_Debug_Panel) return Boolean;
This is wrong. The motion-notify-event callback has the parameters:
1. Target
2. Gdk.Event.Gdk_Event_Motion
3. User data
> The connection is done like this :
> Handler_Motion_Notify.Connect (Widget => Panel.TextView,
> Name =>
> Gtk.Widget.Signal_Motion_Notify_Event,
> Cb => On_Motion_Notify'Access,
> User_Data => t_Debug_Panel(Panel));
>
> This works correctly. But... I need to have access to the event in the
> callback function.
Maybe it does not crash but it is incorrect.
> How can I achieve this ?
There is no shortcut Connect and Callback defined in
User_Return_Callback. Therefore you have to use a general-case callback
with the parameter list:
function On_Motion_Notify
( Object : access Gtk_Text_View_Record'Class;
Params : Glib.Values.GValues;
Data : t_Debug_Panel
) return Boolean;
connected as:
Handler_Motion_Notify.Connect
( Panel.TextView,
"motion-notify-event", -- = Signal_Motion_Notify_Event
On_Motion_Notify'Access,
t_Debug_Panel (Panel)
);
The parameter is accessed using the function Nth or
Gtk.Argument.Unchecked_To_Gdk_Event_Motion, e.g.
Gtk.Argument.Unchecked_To_Gdk_Event_Motion (Params, 1)
P.S. Since the target is practically never used in callbacks, you can
instantiate Gtk.Handlers.User_Return_Callback with GObject_Record. This
way you could use it with all types of widgets. That reduces the number
of instantiations.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Back to comp.lang.ada | Previous | Next — Previous in thread | Next in thread | Find similar
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