Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 1e52b10

Browse files
committed
[[ Bug 19097 ]] Ensure all menus are updated after mouseDown to group
This patch ensures that all menus in the menubar are rebuilt after the mouseDown message has been sent to the menubar group. This fixes the problem where only the menu which was clicked on would be rebuilt, causing all other menus to be stale.
1 parent 3d7c724 commit 1e52b10

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

docs/notes/bugfix-19097.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ensure all menus are updated after mouseDown to menu group
2+

engine/src/desktop-menu.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -935,17 +935,30 @@ void MCPlatformHandleMenuUpdate(MCPlatformMenuRef p_menu)
935935
MCRedrawUnlockScreen();
936936
}
937937

938-
// SN-2014-11-10: [[ Bug 13836 ]] Make sure that
939-
// Now we've got the menu to update, process the new menu spec, but only if the
940-
// menu button still exists!
941-
if (!t_update_menubar && s_menubar_targets[t_parent_menu_index].IsValid())
942-
{
943-
MCButton *t_button = s_menubar_targets[t_parent_menu_index];
944-
945-
MCPlatformRemoveAllMenuItems(p_menu);
946-
MCstacks -> deleteaccelerator(t_button, t_button -> getstack());
947-
populate_menubar_menu_from_button(s_menubar, t_parent_menu_index, p_menu, t_button);
948-
}
938+
// We only send one message - to the group - to rebuild the menus. Therefore,
939+
// after this is done we must rebuild all menubar menus at once.
940+
if (!t_update_menubar)
941+
{
942+
uindex_t t_count;
943+
MCPlatformCountMenuItems(s_menubar, t_count);
944+
for(uindex_t i = 0; i < t_count; i++)
945+
{
946+
MCPlatformMenuRef t_menu;
947+
MCPlatformGetMenuItemProperty(s_menubar, i, kMCPlatformMenuItemPropertySubmenu, kMCPlatformPropertyTypeMenuRef, &t_menu);
948+
949+
// Always remove all items - we can't delete the menu if the button has
950+
// been deleted as it might be referenced by Cocoa still.
951+
MCPlatformRemoveAllMenuItems(t_menu);
952+
953+
// Only rebuild the menu if the button still exists.
954+
if (s_menubar_targets[i].IsValid())
955+
{
956+
MCButton *t_button = s_menubar_targets[i];
957+
MCstacks -> deleteaccelerator(t_button, t_button -> getstack());
958+
populate_menubar_menu_from_button(s_menubar, i, t_menu, t_button);
959+
}
960+
}
961+
}
949962
}
950963

951964
void MCPlatformHandleMenuSelect(MCPlatformMenuRef p_menu, uindex_t p_item_index)

engine/src/mac-menu.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,19 @@ void MCPlatformGetMenuItemProperty(MCPlatformMenuRef p_menu, uindex_t p_index, M
692692
case kMCPlatformMenuItemPropertyTag:
693693
/* UNCHECKED */ MCStringCreateWithCFString((CFStringRef)[t_item representedObject], *(MCStringRef*)r_value);
694694
break;
695+
case kMCPlatformMenuItemPropertySubmenu:
696+
{
697+
NSMenu *t_current_submenu = [t_item submenu];
698+
699+
MCPlatformMenuRef t_current_submenu_ref = nil;
700+
if (t_current_submenu != nil)
701+
{
702+
t_current_submenu_ref = [(MCMenuDelegate *)[t_current_submenu delegate] platformMenuRef];
703+
}
704+
*(MCPlatformMenuRef *)r_value = t_current_submenu_ref;
705+
}
706+
break;
707+
695708
default:
696709
assert(false);
697710
break;

0 commit comments

Comments
 (0)