IRawElementProviderSimple[] ISelectionProvider.GetSelection() { if (m_dataGridContext == null) { return(null); } IList <object> selectedItems = m_dataGridContext.SelectedItems; int count = m_dataGridContext.SelectedItems.Count; if ((count <= 0) || (m_dataChildren.Count <= 0)) { return(null); } List <IRawElementProviderSimple> list = new List <IRawElementProviderSimple>(count); for (int i = 0; i < count; i++) { DataGridItemAutomationPeer peer = m_dataChildren[selectedItems[i]] as DataGridItemAutomationPeer; if (peer != null) { list.Add(this.ProviderFromPeer(peer)); } } return(list.ToArray()); }
internal DataGridContextAutomationPeer GetDetailPeer(object parentItem, DetailConfiguration detailConfig) { DataGridItemAutomationPeer itemAutomationPeer = m_dataChildren[parentItem] as DataGridItemAutomationPeer; if (itemAutomationPeer == null) { return(null); } return(itemAutomationPeer.GetDetailPeer(detailConfig)); }
IRawElementProviderSimple IGridProvider.GetItem(int row, int column) { if (m_dataGridContext == null) { return(null); } // Here we only consider data item. No header / footer are part of the IGridProvider. CollectionView items = m_dataGridContext.Items; if ((row < 0) || (row >= items.Count)) { throw new ArgumentOutOfRangeException("row"); } ReadOnlyObservableCollection <ColumnBase> visibleColumns = m_dataGridContext.VisibleColumns; if ((column < 0) || (column >= visibleColumns.Count)) { throw new ArgumentOutOfRangeException("column"); } object item = m_dataGridContext.Items.GetItemAt(row); DataGridItemAutomationPeer itemPeer = m_dataChildren[item] as DataGridItemAutomationPeer; if (itemPeer == null) { // If the item is not found in the cache, try to force is creation in the caching. CollectionViewGroup[] groups; this.GetParentGroupsContainingItemIndex(row, out groups); this.ForceChildrenCaching(groups); itemPeer = m_dataChildren[item] as DataGridItemAutomationPeer; } if (itemPeer == null) { return(null); } DataGridItemCellAutomationPeer cellPeer = itemPeer.GetDataGridItemCellPeer(visibleColumns[column]); if (cellPeer == null) { return(null); } return(this.ProviderFromPeer(cellPeer)); }
IRawElementProviderSimple[] ITableItemProvider.GetColumnHeaderItems() { DataGridItemAutomationPeer dataGridItemAutomationPeer = m_itemAutomationPeer; if (dataGridItemAutomationPeer == null) { return(new IRawElementProviderSimple[0]); } DataGridContext dataGridContext = dataGridItemAutomationPeer.DataGridContext; if (dataGridContext == null) { return(new IRawElementProviderSimple[0]); } List <AutomationPeer> headersFootersPeer = dataGridContext.Peer.GetColumnHeadersPeer(); if (headersFootersPeer == null) { return(new IRawElementProviderSimple[0]); } int headersFootersPeerCount = headersFootersPeer.Count; List <IRawElementProviderSimple> rawElementProviderSimples = new List <IRawElementProviderSimple>(headersFootersPeerCount); for (int i = 0; i < headersFootersPeerCount; i++) { RowAutomationPeer rowPeer = headersFootersPeer[i] as RowAutomationPeer; if (rowPeer != null) { Cell cell = rowPeer.Owner.Cells[m_column]; if (cell != null) { AutomationPeer automationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(cell); Debug.Assert(automationPeer != null); if (automationPeer != null) { rawElementProviderSimples.Add(this.ProviderFromPeer(automationPeer)); } } } } return(rawElementProviderSimples.ToArray()); }
internal DataGridItemAutomationPeer FindOrCreateItemAutomationPeer(object item, int index) { DataGridItemAutomationPeer itemAutomationPeer = m_dataChildren[item] as DataGridItemAutomationPeer; if (itemAutomationPeer == null) { itemAutomationPeer = this.CreateItemAutomationPeer(item, index); } else { itemAutomationPeer.SetIndex(index); } // Force EventsSource to be updated itemAutomationPeer.GetWrapperPeer(); return(itemAutomationPeer); }
public DataGridItemCellAutomationPeer(DataGridItemAutomationPeer itemAutomationPeer, ColumnBase column) { if (itemAutomationPeer == null) { throw new ArgumentNullException("itemAutomationPeer"); } if (column == null) { throw new ArgumentNullException("column"); } m_itemAutomationPeer = itemAutomationPeer; m_column = column; // Call the GetWrapperPeer since it will force the events of the wrapped peer to be rerooted to us. AutomationPeer wrapperPeer = this.GetWrapperPeer(); }
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); }
internal void RaiseSelectionEvents(IList <object> unselectedItems, IList <object> selectedItems) { if (m_dataChildren.Count == 0) { this.RaiseAutomationEvent(AutomationEvents.SelectionPatternOnInvalidated); return; } int currentSelectedItemCount = (m_dataGridContext == null) ? 0 : m_dataGridContext.SelectedItemsStore.Count; int selectedItemsCount = selectedItems.Count; int unselectedItemsCount = unselectedItems.Count; if (currentSelectedItemCount == 1) { object item; try { // GetItem() can throw if the DataVirtualizing source don't have that item anymore. item = m_dataGridContext.SelectedItemsStore[0].GetItem(m_dataGridContext, 0); } catch { item = null; } if (item != null) { DataGridItemAutomationPeer peer = m_dataChildren[item] as DataGridItemAutomationPeer; if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } } else { this.RaiseAutomationEvent(AutomationEvents.SelectionPatternOnInvalidated); } } else if ((selectedItemsCount + unselectedItemsCount) > 20) { this.RaiseAutomationEvent(AutomationEvents.SelectionPatternOnInvalidated); } else { for (int i = 0; i < selectedItemsCount; i++) { object item; try { // Underlying GetItem() can throw if the DataVirtualizing source don't have that item anymore. item = selectedItems[i]; } catch { item = null; } if (item != null) { DataGridItemAutomationPeer peer = m_dataChildren[item] as DataGridItemAutomationPeer; if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } else { this.RaiseAutomationEvent(AutomationEvents.SelectionPatternOnInvalidated); return; } } for (int i = 0; i < unselectedItemsCount; i++) { object item; try { // Underlying GetItem() can throw if the DataVirtualizing source don't have that item anymore. item = unselectedItems[i]; } catch { item = null; } if (item != null) { DataGridItemAutomationPeer peer = m_dataChildren[item] as DataGridItemAutomationPeer; if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } else { this.RaiseAutomationEvent(AutomationEvents.SelectionPatternOnInvalidated); return; } } } }
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); }
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 = 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); }