Пример #1
0
        public GtkWindow(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            try
            {
                webview = new GtkWebview(bridge);
            }
            catch (DllNotFoundException)
            {
                var dialog = new GtkMessageBox
                {
                    Title   = "Missing dependency",
                    Message = "The dependency 'libwebkit2gtk-4.0' is missing. Make sure it is installed correctly.",
                    Buttons = MessageBoxButtons.Ok,
                };
                dialog.Show();
                Environment.Exit(-1);
            }

            Handle = Gtk.Window.Create(GtkWindowType.Toplevel);

            IntPtr contentBox = Gtk.Box.Create(GtkOrientationType.Vertical, 0);

            Gtk.Widget.ContainerAdd(Handle, contentBox);
            Gtk.Widget.Show(contentBox);

            // Do not show the menu bar, since it could be empty
            menuBarHandle = Gtk.MenuBar.Create();
            Gtk.Box.AddChild(contentBox, menuBarHandle, false, false, 0);

            Gtk.Box.AddChild(contentBox, webview.Handle, true, true, 0);
            Gtk.Widget.Show(webview.Handle);

            accelGroup = Gtk.AccelGroup.Create();
            Gtk.Window.AddAccelGroup(Handle, accelGroup);

            // need to keep the delegates around or they will get garbage collected
            showDelegate    = ShowCallback;
            deleteDelegate  = DeleteCallback;
            destroyDelegate = DestroyCallback;

            GLib.ConnectSignal(Handle, "show", showDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "delete-event", deleteDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "destroy", destroyDelegate, IntPtr.Zero);

            webview.CloseRequested += Webview_CloseRequested;
            webview.TitleChanged   += Webview_TitleChanged;
        }
Пример #2
0
        public GtkWindow(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            webview = new GtkWebview(bridge);
            Handle  = Gtk.Window.Create(GtkWindowType.Toplevel);

            IntPtr scroller = Gtk.Window.CreateScrolled(IntPtr.Zero, IntPtr.Zero);

            Gtk.Widget.ContainerAdd(Handle, scroller);
            Gtk.Widget.ContainerAdd(scroller, webview.Handle);

            // need to keep the delegates around or they will get garbage collected
            showDelegate    = ShowCallback;
            deleteDelegate  = DeleteCallback;
            destroyDelegate = DestroyCallback;

            GLib.ConnectSignal(Handle, "show", showDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "delete-event", deleteDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "destroy", destroyDelegate, IntPtr.Zero);

            webview.CloseRequested += Webview_CloseRequested;
            webview.TitleChanged   += Webview_TitleChanged;
        }