diff --git a/src/modules/colorPicker/ColorPickerUI/App.xaml.cs b/src/modules/colorPicker/ColorPickerUI/App.xaml.cs index 775961da04..5b24467620 100644 --- a/src/modules/colorPicker/ColorPickerUI/App.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/App.xaml.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; using System.Threading; using System.Windows; using ColorPicker.Helpers; @@ -62,7 +66,9 @@ namespace ColorPickerUI protected override void OnExit(ExitEventArgs e) { if (_instanceMutex != null) + { _instanceMutex.ReleaseMutex(); + } CursorManager.RestoreOriginalCursors(); base.OnExit(e); diff --git a/src/modules/colorPicker/ColorPickerUI/Behaviors/AppearAnimationBehavior.cs b/src/modules/colorPicker/ColorPickerUI/Behaviors/AppearAnimationBehavior.cs index 937e762d73..6976e67163 100644 --- a/src/modules/colorPicker/ColorPickerUI/Behaviors/AppearAnimationBehavior.cs +++ b/src/modules/colorPicker/ColorPickerUI/Behaviors/AppearAnimationBehavior.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Interactivity; using System.Windows.Media.Animation; diff --git a/src/modules/colorPicker/ColorPickerUI/Behaviors/ChangeWindowPositionBehavior.cs b/src/modules/colorPicker/ColorPickerUI/Behaviors/ChangeWindowPositionBehavior.cs index 9cbb333f13..27cd29a344 100644 --- a/src/modules/colorPicker/ColorPickerUI/Behaviors/ChangeWindowPositionBehavior.cs +++ b/src/modules/colorPicker/ColorPickerUI/Behaviors/ChangeWindowPositionBehavior.cs @@ -1,4 +1,8 @@ -using System.Windows; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Windows; using System.Windows.Interactivity; using ColorPicker.Helpers; using ColorPicker.Mouse; @@ -59,9 +63,9 @@ namespace ColorPicker.Behaviors windowLeft -= MonitorRightSideDeadZone - ((int)monitorBounds.Right - windowLeft); } - if ((windowTop + MonitorBottomSideDeadZone / dpi.DpiScaleX) > monitorBounds.Bottom / dpi.DpiScaleX) + if ((windowTop + (MonitorBottomSideDeadZone / dpi.DpiScaleX)) > monitorBounds.Bottom / dpi.DpiScaleX) { - windowTop -= MonitorBottomSideDeadZone / dpi.DpiScaleX - (((int)monitorBounds.Bottom / dpi.DpiScaleX - windowTop)); + windowTop -= (MonitorBottomSideDeadZone / dpi.DpiScaleX) - (((int)monitorBounds.Bottom / dpi.DpiScaleX) - windowTop); } AssociatedObject.Left = windowLeft; diff --git a/src/modules/colorPicker/ColorPickerUI/Behaviors/CloseZoomWindowBehavior.cs b/src/modules/colorPicker/ColorPickerUI/Behaviors/CloseZoomWindowBehavior.cs index a8cce491bc..1f50c33057 100644 --- a/src/modules/colorPicker/ColorPickerUI/Behaviors/CloseZoomWindowBehavior.cs +++ b/src/modules/colorPicker/ColorPickerUI/Behaviors/CloseZoomWindowBehavior.cs @@ -1,6 +1,10 @@ -using ColorPicker.Helpers; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.Windows; using System.Windows.Interactivity; +using ColorPicker.Helpers; namespace ColorPicker.Behaviors { diff --git a/src/modules/colorPicker/ColorPickerUI/Behaviors/MoveWindowBehavior.cs b/src/modules/colorPicker/ColorPickerUI/Behaviors/MoveWindowBehavior.cs index c6a6934195..2bde8042a5 100644 --- a/src/modules/colorPicker/ColorPickerUI/Behaviors/MoveWindowBehavior.cs +++ b/src/modules/colorPicker/ColorPickerUI/Behaviors/MoveWindowBehavior.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Interactivity; using System.Windows.Media.Animation; @@ -7,10 +11,10 @@ namespace ColorPicker.Behaviors { public class MoveWindowBehavior : Behavior { + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-security#:~:text=Dependency%20properties%20should%20generally%20be%20considered%20to%20be,make%20security%20guarantees%20about%20a%20dependency%20property%20value.")] public static DependencyProperty LeftProperty = DependencyProperty.Register("Left", typeof(double), typeof(MoveWindowBehavior), new PropertyMetadata(new PropertyChangedCallback(LeftPropertyChanged))); - private static void LeftPropertyChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) + private static void LeftPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var sender = ((MoveWindowBehavior)d).AssociatedObject; var move = new DoubleAnimation(sender.Left, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop); @@ -18,10 +22,10 @@ namespace ColorPicker.Behaviors sender.BeginAnimation(Window.LeftProperty, move, HandoffBehavior.SnapshotAndReplace); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-security#:~:text=Dependency%20properties%20should%20generally%20be%20considered%20to%20be,make%20security%20guarantees%20about%20a%20dependency%20property%20value.")] public static DependencyProperty TopProperty = DependencyProperty.Register("Top", typeof(double), typeof(MoveWindowBehavior), new PropertyMetadata(new PropertyChangedCallback(TopPropertyChanged))); - private static void TopPropertyChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) + private static void TopPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var sender = ((MoveWindowBehavior)d).AssociatedObject; var move = new DoubleAnimation(sender.Top, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop); @@ -35,6 +39,7 @@ namespace ColorPicker.Behaviors { return (double)GetValue(LeftProperty); } + set { SetValue(LeftProperty, value); @@ -47,6 +52,7 @@ namespace ColorPicker.Behaviors { return (double)GetValue(TopProperty); } + set { SetValue(TopProperty, value); diff --git a/src/modules/colorPicker/ColorPickerUI/Behaviors/ResizeBehavior.cs b/src/modules/colorPicker/ColorPickerUI/Behaviors/ResizeBehavior.cs index e1818e7b9a..bfa89e22dd 100644 --- a/src/modules/colorPicker/ColorPickerUI/Behaviors/ResizeBehavior.cs +++ b/src/modules/colorPicker/ColorPickerUI/Behaviors/ResizeBehavior.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Interactivity; using System.Windows.Media.Animation; @@ -7,29 +11,36 @@ namespace ColorPicker.Behaviors { public class ResizeBehavior : Behavior { + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-security#:~:text=Dependency%20properties%20should%20generally%20be%20considered%20to%20be,make%20security%20guarantees%20about%20a%20dependency%20property%20value.")] public static DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(ResizeBehavior), new PropertyMetadata(new PropertyChangedCallback(WidthPropertyChanged))); - private static void WidthPropertyChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) + private static void WidthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var sender = ((ResizeBehavior)d).AssociatedObject; var move = new DoubleAnimation(sender.Width, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop); move.Completed += (s, e1) => { - sender.BeginAnimation(FrameworkElement.WidthProperty, null); sender.Width = (double)e.NewValue; + sender.BeginAnimation(FrameworkElement.WidthProperty, null); + sender.Width = (double)e.NewValue; }; + move.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseOut }; sender.BeginAnimation(FrameworkElement.WidthProperty, move, HandoffBehavior.SnapshotAndReplace); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-security#:~:text=Dependency%20properties%20should%20generally%20be%20considered%20to%20be,make%20security%20guarantees%20about%20a%20dependency%20property%20value.")] public static DependencyProperty HeightProperty = DependencyProperty.Register("Height", typeof(double), typeof(ResizeBehavior), new PropertyMetadata(new PropertyChangedCallback(HeightPropertyChanged))); - private static void HeightPropertyChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) + private static void HeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var sender = ((ResizeBehavior)d).AssociatedObject; var move = new DoubleAnimation(sender.Height, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop); - move.Completed += (s, e1) => { sender.BeginAnimation(FrameworkElement.HeightProperty, null); sender.Height = (double)e.NewValue; }; + move.Completed += (s, e1) => + { + sender.BeginAnimation(FrameworkElement.HeightProperty, null); + sender.Height = (double)e.NewValue; + }; + move.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseOut }; sender.BeginAnimation(FrameworkElement.HeightProperty, move, HandoffBehavior.SnapshotAndReplace); } @@ -40,6 +51,7 @@ namespace ColorPicker.Behaviors { return (double)GetValue(WidthProperty); } + set { SetValue(WidthProperty, value); @@ -52,6 +64,7 @@ namespace ColorPicker.Behaviors { return (double)GetValue(HeightProperty); } + set { SetValue(HeightProperty, value); diff --git a/src/modules/colorPicker/ColorPickerUI/Bootstrapper.cs b/src/modules/colorPicker/ColorPickerUI/Bootstrapper.cs index ad031061d9..ebd546f79f 100644 --- a/src/modules/colorPicker/ColorPickerUI/Bootstrapper.cs +++ b/src/modules/colorPicker/ColorPickerUI/Bootstrapper.cs @@ -1,4 +1,8 @@ -using System.ComponentModel.Composition; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; namespace ColorPicker diff --git a/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj b/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj index 4527a724be..8694070c11 100644 --- a/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj +++ b/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj @@ -230,5 +230,20 @@ Microsoft.PowerToys.Settings.UI.Lib + + + GlobalSuppressions.cs + + + StyleCop.json + + + + + 1.1.118 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + \ No newline at end of file diff --git a/src/modules/colorPicker/ColorPickerUI/Common/RelayCommand.cs b/src/modules/colorPicker/ColorPickerUI/Common/RelayCommand.cs index 2d001441ac..31cb593db0 100644 --- a/src/modules/colorPicker/ColorPickerUI/Common/RelayCommand.cs +++ b/src/modules/colorPicker/ColorPickerUI/Common/RelayCommand.cs @@ -1,5 +1,10 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Input; + namespace ColorPicker.Common { public class RelayCommand : ICommand @@ -13,7 +18,8 @@ namespace ColorPicker.Common _execute = x => { execute.Invoke(); }; } - public RelayCommand(Action execute) : this(x => true, execute) + public RelayCommand(Action execute) + : this(x => true, execute) { } diff --git a/src/modules/colorPicker/ColorPickerUI/Common/ViewModelBase.cs b/src/modules/colorPicker/ColorPickerUI/Common/ViewModelBase.cs index 227100c684..f531b2b271 100644 --- a/src/modules/colorPicker/ColorPickerUI/Common/ViewModelBase.cs +++ b/src/modules/colorPicker/ColorPickerUI/Common/ViewModelBase.cs @@ -1,4 +1,8 @@ -using System.ComponentModel; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; using System.Runtime.CompilerServices; namespace ColorPicker.Common diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs index aa17818022..26b4ed68f3 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Composition; using System.Windows; diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/Logger.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/Logger.cs index 5d665a83a2..17d7764e8e 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/Logger.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/Logger.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; using System.Diagnostics; using System.Globalization; using System.IO; @@ -7,7 +11,7 @@ namespace ColorPicker.Helpers { public static class Logger { - private static string ApplicationLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ColorPicker"); + private static readonly string ApplicationLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ColorPicker"); static Logger() { @@ -30,7 +34,8 @@ namespace ColorPicker.Helpers public static void LogError(string message, Exception ex) { - Log(message + Environment.NewLine + + Log( + message + Environment.NewLine + ex?.Message + Environment.NewLine + "Inner exception: " + Environment.NewLine + ex?.InnerException?.Message + Environment.NewLine + diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/MonitorResolutionHelper.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/MonitorResolutionHelper.cs index ce3e027a1b..d7134585f6 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/MonitorResolutionHelper.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/MonitorResolutionHelper.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; using System.Collections; using System.Collections.Generic; using System.Linq; diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/ZoomWindowHelper.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/ZoomWindowHelper.cs index e8f93280ee..d0c9de2b42 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/ZoomWindowHelper.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/ZoomWindowHelper.cs @@ -1,6 +1,7 @@ -using ColorPicker.Telemetry; -using ColorPicker.ViewModelContracts; -using Microsoft.PowerToys.Telemetry; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Composition; using System.Drawing; @@ -8,6 +9,9 @@ using System.Drawing.Imaging; using System.IO; using System.Windows; using System.Windows.Media.Imaging; +using ColorPicker.Telemetry; +using ColorPicker.ViewModelContracts; +using Microsoft.PowerToys.Telemetry; namespace ColorPicker.Helpers { @@ -19,11 +23,12 @@ namespace ColorPicker.Helpers private const int MaxZoomLevel = 3; private const int MinZoomLevel = 0; + private readonly IZoomViewModel _zoomViewModel; + private readonly AppStateHandler _appStateHandler; + private int _currentZoomLevel = 0; private int _previousZoomLevel = 0; - private readonly IZoomViewModel _zoomViewModel; - private readonly AppStateHandler _appStateHandler; private ZoomWindow _zoomWindow; private double _lastLeft; @@ -79,8 +84,8 @@ namespace ColorPicker.Helpers // we just started zooming, copy screen area if (_previousZoomLevel == 0) { - var x = (int)point.X - BaseZoomImageSize / 2; - var y = (int)point.Y - BaseZoomImageSize / 2; + var x = (int)point.X - (BaseZoomImageSize / 2); + var y = (int)point.Y - (BaseZoomImageSize / 2); var rect = new Rectangle(x, y, BaseZoomImageSize, BaseZoomImageSize); var bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb); var g = Graphics.FromImage(bmp); @@ -143,8 +148,8 @@ namespace ColorPicker.Helpers _previousScaledY = y / dpi.DpiScaleY; } - _lastLeft = Math.Floor(_previousScaledX - ((BaseZoomImageSize * Math.Pow(ZoomFactor, _currentZoomLevel - 1)) / 2)); - _lastTop = Math.Floor(_previousScaledY - ((BaseZoomImageSize * Math.Pow(ZoomFactor, _currentZoomLevel - 1)) / 2)); + _lastLeft = Math.Floor(_previousScaledX - (BaseZoomImageSize * Math.Pow(ZoomFactor, _currentZoomLevel - 1) / 2)); + _lastTop = Math.Floor(_previousScaledY - (BaseZoomImageSize * Math.Pow(ZoomFactor, _currentZoomLevel - 1) / 2)); var justShown = false; if (!_zoomWindow.IsVisible) @@ -155,11 +160,12 @@ namespace ColorPicker.Helpers _zoomViewModel.Width = BaseZoomImageSize; _zoomWindow.Show(); justShown = true; + // make sure color picker window is on top of just opened zoom window AppStateHandler.SetTopMost(); } - // dirty hack - sometimes when we just show a window on a second monitor with different DPI, + // dirty hack - sometimes when we just show a window on a second monitor with different DPI, // window position is not set correctly on a first time, we need to "ping" it again to make it appear on the proper location if (justShown) { diff --git a/src/modules/colorPicker/ColorPickerUI/Keyboard/GlobalKeyboardHook.cs b/src/modules/colorPicker/ColorPickerUI/Keyboard/GlobalKeyboardHook.cs index 495616d18c..52615f7345 100644 --- a/src/modules/colorPicker/ColorPickerUI/Keyboard/GlobalKeyboardHook.cs +++ b/src/modules/colorPicker/ColorPickerUI/Keyboard/GlobalKeyboardHook.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Diagnostics; using System.Runtime.InteropServices; @@ -47,6 +51,7 @@ namespace ColorPicker.Keyboard int errorCode = Marshal.GetLastWin32Error(); throw new Win32Exception(errorCode, $"Failed to remove keyboard hooks for '{Process.GetCurrentProcess().ProcessName}'. Error {errorCode}: {new Win32Exception(Marshal.GetLastWin32Error()).Message}."); } + _windowsHookHandle = IntPtr.Zero; // ReSharper disable once DelegateSubtraction @@ -56,11 +61,13 @@ namespace ColorPicker.Keyboard if (_user32LibraryHandle != IntPtr.Zero) { - if (!FreeLibrary(_user32LibraryHandle)) // reduces reference to library by 1. + // reduces reference to library by 1. + if (!FreeLibrary(_user32LibraryHandle)) { int errorCode = Marshal.GetLastWin32Error(); throw new Win32Exception(errorCode, $"Failed to unload library 'User32.dll'. Error {errorCode}: {new Win32Exception(Marshal.GetLastWin32Error()).Message}."); } + _user32LibraryHandle = IntPtr.Zero; } } @@ -81,7 +88,7 @@ namespace ColorPicker.Keyboard KeyDown = 0x0100, KeyUp = 0x0101, SysKeyDown = 0x0104, - SysKeyUp = 0x0105 + SysKeyUp = 0x0105, } private IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam) diff --git a/src/modules/colorPicker/ColorPickerUI/Keyboard/GlobalKeyboardHookEventArgs.cs b/src/modules/colorPicker/ColorPickerUI/Keyboard/GlobalKeyboardHookEventArgs.cs index 30f5157b2f..f503556637 100644 --- a/src/modules/colorPicker/ColorPickerUI/Keyboard/GlobalKeyboardHookEventArgs.cs +++ b/src/modules/colorPicker/ColorPickerUI/Keyboard/GlobalKeyboardHookEventArgs.cs @@ -1,4 +1,8 @@ -using System.ComponentModel; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; using static ColorPicker.Win32Apis; namespace ColorPicker.Keyboard @@ -6,6 +10,7 @@ namespace ColorPicker.Keyboard internal class GlobalKeyboardHookEventArgs : HandledEventArgs { internal GlobalKeyboardHook.KeyboardState KeyboardState { get; private set; } + internal LowLevelKeyboardInputEvent KeyboardData { get; private set; } internal GlobalKeyboardHookEventArgs( diff --git a/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs b/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs index 89bc444f74..d03272cd6a 100644 --- a/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs +++ b/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.Windows.Input; @@ -59,8 +63,9 @@ namespace ColorPicker.Keyboard private void Hook_KeyboardPressed(object sender, GlobalKeyboardHookEventArgs e) { var virtualCode = e.KeyboardData.VirtualCode; + // ESC pressed - if(virtualCode == KeyInterop.VirtualKeyFromKey(Key.Escape)) + if (virtualCode == KeyInterop.VirtualKeyFromKey(Key.Escape)) { _currentlyPressedKeys.Clear(); _appStateHandler.HideColorPicker(); @@ -113,6 +118,7 @@ namespace ColorPicker.Keyboard return false; } } + return true; } } diff --git a/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml.cs b/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml.cs index d22993270c..fa76fcd67c 100644 --- a/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml.cs @@ -1,6 +1,10 @@ -using ColorPicker.ViewModelContracts; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.ComponentModel.Composition; using System.Windows; +using ColorPicker.ViewModelContracts; namespace ColorPicker { @@ -18,7 +22,6 @@ namespace ColorPicker Hide(); } - [Import] public IMainViewModel MainViewModel { get; set; } diff --git a/src/modules/colorPicker/ColorPickerUI/Mouse/CursorManager.cs b/src/modules/colorPicker/ColorPickerUI/Mouse/CursorManager.cs index a18c2643d5..8ff9a7a59f 100644 --- a/src/modules/colorPicker/ColorPickerUI/Mouse/CursorManager.cs +++ b/src/modules/colorPicker/ColorPickerUI/Mouse/CursorManager.cs @@ -1,7 +1,11 @@ -using ColorPicker.Helpers; -using Microsoft.Win32; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System; using System.IO; +using ColorPicker.Helpers; +using Microsoft.Win32; namespace ColorPicker.Mouse { @@ -19,6 +23,11 @@ namespace ColorPicker.Mouse private static string _originalCrosshairCursorPath; private static string _originalHandCursorPath; + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")] + private const int SPI_SETCURSORS = 0x0057; + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")] + private const int SPIF_SENDCHANGE = 0x02; + public static void SetColorPickerCursor() { BackupOriginalCursors(); @@ -60,21 +69,21 @@ namespace ColorPicker.Mouse { _originalArrowCursorPath = (string)Registry.GetValue(CursorsRegistryPath, ArrowRegistryName, string.Empty); } + if (string.IsNullOrEmpty(_originalIBeamCursorPath)) { _originalIBeamCursorPath = (string)Registry.GetValue(CursorsRegistryPath, IBeamRegistryName, string.Empty); } + if (string.IsNullOrEmpty(_originalCrosshairCursorPath)) { _originalCrosshairCursorPath = (string)Registry.GetValue(CursorsRegistryPath, CrosshairRegistryName, string.Empty); } + if (string.IsNullOrEmpty(_originalHandCursorPath)) { _originalHandCursorPath = (string)Registry.GetValue(CursorsRegistryPath, HandRegistryName, string.Empty); } } - - const int SPI_SETCURSORS = 0x0057; - const int SPIF_SENDCHANGE = 0x02; } } diff --git a/src/modules/colorPicker/ColorPickerUI/Mouse/IMouseInfoProvider.cs b/src/modules/colorPicker/ColorPickerUI/Mouse/IMouseInfoProvider.cs index 2e86d7cc69..317f88c5c6 100644 --- a/src/modules/colorPicker/ColorPickerUI/Mouse/IMouseInfoProvider.cs +++ b/src/modules/colorPicker/ColorPickerUI/Mouse/IMouseInfoProvider.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; using System.Drawing; namespace ColorPicker.Mouse diff --git a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseHook.cs b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseHook.cs index af560a8102..6eedadb4a7 100644 --- a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseHook.cs +++ b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseHook.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Diagnostics; using System.Runtime.InteropServices; @@ -11,15 +15,20 @@ namespace ColorPicker.Mouse internal class MouseHook { + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")] private const int WH_MOUSE_LL = 14; + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")] private const int WM_LBUTTONDOWN = 0x0201; + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")] private const int WM_MOUSEWHEEL = 0x020A; + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")] private const int WHEEL_DELTA = 120; private IntPtr _mouseHookHandle; private HookProc _mouseDelegate; private event MouseUpEventHandler MouseDown; + public event MouseUpEventHandler OnMouseDown { add @@ -27,6 +36,7 @@ namespace ColorPicker.Mouse Subscribe(); MouseDown += value; } + remove { MouseDown -= value; @@ -35,6 +45,7 @@ namespace ColorPicker.Mouse } private event MouseWheelEventHandler MouseWheel; + public event MouseWheelEventHandler OnMouseWheel { add @@ -42,6 +53,7 @@ namespace ColorPicker.Mouse Subscribe(); MouseWheel += value; } + remove { MouseWheel -= value; @@ -69,10 +81,12 @@ namespace ColorPicker.Mouse if (_mouseHookHandle == IntPtr.Zero) { _mouseDelegate = MouseHookProc; - _mouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, + _mouseHookHandle = SetWindowsHookEx( + WH_MOUSE_LL, _mouseDelegate, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0); + if (_mouseHookHandle == IntPtr.Zero) { int errorCode = Marshal.GetLastWin32Error(); @@ -92,8 +106,10 @@ namespace ColorPicker.Mouse { MouseDown.Invoke(null, new System.Drawing.Point(mouseHookStruct.pt.x, mouseHookStruct.pt.y)); } + return new IntPtr(-1); } + if (wParam.ToInt32() == WM_MOUSEWHEEL) { if (MouseWheel != null) @@ -103,6 +119,7 @@ namespace ColorPicker.Mouse } } } + return CallNextHookEx(_mouseHookHandle, nCode, wParam, lParam); } } diff --git a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs index cb29b62d23..a2ba4952ef 100644 --- a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs +++ b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Composition; using System.Drawing; using System.Drawing.Imaging; diff --git a/src/modules/colorPicker/ColorPickerUI/Settings/IUserSettings.cs b/src/modules/colorPicker/ColorPickerUI/Settings/IUserSettings.cs index 889d8039de..19d71d3312 100644 --- a/src/modules/colorPicker/ColorPickerUI/Settings/IUserSettings.cs +++ b/src/modules/colorPicker/ColorPickerUI/Settings/IUserSettings.cs @@ -1,4 +1,8 @@ -using Microsoft.PowerToys.Settings.UI.Lib; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.PowerToys.Settings.UI.Lib; namespace ColorPicker.Settings { diff --git a/src/modules/colorPicker/ColorPickerUI/Settings/SettingItem.cs b/src/modules/colorPicker/ColorPickerUI/Settings/SettingItem.cs index 564c16b990..6f75415bbb 100644 --- a/src/modules/colorPicker/ColorPickerUI/Settings/SettingItem.cs +++ b/src/modules/colorPicker/ColorPickerUI/Settings/SettingItem.cs @@ -1,8 +1,12 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.ComponentModel; namespace ColorPicker.Settings { + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "It does, it is a generic. False positive")] public sealed class SettingItem : INotifyPropertyChanged { private T _value; @@ -18,6 +22,7 @@ namespace ColorPicker.Settings { return _value; } + set { _value = value; diff --git a/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs b/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs index 13124522a4..7655eaef2f 100644 --- a/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs +++ b/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs @@ -1,11 +1,14 @@ -using System.IO; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Composition; +using System.IO; +using System.Threading; +using ColorPicker.Helpers; using Microsoft.PowerToys.Settings.UI.Lib; using Microsoft.PowerToys.Settings.UI.Lib.Utilities; -using ColorPicker.Helpers; -using System.Threading.Tasks; -using System.Threading; -using System; namespace ColorPicker.Settings { @@ -57,6 +60,7 @@ namespace ColorPicker.Settings var defaultColorPickerSettings = new ColorPickerSettings(); defaultColorPickerSettings.Save(); } + var settings = SettingsUtils.GetSettings(ColorPickerModuleName); if (settings != null) { @@ -73,6 +77,7 @@ namespace ColorPicker.Settings { retry = false; } + Logger.LogError("Failed to read changed settings", ex); Thread.Sleep(500); } @@ -81,7 +86,7 @@ namespace ColorPicker.Settings Logger.LogError("Failed to read changed settings", ex); } } - }; + } } } } diff --git a/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerCancelledEvent.cs b/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerCancelledEvent.cs index 39b902caac..00d6bdba22 100644 --- a/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerCancelledEvent.cs +++ b/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerCancelledEvent.cs @@ -1,6 +1,10 @@ -using Microsoft.PowerToys.Telemetry; -using Microsoft.PowerToys.Telemetry.Events; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.Diagnostics.Tracing; +using Microsoft.PowerToys.Telemetry; +using Microsoft.PowerToys.Telemetry.Events; namespace ColorPicker.Telemetry { diff --git a/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerShowEvent.cs b/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerShowEvent.cs index ec8cf8905a..099de5972d 100644 --- a/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerShowEvent.cs +++ b/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerShowEvent.cs @@ -1,6 +1,10 @@ -using Microsoft.PowerToys.Telemetry; -using Microsoft.PowerToys.Telemetry.Events; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.Diagnostics.Tracing; +using Microsoft.PowerToys.Telemetry; +using Microsoft.PowerToys.Telemetry.Events; namespace ColorPicker.Telemetry { diff --git a/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerZoomOpenedEvent.cs b/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerZoomOpenedEvent.cs index edd7e8d8ed..29477fbc17 100644 --- a/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerZoomOpenedEvent.cs +++ b/src/modules/colorPicker/ColorPickerUI/Telemetry/ColorPickerZoomOpenedEvent.cs @@ -1,6 +1,10 @@ -using Microsoft.PowerToys.Telemetry; -using Microsoft.PowerToys.Telemetry.Events; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.Diagnostics.Tracing; +using Microsoft.PowerToys.Telemetry; +using Microsoft.PowerToys.Telemetry.Events; namespace ColorPicker.Telemetry { diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IMainViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IMainViewModel.cs index 4274f687a6..c2f5c8d33e 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IMainViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IMainViewModel.cs @@ -1,4 +1,8 @@ -using System.Windows.Media; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Windows.Media; namespace ColorPicker.ViewModelContracts { diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IZoomViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IZoomViewModel.cs index 5ce79c906d..40fdbfe105 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IZoomViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModelContracts/IZoomViewModel.cs @@ -1,4 +1,8 @@ -using System.Windows.Media.Imaging; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Windows.Media.Imaging; namespace ColorPicker.ViewModelContracts { diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs index 1c8897992c..77abbde6f4 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation 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.Composition; using System.Globalization; using System.Runtime.InteropServices; @@ -9,8 +13,8 @@ using ColorPicker.Helpers; using ColorPicker.Keyboard; using ColorPicker.Mouse; using ColorPicker.Settings; -using ColorPicker.ViewModelContracts; using ColorPicker.Telemetry; +using ColorPicker.ViewModelContracts; using Microsoft.PowerToys.Settings.UI.Lib; using Microsoft.PowerToys.Telemetry; @@ -19,12 +23,12 @@ namespace ColorPicker.ViewModels [Export(typeof(IMainViewModel))] public class MainViewModel : ViewModelBase, IMainViewModel { - private string _hexColor; - private string _rgbColor; - private Brush _colorBrush; private readonly ZoomWindowHelper _zoomWindowHelper; private readonly AppStateHandler _appStateHandler; private readonly IUserSettings _userSettings; + private string _hexColor; + private string _rgbColor; + private Brush _colorBrush; [ImportingConstructor] public MainViewModel( @@ -51,6 +55,7 @@ namespace ColorPicker.ViewModels { return _hexColor; } + private set { _hexColor = value; @@ -64,6 +69,7 @@ namespace ColorPicker.ViewModels { return _rgbColor; } + private set { _rgbColor = value; @@ -77,6 +83,7 @@ namespace ColorPicker.ViewModels { return _colorBrush; } + private set { _colorBrush = value; @@ -133,6 +140,7 @@ namespace ColorPicker.ViewModels Logger.LogError("Failed to set text into clipboard", ex); } } + System.Threading.Thread.Sleep(10); } } diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModels/ZoomViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModels/ZoomViewModel.cs index 34981950b1..b9c41067e0 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModels/ZoomViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModels/ZoomViewModel.cs @@ -1,7 +1,11 @@ -using ColorPicker.Common; -using ColorPicker.ViewModelContracts; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.ComponentModel.Composition; using System.Windows.Media.Imaging; +using ColorPicker.Common; +using ColorPicker.ViewModelContracts; namespace ColorPicker.ViewModels { @@ -26,6 +30,7 @@ namespace ColorPicker.ViewModels { return _zoomArea; } + set { _zoomArea = value; @@ -39,6 +44,7 @@ namespace ColorPicker.ViewModels { return _zoomFactor; } + set { _zoomFactor = value; @@ -52,6 +58,7 @@ namespace ColorPicker.ViewModels { return _desiredWidth; } + set { _desiredWidth = value; @@ -65,6 +72,7 @@ namespace ColorPicker.ViewModels { return _desiredHeight; } + set { _desiredHeight = value; @@ -78,6 +86,7 @@ namespace ColorPicker.ViewModels { return _width; } + set { _width = value; @@ -91,6 +100,7 @@ namespace ColorPicker.ViewModels { return _height; } + set { _height = value; diff --git a/src/modules/colorPicker/ColorPickerUI/Views/MainView.xaml.cs b/src/modules/colorPicker/ColorPickerUI/Views/MainView.xaml.cs index 8b3fad5544..b72a198974 100644 --- a/src/modules/colorPicker/ColorPickerUI/Views/MainView.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/Views/MainView.xaml.cs @@ -1,17 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace ColorPicker.Views { diff --git a/src/modules/colorPicker/ColorPickerUI/Views/ZoomView.xaml.cs b/src/modules/colorPicker/ColorPickerUI/Views/ZoomView.xaml.cs index 16c55cef77..637ccd442d 100644 --- a/src/modules/colorPicker/ColorPickerUI/Views/ZoomView.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/Views/ZoomView.xaml.cs @@ -1,17 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace ColorPicker.Views { diff --git a/src/modules/colorPicker/ColorPickerUI/Win32Apis.cs b/src/modules/colorPicker/ColorPickerUI/Win32Apis.cs index e89edec8dd..243a362607 100644 --- a/src/modules/colorPicker/ColorPickerUI/Win32Apis.cs +++ b/src/modules/colorPicker/ColorPickerUI/Win32Apis.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -6,10 +10,11 @@ namespace ColorPicker { public static class Win32Apis { + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")] public const int WH_KEYBOARD_LL = 13; public const int VkSnapshot = 0x2c; public const int KfAltdown = 0x2000; - public const int LlkhfAltdown = (KfAltdown >> 8); + public const int LlkhfAltdown = KfAltdown >> 8; public const int MonitorinfofPrimary = 0x00000001; public delegate bool MonitorEnumProc( @@ -23,9 +28,7 @@ namespace ColorPicker [DllImport("kernel32.dll", CharSet = CharSet.Auto)] internal static extern bool FreeLibrary(IntPtr hModule); - - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, - CallingConvention = CallingConvention.StdCall)] + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] internal static extern IntPtr GetModuleHandle(string name); [DllImport("user32.dll", CharSet = CharSet.Auto)] @@ -41,21 +44,19 @@ namespace ColorPicker [DllImport("user32.dll")] internal static extern bool GetCursorPos(out PointInter lpPoint); - [DllImport("user32.dll", CharSet = CharSet.Auto, - CallingConvention = CallingConvention.StdCall, SetLastError = true)] + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)] internal static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId); - [DllImport("user32.dll", CharSet = CharSet.Auto, - CallingConvention = CallingConvention.StdCall, SetLastError = true)] + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)] internal static extern bool UnhookWindowsHookEx(IntPtr idHook); - [DllImport("user32.dll", CharSet = CharSet.Auto, - CallingConvention = CallingConvention.StdCall, SetLastError = true)] + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)] internal static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")] internal static extern bool SystemParametersInfo(int uiAction, int uiParam, IntPtr pvParam, int fWinIni); + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")] [StructLayout(LayoutKind.Sequential)] internal struct POINT { @@ -63,6 +64,7 @@ namespace ColorPicker public int y; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")] [StructLayout(LayoutKind.Sequential)] internal struct MSLLHOOKSTRUCT { @@ -78,10 +80,11 @@ namespace ColorPicker { public int X; public int Y; + public static explicit operator System.Windows.Point(PointInter point) => new System.Windows.Point(point.X, point.Y); } - + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")] [StructLayout(LayoutKind.Sequential)] internal struct Rect { @@ -91,15 +94,17 @@ namespace ColorPicker public int bottom; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "false positive, used in MonitorResolutionHelper")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)] internal class MonitorInfoEx { - internal int cbSize = Marshal.SizeOf(typeof(MonitorInfoEx)); - internal Rect rcMonitor = default; - internal Rect rcWork = default; - internal int dwFlags = 0; + public int cbSize = Marshal.SizeOf(typeof(MonitorInfoEx)); + public Rect rcMonitor = default; + public Rect rcWork = default; + public int dwFlags = 0; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] - internal char[] szDevice = new char[32]; + public char[] szDevice = new char[32]; } [StructLayout(LayoutKind.Sequential)] @@ -111,7 +116,7 @@ namespace ColorPicker public int VirtualCode; /// - /// A hardware scan code for the key. + /// A hardware scan code for the key. /// public int HardwareScanCode; @@ -126,10 +131,9 @@ namespace ColorPicker public int TimeStamp; /// - /// Additional information associated with the message. + /// Additional information associated with the message. /// public IntPtr AdditionalInformation; } - } } diff --git a/src/modules/colorPicker/ColorPickerUI/ZoomWindow.xaml.cs b/src/modules/colorPicker/ColorPickerUI/ZoomWindow.xaml.cs index 361ed7c452..2fac62c8b3 100644 --- a/src/modules/colorPicker/ColorPickerUI/ZoomWindow.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/ZoomWindow.xaml.cs @@ -1,4 +1,8 @@ -using System.ComponentModel; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; using System.Windows; namespace ColorPicker @@ -16,12 +20,14 @@ namespace ColorPicker InitializeComponent(); DataContext = this; } + public double DesiredLeft { get { return _left; } + set { _left = value; @@ -35,6 +41,7 @@ namespace ColorPicker { return _top; } + set { _top = value;