public ClientSideProviderDescription (
			ClientSideProviderFactoryCallback clientSideProviderFactoryCallback,
			string className)
		: this (clientSideProviderFactoryCallback, className,
			null, ClientSideProviderMatchIndicator.None)
		{
		}
 public ClientSideProviderDescription(
     ClientSideProviderFactoryCallback clientSideProviderFactoryCallback,
     string className,
     IEnumerable <EventMapping> eventMappings)
     : this(clientSideProviderFactoryCallback : clientSideProviderFactoryCallback, className : className, imageName : string.Empty, flags : ClientSideProviderMatchIndicator.None, eventMappings : eventMappings)
 {
 }
Example #3
0
 public ClientSideProviderDescription(ClientSideProviderFactoryCallback clientSideProviderFactoryCallback, string className, string imageName, ClientSideProviderMatchIndicator flags)
 {
     this._className            = (className != null) ? className.ToLower(CultureInfo.InvariantCulture) : null;
     this._imageName            = (imageName != null) ? imageName.ToLower(CultureInfo.InvariantCulture) : null;
     this._flags                = flags;
     this._proxyFactoryCallback = clientSideProviderFactoryCallback;
 }
 public ClientSideProviderDescription(
     ClientSideProviderFactoryCallback clientSideProviderFactoryCallback,
     string className)
     : this(clientSideProviderFactoryCallback, className,
            null, ClientSideProviderMatchIndicator.None)
 {
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="className">Window classname that the proxy is for. If null is used, the proxy will be called for all
        /// windows if no other proxy has been found for that window.</param>
        /// <param name="clientSideProviderFactoryCallback">Delegate that PAW will call to request the creation of a proxy</param>
        /// <param name="flags">Enum ProxyMatchFlags
        /// otherwise the parameter classname can be contained in the window class name</param>
        /// <param name="imageName">Name of the executable for the process where this window resides.  For example outllib.dll or calc.exe</param>
        public ClientSideProviderDescription(ClientSideProviderFactoryCallback clientSideProviderFactoryCallback, string className, string imageName, ClientSideProviderMatchIndicator flags)
        {
            // Null and Empty string mean different things here
#pragma warning suppress 6507
            if (className != null)
            {
                _className = className.ToLower(System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                _className = null;
            }

            _flags = flags;

            // Null and Empty string mean different things here
#pragma warning suppress 6507
            if (imageName != null)
            {
                _imageName = imageName.ToLower(System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                _imageName = null;
            }

            _proxyFactoryCallback = clientSideProviderFactoryCallback;
        }
Example #6
0
 public ProxyFactoryCallbackWrapper(ClientSideProviderFactoryCallback callback)
 {
     System.Diagnostics.Debug.Assert(callback != null);
     _callback     = callback;
     _serialNumber = _staticSerialNumber;
     System.Threading.Interlocked.Increment(ref _staticSerialNumber);
 }
 public ClientSideProviderDescription(ClientSideProviderFactoryCallback clientSideProviderFactoryCallback, string className, string imageName, ClientSideProviderMatchIndicator flags)
 {
     this._className = (className != null) ? className.ToLower(CultureInfo.InvariantCulture) : null;
     this._imageName = (imageName != null) ? imageName.ToLower(CultureInfo.InvariantCulture) : null;
     this._flags = flags;
     this._proxyFactoryCallback = clientSideProviderFactoryCallback;
 }
Example #8
0
        // helper to return the User32FocusedMenu provider
        internal static IRawElementProviderSimple GetUser32FocusedMenuProvider(IntPtr hwnd)
        {
            ClientSideProviderFactoryCallback menuFactory = ProxyManager.User32FocusedMenuProxyFactory;

            if (menuFactory == null)
            {
                return(null);
            }

            return(menuFactory(hwnd, 0, UnsafeNativeMethods.OBJID_CLIENT));
        }
Example #9
0
        // helper to return the non-client area provider
        internal static IRawElementProviderSimple GetNonClientProvider(IntPtr hwnd)
        {
            ClientSideProviderFactoryCallback nonClientFactory = ProxyManager.NonClientProxyFactory;

            if (nonClientFactory == null)
            {
                return(null);
            }

            return(nonClientFactory(hwnd, 0, UnsafeNativeMethods.OBJID_CLIENT));
        }
 public ClientSideProviderDescription(
     ClientSideProviderFactoryCallback clientSideProviderFactoryCallback,
     string className,
     string imageName,
     ClientSideProviderMatchIndicator flags)
 {
     this.clientSideProviderFactoryCallback = clientSideProviderFactoryCallback;
     this.className = className;
     this.imageName = imageName;
     this.flags     = flags;
 }
		public ClientSideProviderDescription (
			ClientSideProviderFactoryCallback clientSideProviderFactoryCallback,
			string className,
			string imageName,
			ClientSideProviderMatchIndicator flags)
		{
			this.clientSideProviderFactoryCallback = clientSideProviderFactoryCallback;
			this.className = className;
			this.imageName = imageName;
			this.flags = flags;
		}
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="className">Window classname that the proxy is for. If null is used, the proxy will be called for all
        /// windows if no other proxy has been found for that window.</param>
        /// <param name="clientSideProviderFactoryCallback">Delegate that PAW will call to request the creation of a proxy</param>
        public ClientSideProviderDescription(ClientSideProviderFactoryCallback clientSideProviderFactoryCallback, string className)
        {
            // Null and Empty string mean different things here.
#pragma warning suppress 6507
            if (className != null)
                _className = className.ToLower( System.Globalization.CultureInfo.InvariantCulture );
            else
                _className = null;
            _flags = 0;
            _imageName = null;
            _proxyFactoryCallback = clientSideProviderFactoryCallback;
        }
 public ClientSideProviderDescription(
     ClientSideProviderFactoryCallback clientSideProviderFactoryCallback,
     string className,
     string imageName,
     ClientSideProviderMatchIndicator flags,
     IEnumerable <EventMapping> eventMappings)
 {
     this.ClientSideProviderFactoryCallback = clientSideProviderFactoryCallback;
     this.ClassName      = className;
     this.ImageName      = imageName;
     this.Flags          = flags;
     this._eventMappings = eventMappings != null ? new List <EventMapping>(collection: eventMappings) : new List <EventMapping>();
 }
Example #14
0
        // Given an entry from one of the hash-tables or lists, check if it matches the image/classname, and if so, call the
        // factory method to create the proxy.
        // (Because full classname matching is done via hash-table lookup, this only needs to do string comparisons
        // for partial classname matches.)
        static private IRawElementProviderSimple GetProxyFromEntry(ProxyScoping findType, object entry, ref string imageName, NativeMethods.HWND hwnd, int idChild, int idObject, string classNameForPartialMatch)
        {
            // First, determine if the entry matches, and if so, extract the factory callback...
            ClientSideProviderFactoryCallback factoryCallback = null;

            // The entry may be a ClientSideProviderFactoryCallback or ClientSideProviderDescription...
            if (findType == ProxyScoping.ImageOnlyHandlers || findType == ProxyScoping.FallbackHandlers)
            {
                // Handle the fallback and image cases specially. The array for these is an array
                // of ClientSideProviderFactoryCallbacks, not ClientSideProviderDescription.
                factoryCallback = (ClientSideProviderFactoryCallback)entry;
            }
            else
            {
                // Other cases use ClientSideProviderDescription...
                ClientSideProviderDescription pi = (ClientSideProviderDescription)entry;

                // Get the image name if necessary...
#pragma warning suppress 6507 // Null and Empty string mean different things here.
                if (imageName == null && pi.ImageName != null)
                {
                    imageName = GetImageName(hwnd);
                }

                if (pi.ImageName == null || pi.ImageName == imageName)
                {
                    // Check if we have a match for this entry...
                    switch (findType)
                    {
                    case ProxyScoping.ExactMatchApparentClassName:
                        factoryCallback = pi.ClientSideProviderFactoryCallback;
                        break;

                    case ProxyScoping.ExactMatchRealClassName:
                        if ((pi.Flags & ClientSideProviderMatchIndicator.DisallowBaseClassNameMatch) == 0)
                        {
                            factoryCallback = pi.ClientSideProviderFactoryCallback;
                        }
                        break;

                    case ProxyScoping.PartialMatchApparentClassName:
                        if (classNameForPartialMatch.IndexOf(pi.ClassName, StringComparison.Ordinal) >= 0)
                        {
                            factoryCallback = pi.ClientSideProviderFactoryCallback;
                        }
                        break;

                    case ProxyScoping.PartialMatchRealClassName:
                        if (classNameForPartialMatch.IndexOf(pi.ClassName, StringComparison.Ordinal) >= 0 &&
                            ((pi.Flags & ClientSideProviderMatchIndicator.DisallowBaseClassNameMatch) == 0))
                        {
                            factoryCallback = pi.ClientSideProviderFactoryCallback;
                        }
                        break;

                    default:
                        Debug.Assert(false, "unexpected switch() case:");
                        break;
                    }
                }
            }

            // Second part: did we get a match? If so, use the factory callback to obtain an instance...
            if (factoryCallback == null)
            {
                return(null);
            }

            // if we get an exception creating a proxy just don't create the proxy and let the UIAutomation default proxy be used
            // This will still allow the tree to be navigated  and some properties to be made availible.
            // Catching all exceptions here doesn't follow .NET guidelines, but is it ok in this scenario?
            try
            {
                return(factoryCallback(hwnd, idChild, idObject));
            }
            catch (Exception e)
            {
                if (Misc.IsCriticalException(e))
                {
                    throw;
                }

                return(null);
            }
        }
Example #15
0
        // return an array representing the currently registered proxies
        internal static ClientSideProviderDescription[] GetProxyDescriptionTable()
        {
            // the ClientSideProviderDescription table is split into four different collections.  Bundle them all back
            // together to let them be manipulated

            // If a client gets the table before the defaults proxies  are loaded because of use, it should return the default proxies
            LoadDefaultProxies();

            lock (_lockObj)
            {
                int            count = 0;
                IEnumerable [] sourceProxyDescription = { _classHandlers, _partialClassHandlers, _imageOnlyHandlers, _fallbackHandlers };

                // figure out how many there are
                foreach (IEnumerable e in sourceProxyDescription)
                {
                    foreach (Object item in e)
                    {
                        Object o = item;
                        if (o is DictionaryEntry)
                        {
                            o = ((DictionaryEntry)o).Value;
                        }

                        if (o is ClientSideProviderDescription)
                        {
                            count++;
                        }
                        else if (o is ClientSideProviderFactoryCallback)
                        {
                            count++;
                        }
                        else
                        {
                            count += ((ArrayList)o).Count;
                        }
                    }
                }

                ClientSideProviderDescription[] proxyDescriptions = new ClientSideProviderDescription[count];
                count = 0;

                // Because the four collections have a simular stucture in common we can treat like they are the same
                // and build the array in the correct order from each one.
                foreach (IEnumerable e in sourceProxyDescription)
                {
                    foreach (Object item in e)
                    {
                        Object o = item;
                        if (o is DictionaryEntry)
                        {
                            o = ((DictionaryEntry)o).Value;
                        }

                        if (o is ClientSideProviderDescription)
                        {
                            proxyDescriptions[count++] = (ClientSideProviderDescription)o;
                        }
                        else if (o is ClientSideProviderFactoryCallback)
                        {
                            ClientSideProviderFactoryCallback pfc = (ClientSideProviderFactoryCallback)o;
                            proxyDescriptions[count++] = new ClientSideProviderDescription(pfc, null);
                        }
                        else
                        {
                            foreach (Object o1 in (ArrayList)o)
                            {
                                proxyDescriptions[count++] = (ClientSideProviderDescription)o1;
                            }
                        }
                    }
                }

                return(proxyDescriptions);
            }
        }
Example #16
0
        // We need to treat MSAA's FOCUS winevents differently depending on the OBJID -
        // OBJID_CLIENT gets routed to the proxies; _MENU and _SYSMENU get speical treatment.
        private AutomationElement GetFocusedElementFromWinEvent(IntPtr hwnd, int idObject, int idChild)
        {
            try
            {
                IRawElementProviderSimple provider = null;
                // These are the only object types that oleacc proxies allow to take focus.
                // (Native IAccessibles can send focus for other custom OBJID valus, but those are no use
                // to us.)
                // Try and get providers for them ourself - if we don't get anything, then
                // defer to core to get the element for the HWND itself.
                if (idObject == UnsafeNativeMethods.OBJID_CLIENT)
                {
                    // regular focus - pass it off to a proxy...
                    provider = ProxyManager.ProxyProviderFromHwnd(NativeMethods.HWND.Cast(hwnd), idChild, UnsafeNativeMethods.OBJID_CLIENT);
                }
                else if (idObject == UnsafeNativeMethods.OBJID_MENU)
                {
                    // menubar focus - see if there's a menubar pseudo-proxy registered...
                    ClientSideProviderFactoryCallback factory = ProxyManager.NonClientMenuBarProxyFactory;
                    if (factory != null)
                    {
                        provider = factory(hwnd, idChild, idObject);
                    }
                }
                else if (idObject == UnsafeNativeMethods.OBJID_SYSMENU)
                {
                    // system menu box focus - see if there's a sysmenu pseudo-proxy registered...
                    ClientSideProviderFactoryCallback factory = ProxyManager.NonClientSysMenuProxyFactory;
                    if (factory != null)
                    {
                        provider = factory(hwnd, idChild, idObject);
                    }
                }
                else if (idObject <= 0)
                {
                    return(null);
                }
                else
                {
                    // This covers OBJID_CLIENT and custom OBJID cases.
                    // Pass it to the proxy manager: most proxies will just handle OBJID_CLIENT,
                    // but the MSAA proxy can potentally handle other OBJID values.
                    provider = ProxyManager.ProxyProviderFromHwnd(NativeMethods.HWND.Cast(hwnd), idChild, idObject);
                }

                if (provider != null)
                {
                    // Ask the fragment root if any of its children really have the focus
                    IRawElementProviderFragmentRoot fragment = provider as IRawElementProviderFragmentRoot;
                    if (fragment != null)
                    {
                        // if we get back something that is different than what we started with and its not null
                        // use that instead.  This is here to get the subset link in the listview but could be usefull
                        // for listview subitems as well.
                        IRawElementProviderSimple realFocus = fragment.GetFocus();
                        if (realFocus != null && !Object.ReferenceEquals(realFocus, provider))
                        {
                            provider = realFocus;
                        }
                    }

                    SafeNodeHandle hnode = UiaCoreApi.UiaNodeFromProvider(provider);
                    return(AutomationElement.Wrap(hnode));
                }
                else
                {
                    // Didn't find a proxy to handle this hwnd - pass off to core...
                    return(AutomationElement.FromHandle(hwnd));
                }
            }
            catch (Exception e)
            {
                if (Misc.IsCriticalException(e))
                {
                    throw;
                }

                return(null);
            }
        }
 public ProxyFactoryCallbackWrapper(ClientSideProviderFactoryCallback callback)
 {
     System.Diagnostics.Debug.Assert(callback != null);
     _callback = callback;
     _serialNumber = _staticSerialNumber;
     System.Threading.Interlocked.Increment(ref _staticSerialNumber);
 }