diff --git a/src/Greenshot.Base/Controls/GreenshotForm.cs b/src/Greenshot.Base/Controls/GreenshotForm.cs index 34327706f..85bc6bd4d 100644 --- a/src/Greenshot.Base/Controls/GreenshotForm.cs +++ b/src/Greenshot.Base/Controls/GreenshotForm.cs @@ -396,10 +396,10 @@ namespace Greenshot.Base.Controls protected void ApplyLanguage(Control applyTo) { - if (!(applyTo is IGreenshotLanguageBindable languageBindable)) + if (applyTo is not IGreenshotLanguageBindable languageBindable) { // check if it's a menu! - if (!(applyTo is ToolStrip toolStrip)) + if (applyTo is not ToolStrip toolStrip) { return; } @@ -416,20 +416,14 @@ namespace Greenshot.Base.Controls ApplyLanguage(applyTo, languageBindable.LanguageKey); // Repopulate the combox boxes - if (applyTo is IGreenshotConfigBindable configBindable && applyTo is GreenshotComboBox comboxBox) - { - if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName)) - { - IniSection section = IniConfig.GetIniSection(configBindable.SectionName); - if (section != null) - { - // Only update the language, so get the actual value and than repopulate - Enum currentValue = comboxBox.GetSelectedEnum(); - comboxBox.Populate(section.Values[configBindable.PropertyName].ValueType); - comboxBox.SetValue(currentValue); - } - } - } + if (applyTo is not (IGreenshotConfigBindable configBindable and GreenshotComboBox comboxBox)) return; + if (string.IsNullOrEmpty(configBindable.SectionName) || string.IsNullOrEmpty(configBindable.PropertyName)) return; + IniSection section = IniConfig.GetIniSection(configBindable.SectionName); + if (section == null) return; + // Only update the language, so get the actual value and than repopulate + Enum currentValue = comboxBox.GetSelectedEnum(); + comboxBox.Populate(section.Values[configBindable.PropertyName].ValueType); + comboxBox.SetValue(currentValue); } /// @@ -472,10 +466,9 @@ namespace Greenshot.Base.Controls continue; } - if (!(controlObject is Control applyToControl)) + if (controlObject is not Control applyToControl) { - ToolStripItem applyToItem = controlObject as ToolStripItem; - if (applyToItem == null) + if (controlObject is not ToolStripItem applyToItem) { LOG.DebugFormat("No Control or ToolStripItem: {0}", field.Name); continue; diff --git a/src/Greenshot.Base/Core/AbstractDestination.cs b/src/Greenshot.Base/Core/AbstractDestination.cs index e462ba171..c76574bab 100644 --- a/src/Greenshot.Base/Core/AbstractDestination.cs +++ b/src/Greenshot.Base/Core/AbstractDestination.cs @@ -44,7 +44,7 @@ namespace Greenshot.Base.Core public virtual int CompareTo(object obj) { - if (!(obj is IDestination other)) + if (obj is not IDestination other) { return 1; } diff --git a/src/Greenshot.Base/Core/ClipboardHelper.cs b/src/Greenshot.Base/Core/ClipboardHelper.cs index 4878b3d0d..7a30a1143 100644 --- a/src/Greenshot.Base/Core/ClipboardHelper.cs +++ b/src/Greenshot.Base/Core/ClipboardHelper.cs @@ -284,6 +284,9 @@ EndSelection:<<<<<<<4 { if (dataObject == null) return false; + IList formats = GetFormats(dataObject); + Log.DebugFormat("Found formats: {0}", string.Join(",", formats)); + if (dataObject.GetDataPresent(DataFormats.Bitmap) || dataObject.GetDataPresent(DataFormats.Dib) || dataObject.GetDataPresent(DataFormats.Tiff) diff --git a/src/Greenshot.Base/Core/EffectConverter.cs b/src/Greenshot.Base/Core/EffectConverter.cs index 40cb1f5ae..e5742b803 100644 --- a/src/Greenshot.Base/Core/EffectConverter.cs +++ b/src/Greenshot.Base/Core/EffectConverter.cs @@ -3,6 +3,8 @@ using System.ComponentModel; using System.Drawing; using System.Globalization; using System.Text; +using Dapplo.Windows.Common.Extensions; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Effects; namespace Greenshot.Base.Core @@ -136,16 +138,16 @@ namespace Greenshot.Base.Core break; case "ShadowOffset": - Point shadowOffset = new Point(); + NativePoint shadowOffset = new NativePoint(); string[] coordinates = pair[1].Split(','); if (int.TryParse(coordinates[0], out var shadowOffsetX)) { - shadowOffset.X = shadowOffsetX; + shadowOffset = shadowOffset.ChangeX(shadowOffsetX); } if (int.TryParse(coordinates[1], out var shadowOffsetY)) { - shadowOffset.Y = shadowOffsetY; + shadowOffset = shadowOffset.ChangeY(shadowOffsetY); } effect.ShadowOffset = shadowOffset; diff --git a/src/Greenshot.Base/Core/FastBitmap.cs b/src/Greenshot.Base/Core/FastBitmap.cs index 96aa36da6..c0309763f 100644 --- a/src/Greenshot.Base/Core/FastBitmap.cs +++ b/src/Greenshot.Base/Core/FastBitmap.cs @@ -384,7 +384,7 @@ namespace Greenshot.Base.Core protected FastBitmap(Bitmap bitmap, NativeRect area) { Bitmap = bitmap; - var bitmapArea = new NativeRect(Point.Empty, bitmap.Size); + var bitmapArea = new NativeRect(NativePoint.Empty, bitmap.Size); if (area != NativeRect.Empty) { area = area.Intersect(bitmapArea); diff --git a/src/Greenshot.Base/Core/ImageHelper.cs b/src/Greenshot.Base/Core/ImageHelper.cs index e817b79f0..f75cc9def 100644 --- a/src/Greenshot.Base/Core/ImageHelper.cs +++ b/src/Greenshot.Base/Core/ImageHelper.cs @@ -191,7 +191,7 @@ namespace Greenshot.Base.Core /// Private helper method for the FindAutoCropNativeRect /// /// IFastBitmap - /// Point + /// NativePoint /// int /// NativeRect with optional area to scan in /// NativeRect diff --git a/src/Greenshot.Base/Core/ImageIO.cs b/src/Greenshot.Base/Core/ImageIO.cs index ead509456..9d6bbf1cd 100644 --- a/src/Greenshot.Base/Core/ImageIO.cs +++ b/src/Greenshot.Base/Core/ImageIO.cs @@ -558,46 +558,6 @@ namespace Greenshot.Base.Core return fileImage; } - /// - /// Based on: https://www.codeproject.com/KB/cs/IconExtractor.aspx - /// And a hint from: https://www.codeproject.com/KB/cs/IconLib.aspx - /// - /// Stream with the icon information - /// Bitmap with the Vista Icon (256x256) - private static Bitmap ExtractVistaIcon(Stream iconStream) - { - const int sizeIconDir = 6; - const int sizeIconDirEntry = 16; - Bitmap bmpPngExtracted = null; - try - { - byte[] srcBuf = new byte[iconStream.Length]; - iconStream.Read(srcBuf, 0, (int)iconStream.Length); - int iCount = BitConverter.ToInt16(srcBuf, 4); - for (int iIndex = 0; iIndex < iCount; iIndex++) - { - int iWidth = srcBuf[sizeIconDir + sizeIconDirEntry * iIndex]; - int iHeight = srcBuf[sizeIconDir + sizeIconDirEntry * iIndex + 1]; - if (iWidth == 0 && iHeight == 0) - { - int iImageSize = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 8); - int iImageOffset = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 12); - using MemoryStream destStream = new MemoryStream(); - destStream.Write(srcBuf, iImageOffset, iImageSize); - destStream.Seek(0, SeekOrigin.Begin); - bmpPngExtracted = new Bitmap(destStream); // This is PNG! :) - break; - } - } - } - catch - { - return null; - } - - return bmpPngExtracted; - } - /// /// Create an image from a stream, if an extension is supplied more formats are supported. /// diff --git a/src/Greenshot.Base/Core/PluginUtils.cs b/src/Greenshot.Base/Core/PluginUtils.cs index 04cd7add8..d41e545a5 100644 --- a/src/Greenshot.Base/Core/PluginUtils.cs +++ b/src/Greenshot.Base/Core/PluginUtils.cs @@ -113,7 +113,7 @@ namespace Greenshot.Base.Core /// /// path to the exe or dll /// index of the icon - /// Bitmap with the icon or null if something happended + /// Bitmap with the icon or null if something happened public static Image GetCachedExeIcon(string path, int index) { string cacheKey = $"{path}:{index}"; @@ -148,7 +148,7 @@ namespace Greenshot.Base.Core /// /// path to the exe or dll /// index of the icon - /// Bitmap with the icon or null if something happended + /// Bitmap with the icon or null if something happened private static Bitmap GetExeIcon(string path, int index) { if (!File.Exists(path)) @@ -164,7 +164,6 @@ namespace Greenshot.Base.Core Log.DebugFormat("Loaded icon for {0}, with dimensions {1}x{2}", path, appIcon.Width, appIcon.Height); return appIcon; } - return appIcon; } catch (Exception exIcon) { diff --git a/src/Greenshot.Base/Core/WindowCapture.cs b/src/Greenshot.Base/Core/WindowCapture.cs index 0b4bf4e3f..01e1bce56 100644 --- a/src/Greenshot.Base/Core/WindowCapture.cs +++ b/src/Greenshot.Base/Core/WindowCapture.cs @@ -96,12 +96,12 @@ namespace Greenshot.Base.Core using SafeIconHandle safeIcon = NativeIconMethods.CopyIcon(cursorInfo.CursorHandle); if (!NativeIconMethods.GetIconInfo(safeIcon, out var iconInfo)) return capture; - Point cursorLocation = User32Api.GetCursorLocation(); + NativePoint cursorLocation = User32Api.GetCursorLocation(); // Align cursor location to Bitmap coordinates (instead of Screen coordinates) var x = cursorLocation.X - iconInfo.Hotspot.X - capture.ScreenBounds.X; var y = cursorLocation.Y - iconInfo.Hotspot.Y - capture.ScreenBounds.Y; // Set the location - capture.CursorLocation = new Point(x, y); + capture.CursorLocation = new NativePoint(x, y); using (Icon icon = Icon.FromHandle(safeIcon.DangerousGetHandle())) { diff --git a/src/Greenshot.Base/Core/WindowDetails.cs b/src/Greenshot.Base/Core/WindowDetails.cs index 4c0b38f4e..281dde6f4 100644 --- a/src/Greenshot.Base/Core/WindowDetails.cs +++ b/src/Greenshot.Base/Core/WindowDetails.cs @@ -1515,9 +1515,9 @@ namespace Greenshot.Base.Core /// /// Recursive "find children which" /// - /// point to check for - /// - public WindowDetails FindChildUnderPoint(Point point) + /// NativePoint to check for + /// WindowDetails + public WindowDetails FindChildUnderPoint(NativePoint point) { if (!Contains(point)) { diff --git a/src/Greenshot.Base/Effects/DropShadowEffect.cs b/src/Greenshot.Base/Effects/DropShadowEffect.cs index 8f69854bc..b597e4463 100644 --- a/src/Greenshot.Base/Effects/DropShadowEffect.cs +++ b/src/Greenshot.Base/Effects/DropShadowEffect.cs @@ -23,6 +23,7 @@ using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; namespace Greenshot.Base.Effects @@ -42,7 +43,7 @@ namespace Greenshot.Base.Effects public int ShadowSize { get; set; } - public Point ShadowOffset { get; set; } + public NativePoint ShadowOffset { get; set; } public virtual void Reset() { diff --git a/src/Greenshot.Editor/Controls/Pipette.cs b/src/Greenshot.Editor/Controls/Pipette.cs index 23a83c9b1..dc1ae1046 100644 --- a/src/Greenshot.Editor/Controls/Pipette.cs +++ b/src/Greenshot.Editor/Controls/Pipette.cs @@ -129,7 +129,7 @@ namespace Greenshot.Editor.Controls { //Release Capture should consume MouseUp when canceled with the escape key User32Api.ReleaseCapture(); - PipetteUsed?.Invoke(this, new PipetteUsedArgs(_movableShowColorForm.color)); + PipetteUsed?.Invoke(this, new PipetteUsedArgs(_movableShowColorForm.Color)); } base.OnMouseUp(e); diff --git a/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs b/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs index 296cc4ef8..aaad53355 100644 --- a/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs +++ b/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs @@ -55,23 +55,18 @@ namespace Greenshot.Editor.Drawing.Adorners isNotSwitched = !isNotSwitched; } - switch (Position) + return Position switch { - case Positions.TopLeft: - case Positions.BottomRight: - return isNotSwitched ? Cursors.SizeNWSE : Cursors.SizeNESW; - case Positions.TopRight: - case Positions.BottomLeft: - return isNotSwitched ? Cursors.SizeNESW : Cursors.SizeNWSE; - case Positions.MiddleLeft: - case Positions.MiddleRight: - return Cursors.SizeWE; - case Positions.TopCenter: - case Positions.BottomCenter: - return Cursors.SizeNS; - default: - return Cursors.SizeAll; - } + Positions.TopLeft => isNotSwitched ? Cursors.SizeNWSE : Cursors.SizeNESW, + Positions.BottomRight => isNotSwitched ? Cursors.SizeNWSE : Cursors.SizeNESW, + Positions.TopRight => isNotSwitched ? Cursors.SizeNESW : Cursors.SizeNWSE, + Positions.BottomLeft => isNotSwitched ? Cursors.SizeNESW : Cursors.SizeNWSE, + Positions.MiddleLeft => Cursors.SizeWE, + Positions.MiddleRight => Cursors.SizeWE, + Positions.TopCenter => Cursors.SizeNS, + Positions.BottomCenter => Cursors.SizeNS, + _ => Cursors.SizeAll + }; } } diff --git a/src/Greenshot.Editor/Drawing/ImageContainer.cs b/src/Greenshot.Editor/Drawing/ImageContainer.cs index b3317d7bc..21f8d2fa6 100644 --- a/src/Greenshot.Editor/Drawing/ImageContainer.cs +++ b/src/Greenshot.Editor/Drawing/ImageContainer.cs @@ -54,7 +54,7 @@ namespace Greenshot.Editor.Drawing /// This is the offset for the shadow version of the bitmap /// Do not serialize, as the offset is recreated /// - [NonSerialized] private Point _shadowOffset = new Point(-1, -1); + [NonSerialized] private NativePoint _shadowOffset = new NativePoint(-1, -1); public ImageContainer(ISurface parent, string filename) : this(parent) { diff --git a/src/Greenshot.Editor/Drawing/SpeechbubbleContainer.cs b/src/Greenshot.Editor/Drawing/SpeechbubbleContainer.cs index 795c7c768..22dd13379 100644 --- a/src/Greenshot.Editor/Drawing/SpeechbubbleContainer.cs +++ b/src/Greenshot.Editor/Drawing/SpeechbubbleContainer.cs @@ -42,7 +42,7 @@ namespace Greenshot.Editor.Drawing private NativePoint _initialGripperPoint; // Only used for serializing the TargetGripper location - private Point _storedTargetGripperLocation; + private NativePoint _storedTargetGripperLocation; /// /// Store the current location of the target gripper @@ -96,8 +96,8 @@ namespace Greenshot.Editor.Drawing { if (TargetAdorner == null) { - _initialGripperPoint = new Point(mouseX, mouseY); - InitTargetAdorner(new Point(mouseX, mouseY)); + _initialGripperPoint = new NativePoint(mouseX, mouseY); + InitTargetAdorner(_initialGripperPoint); } return base.HandleMouseDown(mouseX, mouseY); diff --git a/src/Greenshot.Editor/Drawing/Surface.cs b/src/Greenshot.Editor/Drawing/Surface.cs index 447c89a59..4b06a38ed 100644 --- a/src/Greenshot.Editor/Drawing/Surface.cs +++ b/src/Greenshot.Editor/Drawing/Surface.cs @@ -1012,7 +1012,7 @@ namespace Greenshot.Editor.Drawing public void Clear(Color newColor) { //create a blank bitmap the same size as original - Bitmap newBitmap = ImageHelper.CreateEmptyLike(Image, Color.Empty); + Bitmap newBitmap = ImageHelper.CreateEmptyLike(Image, newColor); if (newBitmap == null) return; // Make undoable MakeUndoable(new SurfaceBackgroundChangeMemento(this, null), false); @@ -2112,10 +2112,7 @@ namespace Greenshot.Editor.Drawing } // maybe the undo button has to be enabled - if (_movingElementChanged != null) - { - _movingElementChanged(this, new SurfaceElementEventArgs()); - } + _movingElementChanged?.Invoke(this, new SurfaceElementEventArgs()); } /// @@ -2150,10 +2147,7 @@ namespace Greenshot.Editor.Drawing DrawingMode = DrawingModes.None; // maybe the undo button has to be enabled - if (_movingElementChanged != null) - { - _movingElementChanged(this, new SurfaceElementEventArgs()); - } + _movingElementChanged?.Invoke(this, new SurfaceElementEventArgs()); } public void RemoveCropContainer() @@ -2195,7 +2189,7 @@ namespace Greenshot.Editor.Drawing // Make element(s) only move 10,10 if the surface is the same bool isSameSurface = (dcs.ParentID == _uniqueId); dcs.Parent = this; - var moveOffset = isSameSurface ? new Point(10, 10) : Point.Empty; + var moveOffset = isSameSurface ? new NativePoint(10, 10) : NativePoint.Empty; // Here a fix for bug #1475, first calculate the bounds of the complete IDrawableContainerList NativeRect drawableContainerListBounds = NativeRect.Empty; foreach (var element in dcs) @@ -2485,24 +2479,24 @@ namespace Greenshot.Editor.Drawing bool shiftModifier = (ModifierKeys & Keys.Shift) == Keys.Shift; int px = shiftModifier ? 10 : 1; - Point moveBy = Point.Empty; + NativePoint moveBy = NativePoint.Empty; switch (k) { case Keys.Left: case Keys.Left | Keys.Shift: - moveBy = new Point(-px, 0); + moveBy = new NativePoint(-px, 0); break; case Keys.Up: case Keys.Up | Keys.Shift: - moveBy = new Point(0, -px); + moveBy = new NativePoint(0, -px); break; case Keys.Right: case Keys.Right | Keys.Shift: - moveBy = new Point(px, 0); + moveBy = new NativePoint(px, 0); break; case Keys.Down: case Keys.Down | Keys.Shift: - moveBy = new Point(0, px); + moveBy = new NativePoint(0, px); break; case Keys.PageUp: PullElementsUp(); @@ -2580,7 +2574,7 @@ namespace Greenshot.Editor.Drawing return false; } - if (!Point.Empty.Equals(moveBy)) + if (moveBy != NativePoint.Empty) { selectedElements.MakeBoundsChangeUndoable(true); selectedElements.MoveBy(moveBy.X, moveBy.Y); diff --git a/src/Greenshot.Editor/Drawing/SvgContainer.cs b/src/Greenshot.Editor/Drawing/SvgContainer.cs index 45847825f..283f755e8 100644 --- a/src/Greenshot.Editor/Drawing/SvgContainer.cs +++ b/src/Greenshot.Editor/Drawing/SvgContainer.cs @@ -34,7 +34,7 @@ namespace Greenshot.Editor.Drawing [Serializable] public class SvgContainer : VectorGraphicsContainer { - private SvgDocument _svgDocument; + private readonly SvgDocument _svgDocument; public SvgContainer(SvgDocument svgDocument, ISurface parent) : base(parent) { diff --git a/src/Greenshot.Editor/Drawing/TextContainer.cs b/src/Greenshot.Editor/Drawing/TextContainer.cs index d69c1d321..a49fd4bee 100644 --- a/src/Greenshot.Editor/Drawing/TextContainer.cs +++ b/src/Greenshot.Editor/Drawing/TextContainer.cs @@ -291,7 +291,7 @@ namespace Greenshot.Editor.Drawing }; _textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged); - _textBox.LostFocus += textBox_LostFocus; + _textBox.LostFocus += TextBox_LostFocus; _textBox.KeyDown += textBox_KeyDown; } @@ -585,7 +585,7 @@ namespace Greenshot.Editor.Drawing } } - private void textBox_LostFocus(object sender, EventArgs e) + private void TextBox_LostFocus(object sender, EventArgs e) { // next change will be made undoable makeUndoable = true; diff --git a/src/Greenshot.Editor/Forms/DropShadowSettingsForm.cs b/src/Greenshot.Editor/Forms/DropShadowSettingsForm.cs index fcec47c95..c05852109 100644 --- a/src/Greenshot.Editor/Forms/DropShadowSettingsForm.cs +++ b/src/Greenshot.Editor/Forms/DropShadowSettingsForm.cs @@ -22,6 +22,7 @@ using System; using System.Drawing; using System.Windows.Forms; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Effects; namespace Greenshot.Editor.Forms @@ -51,7 +52,7 @@ namespace Greenshot.Editor.Forms private void ButtonOK_Click(object sender, EventArgs e) { _effect.Darkness = trackBar1.Value / (float) 40; - _effect.ShadowOffset = new Point((int) offsetX.Value, (int) offsetY.Value); + _effect.ShadowOffset = new NativePoint((int) offsetX.Value, (int) offsetY.Value); _effect.ShadowSize = (int) thickness.Value; DialogResult = DialogResult.OK; } diff --git a/src/Greenshot.Editor/Forms/MovableShowColorForm.cs b/src/Greenshot.Editor/Forms/MovableShowColorForm.cs index 9a54ce6b6..416ec6407 100644 --- a/src/Greenshot.Editor/Forms/MovableShowColorForm.cs +++ b/src/Greenshot.Editor/Forms/MovableShowColorForm.cs @@ -36,7 +36,7 @@ namespace Greenshot.Editor.Forms /// public partial class MovableShowColorForm : Form { - public Color color + public Color Color { get { return preview.BackColor; } } @@ -99,9 +99,9 @@ namespace Greenshot.Editor.Forms /// /// Get the color from the pixel on the screen at "x,y" /// - /// Point with the coordinates + /// NativePoint with the coordinates /// Color at the specified screenCoordinates - private static Color GetPixelColor(Point screenCoordinates) + private static Color GetPixelColor(NativePoint screenCoordinates) { using SafeWindowDcHandle safeWindowDcHandle = SafeWindowDcHandle.FromDesktop(); try diff --git a/src/Greenshot.Editor/Forms/TornEdgeSettingsForm.cs b/src/Greenshot.Editor/Forms/TornEdgeSettingsForm.cs index db29c227f..46638fc6e 100644 --- a/src/Greenshot.Editor/Forms/TornEdgeSettingsForm.cs +++ b/src/Greenshot.Editor/Forms/TornEdgeSettingsForm.cs @@ -20,8 +20,8 @@ */ using System; -using System.Drawing; using System.Windows.Forms; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Effects; namespace Greenshot.Editor.Forms @@ -56,7 +56,7 @@ namespace Greenshot.Editor.Forms private void ButtonOK_Click(object sender, EventArgs e) { _effect.Darkness = shadowDarkness.Value / (float) 40; - _effect.ShadowOffset = new Point((int) offsetX.Value, (int) offsetY.Value); + _effect.ShadowOffset = new NativePoint((int) offsetX.Value, (int) offsetY.Value); _effect.ShadowSize = (int) thickness.Value; _effect.ToothHeight = (int) toothsize.Value; _effect.VerticalToothRange = (int) verticaltoothrange.Value; diff --git a/src/Greenshot/Forms/AboutForm.cs b/src/Greenshot/Forms/AboutForm.cs index 484a16b42..a9cfc2cfc 100644 --- a/src/Greenshot/Forms/AboutForm.cs +++ b/src/Greenshot/Forms/AboutForm.cs @@ -219,7 +219,7 @@ namespace Greenshot.Forms /// private void LinkLabelClicked(object sender, LinkLabelLinkClickedEventArgs e) { - if (!(sender is LinkLabel linkLabel)) return; + if (sender is not LinkLabel linkLabel) return; var link = linkLabel.Tag?.ToString() ?? linkLabel.Text; try { diff --git a/src/Greenshot/Forms/CaptureForm.cs b/src/Greenshot/Forms/CaptureForm.cs index 6844c8b1c..68e57f040 100644 --- a/src/Greenshot/Forms/CaptureForm.cs +++ b/src/Greenshot/Forms/CaptureForm.cs @@ -73,7 +73,7 @@ namespace Greenshot.Forms private int _mX; private int _mY; - private NativePoint _mouseMovePos = Point.Empty; + private NativePoint _mouseMovePos = NativePoint.Empty; private NativePoint _cursorPos; private CaptureMode _captureMode; private readonly List _windows; @@ -404,7 +404,7 @@ namespace Greenshot.Forms private void HandleMouseDown() { - Point tmpCursorLocation = WindowCapture.GetCursorLocationRelativeToScreenBounds(); + NativePoint tmpCursorLocation = WindowCapture.GetCursorLocationRelativeToScreenBounds(); _mX = tmpCursorLocation.X; _mY = tmpCursorLocation.Y; _mouseDown = true; @@ -508,11 +508,11 @@ namespace Greenshot.Forms } else if (_fixMode == FixMode.Vertical) { - currentMouse = new Point(currentMouse.X, _previousMousePos.Y); + currentMouse = new NativePoint(currentMouse.X, _previousMousePos.Y); } else if (_fixMode == FixMode.Horizontal) { - currentMouse = new Point(_previousMousePos.X, currentMouse.Y); + currentMouse = new NativePoint(_previousMousePos.X, currentMouse.Y); } _previousMousePos = currentMouse; @@ -551,7 +551,7 @@ namespace Greenshot.Forms /// protected override void Animate() { - Point lastPos = _cursorPos; + NativePoint lastPos = _cursorPos; _cursorPos = _mouseMovePos; if (_selectedCaptureWindow != null && lastPos.Equals(_cursorPos) && !IsAnimating(_zoomAnimator) && !IsAnimating(_windowAnimator)) @@ -579,7 +579,7 @@ namespace Greenshot.Forms } // Iterate over the found windows and check if the current location is inside a window - Point cursorPosition = Cursor.Position; + NativePoint cursorPosition = Cursor.Position; _selectedCaptureWindow = null; lock (_windows) { @@ -789,7 +789,7 @@ namespace Greenshot.Forms /// /// preferred destination location for the zoom area /// false to try to find a location which is neither out of screen bounds nor intersects with the selected rectangle - private void VerifyZoomAnimation(Point pos, bool allowZoomOverCaptureRect) + private void VerifyZoomAnimation(NativePoint pos, bool allowZoomOverCaptureRect) { NativeRect screenBounds = DisplayInfo.GetBounds(MousePosition); // convert to be relative to top left corner of all screen bounds diff --git a/src/Greenshot/Helpers/CaptureHelper.cs b/src/Greenshot/Helpers/CaptureHelper.cs index 5ffaa4c27..c002c62ef 100644 --- a/src/Greenshot/Helpers/CaptureHelper.cs +++ b/src/Greenshot/Helpers/CaptureHelper.cs @@ -507,14 +507,12 @@ namespace Greenshot.Helpers // Set capture title, fixing bug #3569703 foreach (WindowDetails window in WindowDetails.GetVisibleWindows()) { - Point estimatedLocation = new Point(CoreConfig.LastCapturedRegion.X + CoreConfig.LastCapturedRegion.Width / 2, + NativePoint estimatedLocation = new NativePoint(CoreConfig.LastCapturedRegion.X + CoreConfig.LastCapturedRegion.Width / 2, CoreConfig.LastCapturedRegion.Y + CoreConfig.LastCapturedRegion.Height / 2); - if (window.Contains(estimatedLocation)) - { - _selectedCaptureWindow = window; - _capture.CaptureDetails.Title = _selectedCaptureWindow.Text; - break; - } + if (!window.Contains(estimatedLocation)) continue; + _selectedCaptureWindow = window; + _capture.CaptureDetails.Title = _selectedCaptureWindow.Text; + break; } // Move cursor, fixing bug #3569703 diff --git a/src/Greenshot/Helpers/IECaptureHelper.cs b/src/Greenshot/Helpers/IECaptureHelper.cs index baf35e16a..0da3d35dc 100644 --- a/src/Greenshot/Helpers/IECaptureHelper.cs +++ b/src/Greenshot/Helpers/IECaptureHelper.cs @@ -722,14 +722,14 @@ namespace Greenshot.Helpers int horizontalPage = 0; // The location of the browser, used as the destination into the bitmap target - Point targetOffset = new Point(); + NativePoint targetOffset = NativePoint.Empty; // Loop of the pages and make a copy of the visible viewport while (horizontalPage * viewportWidth < pageWidth) { // Scroll to location documentContainer.ScrollLeft = viewportWidth * horizontalPage; - targetOffset.X = documentContainer.ScrollLeft; + targetOffset = targetOffset.ChangeX(documentContainer.ScrollLeft); // Variable used for looping vertically int verticalPage = 0; @@ -738,7 +738,7 @@ namespace Greenshot.Helpers // Scroll to location documentContainer.ScrollTop = viewportHeight * verticalPage; //Shoot visible window - targetOffset.Y = documentContainer.ScrollTop; + targetOffset = targetOffset.ChangeY(documentContainer.ScrollTop); // Draw the captured fragment to the target, but "crop" the scrollbars etc while capturing NativeSize viewPortSize = new NativeSize(viewportWidth, viewportHeight); diff --git a/src/Greenshot/Helpers/IEInterop/IEContainer.cs b/src/Greenshot/Helpers/IEInterop/IEContainer.cs index 7d741a992..178dc5643 100644 --- a/src/Greenshot/Helpers/IEInterop/IEContainer.cs +++ b/src/Greenshot/Helpers/IEInterop/IEContainer.cs @@ -40,11 +40,11 @@ namespace Greenshot.Helpers.IEInterop private static readonly Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046"); private static readonly Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E"); private static int _counter; + private readonly NativePoint _startLocation = NativePoint.Empty; private IHTMLDocument2 _document2; private IHTMLDocument3 _document3; private NativePoint _sourceLocation; private NativePoint _destinationLocation; - private NativePoint _startLocation = NativePoint.Empty; private NativeRect _viewportRectangle = NativeRect.Empty; private bool _isDtd; private DocumentContainer _parent; @@ -90,15 +90,15 @@ namespace Greenshot.Helpers.IEInterop // Calculate startLocation for the frames IHTMLWindow2 window2 = document2.parentWindow; IHTMLWindow3 window3 = (IHTMLWindow3) window2; - Point contentWindowLocation = contentWindow.WindowRectangle.Location; + NativePoint contentWindowLocation = contentWindow.WindowRectangle.Location; int x = window3.screenLeft - contentWindowLocation.X; int y = window3.screenTop - contentWindowLocation.Y; // Release IHTMLWindow 2+3 com objects - releaseCom(window2); - releaseCom(window3); + ReleaseCom(window2); + ReleaseCom(window3); - _startLocation = new Point(x, y); + _startLocation = new NativePoint(x, y); Init(document2, contentWindow); } @@ -112,7 +112,7 @@ namespace Greenshot.Helpers.IEInterop /// Helper method to release com objects /// /// - private void releaseCom(object comObject) + private void ReleaseCom(object comObject) { if (comObject != null) { @@ -182,7 +182,7 @@ namespace Greenshot.Helpers.IEInterop int diffY = clientRectangle.Height - ClientHeight; // If there is a border around the inner window, the diff == 4 // If there is a border AND a scrollbar the diff == 20 - if ((diffX == 4 || diffX >= 20) && (diffY == 4 || diffY >= 20)) + if (diffX is 4 or >= 20 && diffY is 4 or >= 20) { var viewportOffset = new NativePoint(2, 2); var viewportSize = new NativeSize(ClientWidth, ClientHeight); @@ -193,9 +193,9 @@ namespace Greenshot.Helpers.IEInterop LOG.DebugFormat("Zoomlevel {0}, {1}", _zoomLevelX, _zoomLevelY); // Release com objects - releaseCom(window2); - releaseCom(screen); - releaseCom(screen2); + ReleaseCom(window2); + ReleaseCom(screen); + ReleaseCom(screen2); } catch (Exception e) { @@ -225,8 +225,8 @@ namespace Greenshot.Helpers.IEInterop LOG.Warn("Problem while trying to get document url!", e); } - _sourceLocation = new Point(ScaleX(_startLocation.X), ScaleY(_startLocation.Y)); - _destinationLocation = new Point(ScaleX(_startLocation.X), ScaleY(_startLocation.Y)); + _sourceLocation = new NativePoint(ScaleX(_startLocation.X), ScaleY(_startLocation.Y)); + _destinationLocation = new NativePoint(ScaleX(_startLocation.X), ScaleY(_startLocation.Y)); if (_parent != null) { @@ -254,7 +254,7 @@ namespace Greenshot.Helpers.IEInterop } // Clean up frameWindow - releaseCom(frameWindow); + ReleaseCom(frameWindow); } catch (Exception e) { @@ -263,7 +263,7 @@ namespace Greenshot.Helpers.IEInterop } // Clean up collection - releaseCom(frameCollection); + ReleaseCom(frameCollection); } catch (Exception ex) { @@ -279,7 +279,7 @@ namespace Greenshot.Helpers.IEInterop { CorrectFrameLocations(frameElement); // Clean up frameElement - releaseCom(frameElement); + ReleaseCom(frameElement); } catch (Exception e) { @@ -294,7 +294,7 @@ namespace Greenshot.Helpers.IEInterop } /// - /// Corrent the frame locations with the information + /// Correct the frame locations with the information /// /// private void CorrectFrameLocations(IHTMLElement frameElement) @@ -311,22 +311,22 @@ namespace Greenshot.Helpers.IEInterop // Release element, but prevent the frameElement to be released if (oldElement != null) { - releaseCom(oldElement); + ReleaseCom(oldElement); } oldElement = element; } while (element != null); - Point elementLocation = new Point((int) x, (int) y); + var elementLocation = new NativePoint((int) x, (int) y); IHTMLElement2 element2 = (IHTMLElement2) frameElement; IHTMLRect rec = element2.getBoundingClientRect(); - Point elementBoundingLocation = new Point(rec.left, rec.top); + var elementBoundingLocation = new NativePoint(rec.left, rec.top); // Release IHTMLRect - releaseCom(rec); + ReleaseCom(rec); LOG.DebugFormat("Looking for iframe to correct at {0}", elementBoundingLocation); foreach (DocumentContainer foundFrame in _frames) { - Point frameLocation = foundFrame.SourceLocation; + NativePoint frameLocation = foundFrame.SourceLocation; if (frameLocation.Equals(elementBoundingLocation)) { // Match found, correcting location @@ -475,7 +475,7 @@ namespace Greenshot.Helpers.IEInterop var element = !_isDtd ? _document2.body : _document3.documentElement; element.setAttribute(attribute, value, 1); // Release IHTMLElement com object - releaseCom(element); + ReleaseCom(element); } /// @@ -488,7 +488,7 @@ namespace Greenshot.Helpers.IEInterop var element = !_isDtd ? _document2.body : _document3.documentElement; var retVal = element.getAttribute(attribute, 1); // Release IHTMLElement com object - releaseCom(element); + ReleaseCom(element); return retVal; }