comp.lang.ada
 help / color / mirror / Atom feed
From: Jack Mitchell <jack@home9999.plus.com>
Subject: Re: Closing a program with GTK
Date: Thu, 26 Jul 2012 22:59:20 +0100
Date: 2012-07-26T22:59:20+01:00	[thread overview]
Message-ID: <eUyoDfD42bEQFwpG@plus.net> (raw)
In-Reply-To: 79iy1peuceu9$.bzuvizc9yuhz.dlg@40tude.net

In message <79iy1peuceu9$.bzuvizc9yuhz.dlg@40tude.net>, Dmitry A. 
Kazakov <mailbox@dmitry-kazakov.de> writes
>On Thu, 22 Sep 2011 14:36:36 +0200, ldries46 wrote:
>
>> The routine On_Window_Destroy is the
>> one that closes the window and ends the program.
>
>According to the code you posted On_Window_Destroy is a signal handler
>connected to the "destroy" event. The intended use of such handler in Gtk
>is to free all resources associated with the widget which are not managed
>by Gtk.
>
>In Gtk you shall never call any handlers explicitly.
>
>> I need that routine carried out. I don't think it is a good idea to alter
>> the gtk.object.destroy routine so what can I do?
>
>Destroy emits the "destroy" event, which in turn notifies all handlers of
>the signal, all reference holders release the reference which then lead to
>deallocation of the widget.
>

Try something like :-

--  Here we just set a handler for delete_event that immediately exits 
GTK.

MY_PROG_PACKAGE.Return_Handlers.Connect
      (Window, "delete_event",
       MY_PROG_PACKAGE.Return_Handlers.To_Marshaller
         ( MY_PROG_Package.Delete_Event'Access ) );

-- more setup

GTK.WINDOW.Show( Window );

--  All GtkAda applications must have a Main. Control ends here
--  and waits for an event to occur (like a key press or mouse event).
GTK.Main.Main;

end MY_PROG;




with Gdk.Event;
with Gtk.Widget;
with Gtk.Handlers;
with GLIB;

package MY_PROG_Package is


    package Handlers is new Gtk.Handlers.User_Callback
      (Widget_Type => gtk.Widget.Gtk_Widget_Record,
       User_Type   => String_Access);

    package Return_Handlers is new Gtk.Handlers.Return_Callback
      (Widget_Type => gtk.Widget.Gtk_Widget_Record,
       Return_Type => Boolean);

    function Delete_Event
      (Widget : access gtk.Widget.Gtk_Widget_Record'Class;
       Event  : Gdk.Event.Gdk_Event) return Boolean;


end MY_PROG_PACKAGE;

-- 
Jack Mitchell



  reply	other threads:[~2012-08-01  2:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-22  1:21 Closing a program with GTK ldries46
2011-09-22  7:20 ` Dmitry A. Kazakov
2011-09-22 10:24   ` ldries46
2011-09-22 12:07     ` Dmitry A. Kazakov
2011-09-22 12:36       ` ldries46
2011-09-22 13:48         ` Dmitry A. Kazakov
2012-07-26 21:59           ` Jack Mitchell [this message]
2011-09-22 23:06         ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox