From f4978a014997656b4592c2b3b866865f76d390ea Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Tue, 1 Apr 2025 17:00:51 +0200 Subject: Adding the FL_MENU_CHATTY flag to Fl_Menu_Item. If set, menu items will also call the callback when highlighting changes. The reason is given with Fl::callback_reason(). #941 --- test/menubar.cxx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/menubar.cxx b/test/menubar.cxx index 6cf22458a..355921eba 100644 --- a/test/menubar.cxx +++ b/test/menubar.cxx @@ -61,7 +61,19 @@ void test_cb(Fl_Widget* w, void*) { G_tty->printf("%s\n", m->label()); } -void quit_cb(Fl_Widget*, void*) {exit(0);} +void quit_cb(Fl_Widget*, void*) { + switch (Fl::callback_reason()) { + case FL_REASON_SELECTED: + exit(0); + case FL_REASON_GOT_FOCUS: + G_tty->printf("Selecting this menu item will quit this application!\n"); + break; + case FL_REASON_LOST_FOCUS: + G_tty->printf("Risk of quitting averted.\n"); + break; + default: break; + } +} Fl_Menu_Item hugemenu[100]; @@ -70,7 +82,7 @@ Fl_Menu_Item menutable[] = { {"&File",0,0,0,FL_SUBMENU}, {"&Open", FL_ALT+'o', 0, 0, FL_MENU_INACTIVE}, {"&Close", 0, 0}, - {"&Quit", FL_ALT+'q', quit_cb, 0, FL_MENU_DIVIDER}, + {"&Quit", FL_ALT+'q', quit_cb, 0, FL_MENU_DIVIDER|FL_MENU_CHATTY}, #if (OVERRIDE_SCALING_SHORTCUTS) {"CTRL/0", FL_COMMAND+'0', 0}, -- cgit v1.2.3