Skip to content
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

Break up Control class #1475

Merged
merged 2 commits into from
Jul 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ internal static double GetDpiScaleRatio(Graphics g, Control control)
if (DpiHelper.IsPerMonitorV2Awareness
&& control != null && control.IsHandleCreated)
{

return control.deviceDpi / DpiHelper.LogicalDpi;
return control._deviceDpi / DpiHelper.LogicalDpi;
}

if (g == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6317,7 +6317,7 @@ public FlatComboAdapter(ComboBox comboBox, bool smallButton)
Offset2Pixels = comboBox.LogicalToDeviceUnits(OFFSET_2PIXELS);

clientRect = comboBox.ClientRectangle;
int dropDownButtonWidth = SystemInformation.GetHorizontalScrollBarArrowWidthForDpi(comboBox.deviceDpi);
int dropDownButtonWidth = SystemInformation.GetHorizontalScrollBarArrowWidthForDpi(comboBox._deviceDpi);
outerBorder = new Rectangle(clientRect.Location, new Size(clientRect.Width - 1, clientRect.Height - 1));
innerBorder = new Rectangle(outerBorder.X + 1, outerBorder.Y + 1, outerBorder.Width - dropDownButtonWidth - 2, outerBorder.Height - 2);
innerInnerBorder = new Rectangle(innerBorder.X + 1, innerBorder.Y + 1, innerBorder.Width - 2, innerBorder.Height - 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public SizeF CurrentAutoScaleDimensions
// Screen Dpi
if (DpiHelper.IsPerMonitorV2Awareness)
{
_currentAutoScaleDimensions = new SizeF((float)deviceDpi, (float)deviceDpi);
_currentAutoScaleDimensions = new SizeF((float)_deviceDpi, (float)_deviceDpi);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// 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.Drawing;
using System.Runtime.InteropServices;

namespace System.Windows.Forms
{
public partial class Control
{
/// <summary>
/// This is a marshaler object that knows how to marshal IFont to Font
/// and back.
/// </summary>
private class ActiveXFontMarshaler : ICustomMarshaler
{
private static ActiveXFontMarshaler s_instance;

public void CleanUpManagedData(object obj)
{
}

public void CleanUpNativeData(IntPtr pObj)
{
Marshal.Release(pObj);
}

internal static ICustomMarshaler GetInstance(string cookie)
{
if (s_instance == null)
{
s_instance = new ActiveXFontMarshaler();
}
return s_instance;
}

public int GetNativeDataSize()
=> -1; // not a value type, so use -1

public IntPtr MarshalManagedToNative(object obj)
{
Font font = (Font)obj;
NativeMethods.tagFONTDESC fontDesc = new NativeMethods.tagFONTDESC();
NativeMethods.LOGFONTW logFont = NativeMethods.LOGFONTW.FromFont(font);

fontDesc.lpstrName = font.Name;
fontDesc.cySize = (long)(font.SizeInPoints * 10000);
fontDesc.sWeight = (short)logFont.lfWeight;
fontDesc.sCharset = logFont.lfCharSet;
fontDesc.fItalic = font.Italic;
fontDesc.fUnderline = font.Underline;
fontDesc.fStrikethrough = font.Strikeout;

Guid iid = typeof(UnsafeNativeMethods.IFont).GUID;

UnsafeNativeMethods.IFont oleFont = UnsafeNativeMethods.OleCreateFontIndirect(fontDesc, ref iid);
IntPtr pFont = Marshal.GetIUnknownForObject(oleFont);

int hr = Marshal.QueryInterface(pFont, ref iid, out IntPtr pIFont);

Marshal.Release(pFont);

if (NativeMethods.Failed(hr))
{
Marshal.ThrowExceptionForHR(hr);
}

return pIFont;
}

public object MarshalNativeToManaged(IntPtr pObj)
{
UnsafeNativeMethods.IFont nativeFont = (UnsafeNativeMethods.IFont)Marshal.GetObjectForIUnknown(pObj);
IntPtr hfont = nativeFont.GetHFont();

Font font;
try
{
font = Font.FromHfont(hfont);
}
catch (Exception e)
{
if (ClientUtils.IsSecurityOrCriticalException(e))
{
throw;
}

font = DefaultFont;
}

return font;
}
}
}
}
Loading