Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Restoring Forms controls in this branch manually.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Wilcox committed Sep 13, 2018
1 parent 9561807 commit e713b3f
Show file tree
Hide file tree
Showing 46 changed files with 3,214 additions and 12 deletions.
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Windows.Forms;
using Microsoft.Toolkit.UI.Controls;

namespace Microsoft.Toolkit.Forms.UI.Controls
{
public interface IWebViewCompatibleAdapter : IWebViewCompatible
{
Control View { get; }
}
}
@@ -0,0 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Forms;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;

namespace Microsoft.Toolkit.Forms.UI.Controls
{
internal abstract class WebBaseCompatibilityAdapter : DependencyObject, IWebViewCompatibleAdapter
{
protected WebBaseCompatibilityAdapter()
{
Initialize();
}

public static DependencyProperty SourceProperty { get; } = DependencyProperty.Register(nameof(Source), typeof(Uri), typeof(WebBaseCompatibilityAdapter));

public abstract Control View { get; }

public abstract Uri Source { get; set; }

public abstract bool CanGoBack { get; }

public abstract bool CanGoForward { get; }

public abstract event EventHandler<WebViewControlNavigationStartingEventArgs> NavigationStarting;

public abstract event EventHandler<WebViewControlContentLoadingEventArgs> ContentLoading;

public abstract event EventHandler<WebViewControlNavigationCompletedEventArgs> NavigationCompleted;

public abstract bool GoBack();

public abstract bool GoForward();

public abstract string InvokeScript(string scriptName);

public abstract void Navigate(Uri url);

public abstract void Navigate(string url);

public abstract void Refresh();

public abstract void Stop();

protected abstract void Initialize();
}
}
@@ -0,0 +1,82 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Windows.Forms;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;

namespace Microsoft.Toolkit.Forms.UI.Controls
{
internal sealed class WebBrowserCompatibilityAdapter : WebBaseCompatibilityAdapter
{
private WebBrowser _browser = new WebBrowser();

private void OnBrowserNavigated(object sender, WebBrowserNavigatedEventArgs e)
{
NavigationCompleted?.Invoke(sender, e);
}

private void OnBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e)
{
NavigationStarting?.Invoke(sender, e);
ContentLoading?.Invoke(sender, e);
}

public override Uri Source { get => _browser.Url; set => _browser.Url = value; }

public override bool CanGoBack => _browser.CanGoBack;

public override bool CanGoForward => _browser.CanGoForward;

public override Control View => _browser;

public override event EventHandler<WebViewControlNavigationStartingEventArgs> NavigationStarting;

public override event EventHandler<WebViewControlContentLoadingEventArgs> ContentLoading;

public override event EventHandler<WebViewControlNavigationCompletedEventArgs> NavigationCompleted;

public override bool GoBack()
{
_browser.GoBack();
return true;
}

public override bool GoForward()
{
_browser.GoForward();
return true;
}

public override string InvokeScript(string scriptName)
{
throw new NotImplementedException();
}

public override void Navigate(Uri url)
{
_browser.Navigate(url);
}

public override void Navigate(string url)
{
_browser.Navigate(url);
}

public override void Refresh()
{
_browser.Refresh();
}

public override void Stop()
{
}

protected override void Initialize()
{
_browser.Navigating += OnBrowserNavigating;
_browser.Navigated += OnBrowserNavigated;
}
}
}
@@ -0,0 +1,111 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;

namespace Microsoft.Toolkit.Forms.UI.Controls
{
internal sealed class WebViewCompatibilityAdapter : WebBaseCompatibilityAdapter, IWebViewCompatibleAdapter, IDisposable
{
private WebView _webView = new WebView();

~WebViewCompatibilityAdapter()
{
Dispose(false);
}

public override event EventHandler<WebViewControlContentLoadingEventArgs> ContentLoading
{
add
{
_webView.ContentLoading += value;
_webView.FrameContentLoading += value;
}

remove
{
_webView.ContentLoading -= value;
_webView.FrameContentLoading -= value;
}
}

public override event EventHandler<WebViewControlNavigationCompletedEventArgs> NavigationCompleted
{
add
{
_webView.NavigationCompleted += value;
_webView.FrameNavigationCompleted += value;
}

remove
{
_webView.NavigationCompleted -= value;
_webView.FrameNavigationCompleted -= value;
}
}

public override event EventHandler<WebViewControlNavigationStartingEventArgs> NavigationStarting
{
add
{
_webView.NavigationStarting += value;
_webView.FrameNavigationStarting += value;
}

remove
{
_webView.NavigationStarting -= value;
_webView.FrameNavigationStarting -= value;
}
}

public override bool CanGoBack => _webView.CanGoBack;

public override bool CanGoForward => _webView.CanGoForward;

public override Uri Source { get => _webView.Source; set => _webView.Source = value; }

public override Control View => _webView;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

public override bool GoBack() => _webView.GoBack();

public override bool GoForward() => _webView.GoForward();

public override string InvokeScript(string scriptName) => _webView.InvokeScript(scriptName);

public override void Navigate(Uri url) => _webView.Navigate(url);

public override void Navigate(string url) => _webView.Navigate(url);

public override void Refresh() => _webView.Refresh();

public override void Stop() => _webView.Stop();

protected override void Initialize()
{
var initWebView = (ISupportInitialize)_webView;
initWebView.BeginInit();
_webView.Dock = DockStyle.Fill;
initWebView.EndInit();
}

private void Dispose(bool disposing)
{
if (disposing)
{
_webView?.Dispose();
_webView = null;
}
}
}
}
88 changes: 88 additions & 0 deletions Microsoft.Toolkit.Forms.UI.Controls.WebView/WebViewCompatible.cs
@@ -0,0 +1,88 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Toolkit.UI.Controls;
using Microsoft.Toolkit.Win32.UI.Controls;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;

namespace Microsoft.Toolkit.Forms.UI.Controls
{
// [Designer(typeof(WebViewCompatibleDesigner))]
[DefaultProperty(Constants.ComponentDefaultProperty)]
[DefaultEvent(Constants.ComponentDefaultEvent)]
[Docking(DockingBehavior.AutoDock)]
[Description("Embeds a view into your application that renders web content using the Microsoft Edge rendering engine")]
public class WebViewCompatible : Control, IWebViewCompatible
{
private const string WinRtType = "Windows.Web.UI.Interop.WebViewControl";
private readonly IWebViewCompatibleAdapter _implementation;
private bool _isWinRtTypePresent;

public WebViewCompatible()
: base()
{
// REVIEW: Why not use WebView.IsSupported?
ApiInformationExtensions.ExecuteIfTypePresent(WinRtType, () => _isWinRtTypePresent = true);

_implementation = _isWinRtTypePresent
? (IWebViewCompatibleAdapter)new WebViewCompatibilityAdapter()
: new WebBrowserCompatibilityAdapter();

_implementation.View.Dock = DockStyle.Fill;
Controls.Add(_implementation.View);
}

public event EventHandler<WebViewControlContentLoadingEventArgs> ContentLoading { add => _implementation.ContentLoading += value; remove => _implementation.ContentLoading -= value; }

public event EventHandler<WebViewControlNavigationCompletedEventArgs> NavigationCompleted { add => _implementation.NavigationCompleted += value; remove => _implementation.NavigationCompleted -= value; }

public event EventHandler<WebViewControlNavigationStartingEventArgs> NavigationStarting { add => _implementation.NavigationStarting += value; remove => _implementation.NavigationStarting -= value; }

public bool CanGoBack => _implementation.CanGoBack;

public bool CanGoForward => _implementation.CanGoForward;

public bool IsLegacy => !_isWinRtTypePresent;

[Category("Web")]
[Bindable(true)]
[DefaultValue(null)]
[TypeConverter(typeof(WebBrowserUriTypeConverter))]
public Uri Source { get => _implementation.Source; set => _implementation.Source = value; }

public Control View { get => _implementation.View; }

public bool GoBack() => _implementation.GoBack();

public bool GoForward() => _implementation.GoForward();

public string InvokeScript(string scriptName) => _implementation.InvokeScript(scriptName);

public void Navigate(Uri url) => _implementation.Navigate(url);

public void Navigate(string url) => _implementation.Navigate(url);

public override void Refresh() => _implementation.Refresh();

public void Stop() => _implementation.Stop();

protected override void Dispose(bool disposing)
{
try
{
if (_implementation is IDisposable disposable)
{
disposable.Dispose();
}
}
finally
{
base.Dispose(disposing);
}
}
}
}
29 changes: 29 additions & 0 deletions Microsoft.Toolkit.Forms.UI.Controls/InkCanvas/InkCanvas.cs
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;

namespace Microsoft.Toolkit.Forms.UI.Controls
{
public class InkCanvas : WindowsXamlHostBaseExt
{
internal Windows.UI.Xaml.Controls.InkCanvas UwpControl => XamlElement as Windows.UI.Xaml.Controls.InkCanvas;

public InkCanvas()
: this(typeof(Windows.UI.Xaml.Controls.InkCanvas).FullName)
{
}

protected InkCanvas(string name)
: base(name)
{
}

/// <summary>
/// Gets <see cref="Windows.UI.Xaml.Controls.InkCanvas.InkPresenter"/>
/// </summary>
public InkPresenter InkPresenter => UwpControl.InkPresenter;
}
}

0 comments on commit e713b3f

Please sign in to comment.