From 882bae4e2fc21044d03c7a019f68c131bae3ef61 Mon Sep 17 00:00:00 2001 From: dannye <33dannye@gmail.com> Date: Tue, 20 Aug 2024 12:51:15 -0500 Subject: [PATCH] Submenus with no callback enter their submenu instead of closing the whole menu --- src/Fl_MacOS_Sys_Menu_Bar.mm | 4 +++- src/Fl_Menu.cxx | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Fl_MacOS_Sys_Menu_Bar.mm b/src/Fl_MacOS_Sys_Menu_Bar.mm index a7c5e2f20..950a52e29 100644 --- a/src/Fl_MacOS_Sys_Menu_Bar.mm +++ b/src/Fl_MacOS_Sys_Menu_Bar.mm @@ -378,7 +378,9 @@ static void createSubMenu( NSMenu *mh, pFl_Menu_Item &mm, const Fl_Menu_Item *m mm = mm->next(0); continue; } - miCnt = [FLMenuItem addNewItem:mm menu:submenu action:selector]; + miCnt = [FLMenuItem addNewItem:mm menu:submenu + action:( (mm->flags & (FL_SUBMENU+FL_SUBMENU_POINTER) && !mm->callback()) ? nil : selector) + ]; setMenuFlags( submenu, miCnt, mm ); setMenuShortcut( submenu, miCnt, mm ); if (mitem && (mm->flags & FL_MENU_INACTIVE || mitem->flags & FL_MENU_INACTIVE)) { diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx index 79228de80..9588ff48a 100644 --- a/src/Fl_Menu.cxx +++ b/src/Fl_Menu.cxx @@ -821,6 +821,7 @@ int menuwindow::handle_part1(int e) { } return 1; case FL_Right: + RIGHT: if (pp.menubar && (pp.menu_number<=0 || (pp.menu_number == pp.nummenus-1))) forward(0); else if (pp.menu_number < pp.nummenus-1) forward(pp.menu_number+1); @@ -833,6 +834,11 @@ int menuwindow::handle_part1(int e) { case FL_Enter: case FL_KP_Enter: case ' ': + // if the current item is a submenu with no callback, + // simulate FL_Right to enter the submenu + if (pp.current_item && (!pp.menubar || pp.menu_number > 0) && + pp.current_item->activevisible() && pp.current_item->submenu() && !pp.current_item->callback_) + goto RIGHT; pp.state = DONE_STATE; return 1; case FL_Escape: @@ -922,8 +928,9 @@ int menuwindow::handle_part1(int e) { pp.p[pp.menu_number]->redraw(); } else #endif - // do nothing if they try to pick inactive items - if (!pp.current_item || pp.current_item->activevisible()) + // do nothing if they try to pick an inactive item, or a submenu with no callback + if (!pp.current_item || (pp.current_item->activevisible() && + (!pp.current_item->submenu() || pp.current_item->callback_ || (pp.menubar && pp.menu_number <= 0)))) pp.state = DONE_STATE; } return 1;