From 006c5d25d55f0ca5681d1697b799f5566def70e7 Mon Sep 17 00:00:00 2001 From: dmitry Date: Tue, 21 May 2019 17:53:06 +0000 Subject: [PATCH] cocoa: adding submenu invalidation, so the menuNeedsUpdate is called git-svn-id: trunk@61262 - --- lcl/interfaces/cocoa/cocoawsmenus.pas | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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;