// Token: 0x0600300F RID: 12303 RVA: 0x000D8250 File Offset: 0x000D6450
 private void OnLayerChanged(object sender, HighlightChangedEventArgs args)
 {
     if (this.Changed != null)
     {
         this.Changed(this, args);
     }
 }
Exemplo n.º 2
0
 // Callback for changes on a single layer.
 private void OnLayerChanged(object sender, HighlightChangedEventArgs args)
 {
     // Forward on the event to any listeners.
     if (this.Changed != null)
     {
         Changed(this, args);
     }
 }
Exemplo n.º 3
0
        // Token: 0x06002BD3 RID: 11219 RVA: 0x000C7B28 File Offset: 0x000C5D28
        private void _OnHighlightChanged(object sender, HighlightChangedEventArgs args)
        {
            int i = 0;
            DocumentSequenceTextPointer documentSequenceTextPointer = null;
            ChildDocumentBlock          childDocumentBlock          = null;
            List <TextSegment>          list = new List <TextSegment>(4);

            while (i < args.Ranges.Count)
            {
                TextSegment textSegment = (TextSegment)args.Ranges[i];
                DocumentSequenceTextPointer documentSequenceTextPointer2 = (DocumentSequenceTextPointer)textSegment.End;
                if (documentSequenceTextPointer == null)
                {
                    documentSequenceTextPointer = (DocumentSequenceTextPointer)textSegment.Start;
                }
                ChildDocumentBlock childDocumentBlock2 = childDocumentBlock;
                childDocumentBlock = documentSequenceTextPointer.ChildBlock;
                if (childDocumentBlock2 != null && childDocumentBlock != childDocumentBlock2 && !(childDocumentBlock2.ChildContainer is NullTextContainer) && list.Count != 0)
                {
                    childDocumentBlock2.ChildHighlightLayer.RaiseHighlightChangedEvent(new ReadOnlyCollection <TextSegment>(list));
                    list.Clear();
                }
                ITextPointer childPointer = documentSequenceTextPointer.ChildPointer;
                if (documentSequenceTextPointer2.ChildBlock != childDocumentBlock)
                {
                    ITextPointer textPointer = documentSequenceTextPointer.ChildPointer.TextContainer.End;
                    if (childPointer.CompareTo(textPointer) != 0)
                    {
                        list.Add(new TextSegment(childPointer, textPointer));
                    }
                    if (!(childDocumentBlock.ChildContainer is NullTextContainer) && list.Count != 0)
                    {
                        childDocumentBlock.ChildHighlightLayer.RaiseHighlightChangedEvent(new ReadOnlyCollection <TextSegment>(list));
                    }
                    childDocumentBlock          = childDocumentBlock.NextBlock;
                    documentSequenceTextPointer = new DocumentSequenceTextPointer(childDocumentBlock, childDocumentBlock.ChildContainer.Start);
                    list.Clear();
                }
                else
                {
                    ITextPointer textPointer = documentSequenceTextPointer2.ChildPointer;
                    if (childPointer.CompareTo(textPointer) != 0)
                    {
                        list.Add(new TextSegment(childPointer, textPointer));
                    }
                    i++;
                    documentSequenceTextPointer = null;
                }
            }
            if (list.Count > 0 && childDocumentBlock != null && !(childDocumentBlock.ChildContainer is NullTextContainer))
            {
                childDocumentBlock.ChildHighlightLayer.RaiseHighlightChangedEvent(new ReadOnlyCollection <TextSegment>(list));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Invalidates a portion of text affected by a highlight change.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnHighlightChanged(object sender, HighlightChangedEventArgs args)
        {
            TextSegment textSegment;
            int i;

            Invariant.Assert(args != null);
            Invariant.Assert(args.Ranges != null);
            Invariant.Assert(_structuralCache != null && _structuralCache.IsFormattedOnce, "Unexpected Highlights.Changed callback before first format!");

            // Detect invalid content change operations.
            if (_structuralCache.IsFormattingInProgress)
            {
                _structuralCache.OnInvalidOperationDetected();
                throw new InvalidOperationException(SR.Get(SRID.FlowDocumentInvalidContnetChange));
            }

            // The only supported highlight type for FlowDocument is SpellerHightlight.
            // TextSelection and HighlightComponent are ignored, because they are handled by
            // separate layer.
            if (args.OwnerType != typeof(SpellerHighlightLayer))
            {
                return;
            }

            if (args.Ranges.Count > 0)
            {

                // Invalidate affected pages and break records.
                // We DTR invalidate if we're using a formatter as well for incremental update.
                if (_formatter == null || !(_formatter is FlowDocumentFormatter))
                {
                    _structuralCache.InvalidateFormatCache(/*Clear structure*/ false);
                }

                // Notify formatter about content invalidation.
                if (_formatter != null)
                {
                    for (i = 0; i < args.Ranges.Count; i++)
                    {
                        textSegment = (TextSegment)args.Ranges[i];
                        _formatter.OnContentInvalidated(false, textSegment.Start, textSegment.End);

                        if (_formatter is FlowDocumentFormatter)
                        {
                            DirtyTextRange dtr = new DirtyTextRange(textSegment.Start.Offset,
                                                                    textSegment.Start.GetOffsetToPosition(textSegment.End),
                                                                    textSegment.Start.GetOffsetToPosition(textSegment.End)
                                                                    );
                            _structuralCache.AddDirtyTextRange(dtr);
                        }
                    }
                }
            }
        }
        //--------------------------------------------------------------------
        // Highlight compositing
        //---------------------------------------------------------------------

        private void _OnHighlightChanged(object sender, HighlightChangedEventArgs args)
        {
            Debug.Assert(sender != null);
            Debug.Assert(args != null);
            Debug.Assert(args.Ranges != null);
#if DEBUG
            {
                Highlights        highlights = this.Highlights;
                StaticTextPointer highlightTransitionPosition;
                StaticTextPointer highlightRangeStart;
                object            selected;

                DocumentsTrace.FixedDocumentSequence.Highlights.Trace("===BeginNewHighlightRange===");
                highlightTransitionPosition = ((ITextContainer)this).CreateStaticPointerAtOffset(0);
                while (true)
                {
                    // Move to the next highlight start.
                    if (!highlights.IsContentHighlighted(highlightTransitionPosition, LogicalDirection.Forward))
                    {
                        highlightTransitionPosition = highlights.GetNextHighlightChangePosition(highlightTransitionPosition, LogicalDirection.Forward);

                        // No more highlights?
                        if (highlightTransitionPosition.IsNull)
                        {
                            break;
                        }
                    }

                    // highlightTransitionPosition is at the start of a new highlight run.
                    selected = highlights.GetHighlightValue(highlightTransitionPosition, LogicalDirection.Forward, typeof(TextSelection));

                    // Save the start position and find the end.
                    highlightRangeStart         = highlightTransitionPosition;
                    highlightTransitionPosition = highlights.GetNextHighlightChangePosition(highlightTransitionPosition, LogicalDirection.Forward);
                    Invariant.Assert(!highlightTransitionPosition.IsNull, "Highlight start not followed by highlight end!");

                    // Store the highlight.
                    if (selected != DependencyProperty.UnsetValue)
                    {
                        DocumentsTrace.FixedDocumentSequence.Highlights.Trace(string.Format("HightlightRange {0}-{1}", highlightRangeStart.ToString(), highlightTransitionPosition.ToString()));
                        if (highlightRangeStart.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text)
                        {
                            DocumentsTrace.FixedDocumentSequence.Highlights.Trace("<HighlightNotOnText>");
                        }
                        else
                        {
                            char[] sb = new char[256];
                            TextPointerBase.GetTextWithLimit(highlightRangeStart.CreateDynamicTextPointer(LogicalDirection.Forward), LogicalDirection.Forward, sb, 0, 256, highlightTransitionPosition.CreateDynamicTextPointer(LogicalDirection.Forward));
                            DocumentsTrace.FixedDocumentSequence.TextOM.Trace(string.Format("HightlightContent [{0}]", new String(sb)));
                        }
                    }
                }
                DocumentsTrace.FixedDocumentSequence.TextOM.Trace("===EndNewHighlightRange===");
            }
#endif
            Debug.Assert(args.Ranges.Count > 0 && ((TextSegment)args.Ranges[0]).Start.CompareTo(((TextSegment)args.Ranges[0]).End) < 0);


            // For each change range we received, we need to figure out
            // affected child TextContainer, and notify it with appropriate
            // ranges that are in the child's address space.
            //
            // We only fire one highlight change notification for any child
            // TextContainer even if there is multiple change ranges fall
            // into the same child TextContainer.
            //
            // We scan the ranges and the child TextContainer in the same loop,
            // moving forward two scanning pointers and at boundary of each
            // TextContainer, we fire a change notification.
            //
            int idxScan = 0;
            DocumentSequenceTextPointer tsScan     = null;
            ChildDocumentBlock          cdbScan    = null;
            List <TextSegment>          rangeArray = new List <TextSegment>(4);
            while (idxScan < args.Ranges.Count)
            {
                TextSegment ts = (TextSegment)args.Ranges[idxScan];
                DocumentSequenceTextPointer tsEnd = (DocumentSequenceTextPointer)ts.End;
                ITextPointer       tpChildStart, tpChildEnd;
                ChildDocumentBlock lastBlock;

                // If tsScan == null, we were done with previous range,
                // so we are going to set tsScan to begining of this range.
                // Otherwise the previous range was split so we will simply
                // start from what was left over from previous loop.
                if (tsScan == null)
                {
                    tsScan = (DocumentSequenceTextPointer)ts.Start;
                }
                lastBlock = cdbScan;
                cdbScan   = tsScan.ChildBlock;

                if (lastBlock != null && cdbScan != lastBlock && !(lastBlock.ChildContainer is NullTextContainer) && rangeArray.Count != 0)
                {
                    // This range is in a different block, so take care of old blocks first
                    lastBlock.ChildHighlightLayer.RaiseHighlightChangedEvent(new ReadOnlyCollection <TextSegment>(rangeArray));
                    rangeArray.Clear();
                }

                tpChildStart = tsScan.ChildPointer;

                if (tsEnd.ChildBlock != cdbScan)
                {
                    // If this range crosses blocks, we are done with current block
                    tpChildEnd = tsScan.ChildPointer.TextContainer.End;
                    if (tpChildStart.CompareTo(tpChildEnd) != 0)
                    {
                        rangeArray.Add(new TextSegment(tpChildStart, tpChildEnd));
                    }
                    // Notify child container
                    if (!(cdbScan.ChildContainer is NullTextContainer) && rangeArray.Count != 0)
                    {
                        cdbScan.ChildHighlightLayer.RaiseHighlightChangedEvent(new ReadOnlyCollection <TextSegment>(rangeArray));
                    }

                    // Move on to next block;
                    cdbScan = cdbScan.NextBlock;
                    tsScan  = new DocumentSequenceTextPointer(cdbScan, cdbScan.ChildContainer.Start);
                    rangeArray.Clear();
                }
                else
                {
                    // Otherwise we need to go on to see if there is more ranges
                    // fall withing the same block. Simply add this change range
                    tpChildEnd = tsEnd.ChildPointer;
                    if (tpChildStart.CompareTo(tpChildEnd) != 0)
                    {
                        rangeArray.Add(new TextSegment(tpChildStart, tpChildEnd));
                    }

                    // Move on to next range
                    idxScan++;
                    tsScan = null;
                }
            }

            // Fire change notification for the last child block.
            if (rangeArray.Count > 0 && (!(cdbScan == null || cdbScan.ChildContainer is NullTextContainer)))
            {
                cdbScan.ChildHighlightLayer.RaiseHighlightChangedEvent(new ReadOnlyCollection <TextSegment>(rangeArray));
            }
        }
Exemplo n.º 6
0
        // ------------------------------------------------------------------
        // Invalidates a portion of text affected by a highlight change.
        // ------------------------------------------------------------------
        private void OnHighlightChanged(object sender, HighlightChangedEventArgs args)
        {
            Invariant.Assert(args != null);
            Invariant.Assert(args.Ranges != null);
            Invariant.Assert(CheckFlags(Flags.FormattedOnce), "Unexpected Highlights.Changed callback before first format!");

            // The only supported highlight type for TextBlock is SpellerHightlight.
            // TextSelection and HighlightComponent are ignored, because they are handled by
            // separate layer.
            if (args.OwnerType != typeof(SpellerHighlightLayer))
            {
                return;
            }

            // NOTE: Assuming that only rendering only properties are changeing
            //       through highlights.
            InvalidateVisual();
        }
Exemplo n.º 7
0
 // Callback for changes on a single layer.
 private void OnLayerChanged(object sender, HighlightChangedEventArgs args)
 {
     // Forward on the event to any listeners.
     if (this.Changed != null)
     {
         Changed(this, args);
     }
 }
Exemplo n.º 8
0
        //---------------------------------------
        // Text Editing
        //---------------------------------------
        private void OnHighlightChanged(object sender, HighlightChangedEventArgs args)
        {
            Debug.Assert(sender != null);
            Debug.Assert(args != null);
            Debug.Assert(args.Ranges != null);

            DocumentsTrace.FixedTextOM.Highlight.Trace(string.Format("HightlightMoved From {0}-{1} To {2}-{3}",0, 0, 0, 0));
            Debug.Assert(args.Ranges.Count > 0 && ((TextSegment)args.Ranges[0]).Start.CompareTo(((TextSegment)args.Ranges[0]).End) < 0);

            // 



            // Add new highlights, if any
            ITextContainer tc = this.FixedContainer;
            Highlights highlights = null;

            // If this document is part of a FixedDocumentSequence, we should use 
            // the highlights that have been set on the sequence.
            FixedDocumentSequence parent = this.Parent as FixedDocumentSequence;
            if (parent != null)
                highlights = parent.TextContainer.Highlights;
            else
                highlights = this.FixedContainer.Highlights;

            StaticTextPointer highlightTransitionPosition;
            StaticTextPointer highlightRangeStart;
            object selected;
            
            //Find out if any highlights have been removed. We need to invalidate those pages
            List<FixedPage> oldHighlightPages = new List<FixedPage>();
            foreach (FixedPage page in _highlights.Keys)
            {
                oldHighlightPages.Add(page);
            }

            _highlights.Clear();

            highlightTransitionPosition = tc.CreateStaticPointerAtOffset(0);

            while (true)
            {
                // Move to the next highlight start.
                if (!highlights.IsContentHighlighted(highlightTransitionPosition, LogicalDirection.Forward))
                {
                    highlightTransitionPosition = highlights.GetNextHighlightChangePosition(highlightTransitionPosition, LogicalDirection.Forward);

                    // No more highlights?
                    if (highlightTransitionPosition.IsNull)
                        break;
                }

                // highlightTransitionPosition is at the start of a new highlight run.
                // Get the highlight data.
                // NB: this code only recognizes typeof(TextSelection) + AnnotationHighlight.
                // We should add code here to handle other properties: foreground/background/etc.
                selected = highlights.GetHighlightValue(highlightTransitionPosition, LogicalDirection.Forward, typeof(TextSelection));

                // Save the start position and find the end.
                highlightRangeStart = highlightTransitionPosition;

                //placeholder for highlight type
                FixedHighlightType fixedHighlightType = FixedHighlightType.None;
                Brush foreground = null;
                Brush background = null;

                // Store the highlight.
                if (selected != DependencyProperty.UnsetValue)
                {
                    //find next TextSelection change.
                    //This is to skip AnnotationHighlight
                    //change positions, since Annotation Highlight is invisible under TextSelection
                    do
                    {
                        highlightTransitionPosition = highlights.GetNextHighlightChangePosition(highlightTransitionPosition, LogicalDirection.Forward);
                        Debug.Assert(!highlightTransitionPosition.IsNull, "Highlight start not followed by highlight end!");
                    }
                    while (highlights.GetHighlightValue(highlightTransitionPosition, LogicalDirection.Forward, typeof(TextSelection)) != DependencyProperty.UnsetValue);
                    fixedHighlightType = FixedHighlightType.TextSelection;
                    foreground = null;
                    background = null;
                }
                else
                {
                    //look for annotation highlight
                    AnnotationHighlightLayer.HighlightSegment highlightSegment = highlights.GetHighlightValue(highlightRangeStart,
                        LogicalDirection.Forward, typeof(HighlightComponent)) as AnnotationHighlightLayer.HighlightSegment;
                    if (highlightSegment != null)
                    {
                        //this is a visible annotation highlight
                        highlightTransitionPosition = highlights.GetNextHighlightChangePosition(highlightTransitionPosition, LogicalDirection.Forward);
                        Debug.Assert(!highlightTransitionPosition.IsNull, "Highlight start not followed by highlight end!");
                        fixedHighlightType = FixedHighlightType.AnnotationHighlight;
                        background = highlightSegment.Fill;

                    }
                }

                //generate fixed highlight if a highlight was has been found
                if (fixedHighlightType != FixedHighlightType.None)
                {
                    this.FixedContainer.GetMultiHighlights((FixedTextPointer)highlightRangeStart.CreateDynamicTextPointer(LogicalDirection.Forward),
                                                            (FixedTextPointer)highlightTransitionPosition.CreateDynamicTextPointer(LogicalDirection.Forward),
                                                           _highlights, fixedHighlightType, foreground, background);

                }
            }

            ArrayList dirtyPages = new ArrayList();
            IList ranges = args.Ranges;

            // Find the dirty page
            for (int i = 0; i < ranges.Count; i++)
            {
                TextSegment textSegment = (TextSegment)ranges[i];
                int startPage = this.FixedContainer.GetPageNumber(textSegment.Start);
                int endPage =  this.FixedContainer.GetPageNumber(textSegment.End);

                for (int count = startPage; count <= endPage; count ++)
                {
                    if (dirtyPages.IndexOf(count) < 0)
                    {
                        dirtyPages.Add(count);
                    }
                }
            }

            ICollection<FixedPage> newHighlightPages = _highlights.Keys as ICollection<FixedPage>;
            
            //Also dirty the pages that had highlights before but not anymore
            foreach (FixedPage page in oldHighlightPages)
            {
                if (!newHighlightPages.Contains(page))
                {
                    int pageNo = GetIndexOfPage(page);
                    Debug.Assert(pageNo >= 0 && pageNo<PageCount);
                    if (pageNo >=0 && pageNo < PageCount && dirtyPages.IndexOf(pageNo) < 0)
                    {
                        dirtyPages.Add(pageNo);
                    }
                }
                
            }
            dirtyPages.Sort();

            foreach (int i in dirtyPages)
            {
                HighlightVisual hv = HighlightVisual.GetHighlightVisual(SyncGetPage(i, false /*forceReload*/));

                if (hv != null)
                {
                    hv.InvalidateHighlights();
                }
            }
        }
        //------------------------------------------------------------------- 
        // Highlight compositing 
        //----------------------------------------------------------------------
 
        private void _OnHighlightChanged(object sender, HighlightChangedEventArgs args)
        {
            Debug.Assert(sender != null);
            Debug.Assert(args != null); 
            Debug.Assert(args.Ranges != null);
#if DEBUG 
            { 
                Highlights highlights = this.Highlights;
                StaticTextPointer highlightTransitionPosition; 
                StaticTextPointer highlightRangeStart;
                object selected;

                DocumentsTrace.FixedDocumentSequence.Highlights.Trace("===BeginNewHighlightRange==="); 
                highlightTransitionPosition = ((ITextContainer)this).CreateStaticPointerAtOffset(0);
                while (true) 
                { 
                    // Move to the next highlight start.
                    if (!highlights.IsContentHighlighted(highlightTransitionPosition, LogicalDirection.Forward)) 
                    {
                        highlightTransitionPosition = highlights.GetNextHighlightChangePosition(highlightTransitionPosition, LogicalDirection.Forward);

                        // No more highlights? 
                        if (highlightTransitionPosition.IsNull)
                            break; 
                    } 

                    // highlightTransitionPosition is at the start of a new highlight run. 
                    selected = highlights.GetHighlightValue(highlightTransitionPosition, LogicalDirection.Forward, typeof(TextSelection));

                    // Save the start position and find the end.
                    highlightRangeStart = highlightTransitionPosition; 
                    highlightTransitionPosition = highlights.GetNextHighlightChangePosition(highlightTransitionPosition, LogicalDirection.Forward);
                    Invariant.Assert(!highlightTransitionPosition.IsNull, "Highlight start not followed by highlight end!"); 
 
                    // Store the highlight.
                    if (selected != DependencyProperty.UnsetValue) 
                    {
                        DocumentsTrace.FixedDocumentSequence.Highlights.Trace(string.Format("HightlightRange {0}-{1}", highlightRangeStart.ToString(), highlightTransitionPosition.ToString()));
                        if (highlightRangeStart.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text)
                        { 
                            DocumentsTrace.FixedDocumentSequence.Highlights.Trace("<HighlightNotOnText>");
                        } 
                        else 
                        {
                            char[] sb = new char[256]; 
                            TextPointerBase.GetTextWithLimit(highlightRangeStart.CreateDynamicTextPointer(LogicalDirection.Forward), LogicalDirection.Forward, sb, 0, 256, highlightTransitionPosition.CreateDynamicTextPointer(LogicalDirection.Forward));
                            DocumentsTrace.FixedDocumentSequence.TextOM.Trace(string.Format("HightlightContent [{0}]", new String(sb)));
                        }
                    } 
                }
                DocumentsTrace.FixedDocumentSequence.TextOM.Trace("===EndNewHighlightRange==="); 
            } 
#endif
            Debug.Assert(args.Ranges.Count > 0 && ((TextSegment)args.Ranges[0]).Start.CompareTo(((TextSegment)args.Ranges[0]).End) < 0); 


            // For each change range we received, we need to figure out
            // affected child TextContainer, and notify it with appropriate 
            // ranges that are in the child's address space.
            // 
            // We only fire one highlight change notification for any child 
            // TextContainer even if there is multiple change ranges fall
            // into the same child TextContainer. 
            //
            // We scan the ranges and the child TextContainer in the same loop,
            // moving forward two scanning pointers and at boundary of each
            // TextContainer, we fire a change notification. 
            //
            int idxScan = 0; 
            DocumentSequenceTextPointer  tsScan  = null; 
            ChildDocumentBlock cdbScan =  null;
            List<TextSegment>  rangeArray = new List<TextSegment>(4); 
            while (idxScan < args.Ranges.Count)
            {
                TextSegment ts = (TextSegment)args.Ranges[idxScan];
                DocumentSequenceTextPointer tsEnd   = (DocumentSequenceTextPointer)ts.End; 
                ITextPointer tpChildStart, tpChildEnd;
                ChildDocumentBlock lastBlock; 
 
                // If tsScan == null, we were done with previous range,
                // so we are going to set tsScan to begining of this range. 
                // Otherwise the previous range was split so we will simply
                // start from what was left over from previous loop.
                if (tsScan == null)
                { 
                    tsScan = (DocumentSequenceTextPointer)ts.Start;
                } 
                lastBlock = cdbScan; 
                cdbScan = tsScan.ChildBlock;
 
                if (lastBlock != null && cdbScan != lastBlock && !(lastBlock.ChildContainer is NullTextContainer) && rangeArray.Count != 0)
                {
                    // This range is in a different block, so take care of old blocks first
                    lastBlock.ChildHighlightLayer.RaiseHighlightChangedEvent(new ReadOnlyCollection<TextSegment>(rangeArray)); 
                    rangeArray.Clear();
                } 
 
                tpChildStart = tsScan.ChildPointer;
 
                if (tsEnd.ChildBlock != cdbScan)
                {
                    // If this range crosses blocks, we are done with current block
                    tpChildEnd = tsScan.ChildPointer.TextContainer.End; 
                    if (tpChildStart.CompareTo(tpChildEnd) != 0)
                    { 
                        rangeArray.Add(new TextSegment(tpChildStart, tpChildEnd)); 
                    }
                    // Notify child container 
                    if (!(cdbScan.ChildContainer is NullTextContainer) && rangeArray.Count != 0)
                    {
                        cdbScan.ChildHighlightLayer.RaiseHighlightChangedEvent(new ReadOnlyCollection<TextSegment>(rangeArray));
                    } 

                    // Move on to next block; 
                    cdbScan = cdbScan.NextBlock; 
                    tsScan  = new DocumentSequenceTextPointer(cdbScan, cdbScan.ChildContainer.Start);
                    rangeArray.Clear(); 
                }
                else
                {
                    // Otherwise we need to go on to see if there is more ranges 
                    // fall withing the same block. Simply add this change range
                    tpChildEnd = tsEnd.ChildPointer; 
                    if (tpChildStart.CompareTo(tpChildEnd) != 0) 
                    {
                        rangeArray.Add(new TextSegment(tpChildStart, tpChildEnd)); 
                    }

                    // Move on to next range
                    idxScan++; 
                    tsScan = null;
                } 
            } 

            // Fire change notification for the last child block. 
            if (rangeArray.Count > 0 && (!(cdbScan == null || cdbScan.ChildContainer is NullTextContainer)))
            {
                cdbScan.ChildHighlightLayer.RaiseHighlightChangedEvent(new ReadOnlyCollection<TextSegment>(rangeArray));
            } 
        }
Exemplo n.º 10
0
        // Callback from the TextContainer when a highlight changes.
        private void OnHighlightChanged(object sender, HighlightChangedEventArgs args)
        {
            // The only supported highlight type for TextBoxView is SpellerHighlight.
            if (args.OwnerType != typeof(SpellerHighlightLayer))
            {
                return;
            }

            if (_dirtyList == null)
            {
                _dirtyList = new DtrList();
            }

            //
            // Add the change to our dirty list.
            //

            foreach (TextSegment segment in args.Ranges)
            {
                int positionsCovered = segment.End.Offset - segment.Start.Offset;
                DirtyTextRange dirtyTextRange = new DirtyTextRange(segment.Start.Offset, positionsCovered, positionsCovered);
                _dirtyList.Merge(dirtyTextRange);
            }

            //
            // Force a re-measure.
            //
            // NB: it's not currently possible to InvalidateArrange here.
            // "Render only" changes from the highlight layer change the way we
            // ultimately feed text to the formatter.  Introducing breaks for
            // highlights may actually change the layout of the text as
            // characters are interpreted in different contexts.  Dev10 Bugs
            // 511849 has an example.
            //
            InvalidateMeasure();
        }
        // Token: 0x06002CE0 RID: 11488 RVA: 0x000CA4F8 File Offset: 0x000C86F8
        private void OnHighlightChanged(object sender, HighlightChangedEventArgs args)
        {
            ITextContainer        fixedContainer        = this.FixedContainer;
            Highlights            highlights            = null;
            FixedDocumentSequence fixedDocumentSequence = base.Parent as FixedDocumentSequence;

            if (fixedDocumentSequence != null)
            {
                highlights = fixedDocumentSequence.TextContainer.Highlights;
            }
            else
            {
                highlights = this.FixedContainer.Highlights;
            }
            List <FixedPage> list = new List <FixedPage>();

            foreach (FixedPage item in this._highlights.Keys)
            {
                list.Add(item);
            }
            this._highlights.Clear();
            StaticTextPointer staticTextPointer = fixedContainer.CreateStaticPointerAtOffset(0);

            for (;;)
            {
                if (!highlights.IsContentHighlighted(staticTextPointer, LogicalDirection.Forward))
                {
                    staticTextPointer = highlights.GetNextHighlightChangePosition(staticTextPointer, LogicalDirection.Forward);
                    if (staticTextPointer.IsNull)
                    {
                        break;
                    }
                }
                object             highlightValue     = highlights.GetHighlightValue(staticTextPointer, LogicalDirection.Forward, typeof(TextSelection));
                StaticTextPointer  textPosition       = staticTextPointer;
                FixedHighlightType fixedHighlightType = FixedHighlightType.None;
                Brush foregroundBrush = null;
                Brush backgroundBrush = null;
                if (highlightValue != DependencyProperty.UnsetValue)
                {
                    do
                    {
                        staticTextPointer = highlights.GetNextHighlightChangePosition(staticTextPointer, LogicalDirection.Forward);
                    }while (highlights.GetHighlightValue(staticTextPointer, LogicalDirection.Forward, typeof(TextSelection)) != DependencyProperty.UnsetValue);
                    fixedHighlightType = FixedHighlightType.TextSelection;
                    foregroundBrush    = null;
                    backgroundBrush    = null;
                }
                else
                {
                    AnnotationHighlightLayer.HighlightSegment highlightSegment = highlights.GetHighlightValue(textPosition, LogicalDirection.Forward, typeof(HighlightComponent)) as AnnotationHighlightLayer.HighlightSegment;
                    if (highlightSegment != null)
                    {
                        staticTextPointer  = highlights.GetNextHighlightChangePosition(staticTextPointer, LogicalDirection.Forward);
                        fixedHighlightType = FixedHighlightType.AnnotationHighlight;
                        backgroundBrush    = highlightSegment.Fill;
                    }
                }
                if (fixedHighlightType != FixedHighlightType.None)
                {
                    this.FixedContainer.GetMultiHighlights((FixedTextPointer)textPosition.CreateDynamicTextPointer(LogicalDirection.Forward), (FixedTextPointer)staticTextPointer.CreateDynamicTextPointer(LogicalDirection.Forward), this._highlights, fixedHighlightType, foregroundBrush, backgroundBrush);
                }
            }
            ArrayList arrayList = new ArrayList();
            IList     ranges    = args.Ranges;

            for (int i = 0; i < ranges.Count; i++)
            {
                TextSegment textSegment = (TextSegment)ranges[i];
                int         pageNumber  = this.FixedContainer.GetPageNumber(textSegment.Start);
                int         pageNumber2 = this.FixedContainer.GetPageNumber(textSegment.End);
                for (int j = pageNumber; j <= pageNumber2; j++)
                {
                    if (arrayList.IndexOf(j) < 0)
                    {
                        arrayList.Add(j);
                    }
                }
            }
            ICollection <FixedPage> keys = this._highlights.Keys;

            foreach (FixedPage fixedPage in list)
            {
                if (!keys.Contains(fixedPage))
                {
                    int indexOfPage = this.GetIndexOfPage(fixedPage);
                    if (indexOfPage >= 0 && indexOfPage < this.PageCount && arrayList.IndexOf(indexOfPage) < 0)
                    {
                        arrayList.Add(indexOfPage);
                    }
                }
            }
            arrayList.Sort();
            foreach (object obj in arrayList)
            {
                int             index           = (int)obj;
                HighlightVisual highlightVisual = HighlightVisual.GetHighlightVisual(this.SyncGetPage(index, false));
                if (highlightVisual != null)
                {
                    highlightVisual.InvalidateHighlights();
                }
            }
        }