File: urllistenerosx.pas

package info (click to toggle)
transgui 5.0.1-5.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 3,792 kB
  • sloc: pascal: 40,152; makefile: 2,294; cs: 347; perl: 347; lisp: 347; sh: 84
file content (47 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
unit URLListenerOSX;
{$mode objfpc}{$H+}
{$modeswitch objectivec2}

interface

uses
  Classes, SysUtils, CocoaAll, InternetConfig, AppleEvents;

type
  THandlerProc = procedure(const url: string);

  { TAppURLHandler }
  
  TAppURLHandler = objcclass(NSObject)
  public
    procedure  getUrlwithReplyEvent(event: NSAppleEventDescriptor; eventReply: NSAppleEventDescriptor); message 'getUrl:withReplyEvent:';
  public
    callBack: THandlerProc;
  end;

procedure RegisterURLHandler(HandlerProc: THandlerProc);
var
  handler : TAppURLHandler;
  eventManager: NSAppleEventManager;
 
implementation

{ TAppURLHandler }

procedure TAppURLHandler.getUrlwithReplyEvent(event: NSAppleEventDescriptor; eventReply: NSAppleEventDescriptor);
var
  url : NSString;
begin
  url:=event.paramDescriptorForKeyword(keyDirectObject).stringValue;
  callBack(url.UTF8String);
end;

procedure RegisterURLHandler(HandlerProc: THandlerProc);
begin
  handler:=TAppURLHandler.alloc.init;
  handler.callBack:=HandlerProc;
  eventManager:=NSAppleEventManager.sharedAppleEventManager;
  eventManager.setEventHandler_andSelector_forEventClass_andEventID(handler,ObjCSelector(handler.getUrlwithReplyEvent), kInternetEventClass,kAEGetURL);
end;

end.