Dialog destruction signals.



I am having some very strange problems concerning the
execution of signal handlers upon the destruction of a
non-modal dialog. Here is the relevant code:

/* -- START CODE -- */

GtkWidget *
edit_dialog(const char *title, const char *filename,
gboolean exists)
{
	char buf[1024] = { 0 };
	int fd, n;
	struct file_info *fi;

	GtkWidget *dialog, *text, *scroll, *vbox;
	GtkWidget *menu_bar, *menu_file, *file_menu,
*file_save, *file_save_as, *file_sep;
	GtkWidget *file_close, *menu_edit, *edit_menu,
*edit_copy, *edit_cut, *edit_paste;
	GtkAccelGroup *accel_group;
	GtkStyle *style;
	GdkFont *font;

	fi = mem_alloc0(sizeof(struct file_info));
	fi->filename = st_strdup(filename);

	if(exists) {
		if((fd = open(filename, O_RDONLY)) < 0) return NULL;
/* caller can check errno */
	}

	dialog = gtk_window_new(GTK_WINDOW_DIALOG);
	gtk_window_set_title(GTK_WINDOW(dialog), title);

	/* dialog construction code here... */

	/* gtk_signal_connect(GTK_OBJECT(dialog),
"delete_event",
		GTK_SIGNAL_FUNC(on_dialog_delete), dialog); */
	gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
		GTK_SIGNAL_FUNC(on_dialog_delete), dialog);

	gtk_widget_show_all(dialog);
	return dialog;
}

static gint
on_dialog_delete(GtkWidget *widget, gpointer data)
{
	GtkWidget *dialog;
	struct file_info *fi;
	int answer;

	dialog = data;

	fi = gtk_object_get_data(GTK_OBJECT(dialog),
"file_info");
	if(!fi->changed) {
		gtk_widget_destroy(dialog);
		return FALSE;
	}

	fi->changed = 0;

	answer = yesnocancel_dialog("This file has
changed.\nDo you wish to save changes?",
		fi->filename, TRUE);

	if(answer == 0) {
		gtk_widget_destroy(dialog);
	} else if(answer == 1) {
		on_file_save(widget, data);
		gtk_widget_destroy(dialog);
	} else {
		return TRUE;
	}
	return FALSE;
}

/* -- END CODE -- */

The problem is that the "delete_event" and "destroy"
signals do not seem to be doing what they are supposed
to. The delete_event signal, according to
documentation, should be emitted before the destroy
signal, and the emission of the destroy signal should
be dependant upon the return value of the signal
handler associated with the delete_event signal. In my
program, connecting to the delete_event signal causes
an assertation failure (caused by the call to
`gtk_object_get_data' above) and then a segfault:

Gtk-WARNING **: invalid unclassed pointer in cast to
`GtkObject'

Gtk-CRITICAL **: file gtkobject.c: line 1080
(gtk_object_get_data): assertion `GTK_IS_OBJECT
(object)' failed.
Segmentation fault (core dumped)

This obviously leads me to believe that the object was
deconstructed and destroyed _before_ the signal
handler for delete_event was called. However,
connecting to the "destroy" signal causes no such
assertation failure. However, when connecting to the
`destroy' signal, the dialog appears to be destroyed,
before the dialog box from the `yesnocancel_dialog'
function appears. But in reality it is only hidden,
because the contents of the GtkText in that dialog can
be saved from the signal handler!

This behaviour is really confusing me; it seems to be
inconsistent with the way the `destroy' and
`delete_event' signals work. Could this perhaps be
caused by that fact that the dialog created is a
GTK_WINDOW_DIALOG and not a GTK_WINDOW_TOPLEVEL?

My second question is, how can I set the icon for my
application? I.E., if the application is minimized,
the icon I have set for the application appears rather
than the default icon as set by the window manager?

Regards,

Farooq


__________________________________________________
Do You Yahoo!?
Yahoo! Photos -- now, 100 FREE prints!
http://photos.yahoo.com




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