public GtkLabelMenuItem(string label) : base(CreateHandle(label)) { // need to keep the delegate around or it will get garbage collected menuActivateDelegate = MenuActivatedCallback; GLib.ConnectSignal(Handle, "activate", menuActivateDelegate, IntPtr.Zero); }
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 GtkWebview(WebviewBridge bridge) { this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); scriptCallbacks = new ConcurrentDictionary <Guid, GAsyncReadyDelegate>(); // need to keep the delegates around or they will get garbage collected scriptDelegate = ScriptCallback; loadFailedDelegate = LoadFailedCallback; loadDelegate = LoadCallback; contextMenuDelegate = ContextMenuCallback; closeDelegate = CloseCallback; titleChangeDelegate = TitleChangeCallback; uriSchemeCallback = UriSchemeCallback; manager = WebKit.Manager.Create(); GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero); using (GLibString name = "external") { WebKit.Manager.RegisterScriptMessageHandler(manager, name); } using (GLibString initScript = Resources.GetInitScript("Linux")) { var script = WebKit.Manager.CreateScript(initScript, WebKitInjectedFrames.AllFrames, WebKitInjectionTime.DocumentStart, IntPtr.Zero, IntPtr.Zero); WebKit.Manager.AddScript(manager, script); WebKit.Manager.UnrefScript(script); } Handle = WebKit.CreateWithUserContentManager(manager); settings = WebKit.Settings.Get(Handle); inspector = WebKit.Inspector.Get(Handle); GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero); customHost = new Uri(UriTools.GetRandomResourceUrl(CustomScheme)); IntPtr context = WebKit.Context.Get(Handle); using (GLibString gscheme = CustomScheme) { WebKit.Context.RegisterUriScheme(context, gscheme, uriSchemeCallback, IntPtr.Zero, IntPtr.Zero); } }
public GtkWebview(WebviewBridge bridge) { this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); // need to keep the delegates around or they will get garbage collected scriptDelegate = ScriptCallback; loadFailedDelegate = LoadFailedCallback; loadDelegate = LoadCallback; contextMenuDelegate = ContextMenuCallback; closeDelegate = CloseCallback; titleChangeDelegate = TitleChangeCallback; manager = WebKit.Manager.Create(); GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero); using (GLibString name = "external") { WebKit.Manager.RegisterScriptMessageHandler(manager, name); } Handle = WebKit.CreateWithUserContentManager(manager); settings = WebKit.Settings.Get(Handle); inspector = WebKit.Inspector.Get(Handle); GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero); const string scheme = "spidereye"; customHost = new Uri(UriTools.GetRandomResourceUrl(scheme)); IntPtr context = WebKit.Context.Get(Handle); using (GLibString gscheme = scheme) { WebKit.Context.RegisterUriScheme(context, gscheme, UriSchemeCallback, IntPtr.Zero, IntPtr.Zero); } }
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; }
public GtkWebview(WindowConfiguration config, IContentProvider contentProvider, WebviewBridge bridge) { this.config = config ?? throw new ArgumentNullException(nameof(config)); this.contentProvider = contentProvider ?? throw new ArgumentNullException(nameof(contentProvider)); this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); // need to keep the delegates around or they will get garbage collected scriptDelegate = ScriptCallback; loadFailedDelegate = LoadFailedCallback; loadDelegate = LoadCallback; contextMenuDelegate = ContextMenuCallback; closeDelegate = CloseCallback; titleChangeDelegate = TitleChangeCallback; if (config.EnableScriptInterface) { manager = WebKit.Manager.Create(); GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero); using (GLibString name = "external") { WebKit.Manager.RegisterScriptMessageHandler(manager, name); } Handle = WebKit.CreateWithUserContentManager(manager); } else { Handle = WebKit.Create(); } GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero); if (config.UseBrowserTitle) { GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero); } if (string.IsNullOrWhiteSpace(config.ExternalHost)) { const string scheme = "spidereye"; customHost = UriTools.GetRandomResourceUrl(scheme); IntPtr context = WebKit.Context.Get(Handle); using (GLibString gscheme = scheme) { WebKit.Context.RegisterUriScheme(context, gscheme, UriSchemeCallback, IntPtr.Zero, IntPtr.Zero); } } var bgColor = new GdkColor(config.BackgroundColor); WebKit.SetBackgroundColor(Handle, ref bgColor); if (enableDevTools) { var settings = WebKit.Settings.Get(Handle); WebKit.Settings.SetEnableDeveloperExtras(settings, true); var inspector = WebKit.Inspector.Get(Handle); WebKit.Inspector.Show(inspector); } }