void IDataGridContextVisitable.AcceptVisitor( int minIndex, int maxIndex, IDataGridContextVisitor visitor, DataGridContextVisitorType visitorType, bool visitDetails, out bool visitWasStopped )
    {
      visitWasStopped = false;

      if( m_startNode == null )
        return;

      GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 );
      nodeHelper.ProcessVisit( m_dataGridContext, minIndex, maxIndex, visitor, visitorType, visitDetails, out visitWasStopped );
    }
    void IDataGridContextVisitable.AcceptVisitor( IDataGridContextVisitor visitor, out bool visitWasStopped )
    {
      IDataGridContextVisitable visitable = this as IDataGridContextVisitable;

      visitable.AcceptVisitor( 0, int.MaxValue, visitor, DataGridContextVisitorType.All, true, out visitWasStopped );
    }
    void IDataGridContextVisitable.AcceptVisitor( int minIndex, int maxIndex, IDataGridContextVisitor visitor, DataGridContextVisitorType visitorType, out bool visitWasStopped )
    {
      IDataGridContextVisitable visitable = this as IDataGridContextVisitable;

      visitable.AcceptVisitor( minIndex, maxIndex, visitor, visitorType, true, out visitWasStopped );
    }
Ejemplo n.º 4
0
        private static void ProcessItemsNodeVisit(
            ItemsGeneratorNode itemsNode,
            DataGridContext sourceContext,
            int minIndex,
            int maxIndex,
            IDataGridContextVisitor visitor,
            DataGridContextVisitorType visitorType,
            bool visitDetails,
            int sourceDataItemIndex,
            ref bool stopVisit)
        {
            var runningIndex = minIndex;

            sourceDataItemIndex += minIndex;

            int masterIndex;
            int detailStartIndex;
            int detailNodeIndex;

            while (runningIndex <= maxIndex)
            {
                var detailNode = itemsNode.GetDetailNodeForIndex(runningIndex, out masterIndex, out detailStartIndex, out detailNodeIndex);

                if (detailNode != null)
                {
                    var detailEndIndex = 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++;
            }
        }
Ejemplo n.º 5
0
        private static void ProcessHeadersNodeVisit(HeadersFootersGeneratorNode headersNode, DataGridContext sourceContext, int minIndex, int maxIndex, IDataGridContextVisitor visitor, ref bool stopVisit)
        {
            for (int i = minIndex; i <= maxIndex; i++)
            {
                var template = headersNode.GetAt(i);

                var groupNode = headersNode.Parent as GroupGeneratorNode;
                if (groupNode != null)
                {
                    visitor.Visit(sourceContext, ( GroupHeaderFooterItem )template, ref stopVisit);
                }
                else
                {
                    visitor.Visit(sourceContext, ( DataTemplate )template, ref stopVisit);
                }

                if (stopVisit)
                {
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        internal void ProcessVisit(
            DataGridContext sourceContext,
            int minIndex,
            int maxIndex,
            IDataGridContextVisitor visitor,
            DataGridContextVisitorType visitorType,
            bool visitDetails,
            out bool visitWasStopped)
        {
            visitWasStopped = false;

            // This is used only for DataGridContextVisitorType.ItemsBlock
            var startSourceDataItemIndex = -1;
            var endSourceDataItemIndex   = -1;

            if (minIndex < 0)
            {
                throw DataGridException.Create <ArgumentException>("The minimum index must be greater than or equal to zero.", sourceContext.DataGridControl, "minIndex");
            }

            if ((visitorType & DataGridContextVisitorType.DataGridContext) == DataGridContextVisitorType.DataGridContext)
            {
                visitor.Visit(sourceContext, ref visitWasStopped);

                if (visitWasStopped)
                {
                    return;
                }
            }

            //Take a shortcut, if the visit is made only for contexts, and there is no child contexts
            //return right away.
            var containsDetails = false;

            foreach (var childContext in sourceContext.GetChildContextsCore())
            {
                containsDetails = true;
                break;
            }

            var processed = false;
            var current   = m_state;

            while (true)
            {
                processed = false;

                var itemCount = current.Node.ItemCount;

                //If the whole current node is below the minIndex, jump over it.
                if ((current.Index + (itemCount - 1)) < minIndex)
                {
                    processed = true;
                }

                //when the index to visit exceeds the range defined, exit the loop.
                if (current.Index > maxIndex)
                {
                    break;
                }

                var minForNode = Math.Max(0, minIndex - current.Index);             // this will give the base offset within the node where to start the visitating!
                var maxForNode = Math.Min(itemCount - 1, maxIndex - current.Index); //this will five the max offset within this node to visit (protected against overlfow )

                if (!processed)
                {
                    var headersNode = current.Node as HeadersFootersGeneratorNode;
                    if (headersNode != null)
                    {
                        var isHeaderFooter = (headersNode.Parent == null);

                        //If the node is a Headers or Footers node AND the visitorType does not contain HeadersFooters
                        if ((isHeaderFooter) && ((visitorType & DataGridContextVisitorType.HeadersFooters) == DataGridContextVisitorType.HeadersFooters))
                        {
                            GeneratorNodeHelper.ProcessHeadersNodeVisit(headersNode, sourceContext, minForNode, maxForNode, visitor, ref visitWasStopped);
                        }
                        else if ((!isHeaderFooter) && ((visitorType & DataGridContextVisitorType.GroupHeadersFooters) == DataGridContextVisitorType.GroupHeadersFooters))
                        {
                            GeneratorNodeHelper.ProcessHeadersNodeVisit(headersNode, sourceContext, minForNode, maxForNode, visitor, ref visitWasStopped);
                        }

                        processed = true;
                    }
                }

                if (!processed)
                {
                    var itemsNode = current.Node as ItemsGeneratorNode;
                    if (itemsNode != null)
                    {
                        if ((visitorType & DataGridContextVisitorType.ItemsBlock) == DataGridContextVisitorType.ItemsBlock)
                        {
                            GeneratorNodeHelper.ProcessItemsNodeBlockVisit(
                                itemsNode, sourceContext,
                                minForNode, maxForNode,
                                visitor, visitorType, visitDetails, containsDetails, current.DataIndex,
                                ref startSourceDataItemIndex, ref endSourceDataItemIndex, ref visitWasStopped);
                        }
                        else if (((visitDetails) && (containsDetails)) ||
                                 ((visitorType & DataGridContextVisitorType.Items) == DataGridContextVisitorType.Items))
                        {
                            GeneratorNodeHelper.ProcessItemsNodeVisit(
                                itemsNode, sourceContext,
                                minForNode, maxForNode,
                                visitor, visitorType, visitDetails, current.DataIndex, ref visitWasStopped);
                        }

                        processed = true;
                    }
                }

                if (!processed)
                {
                    var groupNode = current.Node as GroupGeneratorNode;
                    if (groupNode != null)
                    {
                        if ((visitorType & DataGridContextVisitorType.Groups) == DataGridContextVisitorType.Groups)
                        {
                            visitor.Visit(
                                sourceContext,
                                groupNode.CollectionViewGroup,
                                groupNode.NamesTree,
                                groupNode.Level,
                                groupNode.IsExpanded,
                                groupNode.IsComputedExpanded,
                                ref visitWasStopped);
                        }

                        processed = true;
                    }
                }

                if (!processed)
                {
                    throw DataGridException.Create <DataGridInternalException>("Unable to process the visit.", sourceContext.DataGridControl);
                }

                if (visitWasStopped)
                {
                    break;
                }

                if (GeneratorNodeHelper.MoveToChild(ref current))
                {
                    continue;
                }

                if (GeneratorNodeHelper.MoveToFollowing(ref current))
                {
                    continue;
                }

                break;
            }

            if ((visitorType & DataGridContextVisitorType.ItemsBlock) == DataGridContextVisitorType.ItemsBlock)
            {
                if (startSourceDataItemIndex != -1)
                {
                    var stopVisit = false;
                    visitor.Visit(sourceContext, startSourceDataItemIndex, endSourceDataItemIndex, ref stopVisit);
                    visitWasStopped = visitWasStopped || stopVisit;
                }
            }

            m_state = current;

            this.EnsureState();
        }
Ejemplo n.º 7
0
        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 + 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 = 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++;
            }
        }
Ejemplo n.º 8
0
        public void ProcessVisit(
            DataGridContext sourceContext,
            int minIndex,
            int maxIndex,
            IDataGridContextVisitor visitor,
            DataGridContextVisitorType visitorType,
            bool visitDetails,
            out bool visitWasStopped)
        {
            visitWasStopped = false;

            // This is used only for DataGridContextVisitorType.ItemsBlock
            int startSourceDataItemIndex = -1;
            int endSourceDataItemIndex   = -1;

            if (minIndex < 0)
            {
                throw new ArgumentException("The minimum index must be greater than or equal to zero.");
            }

            if ((visitorType & DataGridContextVisitorType.DataGridContext) == DataGridContextVisitorType.DataGridContext)
            {
                visitor.Visit(sourceContext, ref visitWasStopped);

                if (visitWasStopped)
                {
                    return;
                }
            }

            //Take a shortcut, if the visit is made only for contexts, and there is no child contexts
            //return right away.
            bool containsDetails = false;

            foreach (DataGridContext childContext in sourceContext.GetChildContexts())
            {
                containsDetails = true;
                break;
            }

            bool processed = false;

            do
            {
                //resets the flag that indicates if the node was already processed
                processed = false;

                int itemCount = this.CurrentNode.ItemCount;

                //If the whole current node is below the minIndex, jump over it.
                if ((this.Index + (itemCount - 1)) < minIndex)
                {
                    processed = true;
                }

                //when the index to visit exceeds the range defined, exit the loop.
                if (this.Index > maxIndex)
                {
                    break;
                }

                int minForNode = Math.Max(0, minIndex - this.Index);             // this will give the base offset within the node where to start the visitating!
                int maxForNode = Math.Min(itemCount - 1, maxIndex - this.Index); //this will five the max offset within this node to visit (protected against overlfow )

                if (!processed)
                {
                    HeadersFootersGeneratorNode headersNode = this.CurrentNode as HeadersFootersGeneratorNode;

                    if (headersNode != null)
                    {
                        bool isHeaderFooter = (headersNode.Parent == null);

                        //If the node is a Headers or Footers node AND the visitorType does not contain HeadersFooters
                        if ((isHeaderFooter) && ((visitorType & DataGridContextVisitorType.HeadersFooters) == DataGridContextVisitorType.HeadersFooters))
                        {
                            GeneratorNodeHelper.ProcessHeadersNodeVisit(headersNode, sourceContext, minForNode, maxForNode, visitor, ref visitWasStopped);
                        }
                        else if ((!isHeaderFooter) && ((visitorType & DataGridContextVisitorType.GroupHeadersFooters) == DataGridContextVisitorType.GroupHeadersFooters))
                        {
                            GeneratorNodeHelper.ProcessHeadersNodeVisit(headersNode, sourceContext, minForNode, maxForNode, visitor, ref visitWasStopped);
                        }

                        processed = true;
                    }
                }

                if (!processed)
                {
                    ItemsGeneratorNode itemsNode = this.CurrentNode as ItemsGeneratorNode;

                    if (itemsNode != null)
                    {
                        if ((visitorType & DataGridContextVisitorType.ItemsBlock) == DataGridContextVisitorType.ItemsBlock)
                        {
                            GeneratorNodeHelper.ProcessItemsNodeBlockVisit(
                                itemsNode, sourceContext,
                                minForNode, maxForNode,
                                visitor, visitorType, visitDetails, containsDetails, m_sourceDataIndex,
                                ref startSourceDataItemIndex, ref endSourceDataItemIndex, ref visitWasStopped);
                        }
                        else if (((visitDetails) && (containsDetails)) ||
                                 ((visitorType & DataGridContextVisitorType.Items) == DataGridContextVisitorType.Items))
                        {
                            GeneratorNodeHelper.ProcessItemsNodeVisit(
                                itemsNode, sourceContext,
                                minForNode, maxForNode,
                                visitor, visitorType, visitDetails, m_sourceDataIndex, ref visitWasStopped);
                        }

                        processed = true;
                    }
                }

                if (!processed)
                {
                    GroupGeneratorNode groupNode = this.CurrentNode as GroupGeneratorNode;

                    if (groupNode != null)
                    {
                        if ((visitorType & DataGridContextVisitorType.Groups) == DataGridContextVisitorType.Groups)
                        {
                            visitor.Visit(
                                sourceContext,
                                groupNode.CollectionViewGroup,
                                groupNode.NamesTree,
                                groupNode.Level,
                                groupNode.IsExpanded,
                                groupNode.IsComputedExpanded,
                                ref visitWasStopped);
                        }

                        processed = true;
                    }
                }

                if (!processed)
                {
                    throw new DataGridInternalException();
                }

                if (visitWasStopped)
                {
                    break;
                }

                if (this.MoveToChild())
                {
                    continue;
                }

                if (this.MoveToFollowing())
                {
                    continue;
                }

                break;
            }while(true); //loop is controled by continue and break statements.


            if ((visitorType & DataGridContextVisitorType.ItemsBlock) == DataGridContextVisitorType.ItemsBlock)
            {
                if (startSourceDataItemIndex != -1)
                {
                    bool stopVisit = false;
                    visitor.Visit(sourceContext, startSourceDataItemIndex, endSourceDataItemIndex, ref stopVisit);
                    visitWasStopped |= stopVisit;
                }
            }
        }
    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 + 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 = 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++;
      }
    }
    public void ProcessVisit(
      DataGridContext sourceContext,
      int minIndex,
      int maxIndex,
      IDataGridContextVisitor visitor,
      DataGridContextVisitorType visitorType,
      bool visitDetails,
      out bool visitWasStopped )
    {
      visitWasStopped = false;

      // This is used only for DataGridContextVisitorType.ItemsBlock
      int startSourceDataItemIndex = -1;
      int endSourceDataItemIndex = -1;

      if( minIndex < 0 )
      {
        DataGridException.ThrowSystemException( "The minimum index must be greater than or equal to zero.",
                                                typeof( ArgumentException ), sourceContext.DataGridControl.Name, "minIndex" );
      }

      if( ( visitorType & DataGridContextVisitorType.DataGridContext ) == DataGridContextVisitorType.DataGridContext )
      {
        visitor.Visit( sourceContext, ref visitWasStopped );

        if( visitWasStopped )
          return;
      }

      //Take a shortcut, if the visit is made only for contexts, and there is no child contexts
      //return right away.
      bool containsDetails = false;

      foreach( DataGridContext childContext in sourceContext.GetChildContexts() )
      {
        containsDetails = true;
        break;
      }

      bool processed = false;

      do
      {
        //resets the flag that indicates if the node was already processed
        processed = false;

        int itemCount = this.CurrentNode.ItemCount;

        //If the whole current node is below the minIndex, jump over it.
        if( ( this.Index + ( itemCount - 1 ) ) < minIndex )
        {
          processed = true;
        }

        //when the index to visit exceeds the range defined, exit the loop.
        if( this.Index > maxIndex )
          break;

        int minForNode = Math.Max( 0, minIndex - this.Index ); // this will give the base offset within the node where to start the visitating!
        int maxForNode = Math.Min( itemCount - 1, maxIndex - this.Index ); //this will five the max offset within this node to visit (protected against overlfow )

        if( !processed )
        {
          HeadersFootersGeneratorNode headersNode = this.CurrentNode as HeadersFootersGeneratorNode;

          if( headersNode != null )
          {
            bool isHeaderFooter = ( headersNode.Parent == null );

            //If the node is a Headers or Footers node AND the visitorType does not contain HeadersFooters
            if( ( isHeaderFooter ) && ( ( visitorType & DataGridContextVisitorType.HeadersFooters ) == DataGridContextVisitorType.HeadersFooters ) )
            {
              GeneratorNodeHelper.ProcessHeadersNodeVisit( headersNode, sourceContext, minForNode, maxForNode, visitor, ref visitWasStopped );
            }
            else if( ( !isHeaderFooter ) && ( ( visitorType & DataGridContextVisitorType.GroupHeadersFooters ) == DataGridContextVisitorType.GroupHeadersFooters ) )
            {
              GeneratorNodeHelper.ProcessHeadersNodeVisit( headersNode, sourceContext, minForNode, maxForNode, visitor, ref visitWasStopped );
            }

            processed = true;
          }
        }

        if( !processed )
        {
          ItemsGeneratorNode itemsNode = this.CurrentNode as ItemsGeneratorNode;

          if( itemsNode != null )
          {
            if( ( visitorType & DataGridContextVisitorType.ItemsBlock ) == DataGridContextVisitorType.ItemsBlock )
            {
              GeneratorNodeHelper.ProcessItemsNodeBlockVisit(
                itemsNode, sourceContext,
                minForNode, maxForNode,
                visitor, visitorType, visitDetails, containsDetails, m_sourceDataIndex,
                ref startSourceDataItemIndex, ref endSourceDataItemIndex, ref visitWasStopped );
            }
            else if( ( ( visitDetails ) && ( containsDetails ) )
              || ( ( visitorType & DataGridContextVisitorType.Items ) == DataGridContextVisitorType.Items ) )
            {
              GeneratorNodeHelper.ProcessItemsNodeVisit(
                itemsNode, sourceContext,
                minForNode, maxForNode,
                visitor, visitorType, visitDetails, m_sourceDataIndex, ref visitWasStopped );
            }

            processed = true;
          }
        }

        if( !processed )
        {
          GroupGeneratorNode groupNode = this.CurrentNode as GroupGeneratorNode;

          if( groupNode != null )
          {
            if( ( visitorType & DataGridContextVisitorType.Groups ) == DataGridContextVisitorType.Groups )
            {
              visitor.Visit(
                sourceContext,
                groupNode.CollectionViewGroup,
                groupNode.NamesTree,
                groupNode.Level,
                groupNode.IsExpanded,
                groupNode.IsComputedExpanded,
                ref visitWasStopped );
            }

            processed = true;
          }
        }

        if( !processed )
          throw new DataGridInternalException( "Unable to process the visit.", sourceContext.DataGridControl );

        if( visitWasStopped )
          break;

        if( this.MoveToChild() )
          continue;

        if( this.MoveToFollowing() )
          continue;

        break;
      }
      while( true ); //loop is controled by continue and break statements.


      if( ( visitorType & DataGridContextVisitorType.ItemsBlock ) == DataGridContextVisitorType.ItemsBlock )
      {
        if( startSourceDataItemIndex != -1 )
        {
          bool stopVisit = false;
          visitor.Visit( sourceContext, startSourceDataItemIndex, endSourceDataItemIndex, ref stopVisit );
          visitWasStopped = visitWasStopped || stopVisit;
        }
      }
    }
    private static void ProcessHeadersNodeVisit( HeadersFootersGeneratorNode headersNode, DataGridContext sourceContext, int minIndex, int maxIndex, IDataGridContextVisitor visitor, ref bool stopVisit )
    {
      for( int i = minIndex; i <= maxIndex; i++ )
      {
        object template = headersNode.GetAt( i );

        GroupGeneratorNode groupNode = headersNode.Parent as GroupGeneratorNode;
        if( groupNode != null )
        {
          visitor.Visit( sourceContext, ( GroupHeaderFooterItem )template, ref stopVisit );
        }
        else
        {
          visitor.Visit( sourceContext, ( DataTemplate )template, ref stopVisit );
        }

        if( stopVisit )
          break;
      }
    }
    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 = 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++;
      }
    }