How to exit every fltk window in the world

From OTBWiki
Jump to: navigation, search

One common problem in complex applications with multiple windows is that for now the user has to close each window separately to exit the application. This behaviour is not acceptable.

The main fltk waiting loop is defined in the Fl::run() method:

while(Fl::first_window())
{
   wait(FOREVER);
}

It means that the loop will hold until all fltk windows are hidden or deleted. This is not compatible with the behaviour we want:

  • We want the single exit method of our application to close all windows and return
  • In the testing context, we can not have windows persistence leading to timeout.

Morover, we want the window decorator exit button (usually the upper right cross) of the main application window to call the exit method of the applications. This can be done by defining the Fl_Double_Window callback as beeing this exit method.

A possible solution to close every opened fltk windows is (according to fltk forums):

while(Fl::first_window())
{
  delete Fl::first_window();
}

But this is not a clean solution, since it is deleting objects that might be accessed later.

We decided to create a macro doing exactly the same thing that Fl::run(), except that the condition watched by the while loop will be user defined. It will allow us to watch a specific boolean member telling the application is still running.