How to properly exit an app with several open windows?



My application has a main window and several others which are "spawned"
from the main one (like some open documents). When I close one of the
dependent windows, I want a dialog to pop up asking the user if they want
to save changes etc. and then close it. I've got this working so far.

But how can I transmit a delete signal from the main to a dependent
window? My first attempt was this:
gtk_signal_emit_by_name(GTK_OBJECT(dependent_window), "delete_event").
Indeed, the "delete_event" handler of the dependent window gets called,
but then the application immediately segfaults which must have to do with
the fact that the handler expects some more data. I now circumvented this
problem by sending the "clicked" signal to a "Close" button which that
window happens to have, but I don't like it because it ain't none of the
main window's business to click other window's buttons. Also the main
window can't close itself after the dependent window did.

I thus have not just one, but a whole list of questions:

1) How can I properly make a window receive a "delete" event from within
   my app?

2) How can I transmit back to the main window the information that the
   dependent window was properly closed so that the main window can proceed to
   delete itself and to exit the application?
   
3) Since there may be several open dependent windows, how can I iterate in this
   fashion over all of them, and then quit the application? I suppose for
   this to work, the deleted windows have to signal "delete" back to the
   main window which then checks for any open dependents again. Ugh, this
   sounds ugly.
   
I've been trying to implement this for two days now and I'm totally stumped.
This is an extremely commonplace situation because there exist plenty of
applications that have windows with unsaved data open, so there must be a
commonplace way of dealing with this problem. How?

Thanks,
--Daniel

-- 
Dr. Daniel Haude
Institut für Angewandte Physik
Jungiusstr. 11
D-20355 Hamburg
fon +49 40 42838 7046
fax +49 40 42838 2944




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