Self destructing dialog question
- From: Dov Grobgeld <dov grobgeld gmail com>
- To: Gnome List <gtk-list gnome org>
- Subject: Self destructing dialog question
- Date: Wed, 25 Nov 2009 08:41:58 +0200
I have a small problem that's been bothering me for a while and I have yet to find an elegant solution to it. The problem is related to the notification of the destruction of a dialog window.
Assume I have a program with a widget MyApp that has a member called my_dialog that is created to catch its destruction as follows:
if (!priv->my_dialog) {
priv->my_dialog = my_dialog_new();
g_signal_connect(priv->my_dialog, "delete-event",
G_CALLBACK(cb_my_dialog_destroy), priv);
}
:
static gboolean cb_my_dialog_destroy(GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
MyAppPriv *priv = MY_APP_PRIV(data);
priv->my_dialog = NULL;
return FALSE;
}
I.e. when the dialog is deleted we would like to clear the priv->my_dialog variable. (Of course I could hide the dialog on delete, but I would like to destroy it.)
The MyDialog class inherits from GtkDialog and it creates a dialog button "Close" that is handled in the response callback. So in MyDialog I override the "response" signal handler and when we get the response==GTK_RESPONSE_CLOSE we self destruct by calling gtk_widget_destroy(widget).
But here's the problem, because destroying a widget does not generate a "delete-event" and thus cb_my_dialog_destroy is never called and thus priv->my_dialog is never set to NULL.
Meanwhile I have solved it by overriding the the response signal in MyApp, but I feel that is ugly as I would like to keep the functionality of MyDialog self contained.
Other possible solutions would be to emit a "delete-event" in MyDialog. But my attempts to call g_signal_emit_by_name(widget, "delete-event", NULL, &retval) have caused the program to crash.
Another solution would be to create yet another signal.
Trying to connect to the "destroy-event" in MyApp didn't work. I never got any callback.
So how should this be done?
Thanks!
Dov
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]