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 @@ -32,6 +32,26 @@ private bool IsModal
}
}

internal void ReleaseChildUiaProviders()
{
if (!OsVersion.IsWindows8OrGreater())
{
return;
}

if (_topRowAccessibilityObject is not null)
{
UiaCore.UiaDisconnectProvider(_topRowAccessibilityObject);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can also set _topRowAccessibilityObject and _selectedCellsAccessibilityObject to null here, so that if it gets called twice there is no double disconnect.

_topRowAccessibilityObject = null;
}

if (_selectedCellsAccessibilityObject is not null)
{
UiaCore.UiaDisconnectProvider(_selectedCellsAccessibilityObject);
_selectedCellsAccessibilityObject = null;
}
}

public override AccessibleRole Role
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26104,6 +26104,44 @@ private void ReleaseMouse()
Capture = false;
}

internal override void ReleaseUiaProvider(IntPtr handle)
{
if (!IsAccessibilityObjectCreated)
{
return;
}

if (OsVersion.IsWindows8OrGreater())
{
foreach (DataGridViewRow row in Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
cell.ReleaseUiaProvider();
}

row.HeaderCell.ReleaseUiaProvider();
row.ReleaseUiaProvider();
}

foreach (DataGridViewColumn column in Columns)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you unify argument in this method, please use 0 here.

{
column.HeaderCell.ReleaseUiaProvider();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line does the same as _editingPanel?.ReleaseUiaProvider(IntPtr.Zero); above, so I think you can simply remove _editingPanel?.ReleaseUiaProvider(IntPtr.Zero); and it should work the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReleaseUiaProvider also sets the AO in properties collection to null, I'd rather remove line 26130


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

if (AccessibilityObject is DataGridViewAccessibleObject accessibleObject)
{
accessibleObject.ReleaseChildUiaProviders();
}
}

base.ReleaseUiaProvider(handle);
}

private void RemoveIndividualReadOnlyCellsInColumn(int columnIndex)
{
int cellIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ public DataGridViewCellStyle InheritedStyle
}
}

internal bool IsAccessibilityObjectCreated => Properties.GetObject(s_propCellAccessibilityObject) is AccessibleObject;

/// <summary>
/// Indicates whether or not the parent grid view for this element has an accessible object associated with it.
/// </summary>
Expand Down Expand Up @@ -1292,8 +1294,9 @@ private bool AccessibleRestructuringNeeded
Type editingControlType = DataGridView.EditingControl.GetType();

return
(editingControlType == typeof(DataGridViewComboBoxEditingControl) && !editingControlType.IsSubclassOf(typeof(DataGridViewComboBoxEditingControl))) ||
(editingControlType == typeof(DataGridViewTextBoxEditingControl) && !editingControlType.IsSubclassOf(typeof(DataGridViewTextBoxEditingControl)));
IsAccessibilityObjectCreated &&
((editingControlType == typeof(DataGridViewComboBoxEditingControl) && !editingControlType.IsSubclassOf(typeof(DataGridViewComboBoxEditingControl))) ||
(editingControlType == typeof(DataGridViewTextBoxEditingControl) && !editingControlType.IsSubclassOf(typeof(DataGridViewTextBoxEditingControl))));
}
}

Expand Down Expand Up @@ -4056,6 +4059,21 @@ public virtual Rectangle PositionEditingPanel(Rectangle cellBounds,
return new Rectangle(xEditingControl, yEditingControl, wEditingControl, hEditingControl);
}

internal virtual void ReleaseUiaProvider()
{
if (!IsAccessibilityObjectCreated)
{
return;
}

if (OsVersion.IsWindows8OrGreater())
{
UiaCore.UiaDisconnectProvider(AccessibilityObject);
}

Properties.SetObject(s_propCellAccessibilityObject, null);
}

protected virtual bool SetValue(int rowIndex, object value)
{
object originalValue = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,17 @@ internal void RemoveAtInternal(int index, bool force)
Debug.Assert(!DataGridView.InDisplayIndexAdjustments);

DataGridViewColumn dataGridViewColumn = _items[index];

if (DataGridView.IsAccessibilityObjectCreated && OsVersion.IsWindows8OrGreater())
{
foreach (DataGridViewRow row in DataGridView.Rows)
{
row.Cells[index].ReleaseUiaProvider();
}

dataGridViewColumn.HeaderCell.ReleaseUiaProvider();
}

DataGridView.OnRemovingColumn(dataGridViewColumn, out Point newCurrentCell, force);
InvalidateCachedColumnsOrder();
_items.RemoveAt(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,13 @@ public override object ParseFormattedValue(
}
}

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

base.ReleaseUiaProvider();
}

/// <summary>
/// Gets the row Index and column Index of the cell.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public DataGridViewComboBoxEditingControlAccessibleObject(DataGridViewComboBoxEd
_ownerControl = ownerControl;
}

internal void ClearParent()
{
_parentAccessibleObject = null;
}

public override AccessibleObject? Parent
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,20 @@ protected override void OnHandleCreated(EventArgs e)
base.OnHandleCreated(e);

// The null-check was added as a fix for a https://github.com/dotnet/winforms/issues/2138
_dataGridView?.SetAccessibleObjectParent(AccessibilityObject);
if (_dataGridView?.IsAccessibilityObjectCreated == true)
{
_dataGridView.SetAccessibleObjectParent(AccessibilityObject);
}
}

internal override void ReleaseUiaProvider(nint handle)
{
if (TryGetAccessibilityObject(out AccessibleObject accessibleObject))
{
((DataGridViewComboBoxEditingControlAccessibleObject)accessibleObject).ClearParent();
}

base.ReleaseUiaProvider(handle);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ public override DataGridViewCellStyle InheritedStyle
}
}

internal bool IsAccessibilityObjectCreated => Properties.GetObject(s_propRowAccessibilityObject) is AccessibleObject;

[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsNewRow
Expand Down Expand Up @@ -1728,6 +1730,21 @@ protected internal virtual void PaintHeader(Graphics graphics,
}
}

internal void ReleaseUiaProvider()
{
if (!IsAccessibilityObjectCreated)
{
return;
}

if (OsVersion.IsWindows8OrGreater())
{
Interop.UiaCore.UiaDisconnectProvider(AccessibilityObject);
}

Properties.SetObject(s_propRowAccessibilityObject, null);
}

internal void SetReadOnlyCellCore(DataGridViewCell dataGridViewCell, bool readOnly)
{
Debug.Assert(Index == -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,17 @@ public virtual void RemoveAt(int index)
throw new InvalidOperationException(SR.DataGridView_ForbiddenOperationInEventHandler);
}

if (DataGridView.IsAccessibilityObjectCreated && OsVersion.IsWindows8OrGreater() && this[index] is DataGridViewRow row)
{
foreach (DataGridViewCell cell in row.Cells)
{
cell.ReleaseUiaProvider();
}

row.HeaderCell.ReleaseUiaProvider();
row.ReleaseUiaProvider();
}

if (DataGridView.DataSource is not null)
{
if (DataGridView.DataConnection.List is IBindingList list && list.AllowRemove && list.SupportsChangeNotification)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ internal class DataGridViewTextBoxEditingControlAccessibleObject : TextBoxBaseAc
public DataGridViewTextBoxEditingControlAccessibleObject(DataGridViewTextBoxEditingControl ownerControl) : base(ownerControl)
{ }

internal void ClearParent()
{
_parentAccessibleObject = null;
}

public override AccessibleObject? Parent => _parentAccessibleObject;

public override string Name => Owner.AccessibleName ?? SR.DataGridView_AccEditingControlAccName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public virtual bool RepositionEditingControlOnValueChange
}
}

internal override bool SupportsUiaProviders => true;

public virtual void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
ArgumentNullException.ThrowIfNull(dataGridViewCellStyle);
Expand Down Expand Up @@ -287,6 +285,16 @@ protected override bool ProcessKeyEventArgs(ref Message m)
return base.ProcessKeyEventArgs(ref m);
}

internal override void ReleaseUiaProvider(nint handle)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion - consider unifying argument in this method to nint in the next PR.

Copy link
Contributor

@NikitaSemenovAkvelon NikitaSemenovAkvelon Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to use nint instead of IntPtr in all overrides of the ReleaseUiaProvider method?

Copy link
Contributor

@Tanya-Solyanik Tanya-Solyanik Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to use nint instead of IntPtr in all overrides of the ReleaseUiaProvider method

yes and don't use IntPtr.Zero as input

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK to provide 0 as the default value? I mean ReleaseUiaProvider(nint handle = 0)?

{
if (TryGetAccessibilityObject(out AccessibleObject? accessibleObject))
{
((DataGridViewTextBoxEditingControlAccessibleObject)accessibleObject).ClearParent();
}

base.ReleaseUiaProvider(handle);
}

private static HorizontalAlignment TranslateAlignment(DataGridViewContentAlignment align)
{
if ((align & AnyRight) != 0)
Expand All @@ -306,10 +314,11 @@ private static HorizontalAlignment TranslateAlignment(DataGridViewContentAlignme
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (IsHandleCreated)

// The null-check was added as a fix for a https://github.com/dotnet/winforms/issues/2138
if (IsHandleCreated && _dataGridView?.IsAccessibilityObjectCreated == true)
{
// The null-check was added as a fix for a https://github.com/dotnet/winforms/issues/2138
_dataGridView?.SetAccessibleObjectParent(AccessibilityObject);
_dataGridView.SetAccessibleObjectParent(AccessibilityObject);
}
}
}
Expand Down