From 648a0b25fc2964c7e56859c9b7fb4f69a191dc84 Mon Sep 17 00:00:00 2001 From: rich2014 Date: Mon, 27 May 2024 22:10:35 +0800 Subject: [PATCH] Cocoa: macOS_DockMenuIntf added to facilitate APP to operate Dock Menu --- lcl/interfaces/cocoa/cocoaint.pas | 1 + lcl/interfaces/cocoa/cocoamenus.pas | 12 ++++++++++++ lcl/interfaces/cocoa/cocoaobject.inc | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index b4d3aa6184..c9563212d5 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -62,6 +62,7 @@ type procedure applicationDidResignActive(notification: NSNotification); procedure applicationDidChangeScreenParameters(notification: NSNotification); procedure applicationWillFinishLaunching(notification: NSNotification); + function applicationDockMenu(sender: NSApplication): NSMenu; procedure handleQuitAppEvent_withReplyEvent(event: NSAppleEventDescriptor; replyEvent: NSAppleEventDescriptor); message 'handleQuitAppEvent:withReplyEvent:'; end; diff --git a/lcl/interfaces/cocoa/cocoamenus.pas b/lcl/interfaces/cocoa/cocoamenus.pas index cb33cc4ec7..c02880d159 100644 --- a/lcl/interfaces/cocoa/cocoamenus.pas +++ b/lcl/interfaces/cocoa/cocoamenus.pas @@ -78,6 +78,15 @@ type dontAutoCreateAppMenuItems: Boolean; end; + { TMacOS_DockMenuIntf } + + // Application interface provided to facilitate APP to operate Dock Menu. + // only the LCL TMenuItem is needed to pass in. + TMacOS_DockMenuIntf = class + public + customMenus: TMenuItem; + end; + TMenuItemHandleCreateFunc = function(const AMenuItem: TMenuItem): NSMenuItem; const @@ -85,6 +94,7 @@ const var macOS_AppMenuIntf: TMacOS_AppMenuIntf; + macOS_DockMenuIntf: TMacOS_DockMenuIntf; menuItemHandleCreateFunc: TMenuItemHandleCreateFunc; procedure MenuTrackStarted(mn: NSMenu); @@ -715,11 +725,13 @@ end; initialization macOS_AppMenuIntf:= TMacOS_AppMenuIntf.Create; + macOS_DockMenuIntf:= TMacOS_DockMenuIntf.Create; finalization MenuTrackCancelAll; if menuTrack <> nil then menuTrack.release; FreeAndNil(macOS_AppMenuIntf); + FreeAndNil(macOS_DockMenuIntf); end. diff --git a/lcl/interfaces/cocoa/cocoaobject.inc b/lcl/interfaces/cocoa/cocoaobject.inc index 47eaa4357c..55e9372f8b 100644 --- a/lcl/interfaces/cocoa/cocoaobject.inc +++ b/lcl/interfaces/cocoa/cocoaobject.inc @@ -722,6 +722,13 @@ begin kAEQuitApplication); end; +function TAppDelegate.applicationDockMenu(sender: NSApplication): NSMenu; +begin + Result:= NSMenu.alloc.init; + if Assigned(macOS_DockMenuIntf.customMenus) then + NSMenuAddItemsFromLCLMenu(Result, macOS_DockMenuIntf.customMenus); +end; + procedure TAppDelegate.handleQuitAppEvent_withReplyEvent(event: NSAppleEventDescriptor; replyEvent: NSAppleEventDescriptor); { Capture "Quit Application" Apple Events, either from system shutdown/logout or sent by another application. Don't use [applicationShouldTerminate:]