From 8041a62e594400d3cca487a4b07119a000a3020c Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Wed, 22 Nov 2023 22:31:59 +0100 Subject: [PATCH] Adds Callback Reason to FAQ on Fl_Window::callback --- documentation/src/faq.dox | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/documentation/src/faq.dox b/documentation/src/faq.dox index 766fe5252..e6cdf2341 100644 --- a/documentation/src/faq.dox +++ b/documentation/src/faq.dox @@ -131,6 +131,19 @@ void my_callback(Fl_Widget*, void*) { } \endcode +The reason for calling a window callback can also be found using using the +`Fl::callback_reason()` method: + +\code +void my_callback(Fl_Widget*, void*) { + if (Fl::callback_reason() == FL_REASON_CANCELLED) + return; // ignore that the user pressed the Escape key + if (Fl::callback_reason() == FL_REASON_CLOSED) + save_and_exit(); // user clicked the Close button in the window decoration + exit(0); // fallback for other callback reasons +} +\endcode + It is very common to ask for confirmation before exiting, this can be done with: