#include <stdlib.h>
to call exit().
If you don't do anything about it, FL will call exit(0) when the user tries to close the last remaining window. On an SGI machine running 4DWM, it is possible to pick "Quit" off the window menu, and FL will exit(0) in this case as well. If FL detects an error (such as being unable to open the display or an unsupported visual) it will print a message and call exit(1).
You can override these behaviors with these functions:
The callback can call any FL functions, such as fl_ask(). A
typical implementation:
If you want closing any window to exit the program, just make this
do exit(0).
This is not called if a modal() window is up. Attempting to
close windows other than the top modal() window are ignored.
Attempting to close the top one causes that window's callback() to be
done.
void Fl::set_atclose(void (*cb)(Fl_Window*, void*));
This function will be called when the user tries to close a window (in
most X window managers by clicking on the close box). The window
argument is the window the user tried to close. Under 4DWM (and
perhaps other window managers) the user can pick "Quit" off the menu.
This will also call this function, but the window pointer will be
zero. The void* argument is the user_data() of the window.
int atclose(Fl_Window* w, void*) {
if (!w || w == main_window) {
if (!document_changed() ||
fl_ask("Exit without saving changes?")) exit(0);
} else {
w->hide();
}
}
void Fl::default_atclose(Fl_Window*, void*);
This is the default atclose function. If this is the only window
displayed then the program exits. Otherwise hide() is done to the
window. It may be useful to have your atclose() call this one.
void Fl::set_abort(void (*cb)(const char*,...);
FL will call this when it detects an error and cannot continue. The
most common reason is that the display cannot be opened. The function
must not return. However it can probably use longjmp or raise an
exception, so your program can continue (but it cannot call any FL
functions after that).
void Fl::default_abort(const char*,...);
The default abort function. This fprintf()'s the message on stderr
and then calls exit(1).
void Fl::atclose(Fl_Window*, void*);
void Fl::abort(const char*,...);
You can call the functions directly, if necessary.