Exemple #1
0
            // Token: 0x0600847C RID: 33916 RVA: 0x002483B0 File Offset: 0x002465B0
            private StaticTextPointer GetStaticPositionInChildContainer(StaticTextPointer textPosition, LogicalDirection direction, StaticTextPointer originalPosition)
            {
                StaticTextPointer result = StaticTextPointer.Null;

                if (!textPosition.IsNull)
                {
                    DocumentSequenceTextPointer documentSequenceTextPointer = textPosition.CreateDynamicTextPointer(LogicalDirection.Forward) as DocumentSequenceTextPointer;
                    ITextPointer textPointer = documentSequenceTextPointer.ChildPointer;
                    if (textPointer.TextContainer != originalPosition.TextContainer)
                    {
                        if (this.IsContentHighlighted(originalPosition, direction))
                        {
                            textPointer = ((direction == LogicalDirection.Forward) ? originalPosition.TextContainer.End : originalPosition.TextContainer.Start);
                            result      = textPointer.CreateStaticPointer();
                        }
                        else
                        {
                            result = StaticTextPointer.Null;
                        }
                    }
                    else
                    {
                        result = textPointer.CreateStaticPointer();
                    }
                }
                return(result);
            }
            /// <summary>
            /// Sets parentPosition to be a valid TextPointer in the parent document.  This could either
            /// be the textPosition passed in (if its already on the parent document) or a conversion
            /// of the textPosition passed in.
            /// </summary>
            /// <returns>whether or not parentPosition is valid and should be used</returns>
            private bool EnsureParentPosition(StaticTextPointer textPosition, LogicalDirection direction, out StaticTextPointer parentPosition)
            {
                // Simple case - textPosition is already in the parent TextContainer
                parentPosition = textPosition;

                // If textPosition is on a child TextContainer, we convert it
                if (textPosition.TextContainer.Highlights != this)
                {
                    // This case can't be converted so return false, out parameter should not be used
                    if (textPosition.GetPointerContext(direction) == TextPointerContext.None)
                    {
                        return(false);
                    }

                    // Turn the textPosition (which should be in the scope of a FixedDocument)
                    // into a position in the scope of the DocumentSequence.
                    ITextPointer dynamicTextPointer = textPosition.CreateDynamicTextPointer(LogicalDirection.Forward);
                    ITextPointer parentTextPointer  = ((DocumentSequenceTextContainer)this.TextContainer).MapChildPositionToParent(dynamicTextPointer);
                    Debug.Assert(parentTextPointer != null);
                    parentPosition = parentTextPointer.CreateStaticPointer();
                }

                // Returning true - either we started with a parent position or we converted to one
                return(true);
            }
 // Token: 0x06003010 RID: 12304 RVA: 0x000D8268 File Offset: 0x000D6468
 private void RaiseChangedEventForLayerContent(HighlightLayer highlightLayer)
 {
     if (this.Changed != null)
     {
         List <TextSegment> list = new List <TextSegment>();
         StaticTextPointer  staticTextPointer = this._textContainer.CreateStaticPointerAtOffset(0);
         for (;;)
         {
             if (!highlightLayer.IsContentHighlighted(staticTextPointer, LogicalDirection.Forward))
             {
                 staticTextPointer = highlightLayer.GetNextChangePosition(staticTextPointer, LogicalDirection.Forward);
                 if (staticTextPointer.IsNull)
                 {
                     break;
                 }
             }
             StaticTextPointer staticTextPointer2 = staticTextPointer;
             staticTextPointer = highlightLayer.GetNextChangePosition(staticTextPointer, LogicalDirection.Forward);
             Invariant.Assert(!staticTextPointer.IsNull, "Highlight start not followed by highlight end!");
             list.Add(new TextSegment(staticTextPointer2.CreateDynamicTextPointer(LogicalDirection.Forward), staticTextPointer.CreateDynamicTextPointer(LogicalDirection.Forward)));
         }
         if (list.Count > 0)
         {
             this.Changed(this, new Highlights.LayerHighlightChangedEventArgs(new ReadOnlyCollection <TextSegment>(list), highlightLayer.OwnerType));
         }
     }
 }
Exemple #4
0
 // Token: 0x0600847B RID: 33915 RVA: 0x00248358 File Offset: 0x00246558
 private bool EnsureParentPosition(StaticTextPointer textPosition, LogicalDirection direction, out StaticTextPointer parentPosition)
 {
     parentPosition = textPosition;
     if (textPosition.TextContainer.Highlights != this)
     {
         if (textPosition.GetPointerContext(direction) == TextPointerContext.None)
         {
             return(false);
         }
         ITextPointer tp          = textPosition.CreateDynamicTextPointer(LogicalDirection.Forward);
         ITextPointer textPointer = ((DocumentSequenceTextContainer)base.TextContainer).MapChildPositionToParent(tp);
         parentPosition = textPointer.CreateStaticPointer();
     }
     return(true);
 }
            /// <summary>
            /// Conversion from a StaticTextPointer on a DocumentSequence into a StaticTextPointer
            /// on a specified FixedDocument.  If the conversion results in a pointer on a different
            /// FixedDocument then we return one end of the FixedDocument (based on direction).
            /// </summary>
            /// <param name="textPosition">position in a DocumentSequence to convert</param>
            /// <param name="direction">direction of the desired conversion</param>
            /// <param name="originalPosition">original pointer from FixedDocument</param>
            private StaticTextPointer GetStaticPositionInChildContainer(StaticTextPointer textPosition, LogicalDirection direction, StaticTextPointer originalPosition)
            {
                StaticTextPointer parentTextPointer = StaticTextPointer.Null;

                if (!textPosition.IsNull)
                {
                    DocumentSequenceTextPointer parentChangePosition = textPosition.CreateDynamicTextPointer(LogicalDirection.Forward) as DocumentSequenceTextPointer;
                    Debug.Assert(parentChangePosition != null);

                    // If the DocSequence position translates into a position in a different FixedDocument than
                    // the original request, we return an end of the original FixedDocument (which end depends on direction)
                    ITextPointer childTp = parentChangePosition.ChildPointer;
                    if (childTp.TextContainer != originalPosition.TextContainer)
                    {
                        // If the position we started searching from is highlighted, cut the highlight
                        // at the end of the text container.  Otherwise return null (the highlight must
                        // start in the next document).
                        if (IsContentHighlighted(originalPosition, direction))
                        {
                            childTp = direction == LogicalDirection.Forward ?
                                      originalPosition.TextContainer.End
                                                 : originalPosition.TextContainer.Start;
                            parentTextPointer = childTp.CreateStaticPointer();
                        }
                        else
                        {
                            parentTextPointer = StaticTextPointer.Null;
                        }
                    }
                    else
                    {
                        parentTextPointer = childTp.CreateStaticPointer();
                    }
                }

                return(parentTextPointer);
            }
            /// <summary>
            /// Sets parentPosition to be a valid TextPointer in the parent document.  This could either
            /// be the textPosition passed in (if its already on the parent document) or a conversion 
            /// of the textPosition passed in.
            /// </summary> 
            /// <returns>whether or not parentPosition is valid and should be used</returns> 
            private bool EnsureParentPosition(StaticTextPointer textPosition, LogicalDirection direction, out StaticTextPointer parentPosition)
            { 
                // Simple case - textPosition is already in the parent TextContainer
                parentPosition = textPosition;

                // If textPosition is on a child TextContainer, we convert it 
                if (textPosition.TextContainer.Highlights != this)
                { 
                    // This case can't be converted so return false, out parameter should not be used 
                    if (textPosition.GetPointerContext(direction) == TextPointerContext.None)
                        return false; 

                    // Turn the textPosition (which should be in the scope of a FixedDocument)
                    // into a position in the scope of the DocumentSequence.
                    ITextPointer dynamicTextPointer = textPosition.CreateDynamicTextPointer(LogicalDirection.Forward); 
                    ITextPointer parentTextPointer = ((DocumentSequenceTextContainer)this.TextContainer).MapChildPositionToParent(dynamicTextPointer);
                    Debug.Assert(parentTextPointer != null); 
                    parentPosition = parentTextPointer.CreateStaticPointer(); 
                }
 
                // Returning true - either we started with a parent position or we converted to one
                return true;
            }
            /// <summary>
            /// Conversion from a StaticTextPointer on a DocumentSequence into a StaticTextPointer 
            /// on a specified FixedDocument.  If the conversion results in a pointer on a different 
            /// FixedDocument then we return one end of the FixedDocument (based on direction).
            /// </summary> 
            /// <param name="textPosition">position in a DocumentSequence to convert</param>
            /// <param name="direction">direction of the desired conversion</param>
            /// <param name="originalPosition">original pointer from FixedDocument</param>
            private StaticTextPointer GetStaticPositionInChildContainer(StaticTextPointer textPosition, LogicalDirection direction, StaticTextPointer originalPosition) 
            {
                StaticTextPointer parentTextPointer = StaticTextPointer.Null; 
 
                if (!textPosition.IsNull)
                { 
                    DocumentSequenceTextPointer parentChangePosition = textPosition.CreateDynamicTextPointer(LogicalDirection.Forward) as DocumentSequenceTextPointer;
                    Debug.Assert(parentChangePosition != null);

                    // If the DocSequence position translates into a position in a different FixedDocument than 
                    // the original request, we return an end of the original FixedDocument (which end depends on direction)
                    ITextPointer childTp = parentChangePosition.ChildPointer; 
                    if (childTp.TextContainer != originalPosition.TextContainer) 
                    {
                        // If the position we started searching from is highlighted, cut the highlight 
                        // at the end of the text container.  Otherwise return null (the highlight must
                        // start in the next document).
                        if (IsContentHighlighted(originalPosition, direction))
                        { 
                            childTp = direction == LogicalDirection.Forward ?
                                                   originalPosition.TextContainer.End 
                                                 : originalPosition.TextContainer.Start; 
                            parentTextPointer = childTp.CreateStaticPointer();
                        } 
                        else
                        {
                            parentTextPointer = StaticTextPointer.Null;
                        } 
                    }
                    else 
                    { 
                        parentTextPointer = childTp.CreateStaticPointer();
                    } 
                }

                return parentTextPointer;
            } 
        // 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();
                }
            }
        }