Create a new Toolkit.Windows project

This commit is contained in:
Dan Clark
2024-11-02 20:04:51 +00:00
parent 4f4703c44b
commit c167257aae
12 changed files with 129 additions and 77 deletions
+4 -2
View File
@@ -1,5 +1,7 @@
namespace Toolkit.Windows;
using Toolkit.Foundation;
namespace Toolkit.Windows;
public interface IPointerMonitor :
IInitializer,
IInitialization,
IDisposable;
+8
View File
@@ -0,0 +1,8 @@
namespace Toolkit.Windows;
public enum PointerButton
{
Left,
Middle,
Right
}
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Windows;
public record PointerDragEventArgs(PointerLocation Location);
@@ -0,0 +1,3 @@
namespace Toolkit.Windows;
public record PointerDragReleasedEventArgs(PointerLocation Location, PointerButton Button = PointerButton.Left);
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Windows;
public record PointerLocation(int X, int Y);
@@ -1,57 +1,21 @@
using Windows.Win32;
using System.Drawing;
using Windows.Win32;
using Windows.Win32.UI.WindowsAndMessaging;
using Windows.Win32.Foundation;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using Toolkit.Foundation;
namespace Toolkit.Windows;
public record PointerPressed(PointerLocation Location, PointerButton Button = PointerButton.Left);
public record PointerDragReleased(PointerLocation Location, PointerButton Button = PointerButton.Left);
public record PointerReleased(PointerLocation Location, PointerButton Button = PointerButton.Left);
public record PointerLocation(int X, int Y);
public record PointerMoved(PointerLocation Location);
internal enum WndProcMessages
public class PointerMonitor(IPublisher publisher) :
IPointerMonitor
{
WM_LBUTTONUP = 0x0202,
WM_MBUTTONUP = 0x0208,
WM_RBUTTONUP = 0x0205,
WM_MOUSEMOVE = 0x0200,
WM_SETTINGCHANGE = 0x001A,
WM_MBUTTONDOWN = 0x0207,
WM_LBUTTONDOWN = 0x0201,
WM_RBUTTONDOWN = 0x0204
}
public enum PointerButton
{
Left,
Middle,
Right
}
public record PointerDrag(PointerLocation Location);
public class PointerMonitor : IPointerMonitor
{
private readonly IMessenger messenger;
private bool isDisposed;
private bool isPointerDrag;
private bool isPointerPressed;
private HOOKPROC? mouseEventDelegate;
private UnhookWindowsHookExSafeHandle? mouseHandle;
private bool isPointerDrag;
public PointerMonitor(IMessenger messenger)
{
this.messenger = messenger;
}
~PointerMonitor()
{
Dispose(false);
@@ -63,11 +27,8 @@ public class PointerMonitor : IPointerMonitor
GC.SuppressFinalize(this);
}
public unsafe Task Initialize()
{
public unsafe void Initialize() =>
InitializeHook();
return Task.CompletedTask;
}
protected virtual void Dispose(bool disposing)
{
@@ -85,27 +46,6 @@ public class PointerMonitor : IPointerMonitor
PInvoke.GetModuleHandle("user32.dll"), 0);
}
private unsafe bool TryGetPointer(out Point point)
{
fixed (Point* lpPointLocal = &point)
{
return PInvoke.GetPhysicalCursorPos(lpPointLocal);
}
}
private bool TryGetPointerLocation([MaybeNullWhen(false)] out PointerLocation location)
{
if (TryGetPointer(out Point point))
{
location = new PointerLocation(point.X, point.Y);
return true;
}
location = null;
return false;
}
private LRESULT MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
@@ -160,16 +100,16 @@ public class PointerMonitor : IPointerMonitor
isPointerDrag = true;
}
messenger.Send(new PointerDrag(location));
publisher.Publish(new PointerDragEventArgs(location));
}
messenger.Send(new PointerMoved(location));
publisher.Publish(new PointerMovedEventArgs(location));
}
private void SendPointerPressed(PointerLocation location, PointerButton button)
{
isPointerPressed = true;
messenger.Send(new PointerPressed(location, button));
publisher.Publish(new PointerPressedEventArgs(location, button));
}
private void SendPointerReleased(PointerLocation location, PointerButton button)
@@ -179,11 +119,32 @@ public class PointerMonitor : IPointerMonitor
if (isPointerDrag)
{
isPointerDrag = false;
messenger.Send(new PointerDragReleased(location, button));
publisher.Publish(new PointerDragReleasedEventArgs(location, button));
}
isPointerPressed = false;
messenger.Send(new PointerReleased(location, button));
publisher.Publish(new PointerReleasedEventArgs(location, button));
}
}
private unsafe bool TryGetPointer(out Point point)
{
fixed (Point* lpPointLocal = &point)
{
return PInvoke.GetPhysicalCursorPos(lpPointLocal);
}
}
private bool TryGetPointerLocation([MaybeNullWhen(false)] out PointerLocation location)
{
if (TryGetPointer(out Point point))
{
location = new PointerLocation(point.X, point.Y);
return true;
}
location = null;
return false;
}
}
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Windows;
public record PointerMovedEventArgs(PointerLocation Location);
@@ -0,0 +1,3 @@
namespace Toolkit.Windows;
public record PointerPressedEventArgs(PointerLocation Location, PointerButton Button = PointerButton.Left);
@@ -0,0 +1,3 @@
namespace Toolkit.Windows;
public record PointerReleasedEventArgs(PointerLocation Location, PointerButton Button = PointerButton.Left);
+1 -1
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
+13
View File
@@ -0,0 +1,13 @@
namespace Toolkit.Windows;
internal enum WndProcMessages
{
WM_LBUTTONUP = 0x0202,
WM_MBUTTONUP = 0x0208,
WM_RBUTTONUP = 0x0205,
WM_MOUSEMOVE = 0x0200,
WM_SETTINGCHANGE = 0x001A,
WM_MBUTTONDOWN = 0x0207,
WM_LBUTTONDOWN = 0x0201,
WM_RBUTTONDOWN = 0x0204
}
+51 -1
View File
@@ -9,30 +9,80 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toolkit.UI.Avalonia", "Tool
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toolkit.UI.Controls.Avalonia", "Toolkit.UI.Controls.Avalonia\Toolkit.UI.Controls.Avalonia.csproj", "{8841990D-A246-495D-9A40-C39BA4347505}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Toolkit.Avalonia", "Toolkit.Avalonia\Toolkit.Avalonia.csproj", "{9585A317-4405-4E39-BDBE-23EF822FBF34}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toolkit.Avalonia", "Toolkit.Avalonia\Toolkit.Avalonia.csproj", "{9585A317-4405-4E39-BDBE-23EF822FBF34}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toolkit.Windows", "Toolkit.Windows\Toolkit.Windows.csproj", "{08F06CCE-86F9-4885-84F0-B23B2E5A0813}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{66968F8D-689E-49D8-9370-DFF099C56202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66968F8D-689E-49D8-9370-DFF099C56202}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66968F8D-689E-49D8-9370-DFF099C56202}.Debug|x64.ActiveCfg = Debug|x64
{66968F8D-689E-49D8-9370-DFF099C56202}.Debug|x64.Build.0 = Debug|x64
{66968F8D-689E-49D8-9370-DFF099C56202}.Debug|x86.ActiveCfg = Debug|x86
{66968F8D-689E-49D8-9370-DFF099C56202}.Debug|x86.Build.0 = Debug|x86
{66968F8D-689E-49D8-9370-DFF099C56202}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66968F8D-689E-49D8-9370-DFF099C56202}.Release|Any CPU.Build.0 = Release|Any CPU
{66968F8D-689E-49D8-9370-DFF099C56202}.Release|x64.ActiveCfg = Release|x64
{66968F8D-689E-49D8-9370-DFF099C56202}.Release|x64.Build.0 = Release|x64
{66968F8D-689E-49D8-9370-DFF099C56202}.Release|x86.ActiveCfg = Release|x86
{66968F8D-689E-49D8-9370-DFF099C56202}.Release|x86.Build.0 = Release|x86
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Debug|x64.ActiveCfg = Debug|x64
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Debug|x64.Build.0 = Debug|x64
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Debug|x86.ActiveCfg = Debug|x86
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Debug|x86.Build.0 = Debug|x86
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Release|Any CPU.Build.0 = Release|Any CPU
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Release|x64.ActiveCfg = Release|x64
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Release|x64.Build.0 = Release|x64
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Release|x86.ActiveCfg = Release|x86
{E091FA94-2F15-403A-98D1-4557C2FF9A02}.Release|x86.Build.0 = Release|x86
{8841990D-A246-495D-9A40-C39BA4347505}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8841990D-A246-495D-9A40-C39BA4347505}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8841990D-A246-495D-9A40-C39BA4347505}.Debug|x64.ActiveCfg = Debug|x64
{8841990D-A246-495D-9A40-C39BA4347505}.Debug|x64.Build.0 = Debug|x64
{8841990D-A246-495D-9A40-C39BA4347505}.Debug|x86.ActiveCfg = Debug|x86
{8841990D-A246-495D-9A40-C39BA4347505}.Debug|x86.Build.0 = Debug|x86
{8841990D-A246-495D-9A40-C39BA4347505}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8841990D-A246-495D-9A40-C39BA4347505}.Release|Any CPU.Build.0 = Release|Any CPU
{8841990D-A246-495D-9A40-C39BA4347505}.Release|x64.ActiveCfg = Release|x64
{8841990D-A246-495D-9A40-C39BA4347505}.Release|x64.Build.0 = Release|x64
{8841990D-A246-495D-9A40-C39BA4347505}.Release|x86.ActiveCfg = Release|x86
{8841990D-A246-495D-9A40-C39BA4347505}.Release|x86.Build.0 = Release|x86
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Debug|x64.ActiveCfg = Debug|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Debug|x64.Build.0 = Debug|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Debug|x86.ActiveCfg = Debug|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Debug|x86.Build.0 = Debug|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Release|Any CPU.Build.0 = Release|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Release|x64.ActiveCfg = Release|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Release|x64.Build.0 = Release|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Release|x86.ActiveCfg = Release|Any CPU
{9585A317-4405-4E39-BDBE-23EF822FBF34}.Release|x86.Build.0 = Release|Any CPU
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Debug|Any CPU.ActiveCfg = Debug|x64
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Debug|Any CPU.Build.0 = Debug|x64
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Debug|x64.ActiveCfg = Debug|x64
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Debug|x64.Build.0 = Debug|x64
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Debug|x86.ActiveCfg = Debug|x86
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Debug|x86.Build.0 = Debug|x86
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Release|Any CPU.ActiveCfg = Release|x64
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Release|Any CPU.Build.0 = Release|x64
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Release|x64.ActiveCfg = Release|x64
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Release|x64.Build.0 = Release|x64
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Release|x86.ActiveCfg = Release|x86
{08F06CCE-86F9-4885-84F0-B23B2E5A0813}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE