Merge pull request #22 from HandyOrg/master

fix
This commit is contained in:
眾尋 authored and GitHub committed 2019-05-23 08:41:04 +08:00
commit d112c1b954
9 files changed
+100 -15

No files matched your search

@@ -170,6 +170,8 @@ namespace HandyControl.Controls
CommandBindings.Add(new CommandBinding(ControlCommands.Enlarge, ButtonEnlarge_OnClick));
CommandBindings.Add(new CommandBinding(ControlCommands.RotateLeft, ButtonRotateLeft_OnClick));
CommandBindings.Add(new CommandBinding(ControlCommands.RotateRight, ButtonRotateRight_OnClick));
Loaded += (s, e) => Init();
}
/// <summary>
@@ -210,7 +212,13 @@ namespace HandyControl.Controls
"ShowImgMap", typeof(bool), typeof(ImageViewer), new PropertyMetadata(ValueBoxes.FalseBox));
public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
"ImageSource", typeof(BitmapFrame), typeof(ImageViewer), new PropertyMetadata(default(BitmapFrame)));
"ImageSource", typeof(BitmapFrame), typeof(ImageViewer), new PropertyMetadata(default(BitmapFrame), OnImageSourceChanged));
private static void OnImageSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = (ImageViewer) d;
ctl.Init();
}
public static readonly DependencyProperty IsFullScreenProperty = DependencyProperty.Register(
"IsFullScreen", typeof(bool), typeof(ImageViewer), new PropertyMetadata(ValueBoxes.FalseBox));
@@ -416,7 +424,7 @@ namespace HandyControl.Controls
_canvasSmallImg.MouseLeave += CanvasSmallImg_OnMouseLeave;
}
Init();
_borderSmallIsLoaded = false;
}
private static void OnImageScaleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
@@ -434,7 +442,7 @@ namespace HandyControl.Controls
/// </summary>
private void Init()
{
if (ImageSource == null) return;
if (ImageSource == null || !IsLoaded) return;
double width;
double height;
@@ -464,23 +472,22 @@ namespace HandyControl.Controls
}
_imgWidHeiScale = width / height;
Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
var scaleWindow = DesiredSize.Width / DesiredSize.Height;
var scaleWindow = ActualWidth / ActualHeight;
if (_imgWidHeiScale > scaleWindow)
{
if (width > DesiredSize.Width)
ImageScale = DesiredSize.Width / width;
if (width > ActualWidth)
ImageScale = ActualWidth / width;
}
else if (height > DesiredSize.Height)
else if (height > ActualHeight)
{
ImageScale = DesiredSize.Height / height;
ImageScale = ActualHeight / height;
}
else
{
ImageScale = 1;
}
ImageMargin = new Thickness((DesiredSize.Width - ImageWidth) / 2, (DesiredSize.Height - ImageHeight) / 2, 0, 0);
ImageMargin = new Thickness((ActualWidth - ImageWidth) / 2, (ActualHeight - ImageHeight) / 2, 0, 0);
_imgActualScale = ImageScale;
_imgActualMargin = ImageMargin;
@@ -643,6 +650,7 @@ namespace HandyControl.Controls
/// </summary>
private void InitBorderSmall()
{
if (_canvasSmallImg == null) return;
var scaleWindow = _canvasSmallImg.MaxWidth / _canvasSmallImg.MaxHeight;
if (_imgWidHeiScale > scaleWindow)
{
@@ -6,7 +6,6 @@ using System.Windows.Input;
using System.Windows.Media;
using HandyControl.Data;
using HandyControl.Interactivity;
using HandyControl.Tools;
namespace HandyControl.Controls
@@ -58,6 +58,7 @@ namespace HandyControl.Controls
{
_imageViewer.ImageSource = BitmapFrame.Create(uri);
_imageViewer.ImgPath = uri.AbsolutePath;
if (File.Exists(_imageViewer.ImgPath))
{
var info = new FileInfo(_imageViewer.ImgPath);
@@ -0,0 +1,15 @@
using System;
using System.Windows.Input;
namespace HandyControl.Data
{
internal class KeyboardHookEventArgs : EventArgs
{
public Key Key { get; }
public KeyboardHookEventArgs(int virtualKey)
{
Key = KeyInterop.KeyFromVirtualKey(virtualKey);
}
}
}
@@ -113,6 +113,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Window\Window.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Args\CancelRoutedEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Args\FunctionEventArgs!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Args\KeyboardHookEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Args\MouseHookEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\ColorRange.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\BadgeStatus.cs" />
@@ -246,6 +247,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\SingleOpenHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ValidateHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\VisualHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Hook\KeyboardHook.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Hook\MouseHook.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\BitmapHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\BITMAPINFO.cs" />
@@ -261,7 +263,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\UnsafeNativeMethods.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\WNDCLASS.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\WpfSafeHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\MouseDragElementBehaviorEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\MouseDragElementBehaviorEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularJudgment.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularPatterns.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\RadioGroupItemStyleSelector.cs" />
@@ -2,9 +2,9 @@
using System.Windows.Input;
using System.Windows.Media;
using HandyControl.Data;
using HandyControl.Interactivity;
using HandyControl.Tools;
namespace HandyControl.Tools
namespace HandyControl.Interactivity
{
/// <summary>
/// 鼠标拖动行为,该类是反编译微软的System.Windows.Interactivity程序集得到的,并对其做了些扩展
@@ -0,0 +1,57 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using HandyControl.Data;
using HandyControl.Tools.Interop;
namespace HandyControl.Tools
{
internal class KeyboardHook
{
public static event EventHandler<KeyboardHookEventArgs> KeyDown;
public static event EventHandler<KeyboardHookEventArgs> KeyUp;
private static IntPtr HookId = IntPtr.Zero;
private static readonly UnsafeNativeMethods.HookProc Proc = HookCallback;
public static void Start() => HookId = SetHook(Proc);
public static void Stop() => UnsafeNativeMethods.UnhookWindowsHookEx(HookId);
private static IntPtr SetHook(UnsafeNativeMethods.HookProc proc)
{
using (var curProcess = Process.GetCurrentProcess())
using (var curModule = curProcess.MainModule)
{
if (curModule != null)
{
return UnsafeNativeMethods.SetWindowsHookEx((int)UnsafeNativeMethods.HookType.WH_KEYBOARD_LL, proc,
UnsafeNativeMethods.GetModuleHandle(curModule.ModuleName), 0);
}
return IntPtr.Zero;
}
}
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0)
{
if (wParam == (IntPtr)NativeMethods.WM_KEYDOWN)
{
var virtualKey = Marshal.ReadInt32(lParam);
KeyDown?.Invoke(null, new KeyboardHookEventArgs(virtualKey));
}
else if (wParam == (IntPtr)NativeMethods.WM_KEYUP)
{
var virtualKey = Marshal.ReadInt32(lParam);
KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey));
}
}
return UnsafeNativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam);
}
}
}
@@ -31,6 +31,8 @@ namespace HandyControl.Tools.Interop
NIIF_INFO = 0x00000001,
NIIF_WARNING = 0x00000002,
NIIF_ERROR = 0x00000003,
WM_KEYDOWN = 0x0100,
WM_KEYUP = 0x0101,
WM_MOUSEMOVE = 0x0200,
WM_LBUTTONDOWN = 0x0201,
WM_LBUTTONUP = 0x0202,
@@ -186,7 +186,8 @@ namespace HandyControl.Tools.Interop
public enum HookType
{
WH_MOUSE_LL = 14,
WH_KEYBOARD_LL = 13,
WH_MOUSE_LL = 14
}
[StructLayout(LayoutKind.Sequential)]