Skip to content

Commit

Permalink
Fix For #133
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Jul 24, 2024
1 parent f8e5869 commit 2689307
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<!-- Include PDB in the built .nupkg -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<AvaloniaVersion>11.0.10</AvaloniaVersion>
<AvaloniaVersion>11.1.0</AvaloniaVersion>
<ReactiveUIVersion>20.1.1</ReactiveUIVersion>
<XamarinReactiveUIVersion>19.6.12</XamarinReactiveUIVersion>
<CrissCrossCoreTargetFrameworks>netstandard2.0;net6.0;net8.0</CrissCrossCoreTargetFrameworks>
Expand All @@ -52,9 +52,9 @@
</ItemGroup>
<ItemGroup>
<!--<Compile Update="**\*.cs" DependentUpon="I%(Filename).cs" />-->
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="all" Condition="!Exists('packages.config')" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.139" PrivateAssets="all" Condition="!Exists('packages.config')" />
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.556" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.3" PrivateAssets="All" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.4" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.0.1",
"version": "2.0.2",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/main$"
Expand Down
4 changes: 2 additions & 2 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.139" />
<PackageReference Include="Nuke.Common" Version="8.0.0" />
<PackageReference Include="CP.Nuke.BuildTools" Version="1.0.44" />
</ItemGroup>

<ItemGroup>
<PackageDownload Include="nbgv" Version="[3.6.133]" />
<PackageDownload Include="nbgv" Version="[3.6.139]" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ItemGroup>
<PackageReference Include="Avalonia.Android" Version="$(AvaloniaVersion)" />
<PackageReference Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.1.7" />
<PackageReference Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.1.10" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net8.0-browser</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<WasmMainJSPath>AppBundle\main.js</WasmMainJSPath>
<OutputType>Exe</OutputType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,16 @@
<value>Rukuni</value>
<comment>This text is used as the generic narrator text when the group glyph is showing.</comment>
</data>
<data name="BadgeItemTextOverride" xml:space="preserve">
<value>{0}, {1: d} {2}</value>
</data>
<data name="BadgeIcon" xml:space="preserve">
<value>{0}, gunki</value>
</data>
<data name="BadgeIconTextOverride" xml:space="preserve">
<value>{0}, {1}</value>
</data>
<data name="PersonName" xml:space="preserve">
<value>Mutum</value>
</data>
</root>
2 changes: 1 addition & 1 deletion src/CrissCross.WPF.UI/CrissCross.WPF.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageReference Include="AppBarButton.WPF" Version="1.0.1" />
<PackageReference Include="BBCode.WPF" Version="0.2.0" />
<PackageReference Include="CP.Xaml.Converters" Version="1.0.2" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.122" />
<PackageReference Include="PolySharp" Version="1.14.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
18 changes: 2 additions & 16 deletions src/CrissCross.WPF.WebView2.Test/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.ComponentModel;
using System.Windows;

namespace CrissCross.WPF.WebView2.Test
Expand All @@ -12,25 +11,12 @@ namespace CrissCross.WPF.WebView2.Test
/// </summary>
public partial class MainWindow : Window
{
private int _clickedXTimes = 1;
private int _clickedXTimes;

/// <summary>
/// Initializes a new instance of the <see cref="MainWindow"/> class.
/// </summary>
public MainWindow()
{
InitializeComponent();
}

/// <summary>
/// Raises the <see cref="E:System.Windows.Window.Closing" /> event.
/// </summary>
/// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
protected override void OnClosing(CancelEventArgs e)
{
////WebView2Wpf.Dispose();
base.OnClosing(e);
}
public MainWindow() => InitializeComponent();

private void WindowsXp_Click(object sender, RoutedEventArgs e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/CrissCross.WPF.WebView2/CrissCross.WPF.WebView2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2478.35" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2592.51" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions src/CrissCross.WPF.WebView2/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ namespace CrissCross.WPF;

internal static class NativeMethods
{
private const int GWLEXSTYLE = -0x14;
private const uint WSEXAPPWINDOW = 0x00040000u;
private const uint WSEXTOOLWINDOW = 0x00000080u;

[DllImport("user32.dll")]
internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32.dll")]
internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);

[DllImport("user32.dll", SetLastError = true)]
internal static extern uint GetWindowLong(IntPtr hWnd, int nIndex);

internal static void HideFromAltTab(IntPtr hWnd) =>
_ = NativeMethods.SetWindowLong(hWnd, GWLEXSTYLE, (NativeMethods.GetWindowLong(hWnd, GWLEXSTYLE) | WSEXTOOLWINDOW) & ~WSEXAPPWINDOW);
}
103 changes: 102 additions & 1 deletion src/CrissCross.WPF.WebView2/WebView2Wpf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public class WebView2Wpf : ContentControl, IDisposable
public static readonly DependencyProperty ZoomFactorProperty = DependencyProperty.Register(
nameof(ZoomFactor),
typeof(double),
typeof(WebView2Wpf));
typeof(WebView2Wpf),
new PropertyMetadata(1.0, ZoomFactorPropertyChanged));

/// <summary>
/// The navigate back is enabled property.
Expand All @@ -90,6 +91,35 @@ public class WebView2Wpf : ContentControl, IDisposable
typeof(object),
typeof(WebView2Wpf),
new PropertyMetadata(true, ContentChanged));

/// <summary>
/// The default background color property.
/// </summary>
public static readonly DependencyProperty DefaultBackgroundColorProperty = DependencyProperty.Register(
nameof(DefaultBackgroundColor),
typeof(System.Drawing.Color),
typeof(WebView2Wpf),
new PropertyMetadata(System.Drawing.Color.White, DefaultBackgroundColorPropertyChanged));

/// <summary>
/// The allow external drop property.
/// </summary>
public static readonly DependencyProperty AllowExternalDropProperty = DependencyProperty.Register(
nameof(AllowExternalDrop),
typeof(bool),
typeof(WebView2Wpf),
new PropertyMetadata(true, AllowExternalDropPropertyChanged));

// Using a DependencyProperty as the backing store for DesignModeForegroundColor. This enables animation, styling, binding, etc...
/// <summary>
/// The design mode foreground color property.
/// </summary>
public static readonly DependencyProperty DesignModeForegroundColorProperty = DependencyProperty.Register(
nameof(DesignModeForegroundColor),
typeof(System.Drawing.Color),
typeof(WebView2Wpf),
new PropertyMetadata(System.Drawing.Color.Black, DesignModeForegroundColorChanged));

#pragma warning restore SA1202 // Elements should be ordered by access

private readonly WebView2 _WebBrowser;
Expand Down Expand Up @@ -192,6 +222,19 @@ public CoreWebView2CreationProperties CreationProperties
set => SetValue(CreationPropertiesProperty, value);
}

/// <summary>
/// Gets or sets the color of the design mode foreground.
/// </summary>
/// <value>
/// The color of the design mode foreground.
/// </value>
[Category("Common")]
public System.Drawing.Color DesignModeForegroundColor
{
get => (System.Drawing.Color)GetValue(DesignModeForegroundColorProperty);
set => SetValue(DesignModeForegroundColorProperty, value);
}

/// <summary>
/// Gets or sets the source.
/// </summary>
Expand All @@ -205,6 +248,32 @@ public Uri Source
set => SetValue(SourceProperty, value);
}

/// <summary>
/// Gets or sets the default color of the background.
/// </summary>
/// <value>
/// The default color of the background.
/// </value>
[Category("Common")]
public System.Drawing.Color DefaultBackgroundColor
{
get => (System.Drawing.Color)GetValue(DefaultBackgroundColorProperty);
set => SetValue(DefaultBackgroundColorProperty, value);
}

/// <summary>
/// Gets or sets a value indicating whether [allow external drop].
/// </summary>
/// <value>
/// <c>true</c> if [allow external drop]; otherwise, <c>false</c>.
/// </value>
[Category("Common")]
public bool AllowExternalDrop
{
get => (bool)GetValue(AllowExternalDropProperty);
set => SetValue(AllowExternalDropProperty, value);
}

/// <summary>
/// Gets a value indicating whether this instance can go back.
/// if the WebView can navigate to a previous page in the navigation
Expand Down Expand Up @@ -438,6 +507,38 @@ protected virtual void Dispose(bool disposing)
}
}

private static void DefaultBackgroundColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is WebView2Wpf browser && e.NewValue is System.Drawing.Color color)
{
browser._WebBrowser.DefaultBackgroundColor = color;
}
}

private static void ZoomFactorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is WebView2Wpf browser && e.NewValue is double zoom)
{
browser._WebBrowser.ZoomFactor = zoom;
}
}

private static void AllowExternalDropPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is WebView2Wpf browser && e.NewValue is bool allowDrop)
{
browser._WebBrowser.AllowExternalDrop = allowDrop;
}
}

private static void DesignModeForegroundColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is WebView2Wpf browser && e.NewValue is System.Drawing.Color color)
{
browser._WebBrowser.DesignModeForegroundColor = color;
}
}

private static void CreationPropertiesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is WebView2Wpf browser && e.NewValue is CoreWebView2CreationProperties creationProperties)
Expand Down
13 changes: 11 additions & 2 deletions src/CrissCross.WPF.WebView2/WindowHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public WindowHost(string name, TWindow? window = null)
Window.WindowStyle = WindowStyle.None;
Window.ShowInTaskbar = false;
Window.AllowsTransparency = true;
Window.BorderBrush = Brushes.Transparent;
Window.BorderThickness = new Thickness(0);
Window.Background = Brushes.Transparent;
Window.Loaded += HideFromAltTab;
Window.Show();
WindowHandle = new WindowInteropHelper(Window).Handle;
}

/// <summary>
Expand All @@ -45,7 +47,7 @@ public WindowHost(string name, TWindow? window = null)
/// <value>
/// The window handle.
/// </value>
public IntPtr WindowHandle { get; }
public IntPtr WindowHandle { get; private set; }

/// <summary>
/// Gets the window.
Expand Down Expand Up @@ -96,4 +98,11 @@ protected override void DestroyWindowCore(HandleRef hwnd)
NativeMethods.SetParent(WindowHandle, hwnd.Handle);
}
}

private void HideFromAltTab(object sender, RoutedEventArgs e)
{
Window.Loaded -= HideFromAltTab;
WindowHandle = new WindowInteropHelper(Window).Handle;
NativeMethods.HideFromAltTab(WindowHandle);
}
}
2 changes: 1 addition & 1 deletion src/CrissCross.WPF/CrissCross.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="ReactiveUI.WPF" Version="$(ReactiveUIVersion)" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2478.35" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2592.51" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/CrissCross.WPF/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ namespace CrissCross.WPF;

internal static class NativeMethods
{
private const int GWLEXSTYLE = -0x14;
private const uint WSEXAPPWINDOW = 0x00040000u;
private const uint WSEXTOOLWINDOW = 0x00000080u;

[DllImport("user32.dll")]
internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32.dll")]
internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);

[DllImport("user32.dll", SetLastError = true)]
internal static extern uint GetWindowLong(IntPtr hWnd, int nIndex);

internal static void HideFromAltTab(IntPtr hWnd) =>
_ = NativeMethods.SetWindowLong(hWnd, GWLEXSTYLE, (NativeMethods.GetWindowLong(hWnd, GWLEXSTYLE) | WSEXTOOLWINDOW) & ~WSEXAPPWINDOW);
}
Loading

0 comments on commit 2689307

Please sign in to comment.