diff options
| author | Matthias Melcher <github@matthiasm.com> | 2025-04-01 17:00:51 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2025-04-01 17:00:56 +0200 |
| commit | f4978a014997656b4592c2b3b866865f76d390ea (patch) | |
| tree | 13a365c34b705942195c75fd3186801976786070 /test | |
| parent | 0eb6bb8e6d34b39399cda8b768851a3218eb7e2c (diff) | |
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
Diffstat (limited to 'test')
| -rw-r--r-- | test/menubar.cxx | 16 |
1 files changed, 14 insertions, 2 deletions
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}, |
