-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathTextPattern.cs
216 lines (198 loc) · 11.4 KB
/
TextPattern.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// (c) Copyright Microsoft, 2012.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
// All other rights reserved.
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Automation.Text;
using UIAComWrapperInternal;
using UIAutomationClient = Interop.UIAutomationClient;
namespace System.Windows.Automation
{
public class TextPattern : BasePattern
{
private UIAutomationClient.IUIAutomationTextPattern _pattern;
public static readonly AutomationPattern Pattern = TextPatternIdentifiers.Pattern;
public static readonly AutomationTextAttribute AnimationStyleAttribute = TextPatternIdentifiers.AnimationStyleAttribute;
public static readonly AutomationTextAttribute BackgroundColorAttribute = TextPatternIdentifiers.BackgroundColorAttribute;
public static readonly AutomationTextAttribute BulletStyleAttribute = TextPatternIdentifiers.BulletStyleAttribute;
public static readonly AutomationTextAttribute CapStyleAttribute = TextPatternIdentifiers.CapStyleAttribute;
public static readonly AutomationTextAttribute CultureAttribute = TextPatternIdentifiers.CultureAttribute;
public static readonly AutomationTextAttribute FontNameAttribute = TextPatternIdentifiers.FontNameAttribute;
public static readonly AutomationTextAttribute FontSizeAttribute = TextPatternIdentifiers.FontSizeAttribute;
public static readonly AutomationTextAttribute FontWeightAttribute = TextPatternIdentifiers.FontWeightAttribute;
public static readonly AutomationTextAttribute ForegroundColorAttribute = TextPatternIdentifiers.ForegroundColorAttribute;
public static readonly AutomationTextAttribute HorizontalTextAlignmentAttribute = TextPatternIdentifiers.HorizontalTextAlignmentAttribute;
public static readonly AutomationTextAttribute IndentationFirstLineAttribute = TextPatternIdentifiers.IndentationFirstLineAttribute;
public static readonly AutomationTextAttribute IndentationLeadingAttribute = TextPatternIdentifiers.IndentationLeadingAttribute;
public static readonly AutomationTextAttribute IndentationTrailingAttribute = TextPatternIdentifiers.IndentationTrailingAttribute;
public static readonly AutomationTextAttribute IsHiddenAttribute = TextPatternIdentifiers.IsHiddenAttribute;
public static readonly AutomationTextAttribute IsItalicAttribute = TextPatternIdentifiers.IsItalicAttribute;
public static readonly AutomationTextAttribute IsReadOnlyAttribute = TextPatternIdentifiers.IsReadOnlyAttribute;
public static readonly AutomationTextAttribute IsSubscriptAttribute = TextPatternIdentifiers.IsSubscriptAttribute;
public static readonly AutomationTextAttribute IsSuperscriptAttribute = TextPatternIdentifiers.IsSuperscriptAttribute;
public static readonly AutomationTextAttribute MarginBottomAttribute = TextPatternIdentifiers.MarginBottomAttribute;
public static readonly AutomationTextAttribute MarginLeadingAttribute = TextPatternIdentifiers.MarginLeadingAttribute;
public static readonly AutomationTextAttribute MarginTopAttribute = TextPatternIdentifiers.MarginTopAttribute;
public static readonly AutomationTextAttribute MarginTrailingAttribute = TextPatternIdentifiers.MarginTrailingAttribute;
public static readonly object MixedAttributeValue = TextPatternIdentifiers.MixedAttributeValue;
public static readonly AutomationTextAttribute OutlineStylesAttribute = TextPatternIdentifiers.OutlineStylesAttribute;
public static readonly AutomationTextAttribute OverlineColorAttribute = TextPatternIdentifiers.OverlineColorAttribute;
public static readonly AutomationTextAttribute OverlineStyleAttribute = TextPatternIdentifiers.OverlineStyleAttribute;
public static readonly AutomationTextAttribute StrikethroughColorAttribute = TextPatternIdentifiers.StrikethroughColorAttribute;
public static readonly AutomationTextAttribute StrikethroughStyleAttribute = TextPatternIdentifiers.StrikethroughStyleAttribute;
public static readonly AutomationTextAttribute TabsAttribute = TextPatternIdentifiers.TabsAttribute;
public static readonly AutomationEvent TextChangedEvent = TextPatternIdentifiers.TextChangedEvent;
public static readonly AutomationTextAttribute TextFlowDirectionsAttribute = TextPatternIdentifiers.TextFlowDirectionsAttribute;
public static readonly AutomationEvent TextSelectionChangedEvent = TextPatternIdentifiers.TextSelectionChangedEvent;
public static readonly AutomationTextAttribute UnderlineColorAttribute = TextPatternIdentifiers.UnderlineColorAttribute;
public static readonly AutomationTextAttribute UnderlineStyleAttribute = TextPatternIdentifiers.UnderlineStyleAttribute;
protected TextPattern(AutomationElement el, UIAutomationClient.IUIAutomationTextPattern pattern, bool cached)
: base(el, cached)
{
Debug.Assert(pattern != null);
this._pattern = pattern;
}
internal static object Wrap(AutomationElement el, object pattern, bool cached)
{
return (pattern == null) ? null : new TextPattern(el, (UIAutomationClient.IUIAutomationTextPattern)pattern, cached);
}
public TextPatternRange[] GetSelection()
{
try
{
return TextPatternRange.Wrap(this._pattern.GetSelection(), this);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public TextPatternRange[] GetVisibleRanges()
{
try
{
return TextPatternRange.Wrap(this._pattern.GetVisibleRanges(), this);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public TextPatternRange RangeFromChild(AutomationElement childElement)
{
Utility.ValidateArgumentNonNull(childElement, "childElement");
try
{
return TextPatternRange.Wrap(this._pattern.RangeFromChild(childElement.NativeElement), this);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public TextPatternRange RangeFromPoint(Point screenLocation)
{
try
{
return TextPatternRange.Wrap(this._pattern.RangeFromPoint(Utility.PointManagedToNative(screenLocation)), this);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public TextPatternRange DocumentRange
{
get
{
try
{
return TextPatternRange.Wrap(this._pattern.DocumentRange, this);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
}
public SupportedTextSelection SupportedTextSelection
{
get
{
try
{
return (SupportedTextSelection)this._pattern.SupportedTextSelection;
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
}
}
public class TextPattern2 : TextPattern
{
private UIAutomationClient.IUIAutomationTextPattern2 _pattern;
public static readonly new AutomationPattern Pattern = TextPattern2Identifiers.Pattern;
public static readonly AutomationTextAttribute AnnotationTypesAttribute = TextPattern2Identifiers.AnnotationTypesAttribute;
public static readonly AutomationTextAttribute AnnotationObjectsAttribute = TextPattern2Identifiers.AnnotationObjectsAttribute;
public static readonly AutomationTextAttribute StyleNameAttribute = TextPattern2Identifiers.StyleNameAttribute;
public static readonly AutomationTextAttribute StyleIdAttribute = TextPattern2Identifiers.StyleIdAttribute;
public static readonly AutomationTextAttribute LinkAttribute = TextPattern2Identifiers.LinkAttribute;
public static readonly AutomationTextAttribute IsActiveAttribute = TextPattern2Identifiers.IsActiveAttribute;
public static readonly AutomationTextAttribute SelectionActiveEndAttribute = TextPattern2Identifiers.SelectionActiveEndAttribute;
public static readonly AutomationTextAttribute CaretPositionAttribute = TextPattern2Identifiers.CaretPositionAttribute;
public static readonly AutomationTextAttribute CaretBidiModeAttribute = TextPattern2Identifiers.CaretBidiModeAttribute;
private TextPattern2(AutomationElement el, UIAutomationClient.IUIAutomationTextPattern2 pattern, UIAutomationClient.IUIAutomationTextPattern basePattern, bool cached)
: base(el, basePattern, cached)
{
Debug.Assert(pattern != null);
this._pattern = pattern;
}
internal static new object Wrap(AutomationElement el, object pattern, bool cached)
{
TextPattern2 result = null;
if (pattern != null)
{
UIAutomationClient.IUIAutomationTextPattern basePattern =
(UIAutomationClient.IUIAutomationTextPattern)el.GetRawPattern(TextPattern.Pattern, cached);
if (basePattern != null)
{
result = new TextPattern2(el, (UIAutomationClient.IUIAutomationTextPattern2)pattern,
basePattern, cached);
}
}
return result;
}
public TextPatternRange RangeFromAnnotation(AutomationElement annotation)
{
Utility.ValidateArgumentNonNull(annotation, "annotation");
try
{
return TextPatternRange.Wrap(this._pattern.RangeFromAnnotation(annotation.NativeElement), this);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public TextPatternRange GetCaretRange(out bool isActive)
{
try
{
int intIsActive;
TextPatternRange caretRange = TextPatternRange.Wrap(
this._pattern.GetCaretRange(out intIsActive), this);
isActive = (intIsActive != 0);
return caretRange;
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
}
}