diff --git a/lcl/interfaces/cocoa/cocoawsmenus.pas b/lcl/interfaces/cocoa/cocoawsmenus.pas index 349cfd89b1..b3a15fbd1b 100644 --- a/lcl/interfaces/cocoa/cocoawsmenus.pas +++ b/lcl/interfaces/cocoa/cocoawsmenus.pas @@ -87,6 +87,7 @@ type // of the menu. While LCL allows to modify the menu contents when the submenu // is about to be activated. procedure menuNeedsUpdate(AMenu: NSMenu); message 'menuNeedsUpdate:'; + procedure menuDidClose(AMenu: NSMenu); message 'menuDidClose:'; end; TCocoaMenuItem_HideApp = objcclass(NSMenuItem) @@ -385,6 +386,28 @@ begin menuItemCallback.ItemSelected; end; +procedure TCocoaMenuItem.menuDidClose(AMenu: NSMenu); +var + par : NSMenu; + idx : NSInteger; + mn : NSMenuItem; +begin + // the only purpose of this code is to "invalidate" the submenu of the item. + // an invalidated menu will call menuNeedsUpdate. + // There's no other way in Cocoa to do the "invalidate" + par := amenu.supermenu; + if Assigned(par) then + begin + idx := par.indexOfItemWithSubmenu(AMenu); + if idx<>NSNotFound then + begin + mn := par.itemAtIndex(idx); + mn.setSubmenu(nil); + mn.setSubmenu(AMenu); + end; + end; +end; + procedure TCocoaMenuItem_HideApp.lclItemSelected(sender: id); begin // Applicaiton.Minimize, calls WidgetSet.AppMinimize;