Exemplo n.º 1
0
        private static NativeClassDefinition CreateWindowDelegate()
        {
            var definition = NativeClassDefinition.FromObject(
                "SpiderEyeWindowDelegate",
                AppKit.GetProtocol("NSWindowDelegate"));

            definition.AddMethod <WindowShouldCloseDelegate>(
                "windowShouldClose:",
                "c@:@",
                (self, op, window) =>
            {
                var instance = definition.GetParent <CocoaWindow>(self);
                var args     = new CancelableEventArgs();
                instance.Closing?.Invoke(instance, args);

                return(args.Cancel ? (byte)0 : (byte)1);
            });

            definition.AddMethod <NotificationDelegate>(
                "windowWillClose:",
                "v@:@",
                (self, op, notification) =>
            {
                var instance = definition.GetParent <CocoaWindow>(self);
                instance.webview.TitleChanged -= instance.Webview_TitleChanged;
                instance.Closed?.Invoke(instance, EventArgs.Empty);
            });

            definition.FinishDeclaration();

            return(definition);
        }
Exemplo n.º 2
0
        private static NativeClassDefinition CreateAppDelegate()
        {
            var definition = NativeClassDefinition.FromClass(
                "SpiderEyeAppDelegate",
                AppKit.GetClass("NSResponder"),
                // note: NSApplicationDelegate is not available at runtime and returns null
                AppKit.GetProtocol("NSApplicationDelegate"),
                AppKit.GetProtocol("NSTouchBarProvider"));

            definition.AddMethod <ShouldTerminateDelegate>(
                "applicationShouldTerminateAfterLastWindowClosed:",
                "c@:@",
                (self, op, notification) => (byte)(Application.ExitWithLastWindow ? 1 : 0));

            definition.AddMethod <NotificationDelegate>(
                "applicationDidFinishLaunching:",
                "v@:@",
                (self, op, notification) =>
            {
                var instance = definition.GetParent <CocoaApplication>(self);
                ObjC.Call(instance.Handle, "activateIgnoringOtherApps:", true);
            });

            definition.FinishDeclaration();

            return(definition);
        }