I try make working DnD on Cocoa for now i have:
In "CocoaInt":
from line 52:
{ TCocoaAppDelegate }
TCocoaAppDelegate = objcclass(NSObject, NSApplicationDelegateProtocol)
function applicationShouldTerminate(sender: NSApplication): NSApplicationTerminateReply; message 'applicationShouldTerminate:';
end;
to:
{ TCocoaAppDelegate }
TCocoaAppDelegate = objcclass(NSObject, NSApplicationDelegateProtocol)
function openFiles(sender: NSApplication; filenames: NSArray): Boolean; message 'application:openFiles:';
function applicationShouldTerminate(sender: NSApplication): NSApplicationTerminateReply; message 'applicationShouldTerminate:';
end;
in "cocoaobject.inc"
from line 453:
{ TCocoaAppDelegate }
function TCocoaAppDelegate.applicationShouldTerminate(sender: NSApplication): NSApplicationTerminateReply;
begin
Result := NSTerminateNow;
end;
to:
{ TCocoaAppDelegate }
function TCocoaAppDelegate.openFiles(sender: NSApplication; filenames: NSArray): Boolean;
var
i: Longint;
args: array of String;
begin
//if gOpenFilesProc <> nil then
//begin
if filenames.count > 0 then
begin
SetLength(args, filenames.count);
for i := 0 to filenames.count-1 do
begin
args[i] := NSStringToString(NSString(filenames.objectAtIndex(i)));
end;
Application.IntfDropFiles(args);
//end;
result := true; // Assume success
end
else
result := false; // No proc - failed!
end;
function TCocoaAppDelegate.applicationShouldTerminate(sender: NSApplication): NSApplicationTerminateReply;
begin
Result := NSTerminateNow;
end;
And in Main form of project I use:
procedure TMainForm.OnApplicationDropFiles(Sender: TObject; const FileNames: array of String);
var
i:Longint;
begin
//ShowMessage('Files dropped');
for i := 0 to Length(FileNames)-1 do
begin
Dialogs.ShowMessage(FileNames[i]);
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.AddOnDropFilesHandler(@OnApplicationDropFiles);
end;
and this working for me on Application icon if anybody can check on other OS-es and told me if this solusion works.
Edit: I use Lazazus 1.2.0 OSX Lion 10.7.5 and compile with target x86_64