-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathAutomationInteropProvider.cs
83 lines (72 loc) · 3.31 KB
/
AutomationInteropProvider.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
// (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.Runtime.InteropServices;
using UIAComWrapperInternal;
using Interop.UIAutomationClient;
using UIAutomationClient = Interop.UIAutomationClient;
namespace System.Windows.Automation.Providers
{
public static class AutomationInteropProvider
{
// Constants
public const int AppendRuntimeId = 3;
public const int InvalidateLimit = 20;
public const int RootObjectId = -25;
public static IRawElementProviderSimple HostProviderFromHandle(IntPtr hwnd)
{
Utility.ValidateArgument(hwnd != IntPtr.Zero, "HWND must not be null");
return UiaCoreProviderApi.UiaHostProviderFromHwnd(hwnd);
}
public static void RaiseAutomationEvent(AutomationEvent eventId, IRawElementProviderSimple provider, AutomationEventArgs e)
{
Utility.ValidateArgumentNonNull(eventId, "eventId");
Utility.ValidateArgumentNonNull(provider, "provider");
Utility.ValidateArgumentNonNull(e, "e");
if (e.EventId == AutomationElementIdentifiers.AsyncContentLoadedEvent)
{
AsyncContentLoadedEventArgs args = e as AsyncContentLoadedEventArgs;
if (args == null)
{
throw new ArgumentException("e");
}
UiaCoreProviderApi.UiaRaiseAsyncContentLoadedEvent(provider, args.AsyncContentLoadedState, args.PercentComplete);
}
else
{
if ((e.EventId == WindowPatternIdentifiers.WindowClosedEvent) && !(e is WindowClosedEventArgs))
{
throw new ArgumentException("e");
}
UiaCoreProviderApi.UiaRaiseAutomationEvent(provider, eventId.Id);
}
}
public static void RaiseAutomationPropertyChangedEvent(IRawElementProviderSimple element, AutomationPropertyChangedEventArgs e)
{
Utility.ValidateArgumentNonNull(element, "element");
Utility.ValidateArgumentNonNull(e, "e");
UiaCoreProviderApi.UiaRaiseAutomationPropertyChangedEvent(element, e.Property.Id, e.OldValue, e.NewValue);
}
public static void RaiseStructureChangedEvent(IRawElementProviderSimple provider, StructureChangedEventArgs e)
{
Utility.ValidateArgumentNonNull(provider, "provider");
Utility.ValidateArgumentNonNull(e, "e");
UiaCoreProviderApi.UiaRaiseStructureChangedEvent(provider, (UIAutomationClient.StructureChangeType)e.StructureChangeType, e.GetRuntimeId());
}
public static IntPtr ReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el)
{
Utility.ValidateArgument(hwnd != IntPtr.Zero, "HWND must not be null");
Utility.ValidateArgumentNonNull(el, "el");
return UiaCoreProviderApi.UiaReturnRawElementProvider(hwnd, wParam, lParam, el);
}
public static bool ClientsAreListening
{
get
{
return UiaCoreProviderApi.UiaClientsAreListening();
}
}
}
}