Skip to content

Commit 0479a3e

Browse files
Move sub-classes of "ColumnHeader" and "ErrorProvider" classes to their own files (#4605)
1 parent 6b578d2 commit 0479a3e

10 files changed

+1325
-1260
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#nullable disable
6+
7+
using System.Diagnostics;
8+
9+
namespace System.Windows.Forms
10+
{
11+
public partial class ColumnHeader
12+
{
13+
internal class ColumnHeaderImageListIndexer : ImageList.Indexer
14+
{
15+
private readonly ColumnHeader _owner;
16+
17+
public ColumnHeaderImageListIndexer(ColumnHeader ch)
18+
{
19+
_owner = ch;
20+
}
21+
22+
public override ImageList ImageList
23+
{
24+
get
25+
{
26+
return _owner.ListView?.SmallImageList;
27+
}
28+
set
29+
{
30+
Debug.Assert(false, "We should never set the image list");
31+
}
32+
}
33+
}
34+
}
35+
}

src/System.Windows.Forms/src/System/Windows/Forms/ColumnHeader.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -511,27 +511,5 @@ public override string ToString()
511511
{
512512
return $"{nameof(ColumnHeader)}: Text: {Text}";
513513
}
514-
515-
internal class ColumnHeaderImageListIndexer : ImageList.Indexer
516-
{
517-
private readonly ColumnHeader _owner;
518-
519-
public ColumnHeaderImageListIndexer(ColumnHeader ch)
520-
{
521-
_owner = ch;
522-
}
523-
524-
public override ImageList ImageList
525-
{
526-
get
527-
{
528-
return _owner.ListView?.SmallImageList;
529-
}
530-
set
531-
{
532-
Debug.Assert(false, "We should never set the image list");
533-
}
534-
}
535-
}
536514
}
537515
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#nullable disable
6+
7+
using System.Drawing;
8+
using static Interop;
9+
10+
namespace System.Windows.Forms
11+
{
12+
partial class ErrorProvider
13+
{
14+
internal partial class ControlItem
15+
{
16+
private class ControlItemAccessibleObject : AccessibleObject
17+
{
18+
private readonly ControlItem _controlItem;
19+
private readonly ErrorWindow _window;
20+
private readonly Control _control;
21+
private readonly ErrorProvider _provider;
22+
23+
public ControlItemAccessibleObject(ControlItem controlItem, ErrorWindow window, Control control, ErrorProvider provider)
24+
{
25+
_controlItem = controlItem;
26+
_window = window;
27+
_control = control;
28+
_provider = provider;
29+
}
30+
31+
internal override Rectangle BoundingRectangle => Bounds;
32+
33+
public override Rectangle Bounds => _control.IsHandleCreated ?
34+
_control.RectangleToScreen(_controlItem.GetIconBounds(_provider.Region.Size)) : Rectangle.Empty;
35+
36+
private int ControlItemsCount => _window.ControlItems.Count;
37+
38+
private int CurrentIndex => _window.ControlItems.IndexOf(_controlItem);
39+
40+
/// <summary>
41+
/// Returns the element in the specified direction.
42+
/// </summary>
43+
/// <param name="direction">Indicates the direction in which to navigate.</param>
44+
/// <returns>Returns the element in the specified direction.</returns>
45+
internal override UiaCore.IRawElementProviderFragment FragmentNavigate(UiaCore.NavigateDirection direction)
46+
{
47+
switch (direction)
48+
{
49+
case UiaCore.NavigateDirection.Parent:
50+
return Parent;
51+
case UiaCore.NavigateDirection.NextSibling:
52+
return GetNextSibling();
53+
case UiaCore.NavigateDirection.PreviousSibling:
54+
return GetPreviousSibling();
55+
default:
56+
return base.FragmentNavigate(direction);
57+
}
58+
}
59+
60+
internal override UiaCore.IRawElementProviderFragmentRoot FragmentRoot => Parent;
61+
62+
internal override int GetChildId()
63+
{
64+
return CurrentIndex + 1;
65+
}
66+
67+
private AccessibleObject GetNextSibling()
68+
{
69+
int currentIndex = CurrentIndex;
70+
71+
//Is a last child
72+
if (currentIndex >= ControlItemsCount - 1 || currentIndex < 0)
73+
{
74+
return null;
75+
}
76+
77+
return _window.ControlItems[currentIndex + 1].AccessibilityObject;
78+
}
79+
80+
private AccessibleObject GetPreviousSibling()
81+
{
82+
int currentIndex = CurrentIndex;
83+
84+
//Is a first child
85+
if (currentIndex <= 0 || currentIndex > ControlItemsCount - 1)
86+
{
87+
return null;
88+
}
89+
90+
return _window.ControlItems[currentIndex - 1].AccessibilityObject;
91+
}
92+
93+
/// <summary>
94+
/// Gets the accessible property value.
95+
/// </summary>
96+
/// <param name="propertyID">The accessible property ID.</param>
97+
/// <returns>The accessible property value.</returns>
98+
internal override object GetPropertyValue(UiaCore.UIA propertyID)
99+
{
100+
switch (propertyID)
101+
{
102+
case UiaCore.UIA.RuntimeIdPropertyId:
103+
return RuntimeId;
104+
case UiaCore.UIA.ControlTypePropertyId:
105+
return UiaCore.UIA.ImageControlTypeId;
106+
case UiaCore.UIA.BoundingRectanglePropertyId:
107+
return BoundingRectangle;
108+
case UiaCore.UIA.NamePropertyId:
109+
return Name;
110+
case UiaCore.UIA.HelpTextPropertyId:
111+
return Help;
112+
case UiaCore.UIA.LegacyIAccessibleStatePropertyId:
113+
return State;
114+
case UiaCore.UIA.NativeWindowHandlePropertyId:
115+
return _window.Handle;
116+
case UiaCore.UIA.IsLegacyIAccessiblePatternAvailablePropertyId:
117+
return IsPatternSupported(UiaCore.UIA.LegacyIAccessiblePatternId);
118+
default:
119+
return base.GetPropertyValue(propertyID);
120+
}
121+
}
122+
123+
internal override bool IsIAccessibleExSupported()
124+
{
125+
if (_controlItem != null)
126+
{
127+
return true;
128+
}
129+
130+
return base.IsIAccessibleExSupported();
131+
}
132+
133+
internal override bool IsPatternSupported(UiaCore.UIA patternId)
134+
{
135+
if (patternId == UiaCore.UIA.LegacyIAccessiblePatternId)
136+
{
137+
return true;
138+
}
139+
140+
return base.IsPatternSupported(patternId);
141+
}
142+
143+
internal override bool IsReadOnly => true;
144+
145+
public override string Name
146+
{
147+
get => string.IsNullOrEmpty(base.Name) ? _controlItem.Error : base.Name;
148+
set => base.Name = value;
149+
}
150+
151+
public override AccessibleObject Parent => _window.AccessibilityObject;
152+
153+
public override AccessibleRole Role => AccessibleRole.Alert;
154+
155+
/// <summary>
156+
/// Gets the runtime ID.
157+
/// </summary>
158+
internal override int[] RuntimeId
159+
{
160+
get
161+
{
162+
var runtimeId = new int[4];
163+
164+
runtimeId[0] = _window.AccessibilityObject.RuntimeId[0];
165+
runtimeId[1] = _window.AccessibilityObject.RuntimeId[1];
166+
runtimeId[2] = _window.AccessibilityObject.RuntimeId[2];
167+
runtimeId[3] = _controlItem.GetHashCode();
168+
169+
return runtimeId;
170+
}
171+
}
172+
173+
public override AccessibleStates State => AccessibleStates.HasPopup | AccessibleStates.ReadOnly;
174+
}
175+
}
176+
}
177+
}

0 commit comments

Comments
 (0)