2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
- using System . Diagnostics ;
5
+ using System . Drawing ;
6
6
using System . Runtime . InteropServices ;
7
7
using static Interop ;
8
8
@@ -12,57 +12,57 @@ internal class ListViewLabelEditAccessibleObject : AccessibleObject
12
12
{
13
13
private const string LIST_VIEW_LABEL_EDIT_AUTOMATION_ID = "1" ;
14
14
15
- private ListView _owner ;
16
- private IntPtr _handle ;
15
+ private readonly ListView _owningListView ;
16
+ private readonly IntPtr _handle ;
17
+ private readonly ListViewLabelEditUiaTextProvider _textProvider ;
17
18
private int [ ] ? _runtimeId ;
18
19
19
- public ListViewLabelEditAccessibleObject ( ListView owner , IHandle handle )
20
+ public ListViewLabelEditAccessibleObject ( ListView owningListView , IHandle handle )
20
21
{
21
- _owner = owner ;
22
+ _owningListView = owningListView . OrThrowIfNull ( ) ;
22
23
_handle = handle . Handle ;
23
24
UseStdAccessibleObjects ( _handle ) ;
25
+ _textProvider = new ListViewLabelEditUiaTextProvider ( owningListView , handle , this ) ;
26
+ }
27
+
28
+ private protected override string AutomationId => LIST_VIEW_LABEL_EDIT_AUTOMATION_ID ;
29
+
30
+ internal override UiaCore . IRawElementProviderFragment ? FragmentNavigate ( UiaCore . NavigateDirection direction )
31
+ {
32
+ AccessibleObject parent = _owningListView . AccessibilityObject ;
24
33
25
- ListViewLabelEditUiaTextProvider textProvider = new ( owner , handle , this ) ;
26
- UseTextProviders ( textProvider , textProvider ) ;
34
+ return direction switch
35
+ {
36
+ UiaCore . NavigateDirection . Parent => parent ,
37
+ UiaCore . NavigateDirection . NextSibling => parent . GetChildIndex ( this ) is int childId and >= 0 ? parent . GetChild ( childId + 1 ) : null ,
38
+ UiaCore . NavigateDirection . PreviousSibling => parent . GetChildIndex ( this ) is int childId and >= 0 ? parent . GetChild ( childId - 1 ) : null ,
39
+ _ => base . FragmentNavigate ( direction ) ,
40
+ } ;
27
41
}
28
42
43
+ internal override UiaCore . IRawElementProviderFragmentRoot FragmentRoot => _owningListView . AccessibilityObject ;
44
+
29
45
internal override object ? GetPropertyValue ( UiaCore . UIA propertyID )
30
46
=> propertyID switch
31
47
{
32
- UiaCore . UIA . RuntimeIdPropertyId => RuntimeId ,
33
- UiaCore . UIA . BoundingRectanglePropertyId => Bounds ,
34
48
UiaCore . UIA . ProcessIdPropertyId => Environment . ProcessId ,
35
49
UiaCore . UIA . ControlTypePropertyId => UiaCore . UIA . EditControlTypeId ,
36
- UiaCore . UIA . NamePropertyId => Name ,
37
50
UiaCore . UIA . AccessKeyPropertyId => string . Empty ,
38
51
UiaCore . UIA . HasKeyboardFocusPropertyId => true ,
39
52
UiaCore . UIA . IsKeyboardFocusablePropertyId => ( State & AccessibleStates . Focusable ) == AccessibleStates . Focusable ,
40
- UiaCore . UIA . IsEnabledPropertyId => Enabled ,
41
- UiaCore . UIA . AutomationIdPropertyId => LIST_VIEW_LABEL_EDIT_AUTOMATION_ID ,
42
- UiaCore . UIA . HelpTextPropertyId => Help ?? string . Empty ,
53
+ UiaCore . UIA . IsEnabledPropertyId => _owningListView . Enabled ,
43
54
UiaCore . UIA . IsContentElementPropertyId => true ,
44
- UiaCore . UIA . IsPasswordPropertyId => false ,
45
55
UiaCore . UIA . NativeWindowHandlePropertyId => _handle ,
46
- UiaCore . UIA . IsOffscreenPropertyId => false ,
47
- UiaCore . UIA . IsTextPatternAvailablePropertyId => IsPatternSupported ( UiaCore . UIA . TextPatternId ) ,
48
- UiaCore . UIA . IsTextPattern2AvailablePropertyId => IsPatternSupported ( UiaCore . UIA . TextPattern2Id ) ,
49
- UiaCore . UIA . IsValuePatternAvailablePropertyId => IsPatternSupported ( UiaCore . UIA . ValuePatternId ) ,
50
- UiaCore . UIA . IsLegacyIAccessiblePatternAvailablePropertyId => IsPatternSupported ( UiaCore . UIA . LegacyIAccessiblePatternId ) ,
51
56
_ => base . GetPropertyValue ( propertyID ) ,
52
57
} ;
53
58
54
- internal override UiaCore . IRawElementProviderFragment ? FragmentNavigate ( UiaCore . NavigateDirection direction )
59
+ internal override UiaCore . IRawElementProviderSimple ? HostRawElementProvider
55
60
{
56
- AccessibleObject parent = _owner . AccessibilityObject ;
57
-
58
- return direction switch
61
+ get
59
62
{
60
- UiaCore . NavigateDirection . Parent => parent ,
61
- UiaCore . NavigateDirection . NextSibling => parent . GetChildIndex ( this ) is int childId and >= 0 ? parent . GetChild ( childId + 1 ) : null ,
62
- UiaCore . NavigateDirection . PreviousSibling => parent . GetChildIndex ( this ) is int childId and >= 0 ? parent . GetChild ( childId - 1 ) : null ,
63
- UiaCore . NavigateDirection . FirstChild or UiaCore . NavigateDirection . LastChild => null ,
64
- _ => base . FragmentNavigate ( direction ) ,
65
- } ;
63
+ UiaCore . UiaHostProviderFromHwnd ( new HandleRef ( this , _handle ) , out UiaCore . IRawElementProviderSimple provider ) ;
64
+ return provider ;
65
+ }
66
66
}
67
67
68
68
internal override bool IsPatternSupported ( UiaCore . UIA patternId ) => patternId switch
@@ -74,28 +74,32 @@ public ListViewLabelEditAccessibleObject(ListView owner, IHandle handle)
74
74
_ => base . IsPatternSupported ( patternId ) ,
75
75
} ;
76
76
77
+ public override string Name => User32 . GetWindowText ( _handle ) ;
78
+
77
79
internal override int [ ] RuntimeId => _runtimeId ??= new int [ ] { RuntimeIDFirstItem , PARAM . ToInt ( _handle ) } ;
78
80
79
- internal override UiaCore . IRawElementProviderFragmentRoot ? FragmentRoot => _owner . AccessibilityObject ;
81
+ internal override UiaCore . ITextRangeProvider DocumentRangeInternal
82
+ => _textProvider . DocumentRange ;
80
83
81
- internal override UiaCore . IRawElementProviderSimple ? HostRawElementProvider
82
- {
83
- get
84
- {
85
- UiaCore . UiaHostProviderFromHwnd ( new HandleRef ( this , _handle ) , out UiaCore . IRawElementProviderSimple provider ) ;
86
- return provider ;
87
- }
88
- }
84
+ internal override UiaCore . ITextRangeProvider [ ] ? GetTextSelection ( )
85
+ => _textProvider . GetSelection ( ) ;
89
86
90
- public override string Name => User32 . GetWindowText ( _handle ) ;
87
+ internal override UiaCore . ITextRangeProvider [ ] ? GetTextVisibleRanges ( )
88
+ => _textProvider . GetVisibleRanges ( ) ;
91
89
92
- private bool Enabled
93
- {
94
- get
95
- {
96
- Debug . Assert ( _owner . Enabled ) ;
97
- return _owner . Enabled ;
98
- }
99
- }
90
+ internal override UiaCore . ITextRangeProvider ? GetTextRangeFromChild ( UiaCore . IRawElementProviderSimple childElement )
91
+ => _textProvider . RangeFromChild ( childElement ) ;
92
+
93
+ internal override UiaCore . ITextRangeProvider ? GetTextRangeFromPoint ( Point screenLocation )
94
+ => _textProvider . RangeFromPoint ( screenLocation ) ;
95
+
96
+ internal override UiaCore . SupportedTextSelection SupportedTextSelectionInternal
97
+ => _textProvider . SupportedTextSelection ;
98
+
99
+ internal override UiaCore . ITextRangeProvider ? GetTextCaretRange ( out BOOL isActive )
100
+ => _textProvider . GetCaretRange ( out isActive ) ;
101
+
102
+ internal override UiaCore . ITextRangeProvider GetRangeFromAnnotation ( UiaCore . IRawElementProviderSimple annotationElement )
103
+ => _textProvider . RangeFromAnnotation ( annotationElement ) ;
100
104
}
101
105
}
0 commit comments