Skip to content
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 @@ -35,6 +35,13 @@ public static int MapWindowPoints(HandleRef hWndFrom, HandleRef hWndTo, ref Poin
return result;
}

public static int MapWindowPoints(IntPtr hWndFrom, IHandle hWndTo, ref Point lpPoints, uint cPoints)
{
int result = MapWindowPoints(hWndFrom, hWndTo.Handle, ref lpPoints, cPoints);
GC.KeepAlive(hWndTo);
return result;
}

[DllImport(Libraries.User32, ExactSpelling = true)]
public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, ref RECT lpPoints, uint cPoints);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ internal abstract class UiaTextProvider : ITextProvider

public abstract void SetSelection(int start, int end);

public ES GetEditStyle(IntPtr hWnd) => hWnd != IntPtr.Zero ? (ES)GetWindowLong(new HandleRef(null, hWnd), GWL.STYLE) : ES.LEFT;
public ES GetEditStyle(IHandle hWnd) => (ES)GetWindowLong(hWnd, GWL.STYLE);

public WS_EX GetWindowExStyle(IntPtr hWnd) => hWnd != IntPtr.Zero ? (WS_EX)GetWindowLong(new HandleRef(null, hWnd), GWL.EXSTYLE) : WS_EX.LEFT;
public WS_EX GetWindowExStyle(IHandle hWnd) => (WS_EX)GetWindowLong(hWnd, GWL.EXSTYLE);

public WS GetWindowStyle(IntPtr hWnd) => hWnd != IntPtr.Zero ? (WS)GetWindowLong(new HandleRef(this, hWnd), GWL.STYLE) : WS.DISABLED;
public WS GetWindowStyle(IHandle hWnd) => (WS)GetWindowLong(hWnd, GWL.STYLE);

public double[] RectListToDoubleArray(List<Rectangle> rectArray)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void UiaTextProvider_GetEditStyle_ContainsMultilineStyle_ForMultilineText
style: WS.OVERLAPPED | WS.VISIBLE);
Mock<UiaTextProvider> providerMock = new Mock<UiaTextProvider>(MockBehavior.Strict);

ES actual = providerMock.Object.GetEditStyle(textBox.Handle);
ES actual = providerMock.Object.GetEditStyle(textBox);
Assert.True(actual.HasFlag(ES.MULTILINE));
}

Expand All @@ -35,19 +35,10 @@ public void UiaTextProvider_GetEditStyle_DoesntContainMultilineStyle_ForSingleli
style: WS.OVERLAPPED | WS.VISIBLE);
Mock<UiaTextProvider> providerMock = new Mock<UiaTextProvider>(MockBehavior.Strict);

ES actual = providerMock.Object.GetEditStyle(textBox.Handle);
ES actual = providerMock.Object.GetEditStyle(textBox);
Assert.False(actual.HasFlag(ES.MULTILINE));
}

[StaFact]
public void UiaTextProvider_GetEditStyle_ReturnsLeft_WithoutHandle()
{
Mock<UiaTextProvider> providerMock = new Mock<UiaTextProvider>(MockBehavior.Strict);

ES actual = providerMock.Object.GetEditStyle(IntPtr.Zero);
Assert.Equal(ES.LEFT, actual);
}

[StaFact]
public void UiaTextProvider_GetWindowStyle_ContainsVisible()
{
Expand All @@ -56,38 +47,21 @@ public void UiaTextProvider_GetWindowStyle_ContainsVisible()
style: WS.OVERLAPPED | WS.VISIBLE);
Mock<UiaTextProvider> providerMock = new Mock<UiaTextProvider>(MockBehavior.Strict);

WS actual = providerMock.Object.GetWindowStyle(textBox.Handle);
WS actual = providerMock.Object.GetWindowStyle(textBox);
Assert.True(actual.HasFlag(WS.VISIBLE));
}

[StaFact]
public void UiaTextProvider_GetWindowStyle_ReturnsDisabled_WithoutHandle()
{
Mock<UiaTextProvider> providerMock = new Mock<UiaTextProvider>(MockBehavior.Strict);

WS actual = providerMock.Object.GetWindowStyle(IntPtr.Zero);
Assert.Equal(WS.DISABLED, actual);
}

[StaFact]
public void UiaTextProvider_GetWindowExStyle_ContainsClientedge()
{
using EditControl textBox = new EditControl(
style: WS.OVERLAPPED | WS.VISIBLE);
Mock<UiaTextProvider> providerMock = new Mock<UiaTextProvider>(MockBehavior.Strict);

WS_EX actual = providerMock.Object.GetWindowExStyle(textBox.Handle);
WS_EX actual = providerMock.Object.GetWindowExStyle(textBox);
Assert.True(actual.HasFlag(WS_EX.CLIENTEDGE));
}

[StaFact]
public void UiaTextProvider_GetWindowExStyle_ReturnsLeft_WithoutHandle()
{
Mock<UiaTextProvider> providerMock = new Mock<UiaTextProvider>(MockBehavior.Strict);
WS_EX actual = providerMock.Object.GetWindowExStyle(IntPtr.Zero);
Assert.Equal(WS_EX.LEFT, actual);
}

[StaFact]
public void UiaTextProvider_RectArrayToDoubleArray_ReturnsCorrectValue()
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.Windows.Forms/src/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10720,7 +10720,7 @@ System.Windows.Forms.ScrollProperties.ScrollProperties(System.Windows.Forms.Scro
~System.Windows.Forms.ToolStripControlHost.Control.get -> System.Windows.Forms.Control
~System.Windows.Forms.ToolStripControlHost.ToolStripControlHost(System.Windows.Forms.Control c) -> void
~System.Windows.Forms.ToolStripControlHost.ToolStripControlHost(System.Windows.Forms.Control c, string name) -> void
~System.Windows.Forms.ToolStripControlHost.ToolStripHostedControlAccessibleObject.ToolStripHostedControlAccessibleObject(System.Windows.Forms.Control toolStripHostedControl, System.Windows.Forms.ToolStripControlHost toolStripControlHost) -> void
System.Windows.Forms.ToolStripControlHost.ToolStripHostedControlAccessibleObject.ToolStripHostedControlAccessibleObject(System.Windows.Forms.Control! toolStripHostedControl, System.Windows.Forms.ToolStripControlHost? toolStripControlHost) -> void
~System.Windows.Forms.ToolStripDropDown.ContextMenuStrip.get -> System.Windows.Forms.ContextMenuStrip
~System.Windows.Forms.ToolStripDropDown.ContextMenuStrip.set -> void
~System.Windows.Forms.ToolStripDropDown.OverflowButton.get -> System.Windows.Forms.ToolStripOverflowButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public TextBoxBaseUiaTextProvider(TextBoxBase owner)

// Convert screen to client coordinates.
// (Essentially ScreenToClient but MapWindowPoints accounts for window mirroring using WS_EX_LAYOUTRTL.)
if (MapWindowPoints(new HandleRef(null, IntPtr.Zero), new HandleRef(this, _owningTextBoxBase.Handle), ref clientLocation, 1) == 0)
if (MapWindowPoints(default, _owningTextBoxBase, ref clientLocation, 1) == 0)
{
return new UiaTextRange(new InternalAccessibleObject(_owningTextBoxBase.AccessibilityObject), this, 0, 0);
}
Expand Down Expand Up @@ -177,7 +177,7 @@ public override bool IsScrollable

public override int LinesCount
=> _owningTextBoxBase.IsHandleCreated
? (int)(long)SendMessageW(new HandleRef(this, _owningTextBoxBase.Handle), (WM)EM.GETLINECOUNT)
? (int)(long)SendMessageW(_owningTextBoxBase, (WM)EM.GETLINECOUNT)
: -1;

public override int LinesPerPage
Expand Down Expand Up @@ -222,17 +222,17 @@ public override int TextLength

public override WS_EX WindowExStyle
=> _owningTextBoxBase.IsHandleCreated
? GetWindowExStyle(_owningTextBoxBase.Handle)
? GetWindowExStyle(_owningTextBoxBase)
: WS_EX.LEFT;

public override WS WindowStyle
=> _owningTextBoxBase.IsHandleCreated
? GetWindowStyle(_owningTextBoxBase.Handle)
? GetWindowStyle(_owningTextBoxBase)
: WS.OVERLAPPED;

public override ES EditStyle
=> _owningTextBoxBase.IsHandleCreated
? GetEditStyle(_owningTextBoxBase.Handle)
? GetEditStyle(_owningTextBoxBase)
: ES.LEFT;

public override int GetLineFromCharIndex(int charIndex)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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.

#nullable disable

using static Interop;

namespace System.Windows.Forms
Expand All @@ -17,21 +15,21 @@ public partial class ToolStripControlHost
/// </summary>
public class ToolStripHostedControlAccessibleObject : Control.ControlAccessibleObject
{
private ToolStripControlHost _toolStripControlHost;
private ToolStripControlHost? _toolStripControlHost;
private Control _toolStripHostedControl;

/// <summary>
/// Creates the new instance of ToolStripHostedControlAccessibleObject.
/// </summary>
/// <param name="toolStripHostedControl">The ToolStrip control hosted in the ToolStripControlHost container.</param>
/// <param name="toolStripControlHost">The ToolStripControlHost container which hosts the control.</param>
public ToolStripHostedControlAccessibleObject(Control toolStripHostedControl, ToolStripControlHost toolStripControlHost) : base(toolStripHostedControl)
public ToolStripHostedControlAccessibleObject(Control toolStripHostedControl, ToolStripControlHost? toolStripControlHost) : base(toolStripHostedControl)
{
_toolStripControlHost = toolStripControlHost;
_toolStripHostedControl = toolStripHostedControl;
}

internal override UiaCore.IRawElementProviderFragmentRoot FragmentRoot
internal override UiaCore.IRawElementProviderFragmentRoot? FragmentRoot
{
get
{
Expand All @@ -46,7 +44,7 @@ internal override UiaCore.IRawElementProviderFragmentRoot FragmentRoot
}
}

internal override UiaCore.IRawElementProviderFragment FragmentNavigate(UiaCore.NavigateDirection direction)
internal override UiaCore.IRawElementProviderFragment? FragmentNavigate(UiaCore.NavigateDirection direction)
{
if (_toolStripHostedControl != null &&
_toolStripControlHost != null)
Expand All @@ -63,7 +61,7 @@ internal override UiaCore.IRawElementProviderFragment FragmentNavigate(UiaCore.N
return base.FragmentNavigate(direction);
}

internal override object GetPropertyValue(UiaCore.UIA propertyID)
internal override object? GetPropertyValue(UiaCore.UIA propertyID)
{
switch (propertyID)
{
Expand Down
Loading