Пример #1
0
        public CocoaWindow(WindowConfiguration config, WebviewBridge bridge)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (bridge == null)
            {
                throw new ArgumentNullException(nameof(bridge));
            }

            Handle = AppKit.Call("NSWindow", "alloc");

            canResizeField = config.CanResize;
            var style = GetWantedStyleMask();

            ObjC.SendMessage(
                Handle,
                ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"),
                new CGRect(0, 0, config.Size.Width, config.Size.Height),
                new UIntPtr((uint)style),
                new UIntPtr(2),
                false);

            webview = new CocoaWebview(bridge);
            ObjC.Call(Handle, "setContentView:", webview.Handle);

            webview.TitleChanged += Webview_TitleChanged;

            windowDelegate = WindowDelegateDefinition.CreateInstance(this);
            ObjC.Call(Handle, "setDelegate:", windowDelegate.Handle);
        }
Пример #2
0
        public CocoaStatusIcon()
        {
            var statusBar = AppKit.Call("NSStatusBar", "systemStatusBar");

            statusItem = ObjC.Call(statusBar, "statusItemWithLength:", -2.0); // -1 = variable size; -2 = square size
            ObjC.Call(statusItem, "setHighlightMode:", true);
            statusBarButton = ObjC.Call(statusItem, "button");
            ObjC.Call(statusBarButton, "setImageScaling:", 3); // 3 = scale proportionally up or down
        }
Пример #3
0
        public CocoaWindow(WindowConfiguration config, IUiFactory windowFactory)
        {
            if (windowFactory == null)
            {
                throw new ArgumentNullException(nameof(windowFactory));
            }

            this.config = config ?? throw new ArgumentNullException(nameof(config));

            Interlocked.Increment(ref count);

            // need to keep the delegates around or they will get garbage collected
            windowShouldCloseDelegate = WindowShouldCloseCallback;
            windowWillCloseDelegate   = WindowWillCloseCallback;

            Handle = AppKit.Call("NSWindow", "alloc");

            var style = NSWindowStyleMask.Titled | NSWindowStyleMask.Closable | NSWindowStyleMask.Miniaturizable;

            if (config.CanResize)
            {
                style |= NSWindowStyleMask.Resizable;
            }

            ObjC.SendMessage(
                Handle,
                ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"),
                new CGRect(0, 0, config.Width, config.Height),
                (int)style,
                2,
                0);

            Title = config.Title;

            IntPtr bgColor = NSColor.FromHex(config.BackgroundColor);

            ObjC.Call(Handle, "setBackgroundColor:", bgColor);

            var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder);

            bridge  = new WebviewBridge();
            webview = new CocoaWebview(config, contentProvider, bridge);
            ObjC.Call(Handle, "setContentView:", webview.Handle);

            if (config.EnableScriptInterface)
            {
                bridge.Init(this, webview, windowFactory);
            }

            if (config.UseBrowserTitle)
            {
                webview.TitleChanged += Webview_TitleChanged;
                bridge.TitleChanged  += Webview_TitleChanged;
            }

            SetWindowDelegate(Handle);
        }
Пример #4
0
        public CocoaStatusIcon(string title)
        {
            var statusBar = AppKit.Call("NSStatusBar", "systemStatusBar");

            statusItem = ObjC.Call(statusBar, "statusItemWithLength:", -2.0); // -1 = variable size; -2 = square size
            ObjC.Call(statusItem, "setHighlightMode:", true);
            statusBarButton = ObjC.Call(statusItem, "button");
            ObjC.Call(statusBarButton, "setImageScaling:", new UIntPtr((uint)NSImageScaling.ProportionallyUpOrDown));
            Title = title;
        }
Пример #5
0
 private CocoaLabelMenuItem(string label, string action)
     : base(AppKit.Call("NSMenuItem", "alloc"))
 {
     ObjC.Call(
         Handle,
         "initWithTitle:action:keyEquivalent:",
         NSString.Create(label),
         ObjC.RegisterName(action),
         NSString.Create(string.Empty));
 }
Пример #6
0
        public CocoaApplication()
        {
            Factory = new CocoaUiFactory();
            SynchronizationContext = new CocoaSynchronizationContext();

            Handle      = AppKit.Call("NSApplication", "sharedApplication");
            appDelegate = AppDelegateDefinition.CreateInstance(this);

            ObjC.Call(Handle, "setActivationPolicy:", IntPtr.Zero);
            ObjC.Call(Handle, "setDelegate:", appDelegate.Handle);
        }
Пример #7
0
 public CocoaMenu(string title)
 {
     if (title != null)
     {
         Handle = AppKit.Call("NSMenu", "alloc");
         ObjC.Call(Handle, "initWithTitle:", NSString.Create(title));
     }
     else
     {
         Handle = AppKit.Call("NSMenu", "new");
     }
 }
Пример #8
0
        public CocoaApplication()
        {
            Factory = new CocoaUiFactory();
            SynchronizationContext = new CocoaSynchronizationContext();

            Handle      = AppKit.Call("NSApplication", "sharedApplication");
            appDelegate = AppDelegateDefinition.CreateInstance(this);

            ObjC.Call(Handle, "setActivationPolicy:", IntPtr.Zero);
            ObjC.Call(Handle, "setDelegate:", appDelegate.Handle);

            ObjC.SetProperty(AppKit.GetClass("NSWindow"), "allowsAutomaticWindowTabbing", false);
        }
Пример #9
0
        public CocoaLabelMenuItem(string label)
            : base(AppKit.Call("NSMenuItem", "alloc"))
        {
            // need to keep the delegate around or it will get garbage collected
            menuDelegate = MenuCallback;

            ObjC.Call(
                Handle,
                "initWithTitle:action:keyEquivalent:",
                NSString.Create(label),
                ObjC.RegisterName("menuCallback:"),
                NSString.Create(string.Empty));

            SetCallbackClass();
        }
Пример #10
0
        private unsafe void UpdateIcon(AppIcon?icon)
        {
            var image = IntPtr.Zero;

            if (icon != null && icon.Icons.Length > 0)
            {
                byte[] data = icon.GetIconData(icon.DefaultIcon);
                fixed(byte *dataPtr = data)
                {
                    IntPtr nsData = Foundation.Call(
                        "NSData",
                        "dataWithBytesNoCopy:length:freeWhenDone:",
                        (IntPtr)dataPtr,
                        new IntPtr(data.Length),
                        IntPtr.Zero);

                    image = AppKit.Call("NSImage", "alloc");
                    ObjC.Call(image, "initWithData:", nsData);
                    ObjC.Call(statusBarButton, "setImage:", image);
                }
            }

            ObjC.Call(statusBarButton, "setImage:", image);
        }
Пример #11
0
        public static NSDialog CreateAlert()
        {
            var alert = AppKit.Call("NSAlert", "new");

            return(new NSDialog(alert, ObjC.Call(alert, "window"), true));
        }
Пример #12
0
 internal static IntPtr GetApp()
 {
     return(AppKit.Call("NSApplication", "sharedApplication"));
 }
Пример #13
0
 public CocoaSeparatorMenuItem()
     : base(AppKit.Call("NSMenuItem", "separatorItem"))
 {
 }
Пример #14
0
        public static NSDialog CreateOpenPanel()
        {
            var panel = AppKit.Call("NSOpenPanel", "openPanel");

            return(new NSDialog(panel, panel, false));
        }
Пример #15
0
        public static NSDialog CreateSavePanel()
        {
            var panel = AppKit.Call("NSSavePanel", "savePanel");

            return(new NSDialog(panel, panel, false));
        }
Пример #16
0
        public static IntPtr FromHex(string?hex)
        {
            ColorTools.ParseHex(hex, out byte r, out byte g, out byte b);

            return(AppKit.Call("NSColor", "colorWithRed:green:blue:alpha:", r / 255d, g / 255d, b / 255d, 1d));
        }
Пример #17
0
 public CocoaMenu()
     : base(AppKit.Call("NSMenu", "new"))
 {
     ObjC.Call(Handle, "setAutoenablesItems:", false);
 }
Пример #18
0
 public void AddSeparatorMenuItem()
 {
     var item = AppKit.Call("NSMenuItem", "separatorItem");
     AddItem(item);
 }