From 5c6ec56b33d9eb5a9261eb72128d86f8e6ff5305 Mon Sep 17 00:00:00 2001 From: dannye <33dannye@gmail.com> Date: Sun, 6 Oct 2024 12:19:54 -0500 Subject: [PATCH] Submenus with no callback enter their submenu instead of closing the whole menu (#1043) Thanks for those nice changes. --- 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 effaafd9c..6332673da 100644 --- a/src/Fl_Menu.cxx +++ b/src/Fl_Menu.cxx @@ -824,6 +824,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); @@ -836,6 +837,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: @@ -924,8 +930,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;