On 07.10.2011 21:00, Marko wrote:
> The correct behaviour should be that when the main application window is
> closed any open subwindows should just close also.
Please see Ian's post for more info on that.
> When I click the close button on the main window I tried deleting the input
> dialog window in the main window destructor, but I notice that clicking the
> close button on the main window does not call that windows destructor.
To extend Ian's reply: To close a window means in FLTK to hide()
it (only). It will not be destroyed, hence the destructor isn't
called. As Ian wrote, the correct way to do something when the
user closes a window is to set up a callback for this window.
The callback will be called when the user hits the window's close
button, and the default action is to hide() the window. So, if you
want to do this, be sure to call hide() on the main window too,
otherwise the main window will not be closed. See appended example
code how to do it with two windows. If you need to close more than
one other window, then you may need to use an array of pointers in
the user_data argument of the callback or use some other known
(maybe global) variables.
Albrecht
--- snip ---
// file: two_windows.cxx
// use: "fltk-config --compile two_windows.cxx" to compile
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl.H>
void close_cb(Fl_Widget *w1, void *w2) {
Fl_Window *a = (Fl_Window *)w1;
Fl_Window *b = (Fl_Window *)w2;
b->hide(); // close "other" window
a->hide(); // close "this" window
}
int main (int argc, char **argv) {
Fl_Window *win1 = new Fl_Window(100,100,100,100);
Fl_Box *box1 = new Fl_Box( 10,10,80,80,"FIRST");
win1->end();
Fl_Window *win2 = new Fl_Window(250,100,100,100);
Fl_Box *box2 = new Fl_Box( 10,10,80,80,"SECOND");
win2->end();
win1->callback(close_cb,win2); // first window closes second window
// win2->callback(close_cb,win1); // second closes first, if enabled
win1->show(argc,argv);
win2->show();
return Fl::run();
}
--- snip ---
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk