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 /src/Fl_Menu.cxx | |
| 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 'src/Fl_Menu.cxx')
| -rw-r--r-- | src/Fl_Menu.cxx | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx index 500b20a5c..a91666ad3 100644 --- a/src/Fl_Menu.cxx +++ b/src/Fl_Menu.cxx @@ -146,6 +146,7 @@ class menuwindow : public window_with_items { public: menutitle* title; int handle(int) FL_OVERRIDE; + void hide() override; int itemheight; // zero == menubar int numitems; int selected; @@ -480,6 +481,11 @@ menuwindow::~menuwindow() { delete title; } +void menuwindow::hide() { + set_selected(-1); + window_with_items::hide(); +} + void menuwindow::position(int X, int Y) { if (title) {title->position(X, title->y()+Y-y());} Fl_Menu_Window::position(X, Y); @@ -592,7 +598,20 @@ void menuwindow::draw() { } void menuwindow::set_selected(int n) { - if (n != selected) {selected = n; damage(FL_DAMAGE_CHILD);} + if (n != selected) { + if ((selected!=-1) && (menu)) { + const Fl_Menu_Item *mi = menu->next(selected); + if ((mi) && (mi->callback_) && (mi->flags & FL_MENU_CHATTY)) + mi->do_callback(this, FL_REASON_LOST_FOCUS); + } + selected = n; + if ((selected!=-1) && (menu)) { + const Fl_Menu_Item *mi = menu->next(selected); + if ((mi) && (mi->callback_) && (mi->flags & FL_MENU_CHATTY)) + mi->do_callback(this, FL_REASON_GOT_FOCUS); + } + damage(FL_DAMAGE_CHILD); + } } //////////////////////////////////////////////////////////////// |
