private static void ProcessItemsNodeBlockVisit( ItemsGeneratorNode itemsNode, DataGridContext sourceContext, int minIndex, int maxIndex, IDataGridContextVisitor visitor, DataGridContextVisitorType visitorType, bool visitDetails, bool containsDetails, int sourceDataItemIndex, ref int startSourceDataItemIndex, ref int endSourceDataItemIndex, ref bool stopVisit) { if (maxIndex < minIndex) { return; } int runningIndex = minIndex; sourceDataItemIndex += minIndex - itemsNode.CountDetailsBeforeGlobalIndex(minIndex); if (!containsDetails) { // If we contains no detail, we take a quick way out of it. if (startSourceDataItemIndex == -1) { startSourceDataItemIndex = sourceDataItemIndex; } else { if ((endSourceDataItemIndex + 1) != sourceDataItemIndex) { visitor.Visit(sourceContext, startSourceDataItemIndex, endSourceDataItemIndex, ref stopVisit); if (stopVisit) { return; } startSourceDataItemIndex = sourceDataItemIndex; } } endSourceDataItemIndex = sourceDataItemIndex + System.Math.Min(maxIndex - minIndex, itemsNode.Items.Count - 1); return; } int masterIndex; int detailStartIndex; int detailNodeIndex; while (runningIndex <= maxIndex) { DetailGeneratorNode detailNode = itemsNode.GetDetailNodeForIndex(runningIndex, out masterIndex, out detailStartIndex, out detailNodeIndex); if (detailNode != null) { int detailEndIndex = System.Math.Min(detailNode.ItemCount - 1, detailStartIndex + (maxIndex - runningIndex)); sourceDataItemIndex -= detailStartIndex; bool visitWasStopped; (( IDataGridContextVisitable )detailNode.DetailGenerator).AcceptVisitor( detailStartIndex, detailEndIndex, visitor, visitorType, visitDetails, out visitWasStopped); stopVisit = stopVisit || visitWasStopped; if (stopVisit) { break; } runningIndex += detailNode.ItemCount - detailStartIndex - 1; } else { // set the first data index that will be visited for that items block if (startSourceDataItemIndex == -1) { startSourceDataItemIndex = sourceDataItemIndex; endSourceDataItemIndex = sourceDataItemIndex; } else { if ((endSourceDataItemIndex + 1) != sourceDataItemIndex) { visitor.Visit(sourceContext, startSourceDataItemIndex, endSourceDataItemIndex, ref stopVisit); if (stopVisit) { break; } startSourceDataItemIndex = sourceDataItemIndex; } endSourceDataItemIndex = sourceDataItemIndex; } sourceDataItemIndex++; } runningIndex++; } }
private static void ProcessItemsNodeVisit( ItemsGeneratorNode itemsNode, DataGridContext sourceContext, int minIndex, int maxIndex, IDataGridContextVisitor visitor, DataGridContextVisitorType visitorType, bool visitDetails, int sourceDataItemIndex, ref bool stopVisit) { int runningIndex = minIndex; sourceDataItemIndex += minIndex; int masterIndex; int detailStartIndex; int detailNodeIndex; while (runningIndex <= maxIndex) { DetailGeneratorNode detailNode = itemsNode.GetDetailNodeForIndex(runningIndex, out masterIndex, out detailStartIndex, out detailNodeIndex); if (detailNode != null) { int detailEndIndex = System.Math.Min(detailNode.ItemCount - 1, detailStartIndex + (maxIndex - runningIndex)); sourceDataItemIndex -= detailStartIndex; if (visitDetails) { bool visitWasStopped; (( IDataGridContextVisitable )detailNode.DetailGenerator).AcceptVisitor( detailStartIndex, detailEndIndex, visitor, visitorType, visitDetails, out visitWasStopped); stopVisit = stopVisit || visitWasStopped; if (stopVisit) { break; } runningIndex += detailNode.ItemCount - detailStartIndex - 1; } } else { if ((visitorType & DataGridContextVisitorType.Items) == DataGridContextVisitorType.Items) { object dataItem = itemsNode.GetAt(runningIndex); visitor.Visit(sourceContext, sourceDataItemIndex, dataItem, ref stopVisit); if (stopVisit) { break; } } sourceDataItemIndex++; } runningIndex++; } }