-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathAutomationElement.cs
More file actions
860 lines (787 loc) · 36.6 KB
/
AutomationElement.cs
File metadata and controls
860 lines (787 loc) · 36.6 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
// (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.Collections.Generic;
using System.Diagnostics;
using Interop.UIAutomationClient;
using UIAutomationClient = Interop.UIAutomationClient;
using UIAComWrapperInternal;
namespace System.Windows.Automation
{
public enum AutomationElementMode
{
None,
Full
}
public sealed class AutomationElement
{
private UIAutomationClient.IUIAutomationElement _obj;
public static readonly AutomationProperty AcceleratorKeyProperty = AutomationElementIdentifiers.AcceleratorKeyProperty;
public static readonly AutomationProperty AccessKeyProperty = AutomationElementIdentifiers.AccessKeyProperty;
public static readonly AutomationEvent AsyncContentLoadedEvent = AutomationElementIdentifiers.AsyncContentLoadedEvent;
public static readonly AutomationEvent AutomationFocusChangedEvent = AutomationElementIdentifiers.AutomationFocusChangedEvent;
public static readonly AutomationProperty AutomationIdProperty = AutomationElementIdentifiers.AutomationIdProperty;
public static readonly AutomationEvent AutomationPropertyChangedEvent = AutomationElementIdentifiers.AutomationPropertyChangedEvent;
public static readonly AutomationProperty BoundingRectangleProperty = AutomationElementIdentifiers.BoundingRectangleProperty;
public static readonly AutomationProperty ClassNameProperty = AutomationElementIdentifiers.ClassNameProperty;
public static readonly AutomationProperty ClickablePointProperty = AutomationElementIdentifiers.ClickablePointProperty;
public static readonly AutomationProperty ControlTypeProperty = AutomationElementIdentifiers.ControlTypeProperty;
public static readonly AutomationProperty CultureProperty = AutomationElementIdentifiers.CultureProperty;
public static readonly AutomationProperty FrameworkIdProperty = AutomationElementIdentifiers.FrameworkIdProperty;
public static readonly AutomationProperty HasKeyboardFocusProperty = AutomationElementIdentifiers.HasKeyboardFocusProperty;
public static readonly AutomationProperty HelpTextProperty = AutomationElementIdentifiers.HelpTextProperty;
public static readonly AutomationProperty IsContentElementProperty = AutomationElementIdentifiers.IsContentElementProperty;
public static readonly AutomationProperty IsControlElementProperty = AutomationElementIdentifiers.IsControlElementProperty;
public static readonly AutomationProperty IsDockPatternAvailableProperty = AutomationElementIdentifiers.IsDockPatternAvailableProperty;
public static readonly AutomationProperty IsEnabledProperty = AutomationElementIdentifiers.IsEnabledProperty;
public static readonly AutomationProperty IsExpandCollapsePatternAvailableProperty = AutomationElementIdentifiers.IsExpandCollapsePatternAvailableProperty;
public static readonly AutomationProperty IsGridItemPatternAvailableProperty = AutomationElementIdentifiers.IsGridItemPatternAvailableProperty;
public static readonly AutomationProperty IsGridPatternAvailableProperty = AutomationElementIdentifiers.IsGridPatternAvailableProperty;
public static readonly AutomationProperty IsInvokePatternAvailableProperty = AutomationElementIdentifiers.IsInvokePatternAvailableProperty;
public static readonly AutomationProperty IsKeyboardFocusableProperty = AutomationElementIdentifiers.IsKeyboardFocusableProperty;
public static readonly AutomationProperty IsMultipleViewPatternAvailableProperty = AutomationElementIdentifiers.IsMultipleViewPatternAvailableProperty;
public static readonly AutomationProperty IsOffscreenProperty = AutomationElementIdentifiers.IsOffscreenProperty;
public static readonly AutomationProperty IsPasswordProperty = AutomationElementIdentifiers.IsPasswordProperty;
public static readonly AutomationProperty IsRangeValuePatternAvailableProperty = AutomationElementIdentifiers.IsRangeValuePatternAvailableProperty;
public static readonly AutomationProperty IsRequiredForFormProperty = AutomationElementIdentifiers.IsRequiredForFormProperty;
public static readonly AutomationProperty IsScrollItemPatternAvailableProperty = AutomationElementIdentifiers.IsScrollItemPatternAvailableProperty;
public static readonly AutomationProperty IsScrollPatternAvailableProperty = AutomationElementIdentifiers.IsScrollPatternAvailableProperty;
public static readonly AutomationProperty IsSelectionItemPatternAvailableProperty = AutomationElementIdentifiers.IsSelectionItemPatternAvailableProperty;
public static readonly AutomationProperty IsSelectionPatternAvailableProperty = AutomationElementIdentifiers.IsSelectionPatternAvailableProperty;
public static readonly AutomationProperty IsTableItemPatternAvailableProperty = AutomationElementIdentifiers.IsTableItemPatternAvailableProperty;
public static readonly AutomationProperty IsTablePatternAvailableProperty = AutomationElementIdentifiers.IsTablePatternAvailableProperty;
public static readonly AutomationProperty IsTextPatternAvailableProperty = AutomationElementIdentifiers.IsTextPatternAvailableProperty;
public static readonly AutomationProperty IsTogglePatternAvailableProperty = AutomationElementIdentifiers.IsTogglePatternAvailableProperty;
public static readonly AutomationProperty IsTransformPatternAvailableProperty = AutomationElementIdentifiers.IsTransformPatternAvailableProperty;
public static readonly AutomationProperty IsValuePatternAvailableProperty = AutomationElementIdentifiers.IsValuePatternAvailableProperty;
public static readonly AutomationProperty IsWindowPatternAvailableProperty = AutomationElementIdentifiers.IsWindowPatternAvailableProperty;
public static readonly AutomationProperty ItemStatusProperty = AutomationElementIdentifiers.ItemStatusProperty;
public static readonly AutomationProperty ItemTypeProperty = AutomationElementIdentifiers.ItemTypeProperty;
public static readonly AutomationProperty LabeledByProperty = AutomationElementIdentifiers.LabeledByProperty;
public static readonly AutomationEvent LayoutInvalidatedEvent = AutomationElementIdentifiers.LayoutInvalidatedEvent;
public static readonly AutomationProperty LocalizedControlTypeProperty = AutomationElementIdentifiers.LocalizedControlTypeProperty;
public static readonly AutomationEvent MenuClosedEvent = AutomationElementIdentifiers.MenuClosedEvent;
public static readonly AutomationEvent MenuOpenedEvent = AutomationElementIdentifiers.MenuOpenedEvent;
public static readonly AutomationProperty NameProperty = AutomationElementIdentifiers.NameProperty;
public static readonly AutomationProperty NativeWindowHandleProperty = AutomationElementIdentifiers.NativeWindowHandleProperty;
public static readonly object NotSupported = AutomationElementIdentifiers.NotSupported;
public static readonly AutomationProperty OrientationProperty = AutomationElementIdentifiers.OrientationProperty;
public static readonly AutomationProperty ProcessIdProperty = AutomationElementIdentifiers.ProcessIdProperty;
public static readonly AutomationProperty RuntimeIdProperty = AutomationElementIdentifiers.RuntimeIdProperty;
public static readonly AutomationEvent StructureChangedEvent = AutomationElementIdentifiers.StructureChangedEvent;
public static readonly AutomationEvent ToolTipClosedEvent = AutomationElementIdentifiers.ToolTipClosedEvent;
public static readonly AutomationEvent ToolTipOpenedEvent = AutomationElementIdentifiers.ToolTipOpenedEvent;
public static readonly AutomationProperty IsLegacyIAccessiblePatternAvailableProperty = AutomationElementIdentifiers.IsLegacyIAccessiblePatternAvailableProperty;
public static readonly AutomationProperty IsItemContainerPatternAvailableProperty = AutomationElementIdentifiers.IsItemContainerPatternAvailableProperty;
public static readonly AutomationProperty IsVirtualizedItemPatternAvailableProperty = AutomationElementIdentifiers.IsVirtualizedItemPatternAvailableProperty;
public static readonly AutomationProperty IsSynchronizedInputPatternAvailableProperty = AutomationElementIdentifiers.IsSynchronizedInputPatternAvailableProperty;
public static readonly AutomationProperty AriaRoleProperty = AutomationElementIdentifiers.AriaRoleProperty;
public static readonly AutomationProperty AriaPropertiesProperty = AutomationElementIdentifiers.AriaPropertiesProperty;
public static readonly AutomationProperty IsDataValidForFormProperty = AutomationElementIdentifiers.IsDataValidForFormProperty;
public static readonly AutomationProperty ControllerForProperty = AutomationElementIdentifiers.ControllerForProperty;
public static readonly AutomationProperty DescribedByProperty = AutomationElementIdentifiers.DescribedByProperty;
public static readonly AutomationProperty FlowsToProperty = AutomationElementIdentifiers.FlowsToProperty;
public static readonly AutomationProperty ProviderDescriptionProperty = AutomationElementIdentifiers.ProviderDescriptionProperty;
public static readonly AutomationEvent MenuModeStartEvent = AutomationElementIdentifiers.MenuModeStartEvent;
public static readonly AutomationEvent MenuModeEndEvent = AutomationElementIdentifiers.MenuModeEndEvent;
// New for Windows 8
public static readonly AutomationProperty IsObjectModelPatternAvailableProperty = AutomationElementIdentifiers.IsObjectModelPatternAvailableProperty;
public static readonly AutomationProperty IsAnnotationPatternAvailableProperty = AutomationElementIdentifiers.IsAnnotationPatternAvailableProperty;
public static readonly AutomationProperty IsTextPattern2AvailableProperty = AutomationElementIdentifiers.IsTextPattern2AvailableProperty;
public static readonly AutomationProperty IsStylesPatternAvailableProperty = AutomationElementIdentifiers.IsStylesPatternAvailableProperty;
public static readonly AutomationProperty IsSpreadsheetPatternAvailableProperty = AutomationElementIdentifiers.IsSpreadsheetPatternAvailableProperty;
public static readonly AutomationProperty IsSpreadsheetItemPatternAvailableProperty = AutomationElementIdentifiers.IsSpreadsheetItemPatternAvailableProperty;
public static readonly AutomationProperty IsTransformPattern2AvailableProperty = AutomationElementIdentifiers.IsTransformPattern2AvailableProperty;
public static readonly AutomationProperty IsTextChildPatternAvailableProperty = AutomationElementIdentifiers.IsTextChildPatternAvailableProperty;
public static readonly AutomationProperty IsDragPatternAvailableProperty = AutomationElementIdentifiers.IsDragPatternAvailableProperty;
public static readonly AutomationProperty IsDropTargetPatternAvailableProperty = AutomationElementIdentifiers.IsDropTargetPatternAvailableProperty;
public static readonly AutomationProperty OptimizeForVisualContentProperty = AutomationElementIdentifiers.OptimizeForVisualContentProperty;
public static readonly AutomationProperty LiveSettingProperty = AutomationElementIdentifiers.LiveSettingProperty;
public static readonly AutomationEvent SystemAlertEvent = AutomationElementIdentifiers.SystemAlertEvent;
public static readonly AutomationEvent LiveRegionChangedEvent = AutomationElementIdentifiers.LiveRegionChangedEvent;
public static readonly AutomationEvent HostedFragmentRootsInvalidatedEvent = AutomationElementIdentifiers.HostedFragmentRootsInvalidatedEvent;
internal AutomationElement(UIAutomationClient.IUIAutomationElement obj)
{
Debug.Assert(obj != null);
this._obj = obj;
}
public static AutomationElement Wrap(UIAutomationClient.IUIAutomationElement obj)
{
return (obj == null) ? null : new AutomationElement(obj);
}
public override bool Equals(object obj)
{
AutomationElement element = obj as AutomationElement;
return (((obj != null) && (element != null)) && (Automation.Factory.CompareElements(this._obj, element._obj) != 0));
}
~AutomationElement()
{
}
public AutomationElementCollection FindAll(TreeScope scope, Condition condition)
{
Utility.ValidateArgumentNonNull(condition, "condition");
try
{
UIAutomationClient.IUIAutomationElementArray elemArray =
this._obj.FindAllBuildCache(
(UIAutomationClient.TreeScope)scope,
condition.NativeCondition,
CacheRequest.CurrentNativeCacheRequest);
return AutomationElementCollection.Wrap(elemArray);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public AutomationElement FindFirst(TreeScope scope, Condition condition)
{
Utility.ValidateArgumentNonNull(condition, "condition");
try
{
UIAutomationClient.IUIAutomationElement elem =
this._obj.FindFirstBuildCache(
(UIAutomationClient.TreeScope)scope,
condition.NativeCondition,
CacheRequest.CurrentNativeCacheRequest);
return AutomationElement.Wrap(elem);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public static AutomationElement FromHandle(IntPtr hwnd)
{
Utility.ValidateArgument(hwnd != IntPtr.Zero, "Hwnd cannot be null");
try
{
UIAutomationClient.IUIAutomationElement element =
Automation.Factory.ElementFromHandleBuildCache(hwnd, CacheRequest.CurrentNativeCacheRequest);
return AutomationElement.Wrap(element);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public static AutomationElement FromIAccessible(Accessibility.IAccessible acc, int childId)
{
Utility.ValidateArgumentNonNull(acc, "acc");
try
{
UIAutomationClient.IUIAutomationElement element =
Automation.Factory.ElementFromIAccessibleBuildCache(
(UIAutomationClient.IAccessible)acc,
childId,
CacheRequest.CurrentNativeCacheRequest);
return AutomationElement.Wrap(element);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public static AutomationElement FromLocalProvider(object /* IRawElementProviderSimple */ localImpl)
{
Utility.ValidateArgumentNonNull(localImpl, "localImpl");
// It's not clear how you'd do this -- COM API doesn't give you
// the chance to wrap a provider like this.
throw new NotImplementedException();
}
public static AutomationElement FromPoint(Point pt)
{
try
{
UIAutomationClient.IUIAutomationElement element =
Automation.Factory.ElementFromPointBuildCache(
Utility.PointManagedToNative(pt),
CacheRequest.CurrentNativeCacheRequest);
return AutomationElement.Wrap(element);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public object GetCachedPattern(AutomationPattern pattern)
{
object patternObj;
if (!this.TryGetCachedPattern(pattern, out patternObj))
{
throw new InvalidOperationException("Unsupported pattern");
}
return patternObj;
}
public object GetCachedPropertyValue(AutomationProperty property)
{
return this.GetCachedPropertyValue(property, false);
}
public object GetCachedPropertyValue(AutomationProperty property, bool ignoreDefaultValue)
{
Utility.ValidateArgumentNonNull(property, "property");
try
{
object obj = this._obj.GetCachedPropertyValueEx(property.Id, (ignoreDefaultValue) ? 1 : 0);
return Utility.WrapObjectAsProperty(property, obj);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public Point GetClickablePoint()
{
Point point;
if (!this.TryGetClickablePoint(out point))
{
throw new NoClickablePointException();
}
return point;
}
public object GetCurrentPattern(AutomationPattern pattern)
{
object patternObj;
if (!this.TryGetCurrentPattern(pattern, out patternObj))
{
throw new InvalidOperationException("Unsupported pattern");
}
return patternObj;
}
public object GetCurrentPropertyValue(AutomationProperty property)
{
return this.GetCurrentPropertyValue(property, false);
}
public object GetCurrentPropertyValue(AutomationProperty property, bool ignoreDefaultValue)
{
Utility.ValidateArgumentNonNull(property, "property");
try
{
object obj = this._obj.GetCurrentPropertyValueEx(property.Id, (ignoreDefaultValue) ? 1 : 0);
return Utility.WrapObjectAsProperty(property, obj);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
internal object GetPropertyValue(AutomationProperty property, bool cached)
{
if (cached)
{
return GetCachedPropertyValue(property);
}
else
{
return GetCurrentPropertyValue(property);
}
}
public override int GetHashCode()
{
int[] runtimeId = GetRuntimeId();
int num = 0;
if (runtimeId == null)
{
throw new InvalidOperationException("Operation cannot be performed");
}
foreach (int i in runtimeId)
{
num = (num * 4) ^ i;
}
return num;
}
internal object GetRawPattern(AutomationPattern pattern, bool isCached)
{
try
{
if (isCached)
{
return this._obj.GetCachedPattern(pattern.Id);
}
else
{
return this._obj.GetCurrentPattern(pattern.Id);
}
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public int[] GetRuntimeId()
{
try
{
return (int[])this._obj.GetRuntimeId();
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public AutomationPattern[] GetSupportedPatterns()
{
int[] rawPatternIds;
string[] rawPatternNames;
try
{
Automation.Factory.PollForPotentialSupportedPatterns(this._obj, out rawPatternIds, out rawPatternNames);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
int[] patternIds = (int[])rawPatternIds;
// This element may support patterns that are not registered for this
// client. Filter them out.
List<AutomationPattern> patterns = new List<AutomationPattern>();
foreach (int patternId in patternIds)
{
AutomationPattern pattern = AutomationPattern.LookupById(patternId);
if (pattern != null)
{
patterns.Add(pattern);
}
}
return patterns.ToArray();
}
public AutomationProperty[] GetSupportedProperties()
{
int[] rawPropertyIds;
string[] rawPropertyNames;
try
{
Automation.Factory.PollForPotentialSupportedProperties(this._obj, out rawPropertyIds, out rawPropertyNames);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
int[] propertyIds = (int[])rawPropertyIds;
// This element may support properties that are not registered for this
// client. Filter them out.
List<AutomationProperty> properties = new List<AutomationProperty>();
foreach (int propertyId in propertyIds)
{
AutomationProperty property = AutomationProperty.LookupById(propertyId);
if (property != null)
{
properties.Add(property);
}
}
return properties.ToArray();
}
public AutomationElement GetUpdatedCache(CacheRequest request)
{
try
{
return AutomationElement.Wrap(this._obj.BuildUpdatedCache(request.NativeCacheRequest));
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public static bool operator ==(AutomationElement left, AutomationElement right)
{
if (object.Equals(left, null))
{
return (object.Equals(right, null));
}
if (object.Equals(right, null))
{
return (object.Equals(left, null));
}
return left.Equals(right);
}
public static bool operator !=(AutomationElement left, AutomationElement right)
{
return !(left == right);
}
public void SetFocus()
{
try
{
this._obj.SetFocus();
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public bool TryGetCachedPattern(AutomationPattern pattern, out object patternObject)
{
patternObject = null;
Utility.ValidateArgumentNonNull(pattern, "pattern");
try
{
object nativePattern = this._obj.GetCachedPattern(pattern.Id);
patternObject = Utility.WrapObjectAsPattern(this, nativePattern, pattern, true /* cached */);
return (patternObject != null);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public bool TryGetClickablePoint(out Point pt)
{
pt = new Point(0.0, 0.0);
UIAutomationClient.tagPOINT nativePoint = new UIAutomationClient.tagPOINT();
try
{
bool success = this._obj.GetClickablePoint(out nativePoint) != 0;
if (success)
{
pt.X = nativePoint.x;
pt.Y = nativePoint.y;
}
return success;
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public bool TryGetCurrentPattern(AutomationPattern pattern, out object patternObject)
{
patternObject = null;
Utility.ValidateArgumentNonNull(pattern, "pattern");
try
{
object nativePattern = this._obj.GetCurrentPattern(pattern.Id);
patternObject = Utility.WrapObjectAsPattern(this, nativePattern, pattern, false /* cached */);
return (patternObject != null);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
public AutomationElementInformation Cached
{
get
{
return new AutomationElementInformation(this, true);
}
}
public AutomationElementCollection CachedChildren
{
get
{
try
{
return AutomationElementCollection.Wrap(this._obj.GetCachedChildren());
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
}
public AutomationElement CachedParent
{
get
{
try
{
return AutomationElement.Wrap(this._obj.GetCachedParent());
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
}
public AutomationElementInformation Current
{
get
{
return new AutomationElementInformation(this, false);
}
}
public UIAutomationClient.IUIAutomationElement NativeElement
{
get
{
return this._obj;
}
}
public static AutomationElement FocusedElement
{
get
{
try
{
return AutomationElement.Wrap(Automation.Factory.GetFocusedElement());
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
}
public static AutomationElement RootElement
{
get
{
try
{
IUIAutomationElement element =
Automation.Factory.GetRootElementBuildCache(
CacheRequest.CurrentNativeCacheRequest);
return AutomationElement.Wrap(element);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
}
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct AutomationElementInformation
{
private AutomationElement _el;
private bool _isCached;
internal AutomationElementInformation(AutomationElement el, bool isCached)
{
this._el = el;
this._isCached = isCached;
}
public ControlType ControlType
{
get
{
return (ControlType)this._el.GetPropertyValue(AutomationElement.ControlTypeProperty, _isCached);
}
}
public string LocalizedControlType
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.LocalizedControlTypeProperty, _isCached);
}
}
public string Name
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.NameProperty, _isCached);
}
}
public string AcceleratorKey
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.AcceleratorKeyProperty, _isCached);
}
}
public string AccessKey
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.AccessKeyProperty, _isCached);
}
}
public bool HasKeyboardFocus
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.HasKeyboardFocusProperty, _isCached);
}
}
public bool IsKeyboardFocusable
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.IsKeyboardFocusableProperty, _isCached);
}
}
public bool IsEnabled
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.IsEnabledProperty, _isCached);
}
}
public Rect BoundingRectangle
{
get
{
return (Rect)this._el.GetPropertyValue(AutomationElement.BoundingRectangleProperty, _isCached);
}
}
public string HelpText
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.HelpTextProperty, _isCached);
}
}
public bool IsControlElement
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.IsControlElementProperty, _isCached);
}
}
public bool IsContentElement
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.IsContentElementProperty, _isCached);
}
}
public AutomationElement LabeledBy
{
get
{
return (AutomationElement)this._el.GetPropertyValue(AutomationElement.LabeledByProperty, _isCached);
}
}
public string AutomationId
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.AutomationIdProperty, _isCached);
}
}
public string ItemType
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.ItemTypeProperty, _isCached);
}
}
public bool IsPassword
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.IsPasswordProperty, _isCached);
}
}
public string ClassName
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.ClassNameProperty, _isCached);
}
}
public int NativeWindowHandle
{
get
{
return (int)this._el.GetPropertyValue(AutomationElement.NativeWindowHandleProperty, _isCached);
}
}
public int ProcessId
{
get
{
return (int)this._el.GetPropertyValue(AutomationElement.ProcessIdProperty, _isCached);
}
}
public bool IsOffscreen
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.IsOffscreenProperty, _isCached);
}
}
public OrientationType Orientation
{
get
{
return (OrientationType)this._el.GetPropertyValue(AutomationElement.OrientationProperty, _isCached);
}
}
public string FrameworkId
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.FrameworkIdProperty, _isCached);
}
}
public bool IsRequiredForForm
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.IsRequiredForFormProperty, _isCached);
}
}
public string ItemStatus
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.ItemStatusProperty, _isCached);
}
}
public string AriaRole
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.AriaRoleProperty, _isCached);
}
}
public string AriaProperties
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.AriaPropertiesProperty, _isCached);
}
}
public bool IsDataValidForForm
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.IsDataValidForFormProperty, _isCached);
}
}
public AutomationElement ControllerFor
{
get
{
return (AutomationElement)this._el.GetPropertyValue(AutomationElement.ControllerForProperty, _isCached);
}
}
public AutomationElement DescribedBy
{
get
{
return (AutomationElement)this._el.GetPropertyValue(AutomationElement.DescribedByProperty, _isCached);
}
}
public AutomationElement FlowsTo
{
get
{
return (AutomationElement)this._el.GetPropertyValue(AutomationElement.FlowsToProperty, _isCached);
}
}
public string ProviderDescription
{
get
{
return (string)this._el.GetPropertyValue(AutomationElement.ProviderDescriptionProperty, _isCached);
}
}
public bool OptimizeForVisualContent
{
get
{
return (bool)this._el.GetPropertyValue(AutomationElement.OptimizeForVisualContentProperty, _isCached);
}
}
public LiveSetting LiveSetting
{
get
{
return (LiveSetting)this._el.GetPropertyValue(AutomationElement.LiveSettingProperty, _isCached);
}
}
}
}
}