public GtkWindow(WindowConfiguration config, IUiFactory windowFactory) { if (windowFactory == null) { throw new ArgumentNullException(nameof(windowFactory)); } this.config = config ?? throw new ArgumentNullException(nameof(config)); var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder); bridge = new WebviewBridge(); webview = new GtkWebview(config, contentProvider, bridge); Handle = Gtk.Window.Create(GtkWindowType.Toplevel); Title = config.Title; Gtk.Window.SetResizable(Handle, config.CanResize); Gtk.Window.SetDefaultSize(Handle, config.Width, config.Height); string backgroundColor = config.BackgroundColor; if (string.IsNullOrWhiteSpace(backgroundColor)) { backgroundColor = "#FFFFFF"; } SetBackgroundColor(backgroundColor); 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 deleteDelegate = DeleteCallback; destroyDelegate = DestroyCallback; GLib.ConnectSignal(Handle, "delete-event", deleteDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "destroy", destroyDelegate, IntPtr.Zero); webview.CloseRequested += Webview_CloseRequested; if (config.EnableScriptInterface) { bridge.Init(this, webview, windowFactory); } if (config.UseBrowserTitle) { webview.TitleChanged += Webview_TitleChanged; bridge.TitleChanged += Webview_TitleChanged; } SetIcon(config.Icon); }
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; }
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; }