// fire the element seleceted event if there is a client listening for it. private void MaybeFireSelectionItemEvent(AutomationEvent eventId, Hashtable eventTable, IntPtr hwnd, int idObject, int idChild) { // if the 2-nd level table contains an entry for this property if (eventTable.ContainsKey(eventId)) { // create a provider associated with this event and check whether the provider supports the selection item pattern. MsaaNativeProvider provider = (MsaaNativeProvider)MsaaNativeProvider.Create(hwnd, idChild, idObject); if (provider != null && provider.IsPatternSupported(SelectionItemPattern.Pattern)) { // fire the event AutomationEventArgs eventArgs = new AutomationEventArgs(eventId); //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Firing {0} for {1}", eventId, hwnd), "NativeMsaaProxy"); AutomationInteropProvider.RaiseAutomationEvent(eventId, provider, eventArgs); } } }
// fire the property change event if there is a client listening for it. // pattern is the pattern that the property belongs to. the provider is tested to ensure it supports that pattern. private void MaybeFirePropertyChangeEvent(AutomationPattern pattern, AutomationProperty property, Hashtable eventTable, IntPtr hwnd, int idObject, int idChild, bool clientToo) { // if the 2-nd level table contains an entry for this property and the root element should be included (or not) if (eventTable.ContainsKey(property) && (clientToo || !IsClientObject(idObject, idChild))) { // create a provider associated with this event and check whether it supports the pattern, if specified. MsaaNativeProvider provider = (MsaaNativeProvider)MsaaNativeProvider.Create(hwnd, idChild, idObject); if (provider != null && (pattern == null || provider.IsPatternSupported(pattern))) { // get the new property value from the provider. object newValue = ((IRawElementProviderSimple)provider).GetPropertyValue(property.Id); // fire the event AutomationPropertyChangedEventArgs eventArgs = new AutomationPropertyChangedEventArgs(property, null, newValue); //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Firing {0} change event for {1}", property, hwnd), "NativeMsaaProxy"); AutomationInteropProvider.RaiseAutomationPropertyChangedEvent(provider, eventArgs); } } }