/// <summary> /// Handle's the Windows IE browser's key press events. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void OnKeyPress(object sender, HtmlElementEventArgs e) { if (browser is TWWebBrowserIE) { TWWebBrowserIE ieBrowser = browser as TWWebBrowserIE; // By default, we assume that the key press is not significant, so we set the // event args' return value to false, so event propagation continues. e.ReturnValue = false; int keyCode = e.KeyPressedCode; if (e.CtrlKeyPressed) { keyCode += 96; if (keyCode == 'c') { Copy?.Invoke(this, new CopyEventArgs() { Text = ieBrowser.GetSelectedText() }); } else if (keyCode == 'a') { ieBrowser.SelectAll(); } else if (keyCode == 'f') { // We just send the appropriate keypress event to the WebBrowser. This doesn't // seem to work well for ctrl + a, and doesn't work at all for ctrl + c. SendKeys.SendWait("^f"); } } } }
/// <summary> /// Populate the view given the specified text. /// </summary> /// <param name="contents"></param> /// <param name="editingEnabled"></param> /// <returns></returns> private void PopulateView(string contents, bool isURI = false) { if (browser == null) { if (ProcessUtilities.CurrentOS.IsWindows) { browser = CreateIEBrowser(vbox2); /// UGH! Once the browser control gets keyboard focus, it doesn't relinquish it to /// other controls. It's actually a COM object, I guess, and running /// with a different message loop, and probably in a different thread. /// /// Well, this hack works, more or less. if (vbox2.Toplevel is Window) { (vbox2.Toplevel as Window).SetFocus += MainWindow_SetFocus; } frame1.Unrealized += Frame1_Unrealized; if (this is MapView) // If we're only displaying a map, remove the unneeded scrollbar { (browser as TWWebBrowserIE).Browser.ScrollBarsEnabled = false; } } else if (ProcessUtilities.CurrentOS.IsMac) { browser = CreateSafariBrowser(vbox2); } else { browser = CreateWebKitBrowser(vbox2); } } if (isURI) { browser.Navigate(contents); } else { browser.LoadHTML(contents); } if (browser is TWWebBrowserIE && (browser as TWWebBrowserIE).Browser != null) { TWWebBrowserIE ieBrowser = browser as TWWebBrowserIE; keyPressObject = ieBrowser.Browser.Document.ActiveElement; if (keyPressObject != null) { (keyPressObject as HtmlElement).KeyPress += OnKeyPress; } ieBrowser.BackgroundColour = Utility.Colour.FromGtk(MainWidget.Style.Background(StateType.Normal)); ieBrowser.ForegroundColour = Utility.Colour.FromGtk(MainWidget.Style.Foreground(StateType.Normal)); } //browser.Navigate("http://blend-bp.nexus.csiro.au/wiki/index.php"); }
// Although this isn't the obvious way to handle window resizing, // I couldn't find any better technique. public void OnWidgetExpose(object o, ExposeEventArgs args) { int height, width; frame1.GdkWindow.GetSize(out width, out height); frame1.SetSizeRequest(width, height); if (browser is TWWebBrowserIE) { TWWebBrowserIE brow = browser as TWWebBrowserIE; if (brow.unmapped) { brow.Remap(); } if (brow.wb.Height != height || brow.wb.Width != width) { brow.socket.SetSizeRequest(width, height); brow.wb.Height = height; brow.wb.Width = width; } } }