public void RemoveStructureChangedEventHandler(IElement element, StructureChangedEventHandler eventHandler) { int handlerId = eventHandlerManager.GetStructureEventIdByHandler(eventHandler); if (handlerId == -1) { return; } if (element == null) { //the element is the RootElement RootElementEventsManager.RemoveStructureEventRequest(handlerId); foreach (var entry in GetUiaApplications()) { entry.Value.RemoveRootElementStructureChangedEventHandler(handlerId); } } else { UiaDbusElement uiaDbusElement = element as UiaDbusElement; if (uiaDbusElement == null) { Log.Error("[RemoveStructureChangedEventHandler] " + "The element sent to UiaDbusSource is not UiaDbusElement"); return; } string busName = uiaDbusElement.BusName; DCI.IApplication app = Bus.Session.GetObject <DCI.IApplication> (busName, new ObjectPath(DC.Constants.ApplicationPath)); int [] runtimeId = uiaDbusElement.RuntimeId; app.RemoveStructureChangedEventHandler(runtimeId, handlerId); } }
private object DeserializeAutomationPropertyValue(string busName, int propId, object value) { object ret = null; if (propId == TableItemPatternIdentifiers.ColumnHeaderItemsProperty.Id || propId == TableItemPatternIdentifiers.RowHeaderItemsProperty.Id || propId == TablePatternIdentifiers.ColumnHeadersProperty.Id || propId == TablePatternIdentifiers.RowHeadersProperty.Id || propId == SelectionPatternIdentifiers.SelectionProperty.Id) { string [] paths = (string [])value; AutomationElement [] elements = new AutomationElement [paths.Length]; for (var i = 0; i < paths.Length; i++) { UiaDbusElement elem = GetOrCreateElement(busName, paths [i]); elements [i] = SourceManager.GetOrCreateAutomationElement(elem); } ret = elements; } else if (propId == AutomationElementIdentifiers.LabeledByProperty.Id || propId == GridItemPatternIdentifiers.ContainingGridProperty.Id || propId == SelectionItemPatternIdentifiers.SelectionContainerProperty.Id) { string path = (string)value; UiaDbusElement elem = GetOrCreateElement(busName, path); ret = SourceManager.GetOrCreateAutomationElement(elem); } else { ret = DC.DbusSerializer.DeserializeValue(propId, value); } return(ret); }
internal UiaDbusElement [] GetOrCreateElements(string busName, string [] paths) { var elements = new UiaDbusElement [paths.Length]; for (int i = 0; i < paths.Length; i++) { elements [i] = this.GetOrCreateElement(busName, paths [i]); } return(elements); }
private UiaDbusElement CreateElement(DCI.IAutomationElement dbusElement, string busName, string elementPath) { if (dbusElement == null) { return(null); } UiaDbusElement element = new UiaDbusElement(dbusElement, busName, elementPath, this); lock (elementMapping) elementMapping.Add(new DbusElementTuple(busName, elementPath), element); return(element); }
private void EnsureAutomationEventsSetUp(DCI.IApplication app, string busName) { if (!automationEventBusNames.Contains(busName)) { automationEventBusNames.Add(busName); app.AutomationEvent += delegate(int hId, int evtId, string providerPath) { var handler = eventHandlerManager.GetAutomationEventHandlerById(hId); if (handler != null) { UiaDbusElement elem = GetOrCreateElement(busName, providerPath); AutomationElement ae = SourceManager.GetOrCreateAutomationElement(elem); var args = new AutomationEventArgs(AutomationEvent.LookupById(evtId)); handler(ae, args); } }; } }
private void EnsureStructureEventsSetUp(DCI.IApplication app, string busName) { if (!structureEventBusNames.Contains(busName)) { structureEventBusNames.Add(busName); app.StructureChanged += delegate(int hId, int evtId, string providerPath, StructureChangeType changeType) { var handler = eventHandlerManager.GetStructureEventHandlerById(hId); if (handler != null) { UiaDbusElement elem = GetOrCreateElement(busName, providerPath); AutomationElement ae = SourceManager.GetOrCreateAutomationElement(elem); var args = new StructureChangedEventArgs(changeType, elem.RuntimeId); handler(ae, args); } }; } }
public ITextPatternRange RangeFromChild(IElement childElement) { UiaDbusElement uiaDbusElement = childElement as UiaDbusElement; if (uiaDbusElement == null) { throw new InvalidOperationException("The childElement parameter " + "is not a child of the AutomationElement associated with the " + "TextPattern or from the array of children of the TextPatternRange."); } string rangePath = null; try { rangePath = pattern.RangePathFromChild(uiaDbusElement.DbusPath); } catch (Exception ex) { throw DbusExceptionTranslator.Translate(ex); } return(GetTextPatternRange(rangePath)); }
public void AddAutomationPropertyChangedEventHandler(IElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, AutomationProperty [] properties) { int [] propertyIds = new int [properties.Length]; for (int i = 0; i < properties.Length; i++) { propertyIds [i] = properties [i].Id; } if (element == null) { //the element is the RootElement // TODO clean up registered handlers when they're removed int handlerId = eventHandlerManager.RegisterPropertyEventHandler(eventHandler); RootElementEventsManager.AddPropertyEventRequest(scope, handlerId, propertyIds); foreach (var entry in GetUiaApplications()) { string busName = entry.Key; var app = entry.Value; EnsurePropertyEventsSetUp(app, busName); app.AddRootElementAutomationPropertyChangedEventHandler( scope, handlerId, propertyIds); } } else { UiaDbusElement uiaDbusElement = element as UiaDbusElement; if (uiaDbusElement == null) { Log.Error("[AddAutomationPropertyChangedEventHandler] The element sent to UiaDbusSource is not UiaDbusElement"); return; } string busName = uiaDbusElement.BusName; DCI.IApplication app = Bus.Session.GetObject <DCI.IApplication> (busName, new ObjectPath(DC.Constants.ApplicationPath)); int [] runtimeId = uiaDbusElement.RuntimeId; int handlerId = eventHandlerManager.RegisterPropertyEventHandler(eventHandler); EnsurePropertyEventsSetUp(app, busName); app.AddAutomationPropertyChangedEventHandler(runtimeId, scope, handlerId, propertyIds); } }
private void EnsurePropertyEventsSetUp(DCI.IApplication app, string busName) { if (!propertyEventBusNames.Contains(busName)) { propertyEventBusNames.Add(busName); app.AutomationPropertyChanged += delegate( int hId, int evtId, string providerPath, int propertyId, object oldValue, object newValue) { var handler = eventHandlerManager.GetPropertyEventHandlerById(hId); if (handler != null) { UiaDbusElement elem = GetOrCreateElement(busName, providerPath); AutomationElement ae = SourceManager.GetOrCreateAutomationElement(elem); oldValue = DeserializeAutomationPropertyValue(busName, propertyId, oldValue); newValue = DeserializeAutomationPropertyValue(busName, propertyId, newValue); var args = new AutomationPropertyChangedEventArgs( AutomationProperty.LookupById(propertyId), oldValue, newValue); handler(ae, args); } }; } }
public void AddAutomationEventHandler(AutomationEvent eventId, IElement element, TreeScope scope, AutomationEventHandler eventHandler) { if (element == null) { //the element is the RootElement // TODO clean up registered handlers when they're removed int handlerId = eventHandlerManager.RegisterAutomationEventHandler(eventHandler); RootElementEventsManager.AddAutomationEventRequest(eventId.Id, scope, handlerId); foreach (var entry in GetUiaApplications()) { string busName = entry.Key; var app = entry.Value; EnsureAutomationEventsSetUp(app, busName); app.AddRootElementAutomationEventHandler(eventId.Id, scope, handlerId); } } else { UiaDbusElement uiaDbusElement = element as UiaDbusElement; if (uiaDbusElement == null) { Log.Error("[AddAutomationEventHandler] The element sent to UiaDbusSource is not UiaDbusElement"); return; } string busName = uiaDbusElement.BusName; DCI.IApplication app = Bus.Session.GetObject <DCI.IApplication> (busName, new ObjectPath(DC.Constants.ApplicationPath)); int [] runtimeId = uiaDbusElement.RuntimeId; int handlerId = eventHandlerManager.RegisterAutomationEventHandler(eventHandler); EnsureAutomationEventsSetUp(app, busName); app.AddAutomationEventHandler(eventId.Id, runtimeId, scope, handlerId); } }
private UiaDbusElement CreateElement (DCI.IAutomationElement dbusElement, string busName, string elementPath) { if (dbusElement == null) return null; UiaDbusElement element = new UiaDbusElement (dbusElement, busName, elementPath, this); lock (elementMapping) elementMapping.Add (new DbusElementTuple (busName, elementPath), element); return element; }
internal UiaDbusElement [] GetOrCreateElements (string busName, string [] paths) { var elements = new UiaDbusElement [paths.Length]; for (int i = 0; i < paths.Length; i++) { elements [i] = this.GetOrCreateElement (busName, paths [i]); } return elements; }