#include <stdlib.h>
to call exit().
If you don't do anything about it, fltk 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 fltk will exit(0) in this case as well. If fltk 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 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.
This can call any fltk 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 Fl::modal() is non-zero. In this case
attempting to close windows other than the Fl::modal() one are
ignored. Attempting to close the Fl::modal() window causes that
window's callback() to be done.
Supposedly Fl::warning means that there was a recoverable problem,
the display may be messed up but the user can probably keep working
(all X protocol errors call this). Fl::error means there is a
recoverable error, but the display is so messed up it is unlikely the
user can continue (very little calls this now). Fl::fatal must not
return, as fltk is in an unusable state (however your version may be
able to use longjmp or an exception to continue, as long as it does
not call fltk again).
void (*Fl::atclose)(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). You can
override it's behavior by setting the function pointer to your own
routine.
static 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();
}
}
...somewhere in main():
Fl::atclose = atclose;
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::warning)(const char*,...);
void (*Fl::error)(const char*,...);
void (*Fl::fatal)(const char*,...);
Fltk will call these to print messages when unexpected conditions
occur. By default they fprintf to stderr, and Fl::error and Fl::fatal
call exit(1). You can override the behavior by setting the function
pointers to your own routines.