Cocoa: macOS_DockMenuIntf added to facilitate APP to operate Dock Menu

This commit is contained in:
rich2014 2024-05-27 22:10:35 +08:00
parent 4df4532e13
commit 648a0b25fc
3 changed files with 20 additions and 0 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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:]