Exemplo n.º 1
0
        public GeneratorNode CreateItemsGeneratorNode(
            IList collection,
            GeneratorNode parent,
            GeneratorNode previous,
            GeneratorNode next,
            CustomItemContainerGenerator generator)
        {
            Debug.Assert(collection != null, "collection cannot be null for CreateItemsGeneratorNode()");
            Debug.Assert(generator != null);

            INotifyCollectionChanged notifyCollection = collection as INotifyCollectionChanged;

            Debug.Assert(notifyCollection != null, "collection must be a INotifyCollectionChanged for CreateItemsGeneratorNode()");

            ItemCollection itemCollection = collection as ItemCollection;

            if (itemCollection != null)
            {
                DataGridCollectionView dgcv = itemCollection.SourceCollection as DataGridCollectionView;
                if (dgcv != null)
                {
                    collection = dgcv;
                }
            }

            ItemsGeneratorNode node = new ItemsGeneratorNode(collection, parent);

            this.SetupCollectionGeneratorNode(node, parent, previous, next);


            node.AdjustLeafCount(node.Items.Count);

            return(node);
        }
Exemplo n.º 2
0
        public void AddRef(CustomItemContainerGenerator reference)
        {
            Debug.Assert(reference != null);

            if (m_generators.Contains(reference))
            {
                return;
            }

            m_generators.Add(reference);
        }
Exemplo n.º 3
0
        public DetailGeneratorNode(DataGridContext context, CustomItemContainerGenerator generator)
            : base(null)
        {
            if (generator == null)
            {
                throw new ArgumentNullException("generator");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            m_generator = generator;
            m_context   = context;
            m_itemCount = generator.ItemCount;
        }
Exemplo n.º 4
0
        private void InitializeGenerator()
        {
            DataGridControl dataGridControl = this.ParentDataGridControl;

            if (dataGridControl == null)
            {
                throw new DataGridInternalException("No DataGridContext set on the DataGridItemsHost while trying to initalize the ItemContainerGenerator");
            }

            if (m_generator == null)
            {
                m_generator = dataGridControl.CustomItemContainerGenerator;
            }

            Debug.Assert(m_generator != null);

            m_generator.ItemsChanged      += this.HandleGeneratorItemsChanged;
            m_generator.ContainersRemoved += this.HandleGeneratorContainersRemoved;

            m_generatorInitialized = true;
        }
Exemplo n.º 5
0
        protected override void StopListening(object source)
        {
            DataGridControl dataGridControl = source as DataGridControl;

            if (dataGridControl != null)
            {
                dataGridControl.DetailsChanged -= this.OnDetailsChanged;
                return;
            }
            else
            {
                CustomItemContainerGenerator generator = source as CustomItemContainerGenerator;
                if (generator != null)
                {
                    generator.DetailsChanged -= this.OnDetailsChanged;
                    return;
                }
            }

            throw new InvalidOperationException("An attempt was made to use a source other than a DataGridControl or CustomItemContainerGenerator.");
        }
        protected override List <AutomationPeer> GetChildrenCore()
        {
            Group owner = this.Owner;
            GroupGeneratorNode generatorNode = owner.GeneratorNode;

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

            DataGridContext dataGridContext = owner.DataGridContext;

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

            CustomItemContainerGenerator customItemContainerGenerator = dataGridContext.CustomItemContainerGenerator;
            IList <object> items;
            bool           itemsIsAllItems = false;

            // The way Microsoft check if we are called by an automation that support Virtualization.
            if ((ItemContainerPatternIdentifiers.Pattern != null) && (owner.IsBottomLevel) && (dataGridContext.DataGridControl.ItemsHost is DataGridItemsHost))
            {
                items = customItemContainerGenerator.GetRealizedDataItemsForGroup(generatorNode);
            }
            else
            {
                items           = owner.GetItems();
                itemsIsAllItems = true;
            }

            int       itemsCount              = (items == null) ? 0 : items.Count;
            Hashtable oldDataChildren         = m_dataChildren;
            Hashtable oldHeaderFooterChildren = m_headerFooterChildren;

            // 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 = itemsCount + headersCount + footersCount;

            m_dataChildren         = new Hashtable(itemsCount);
            m_headerFooterChildren = new Hashtable(headersCount + footersCount);

            if (childrenCount == 0)
            {
                return(null);
            }

            DataGridContextAutomationPeer dataGridContextAutomationPeer = dataGridContext.Peer;
            Hashtable dataGridContextItemsPeer = dataGridContextAutomationPeer.ItemPeers;

            DataGridGroupAutomationPeer groupAutomationPeer;
            DataGridItemAutomationPeer  itemAutomationPeer;
            List <AutomationPeer>       list = new List <AutomationPeer>(childrenCount);

            if (headerNode != null)
            {
                DataGridGroupAutomationPeer.AddHeaderPeer(dataGridContext, headerNode, list, m_headerFooterChildren, oldHeaderFooterChildren);
            }

            int index = 0;

            for (int i = 0; i < itemsCount; i++)
            {
                Object item = items[i];
                CollectionViewGroup collectionViewGroup = item as CollectionViewGroup;

                if (collectionViewGroup == null)
                {
                    if ((i == 0) && (itemsIsAllItems))
                    {
                        GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper(generatorNode, 0, 0);
                        nodeHelper.ReverseCalculateIndex();
                        index = nodeHelper.SourceDataIndex;
                    }

                    itemAutomationPeer = oldDataChildren[item] as DataGridItemAutomationPeer;

                    if (itemAutomationPeer == null)
                    {
                        if (itemsIsAllItems)
                        {
                            itemAutomationPeer = dataGridContextAutomationPeer.CreateItemAutomationPeerInternal(item, index + i);
                        }
                        else
                        {
                            itemAutomationPeer = dataGridContextAutomationPeer.CreateItemAutomationPeerInternal(item, -1);
                        }
                    }
                    else
                    {
                        if (itemsIsAllItems)
                        {
                            itemAutomationPeer.SetIndex(index + i);
                        }
                        else
                        {
                            itemAutomationPeer.SetIndex(-1);
                        }
                    }

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

                    if (m_dataChildren[item] == null)
                    {
                        Debug.Assert(itemAutomationPeer != null);
                        list.Add(itemAutomationPeer);
                        m_dataChildren[item] = itemAutomationPeer;

                        if (dataGridContextItemsPeer[item] == null)
                        {
                            dataGridContextItemsPeer[item] = itemAutomationPeer;
                        }
                    }
                }
                else
                {
                    Group uiGroup =
                        customItemContainerGenerator.GetGroupFromCollectionViewGroup(this.Owner, collectionViewGroup);

                    if (uiGroup != null)
                    {
                        groupAutomationPeer = uiGroup.CreateAutomationPeer() as DataGridGroupAutomationPeer;

                        if (groupAutomationPeer != null)
                        {
                            list.Add(groupAutomationPeer);
                        }
                    }
                }
            }

            if (footerNode != null)
            {
                DataGridGroupAutomationPeer.AddFooterPeer(dataGridContext, footerNode, list, m_headerFooterChildren, oldHeaderFooterChildren);
            }

            return(list);
        }
Exemplo n.º 7
0
        public void RemoveRef(CustomItemContainerGenerator reference)
        {
            Debug.Assert(reference != null);

            m_generators.Remove(reference);
        }
        protected override List <AutomationPeer> GetChildrenCore()
        {
            if (m_dataGridContext == null)
            {
                return(null);
            }

            if (m_oldColumnCount == -1)
            {
                m_oldColumnCount = m_dataGridContext.VisibleColumns.Count;
                m_dataGridContext.Columns.VisibleColumnsUpdated += new EventHandler(Columns_VisibleColumnsUpdated);
            }

            CustomItemContainerGenerator itemGenerator = m_dataGridContext.CustomItemContainerGenerator;
            IEnumerable items;
            int         itemsCount;
            bool        itemsIsAllItems = false;

            // The way Microsoft check if we are called by an automation that support Virtualization.
            if ((ItemContainerPatternIdentifiers.Pattern != null) && (m_dataGridControl.ItemsHost is DataGridItemsHost))
            {
                List <object> realizedItems = itemGenerator.GetRealizedDataItems();
                items      = realizedItems;
                itemsCount = realizedItems.Count;
            }
            else
            {
                CollectionView viewItems = m_dataGridContext.Items;
                items           = viewItems;
                itemsCount      = viewItems.Count;
                itemsIsAllItems = true;
            }

            Hashtable oldDataChildren         = m_dataChildren;
            Hashtable oldHeaderFooterChildren = m_headerFooterChildren;

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

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

            int childrenCount = headersCount + footersCount;

            if (m_parentDataGridContext == null)
            {
                // Add the fixed header / footer count to the children
                Panel fixedPanel = m_dataGridControl.FixedHeadersHostPanel;

                if (fixedPanel != null)
                {
                    childrenCount += fixedPanel.Children.Count;
                }

                fixedPanel = m_dataGridControl.FixedFootersHostPanel;

                if (fixedPanel != null)
                {
                    childrenCount += fixedPanel.Children.Count;
                }
            }

            ReadOnlyObservableCollection <object> groups = m_dataGridContext.Items.Groups;

            if (groups != null)
            {
                // Add the group count to the children
                childrenCount += groups.Count;
            }
            else
            {
                childrenCount += itemsCount;
            }

            m_dataChildren         = new Hashtable(itemsCount);
            m_headerFooterChildren = new Hashtable(headersCount + footersCount);

            if (childrenCount == 0)
            {
                return(null);
            }

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

            this.AddChildrenHeaders(headerNode, oldHeaderFooterChildren, list);

            if (groups != null)
            {
                CustomItemContainerGenerator customItemContainerGenerator = m_dataGridContext.CustomItemContainerGenerator;
                DataGridGroupAutomationPeer  peer;
                itemsCount = groups.Count;

                for (int i = 0; i < itemsCount; i++)
                {
                    CollectionViewGroup collectionViewGroup = groups[i] as CollectionViewGroup;

                    if (collectionViewGroup != null)
                    {
                        Group uiGroup =
                            customItemContainerGenerator.GetGroupFromCollectionViewGroup(null, collectionViewGroup);

                        if (uiGroup != null)
                        {
                            peer = uiGroup.CreateAutomationPeer() as DataGridGroupAutomationPeer;

                            if (peer != null)
                            {
                                list.Add(peer);
                            }
                        }
                    }
                }
            }
            else
            {
                int index = 0;

                foreach (object item in ( IEnumerable )items)
                {
                    DataGridItemAutomationPeer itemAutomationPeer =
                        oldDataChildren[item] as DataGridItemAutomationPeer;

                    if (itemAutomationPeer == null)
                    {
                        if (itemsIsAllItems)
                        {
                            itemAutomationPeer = this.CreateItemAutomationPeer(item, index);
                            index++;
                        }
                        else
                        {
                            itemAutomationPeer = this.CreateItemAutomationPeer(item, -1);
                        }
                    }
                    else
                    {
                        if (itemsIsAllItems)
                        {
                            itemAutomationPeer.SetIndex(index);
                            index++;
                        }
                        else
                        {
                            itemAutomationPeer.SetIndex(-1);
                        }
                    }

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

                    if (m_dataChildren[item] == null)
                    {
                        list.Add(itemAutomationPeer);
                        m_dataChildren[item] = itemAutomationPeer;
                    }
                }
            }

            this.AddChildrenFooters(footerNode, oldHeaderFooterChildren, list);
            return(list);
        }