Skip to content

Commit

Permalink
Changed type of the handle parameter from IntPtr to HWND in the…
Browse files Browse the repository at this point in the history
… `Control.ReleaseUiaProvider` method (#8351)

Replaced type of the handle parameter from IntPtr to  HWND
  • Loading branch information
NikitaSemenovAkvelon authored Jan 4, 2023
1 parent 7beb876 commit 7fd92af
Show file tree
Hide file tree
Showing 30 changed files with 38 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal partial class Interop
internal static partial class UiaCore
{
[DllImport(Libraries.UiaCore, CharSet = CharSet.Unicode)]
public static extern nint UiaReturnRawElementProvider(IntPtr hwnd, nint wParam, nint lParam, IRawElementProviderSimple? el);
public static extern nint UiaReturnRawElementProvider(HWND hwnd, nint wParam, nint lParam, IRawElementProviderSimple? el);

public static nint UiaReturnRawElementProvider(IHandle<HWND> hwnd, WPARAM wParam, LPARAM lParam, IRawElementProviderSimple? el)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override void WndProc(ref Message m)
{
if (Handle != IntPtr.Zero)
{
UiaCore.UiaReturnRawElementProvider(Handle, wParam: 0, lParam: 0, el: null);
UiaCore.UiaReturnRawElementProvider(HWND, wParam: 0, lParam: 0, el: null);
}

if (OsVersion.IsWindows8OrGreater())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3228,7 +3228,7 @@ private void ReleaseChildWindow()
}
}

internal override void ReleaseUiaProvider(IntPtr handle)
internal override void ReleaseUiaProvider(HWND handle)
{
if (!IsAccessibilityObjectCreated)
{
Expand Down
9 changes: 5 additions & 4 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,8 @@ public IntPtr Handle

internal IntPtr HandleInternal => _window.Handle;

internal HWND HWNDInternal => _window.HWND;

/// <summary>
/// True if this control has child controls in its collection. This
/// is more efficient than checking for Controls.Count > 0, but has the
Expand Down Expand Up @@ -9967,9 +9969,9 @@ public virtual void Refresh()
/// Releases UI Automation provider for specified window.
/// </summary>
/// <param name="handle">The window handle.</param>
internal virtual void ReleaseUiaProvider(IntPtr handle)
internal virtual void ReleaseUiaProvider(HWND handle)
{
if (handle != IntPtr.Zero)
if (!handle.IsNull)
{
// When a window that previously returned providers has been destroyed,
// you should notify UI Automation by calling the UiaReturnRawElementProvider
Expand Down Expand Up @@ -12114,7 +12116,7 @@ private void WmDestroy(ref Message m)

if (SupportsUiaProviders)
{
ReleaseUiaProvider(HandleInternal);
ReleaseUiaProvider(HWNDInternal);
}

OnHandleDestroyed(EventArgs.Empty);
Expand Down Expand Up @@ -13640,7 +13642,6 @@ internal ToolStripControlHost? ToolStripControlHost
HWND IHandle<HWND>.Handle => HWND;

internal HWND HWND => (HWND)Handle;
internal HWND HWNDInternal => (HWND)HandleInternal;

internal virtual bool AllowsChildrenToShowToolTips() => true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26104,7 +26104,7 @@ private void ReleaseMouse()
Capture = false;
}

internal override void ReleaseUiaProvider(IntPtr handle)
internal override void ReleaseUiaProvider(HWND handle)
{
if (!IsAccessibilityObjectCreated)
{
Expand All @@ -26129,7 +26129,7 @@ internal override void ReleaseUiaProvider(IntPtr handle)
column.HeaderCell.ReleaseUiaProvider();
}

_editingPanel?.ReleaseUiaProvider(IntPtr.Zero);
_editingPanel?.ReleaseUiaProvider(HWND.Null);
_editingPanelAccessibleObject = null;
_topLeftHeaderCell?.ReleaseUiaProvider();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,7 @@ public override object ParseFormattedValue(

internal override void ReleaseUiaProvider()
{
EditingComboBox?.ReleaseUiaProvider(IntPtr.Zero);
EditingComboBox?.ReleaseUiaProvider(HWND.Null);

base.ReleaseUiaProvider();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected override void OnHandleCreated(EventArgs e)
}
}

internal override void ReleaseUiaProvider(nint handle)
internal override void ReleaseUiaProvider(HWND handle)
{
if (TryGetAccessibilityObject(out AccessibleObject accessibleObject))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ protected override bool ProcessKeyEventArgs(ref Message m)
return base.ProcessKeyEventArgs(ref m);
}

internal override void ReleaseUiaProvider(nint handle)
internal override void ReleaseUiaProvider(HWND handle)
{
if (TryGetAccessibilityObject(out AccessibleObject? accessibleObject))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,7 @@ protected override void RefreshItem(int index)
Items.SetItemInternal(index, Items[index]);
}

internal override void ReleaseUiaProvider(IntPtr handle)
internal override void ReleaseUiaProvider(HWND handle)
{
ClearListItemAccessibleObjects();
base.ReleaseUiaProvider(handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5139,7 +5139,7 @@ public void RedrawItems(int startIndex, int endIndex, bool invalidateOnly)
}
}

internal override void ReleaseUiaProvider(nint handle)
internal override void ReleaseUiaProvider(HWND handle)
{
if (!OsVersion.IsWindows8OrGreater() || !IsAccessibilityObjectCreated)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override void ReleaseHandle()
// you should notify UI Automation by calling the UiaReturnRawElementProvider
// as follows: UiaReturnRawElementProvider(hwnd, 0, 0, NULL). This call tells
// UI Automation that it can safely remove all map entries that refer to the specified window.
UiaCore.UiaReturnRawElementProvider(Handle, wParam: 0, lParam: 0, el: null);
UiaCore.UiaReturnRawElementProvider(HWND, wParam: 0, lParam: 0, el: null);
}

if (OsVersion.IsWindows8OrGreater())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ protected virtual void OnRightToLeftLayoutChanged(EventArgs e)
_onRightToLeftLayoutChanged?.Invoke(this, e);
}

internal override void ReleaseUiaProvider(nint handle)
internal override void ReleaseUiaProvider(HWND handle)
{
if (OsVersion.IsWindows8OrGreater() && IsAccessibilityObjectCreated)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public void Remove(TabPage value)
_owner.Controls.Remove(value);
if (value.IsHandleCreated)
{
value.ReleaseUiaProvider(value.HandleInternal);
value.ReleaseUiaProvider(value.HWNDInternal);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ protected override void OnPaintBackground(PaintEventArgs e)
}
}

internal override void ReleaseUiaProvider(IntPtr handle)
internal override void ReleaseUiaProvider(HWND handle)
{
if (OsVersion.IsWindows8OrGreater())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4166,7 +4166,7 @@ public ToolStripItem GetItemAt(Point point)
return null;
}

internal override void ReleaseUiaProvider(IntPtr handle)
internal override void ReleaseUiaProvider(HWND handle)
{
if (!IsAccessibilityObjectCreated)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ protected override void SetVisibleCore(bool visible)

internal override void ReleaseUiaProvider()
{
_control?.ReleaseUiaProvider(IntPtr.Zero);
_control?.ReleaseUiaProvider(HWND.Null);
base.ReleaseUiaProvider();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ protected internal override bool ProcessDialogKey(Keys keyData)

internal override void ReleaseUiaProvider()
{
_dropDown?.ReleaseUiaProvider(IntPtr.Zero);
_dropDown?.ReleaseUiaProvider(HWND.Null);
base.ReleaseUiaProvider();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public TreeView()
SetStyle(ControlStyles.UseTextForAccessibility, false);
}

internal override void ReleaseUiaProvider(IntPtr handle)
internal override void ReleaseUiaProvider(HWND handle)
{
foreach (TreeNode rootNode in Nodes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ protected override void OnPaint(PaintEventArgs e)
protected virtual void OnUpDown(UpDownEventArgs upevent)
=> _upDownEventHandler?.Invoke(this, upevent);

internal override void ReleaseUiaProvider(IntPtr handle)
internal override void ReleaseUiaProvider(HWND handle)
{
if (IsAccessibilityObjectCreated
&& OsVersion.IsWindows8OrGreater()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,14 @@ internal override Rectangle ApplyBoundsConstraints(int suggestedX, int suggested
return base.ApplyBoundsConstraints(suggestedX, suggestedY, proposedWidth, PreferredHeight);
}

internal override void ReleaseUiaProvider(IntPtr handle)
internal override void ReleaseUiaProvider(HWND handle)
{
// UpDownEdit as TextBox is a control, that should disconnect its accessible object itself,
// but if it supports Uia providers. If no, force disconnecting for UpDownEdit accessible object
// as a part of UIA tree of Domain/NumericUpDown controls.
if (!_upDownEdit.SupportsUiaProviders)
{
_upDownEdit.ReleaseUiaProvider(_upDownEdit.HandleInternal);
_upDownEdit.ReleaseUiaProvider(_upDownEdit.HWNDInternal);
}

base.ReleaseUiaProvider(handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void ListViewColumnHeaderAccessibleObject_IsDisconnected_WhenListViewRele
EnforceAccessibleObjectCreation(columnHeader);
_ = listView.AccessibilityObject;

listView.ReleaseUiaProvider(listView.Handle);
listView.ReleaseUiaProvider(listView.HWND);

Assert.Null(columnHeader.TestAccessor().Dynamic._accessibilityObject);
Assert.True(listView.IsHandleCreated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public void ComboBox_ReleaseUiaProvider_ClearsItemsAccessibleObjects()

Assert.Equal(comboBox.Items.Count, accessibleObject.ItemAccessibleObjects.Count);

comboBox.ReleaseUiaProvider(comboBox.Handle);
comboBox.ReleaseUiaProvider(comboBox.HWND);

Assert.Equal(0, accessibleObject.ItemAccessibleObjects.Count);
Assert.True(comboBox.IsHandleCreated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void ListBox_ReleaseUiaProvider_ClearsItemsAccessibleObjects()
using ListBox listBox = CreateListBoxWithItems();
ListBoxAccessibleObject accessibleObject = InitListBoxItemsAccessibleObjects(listBox);

listBox.ReleaseUiaProvider(listBox.Handle);
listBox.ReleaseUiaProvider(listBox.HWND);

Assert.Equal(0, accessibleObject.TestAccessor().Dynamic._itemAccessibleObjects.Count);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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.

Expand Down Expand Up @@ -1353,7 +1353,7 @@ public void ListViewGroupAccessibleObject_IsDisconnected_WhenListViewReleasesUia
EnforceAccessibleObjectCreation(group);
EnforceAccessibleObjectCreation(listView.DefaultGroup);

listView.ReleaseUiaProvider(listView.Handle);
listView.ReleaseUiaProvider(listView.HWND);

Assert.Null(group.TestAccessor().Dynamic._accessibilityObject);
Assert.Null(listView.DefaultGroup.TestAccessor().Dynamic._accessibilityObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ public void ListViewItemAccessibleObject_IsDisconnected_WhenListViewReleasesUiaP
listView.Items.Add(item);
EnforceAccessibleObjectCreation(item);

listView.ReleaseUiaProvider(listView.Handle);
listView.ReleaseUiaProvider(listView.HWND);

Assert.Null(item.TestAccessor().Dynamic._accessibilityObject);
Assert.True(listView.IsHandleCreated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ public void ListViewSubItemAccessibleObject_IsDisconnected_WhenListViewReleasesU
listView.Items.Add(listViewItem);
EnforceAccessibleObjectCreation(listViewItem);

listView.ReleaseUiaProvider(listView.Handle);
listView.ReleaseUiaProvider(listView.HWND);

Assert.Null(listViewSubItem.TestAccessor().Dynamic._accessibilityObject);
Assert.True(listView.IsHandleCreated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5745,7 +5745,7 @@ public void ListView_ReleaseUiaProvider_DoesNotForceDefaultGroupCreation()
using ListView listView = new();
_ = listView.AccessibilityObject;

listView.ReleaseUiaProvider(listView.Handle);
listView.ReleaseUiaProvider(listView.HWND);

Assert.Null(listView.TestAccessor().Dynamic._defaultGroup);
Assert.True(listView.IsHandleCreated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void TabAccessibilityObject_IsDisconnected_WhenTabPageReleasesUiaProvider
using TabPage tabPage = new();
EnforceTabAccessibilityObjectCreation(tabPage);

tabPage.ReleaseUiaProvider(tabPage.Handle);
tabPage.ReleaseUiaProvider(tabPage.HWND);

Assert.Null(tabPage.TestAccessor().Dynamic._tabAccessibilityObject);
Assert.True(tabPage.IsHandleCreated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7076,7 +7076,7 @@ public void ToolStripItem_Releases_UiaProvider()
_ = toolStrip.AccessibilityObject;
Assert.True(toolStrip.IsAccessibilityObjectCreated);

toolStrip.ReleaseUiaProvider(toolStrip.Handle);
toolStrip.ReleaseUiaProvider(toolStrip.HWND);

Assert.Equal(1, toolStrip.Disconnects);
Assert.True(toolStripDropDownItem1.IsAccessibleObjectCleared());
Expand Down Expand Up @@ -15574,7 +15574,7 @@ public ToolStripWithDisconnectCount() : base() { }

public int Disconnects { get; private set; }

internal new void ReleaseUiaProvider(IntPtr handle)
internal new void ReleaseUiaProvider(HWND handle)
{
base.ReleaseUiaProvider(handle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public void TreeNodeAccessibleObject_IsDisconnected_WhenTreeViewIsReleased()
secondLevelNode.Nodes.Add(thirdLevelNode);
control.CreateControl();

control.ReleaseUiaProvider(control.Handle);
control.ReleaseUiaProvider(control.HWND);

Assert.True(firstLevelNode.IsAccessibilityObjectDisconnected);
Assert.True(secondLevelNode.IsAccessibilityObjectDisconnected);
Expand Down

0 comments on commit 7fd92af

Please sign in to comment.