Example #1
0
        public void RemoveAutomationEventHandler(AutomationEvent eventId,
                                                 IElement element,
                                                 AutomationEventHandler eventHandler)
        {
            int handlerId = eventHandlerManager.GetAutomationEventIdByHandler(eventHandler);

            if (handlerId == -1)
            {
                return;
            }
            if (element == null)
            {
                //the element is the RootElement
                RootElementEventsManager.RemoveAutomationEventRequest(eventId.Id, handlerId);
                foreach (var entry in GetUiaApplications())
                {
                    entry.Value.RemoveRootElementAutomationEventHandler(
                        eventId.Id, handlerId);
                }
            }
            else
            {
                UiaDbusElement uiaDbusElement = element as UiaDbusElement;
                if (uiaDbusElement == null)
                {
                    Log.Error("[RemoveAutomationEventHandler] 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.RemoveAutomationEventHandler(eventId.Id, runtimeId, handlerId);
            }
        }
Example #2
0
        public IElement [] GetRootElements()
        {
            List <IElement> dbusElements = new List <IElement> ();

            foreach (string busName in GetUiaDbusNames())
            {
                DCI.IApplication app =
                    Bus.Session.GetObject <DCI.IApplication> (busName,
                                                              new ObjectPath(DC.Constants.ApplicationPath));
                if (app == null)
                {
                    continue;
                }
                string [] rootElementPaths;
                try {
                    rootElementPaths = app.GetRootElementPaths();
                } catch {
                    continue;
                }

                foreach (string elementPath in rootElementPaths)
                {
                    var rootElement = GetOrCreateElement(busName, elementPath);
                    if (rootElement != null)
                    {
                        dbusElements.Add(rootElement);
                    }
                }
            }

            Log.Debug("UiaDbusAutomationSource: GetRootElements count will be: " + dbusElements.Count);
            return(dbusElements.ToArray());
        }
Example #3
0
        private void BindApplicationEventHandlers(string busName)
        {
            DCI.IApplication app = Bus.Session.GetObject <DCI.IApplication> (busName,
                                                                             new ObjectPath(DC.Constants.ApplicationPath));
            app.RootElementsChanged += OnRootElementsChanged;

            if (listenFocusChangeStarted)
            {
                app.FocusChanged += delegate(string providerPath) {
                    if (!string.IsNullOrEmpty(providerPath))
                    {
                        lock (focusChangedHandlers) {
                            foreach (var handler in focusChangedHandlers)
                            {
                                handler(GetOrCreateElement(busName, providerPath), -1, -1);
                            }
                        }
                    }
                }
            }
            ;

            var automationEventRequests = RootElementEventsManager.ActiveAutomationEventRequests;

            if (automationEventRequests.Length > 0)
            {
                foreach (var req in automationEventRequests)
                {
                    app.AddRootElementAutomationEventHandler(req.EventId, req.Scope, req.HandlerId);
                }
                EnsureAutomationEventsSetUp(app, busName);
            }
            var propertyEventRequests = RootElementEventsManager.ActivePropertyEventRequests;

            if (propertyEventRequests.Length > 0)
            {
                foreach (var req in propertyEventRequests)
                {
                    app.AddRootElementAutomationPropertyChangedEventHandler(
                        req.Scope, req.HandlerId, req.PropertyIds);
                }
                EnsurePropertyEventsSetUp(app, busName);
            }
            var structureEventRequests = RootElementEventsManager.ActiveStructureEventRequests;

            if (structureEventRequests.Length > 0)
            {
                foreach (var req in structureEventRequests)
                {
                    app.AddRootElementStructureChangedEventHandler(
                        req.Scope, req.HandlerId);
                }
                EnsureStructureEventsSetUp(app, busName);
            }
        }
Example #4
0
 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);
             }
         };
     }
 }
Example #5
0
 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);
             }
         };
     }
 }
Example #6
0
        private Dictionary <string, DCI.IApplication> GetUiaApplications()
        {
            Dictionary <string, DCI.IApplication> dbusApps =
                new Dictionary <string, DCI.IApplication> ();

            foreach (string busName in GetUiaDbusNames())
            {
                DCI.IApplication app =
                    Bus.Session.GetObject <DCI.IApplication> (busName,
                                                              new ObjectPath(DC.Constants.ApplicationPath));
                if (app == null)
                {
                    continue;
                }
                dbusApps [busName] = app;
            }

            return(dbusApps);
        }
Example #7
0
        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);
            }
        }
Example #8
0
 public IElement GetFocusedElement()
 {
     foreach (string busName in GetUiaDbusNames())
     {
         DCI.IApplication app =
             Bus.Session.GetObject <DCI.IApplication> (busName,
                                                       new ObjectPath(DC.Constants.ApplicationPath));
         if (app == null)
         {
             continue;
         }
         string elementPath = app.GetFocusedElementPath();
         if (!string.IsNullOrEmpty(elementPath))
         {
             return(GetOrCreateElement(busName, elementPath));
         }
     }
     return(null);
 }
Example #9
0
 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);
             }
         };
     }
 }
Example #10
0
        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);
            }
        }