Exemplo n.º 1
0
        internal List <AutomationPeer> GetColumnHeadersPeer()
        {
            if (m_dataGridContext == null)
            {
                return(null);
            }

            List <AutomationPeer> list = new List <AutomationPeer>(16);

            this.AddChildrenHeaders(m_dataGridContext.CustomItemContainerGenerator.Header, m_headerFooterChildren, list);
            this.AddChildrenFooters(m_dataGridContext.CustomItemContainerGenerator.Footer, m_headerFooterChildren, list);
            int listCount = list.Count;

            List <AutomationPeer> columnHeaders = new List <AutomationPeer>(listCount);

            for (int i = 0; i < listCount; i++)
            {
                HeaderFooterItemAutomationPeer headerFooterItemPeer = list[i] as HeaderFooterItemAutomationPeer;

                if (headerFooterItemPeer == null)
                {
                    continue;
                }

                if (headerFooterItemPeer.GetAutomationControlType() == AutomationControlType.Header)
                {
                    columnHeaders.Add(headerFooterItemPeer);
                }
            }

            return(columnHeaders);
        }
Exemplo n.º 2
0
        private void AddChildrenFooters(
            HeadersFootersGeneratorNode footerNode,
            Hashtable oldHeaderFooterChildren,
            List <AutomationPeer> list)
        {
            if (m_parentDataGridContext == null)
            {
                // Add fixed header to the children list
                Panel fixedFooterPanel = m_dataGridControl.FixedFootersHostPanel;

                if (fixedFooterPanel != null)
                {
                    int index = 0;

                    foreach (DependencyObject headerFooter in fixedFooterPanel.Children)
                    {
                        HeaderFooterItem headerFooterItem = headerFooter as HeaderFooterItem;

                        if (headerFooterItem != null)
                        {
                            HeaderFooterItemAutomationPeer automationPeer = oldHeaderFooterChildren[headerFooter] as HeaderFooterItemAutomationPeer;

                            if (automationPeer == null)
                            {
                                automationPeer = new HeaderFooterItemAutomationPeer(m_dataGridContext, headerFooter);
                            }

                            automationPeer.SetExtraInfo(HeaderFooterItemAutomationPeer.HeaderFooterType.FixedFooter, index);
                            m_headerFooterChildren[headerFooter] = automationPeer;
                            list.Add(automationPeer);
                        }

                        index++;
                    }
                }
            }

            if (footerNode != null)
            {
                DataGridGroupAutomationPeer.AddFooterPeer(m_dataGridContext, footerNode, list, m_headerFooterChildren, oldHeaderFooterChildren);
            }
        }
        internal static void AddFooterPeer(
            DataGridContext dataGridContext,
            HeadersFootersGeneratorNode node,
            List <AutomationPeer> list,
            Hashtable children,
            Hashtable oldChildren)
        {
            int headersCount = node.ItemCount;

            for (int i = 0; i < headersCount; i++)
            {
                // We use GetAt since it does not return the same thing as .Items.
                // We need to get a GroupHeaderFooterItem.
                object item = node.GetAt(i);

                if (item != null)
                {
                    HeaderFooterItemAutomationPeer automationPeer =
                        oldChildren[item] as HeaderFooterItemAutomationPeer;

                    if (automationPeer == null)
                    {
                        automationPeer = new HeaderFooterItemAutomationPeer(dataGridContext, item);
                    }

                    Debug.Assert(automationPeer != null);

                    // we set ExtraInfo even if the header was already created since the position can change.
                    automationPeer.SetExtraInfo(HeaderFooterItemAutomationPeer.HeaderFooterType.Footer, i);

                    // Force EventsSource to be updated
                    automationPeer.GetWrapperPeer();

                    list.Add(automationPeer);
                    children[item] = automationPeer;
                }
            }
        }
        public IRawElementProviderSimple FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
        {
            if ((propertyId != 0) && (!DataGridGroupAutomationPeer.IsPropertySupportedForFindItem(propertyId)))
            {
                throw new ArgumentException("Property not supported");
            }

            Group owner = this.Owner;
            GroupGeneratorNode generatorNode = owner.GeneratorNode;

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

            DataGridContext dataGridContext = owner.DataGridContext;

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

            this.ResetChildrenCache();
            IList <object> items      = owner.GetItems();
            int            itemsCount = (items == null) ? 0 : items.Count;

            DataGridItemAutomationPeer     startAfterItemPeer         = null;
            HeaderFooterItemAutomationPeer startAfterHeaderFooterPeer = null;

            if (startAfter != null)
            {
                AutomationPeer startAfterPeer = this.PeerFromProvider(startAfter);

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

                startAfterItemPeer         = startAfterPeer as DataGridItemAutomationPeer;
                startAfterHeaderFooterPeer = startAfterPeer as HeaderFooterItemAutomationPeer;
            }

            int startIndex = 0;

            // Get header count
            HeadersFootersGeneratorNode headerNode = generatorNode.GetHeaderNode();
            int headersCount = (headerNode == null) ? 0 : headerNode.ItemCount;

            // Get footer count
            HeadersFootersGeneratorNode footerNode = generatorNode.GetFooterNode();
            int footersCount = (footerNode == null) ? 0 : footerNode.ItemCount;

            int childrenCount = headersCount + footersCount + itemsCount;

            if (startAfterItemPeer != null)
            {
                startIndex = headersCount + startAfterItemPeer.Index + 1;
            }
            else if (startAfterHeaderFooterPeer != null)
            {
                startIndex = startAfterHeaderFooterPeer.Index + 1;

                switch (startAfterHeaderFooterPeer.Type)
                {
                case HeaderFooterItemAutomationPeer.HeaderFooterType.Header:
                {
                    break;
                }

                case HeaderFooterItemAutomationPeer.HeaderFooterType.Footer:
                {
                    startIndex += headersCount + itemsCount;
                    break;
                }
                }
            }

            if (propertyId == 0)
            {
                AutomationPeer peer = this.GetPeerForChildrenIndex(startIndex);

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

                return(this.ProviderFromPeer(peer));
            }

            object propertyValue = null;

            for (int i = startIndex; i < childrenCount; i++)
            {
                AutomationPeer peer = this.GetPeerForChildrenIndex(i);

                if (peer != null)
                {
                    try
                    {
                        propertyValue = peer.GetPropertyValue(propertyId);
                    }
                    catch (Exception exception)
                    {
                        if (exception is ElementNotAvailableException)
                        {
                            continue;
                        }
                    }

                    if (object.Equals(value, propertyValue))
                    {
                        return(this.ProviderFromPeer(peer));
                    }
                }
            }

            return(null);
        }
Exemplo n.º 5
0
        public IRawElementProviderSimple FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
        {
            if ((propertyId != 0) && (!DataGridContextAutomationPeer.IsPropertySupportedForFindItem(propertyId)))
            {
                throw new ArgumentException("Property not supported");
            }

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

            CollectionView items      = m_dataGridContext.Items;
            int            itemsCount = (items == null) ? 0 : items.Count;

            DataGridItemAutomationPeer     startAfterItemPeer         = null;
            HeaderFooterItemAutomationPeer startAfterHeaderFooterPeer = null;

            if (startAfter != null)
            {
                AutomationPeer startAfterPeer = this.PeerFromProvider(startAfter);

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

                startAfterItemPeer         = startAfterPeer as DataGridItemAutomationPeer;
                startAfterHeaderFooterPeer = startAfterPeer as HeaderFooterItemAutomationPeer;
            }

            int startIndex = 0;

            // Get header count
            HeadersFootersGeneratorNode headerNode = m_dataGridContext.CustomItemContainerGenerator.Header;
            int   headersCount      = (headerNode == null) ? 0 : headerNode.ItemCount;
            int   fixedHeadersCount = 0;
            Panel fixedHeadersPanel = null;

            // Get footer count
            HeadersFootersGeneratorNode footerNode = m_dataGridContext.CustomItemContainerGenerator.Footer;
            int   footersCount      = (footerNode == null) ? 0 : footerNode.ItemCount;
            int   fixedFootersCount = 0;
            Panel fixedFootersPanel = null;

            if (m_parentDataGridContext == null)
            {
                // Add the fixed header / footer count to the children
                fixedHeadersPanel = m_dataGridControl.FixedHeadersHostPanel;
                fixedHeadersCount = (fixedHeadersPanel != null) ? fixedHeadersPanel.Children.Count : 0;
                fixedFootersPanel = m_dataGridControl.FixedFootersHostPanel;
                fixedFootersCount = (fixedFootersPanel != null) ? fixedFootersPanel.Children.Count : 0;
            }

            int childrenCount = headersCount + fixedHeadersCount + footersCount + fixedFootersCount + itemsCount;

            if (startAfterItemPeer != null)
            {
                startIndex = fixedHeadersCount + headersCount + startAfterItemPeer.Index + 1;
            }
            else if (startAfterHeaderFooterPeer != null)
            {
                startIndex = startAfterHeaderFooterPeer.Index + 1;

                switch (startAfterHeaderFooterPeer.Type)
                {
                case HeaderFooterItemAutomationPeer.HeaderFooterType.FixedHeader:
                {
                    break;
                }

                case HeaderFooterItemAutomationPeer.HeaderFooterType.Header:
                {
                    startIndex += fixedHeadersCount;
                    break;
                }

                case HeaderFooterItemAutomationPeer.HeaderFooterType.Footer:
                {
                    startIndex += fixedHeadersCount + headersCount + itemsCount;
                    break;
                }

                case HeaderFooterItemAutomationPeer.HeaderFooterType.FixedFooter:
                {
                    startIndex += fixedHeadersCount + headersCount + footersCount + itemsCount;
                    break;
                }
                }
            }

            // Force a children refresh and update our inner caching
            this.GetChildren();

            if (propertyId == 0)
            {
                AutomationPeer peer = this.GetPeerForChildrenIndex(startIndex);

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

                return(this.ProviderFromPeer(peer));
            }

            object propertyValue = null;

            // Search in footer/Fixed footer first
            if (footersCount + fixedFootersCount > 0)
            {
                int footerStartIndex = System.Math.Max(startIndex, childrenCount - footersCount - fixedFootersCount);

                for (int i = startIndex; i < childrenCount; i++)
                {
                    AutomationPeer peer = this.GetPeerForChildrenIndex(i);

                    if (peer != null)
                    {
                        try
                        {
                            propertyValue = peer.GetPropertyValue(propertyId);
                        }
                        catch (Exception exception)
                        {
                            if (exception is ElementNotAvailableException)
                            {
                                continue;
                            }
                        }

                        if (object.Equals(value, propertyValue))
                        {
                            return(this.ProviderFromPeer(peer));
                        }
                    }
                }

                childrenCount -= footersCount + fixedFootersCount;
            }

            // Search in the header/Fixed header and data item
            for (int i = startIndex; i < childrenCount; i++)
            {
                AutomationPeer peer = this.GetPeerForChildrenIndex(i);

                if (peer != null)
                {
                    try
                    {
                        propertyValue = peer.GetPropertyValue(propertyId);
                    }
                    catch (Exception exception)
                    {
                        if (exception is ElementNotAvailableException)
                        {
                            continue;
                        }
                    }

                    if (object.Equals(value, propertyValue))
                    {
                        return(this.ProviderFromPeer(peer));
                    }
                }
            }

            return(null);
        }