Re: [gtk-list] Tracking object deletion



On Thu, 11 Dec 1997, Kenneth Albanowski wrote:

> 
> What's the proper way (if any) to get a function invoked when a GtkObject
> (or descendant) is being destroyed?
> 
> In reworking my Perl module, it looks like that is the safest approach,
> but it is unclear what approach to use. It looks like an after connection
> to "destroy" will work, but I wonder what order after signals are called
> in, and whether any of them (perhaps even ones installed via Perl) might
> be interested in using the object that is in the process of being
> destroyed.
> 
> Might it be better to have a "destroy" slot (analogous to before & after)
> that is solely for this purpose?

OK, I've now tried signal_connect_after("destroy"), and it doesn't appear
to do anything. Am I misunderstanding the use of the function, or is
object destruction interfering with the signal generation? A normal
signal_connect works fine.

Note that I'm interested in a _really_ "after" signal call, ideally after
every other possible signal has been called, as my only task is to
disconnect Perl from the corresponding Gtk object. It would be OK to have
similar disconnection functions called after mine, but that is about it.

There also seems to be some issues with "destroy" signals during shutdown.
Consider the following variant on simple.c, running under gtk 971109:
despite calling gtk_widget_destroy() for both window and button, only one
message gets through when gtk_exit() is invoked. If the gtk_exit() call is
removed, both widgets get the signal. 

(And no, destroying the button is not necessary, that will happen
automatically. This does not change the behaviour with gtk_exit(),
however).

gtk_main_quit() has the same results, and if neither widget is destroyed,
then neither exit function will clean them up -- it seems the Gtk really
should clean up the existing widgets, where possible, before shutting
down.

---- cut variant of simple.c ----

#include <gtk/gtk.h>
#include <gdk/gdkprivate.h>

GtkWidget *window;
GtkWidget *button;


void
hello ()
{
  g_print ("Causing destruction\n");
  gtk_widget_destroy(window);
  gtk_widget_destroy(button);
  gtk_exit(1);
}

void destroy_window(void) {
  g_print ("destroying window\n");
}

void destroy_button(void) {
  g_print ("destroying button\n");
}

int
main (int argc, char *argv[])
{

  gdk_progclass = g_strdup ("XTerm");
  gtk_init (&argc, &argv);

  window = gtk_widget_new (gtk_window_get_type (),
			   "GtkObject::user_data", NULL,
			   "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
			   "GtkWindow::title", "hello world",
			   "GtkWindow::allow_grow", FALSE,
			   "GtkWindow::allow_shrink", FALSE,
			   "GtkObject::signal::destroy", destroy_window, NULL,
			   "GtkContainer::border_width", 10,
			   NULL);
  button = gtk_widget_new (gtk_button_get_type (),
			   "GtkButton::label", "hello world",
			   "GtkObject::signal::clicked", hello, NULL,
			   "GtkObject::signal::destroy", destroy_button, NULL,
			   "GtkWidget::parent", window,
			   "GtkWidget::visible", TRUE,
			   NULL);
			   
  gtk_widget_show (window);

  gtk_main ();

  return 0;
}


-- 
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]