Skip to content

Porting several outstanding UITypeEditors #2288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
* text=auto

# Collapse XLF files in PRs by default
*.xlf linguist-generated=true
20 changes: 20 additions & 0 deletions src/Common/src/Interop/Kernel32/Interop.MultiByteToWideChar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation 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;

internal partial class Interop
{
internal partial class Kernel32
{
// SECREVIEW: From MSDN: Using the MultiByteToWideChar/WideCharToMultiByte function incorrectly can compromise the security of your application.
// Calling the WideCharToMultiByte function can easily cause a buffer overrun because the size of the In buffer equals the number
// of WCHARs in the string, while the size of the Out buffer equals the number of bytes. To avoid a buffer overrun, be sure to specify
// a buffer size appropriate for the data type the buffer receives. For more information, see Security Considerations: International Features.
// Always call these functions passing a null destination buffer to get its size and the create the buffer with the exact size.
[DllImport(ExternDll.Kernel32, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int MultiByteToWideChar(int CodePage, int dwFlags, byte[] lpMultiByteStr, int cchMultiByte, char[] lpWideCharStr, int cchWideChar);
}
}
13 changes: 13 additions & 0 deletions src/System.Design/src/System.Design.Forwards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

using System.Runtime.CompilerServices;

[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.DataMemberFieldConverter))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.FormatStringEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.HelpNamespaceEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ImageCollectionEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ImageIndexEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.LinkAreaEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListControlStringCollectionEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewGroupCollectionEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewItemCollectionEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewSubItemCollectionEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.MaskPropertyEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.MaskedTextBoxTextEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.SelectedPathEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringArrayEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringCollectionEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.TabPageCollectionEditor))]
23 changes: 23 additions & 0 deletions src/System.Windows.Forms.Design.Editors/src/Misc/DpiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ public static bool IsScalingRequired
}
}

/// <summary>
/// scale logical pixel to the factor
/// </summary>
public static int ConvertToGivenDpiPixel(int value, double pixelFactor)
{
var scaledValue = (int)Math.Round(value * pixelFactor);
return scaledValue == 0 ? 1 : scaledValue;
}

/// <summary>
/// Transforms a horizontal or vertical integer coordinate from logical to device units
/// by scaling it up for current DPI and rounding to nearest integer value
Expand All @@ -142,6 +151,20 @@ public static int LogicalToDeviceUnits(int value, int devicePixels = 0)
return (int)Math.Round(scalingFactor * (double)value);
}

/// <summary>
/// Transforms a horizontal or vertical integer coordinate from logical to device units
/// by scaling it up for current DPI and rounding to nearest integer value
/// </summary>
public static double LogicalToDeviceUnits(double value, int devicePixels = 0)
{
if (devicePixels == 0)
{
return LogicalToDeviceUnitsScalingFactor * value;
}
double scalingFactor = devicePixels / LogicalDpi;
return scalingFactor * value;
}

/// <summary>
/// Transforms a horizontal integer coordinate from logical to device units
/// by scaling it up for current DPI and rounding to nearest integer value
Expand Down
Loading