Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static unsafe IntPtr Create(string value)
        {
            if (value == null)
            {
                return(IntPtr.Zero);
            }

            fixed(char *ptr = value)
            {
                return(ObjC.SendMessage(
                           ObjC.GetClass("NSString"),
                           ObjC.RegisterName("stringWithCharacters:length:"),
                           (IntPtr)ptr,
                           new UIntPtr((uint)value.Length)));
            }
        }
Ejemplo n.º 4
0
 private void Iterate()
 {
     ObjC.SendMessage(loop, method, mode, date);
 }