// Returns true iff the indicated content has scoping highlights.
        internal override bool IsContentHighlighted(StaticTextPointer textPosition, LogicalDirection direction)
        {
            int segmentCount;
            TextSegment textSegment;

            // No highlight when the selection is for interim character.
            if (_selection.IsInterimSelection)
            {
                return false;
            }

            // Check all segments of selection
            List<TextSegment> textSegments = _selection.TextSegments;
            segmentCount = textSegments.Count;
            for (int segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
            {
                textSegment = textSegments[segmentIndex];

                if ((direction == LogicalDirection.Forward && textSegment.Start.CompareTo(textPosition) <= 0 && textPosition.CompareTo(textSegment.End) < 0) || //
                    (direction == LogicalDirection.Backward && textSegment.Start.CompareTo(textPosition) < 0 && textPosition.CompareTo(textSegment.End) <= 0))
                {
                    return true;
                }

            }
            return false;
        }
 // 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));
         }
     }
 }
Esempio n. 3
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);
            }
Esempio n. 4
0
        /// <summary>
        /// Returns the position of the next highlight start or end in an
        /// indicated direction, or null if there is no such position.
        /// </summary>
        /// <param name="textPosition">
        /// Position to query.
        /// </param>
        /// <param name="direction">
        /// Direction of content to query.
        /// </param>
        internal virtual StaticTextPointer GetNextHighlightChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            StaticTextPointer changePosition;
            StaticTextPointer closestChangePosition;
            int i;

            closestChangePosition = StaticTextPointer.Null;

            // Calculate the min of the layers' transitions.
            for (i = 0; i < this.LayerCount; i++)
            {
                changePosition = GetLayer(i).GetNextChangePosition(textPosition, direction);

                if (!changePosition.IsNull)
                {
                    if (closestChangePosition.IsNull)
                    {
                        closestChangePosition = changePosition;
                    }
                    else if (direction == LogicalDirection.Forward)
                    {
                        closestChangePosition = StaticTextPointer.Min(closestChangePosition, changePosition);
                    }
                    else
                    {
                        closestChangePosition = StaticTextPointer.Max(closestChangePosition, changePosition);
                    }
                }
            }

            return(closestChangePosition);
        }
Esempio n. 5
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        /// <summary>
        /// Returns the value of a property stored on scoping highlight, if any.
        /// </summary>
        /// <param name="textPosition">
        /// Position to query.
        /// </param>
        /// <param name="direction">
        /// Direction of content to query.
        /// </param>
        /// <param name="highlightLayerOwnerType">
        /// Type of the matching highlight layer owner.
        /// </param>
        /// <returns>
        /// The highlight value if set on any scoping highlight.  If no property
        /// value is set, returns DependencyProperty.UnsetValue.
        /// </returns>
        internal virtual object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction, Type highlightLayerOwnerType)
        {
            int            layerIndex;
            object         value;
            HighlightLayer layer;

            value = DependencyProperty.UnsetValue;

            // Take the value on the closest layer.  "Closest" == added first.
            for (layerIndex = 0; layerIndex < this.LayerCount; layerIndex++)
            {
                layer = GetLayer(layerIndex);

                if (layer.OwnerType == highlightLayerOwnerType)
                {
                    value = layer.GetHighlightValue(textPosition, direction);
                    if (value != DependencyProperty.UnsetValue)
                    {
                        break;
                    }
                }
            }

            return(value);
        }
Esempio n. 6
0
        // Token: 0x060035AE RID: 13742 RVA: 0x000F3B04 File Offset: 0x000F1D04
        private int FindIndex(StaticTextPointer position, LogicalDirection direction)
        {
            int num  = -1;
            int i    = 0;
            int num2 = this._runList.Count;

            while (i < num2)
            {
                num = (i + num2) / 2;
                SpellerStatusTable.Run run = this.GetRun(num);
                if ((direction == LogicalDirection.Forward && position.CompareTo(run.Position) < 0) || (direction == LogicalDirection.Backward && position.CompareTo(run.Position) <= 0))
                {
                    num2 = num;
                }
                else
                {
                    if ((direction != LogicalDirection.Forward || position.CompareTo(this.GetRunEndPosition(num)) < 0) && (direction != LogicalDirection.Backward || position.CompareTo(this.GetRunEndPosition(num)) <= 0))
                    {
                        break;
                    }
                    i = num + 1;
                }
            }
            if (i >= num2)
            {
                num = -1;
            }
            return(num);
        }
Esempio n. 7
0
        /// <summary>
        /// Returns the closest neighboring TextPointer in an indicated
        /// direction where a property value calculated from an embedded
        /// object, scoping text element, or scoping highlight could
        /// change.
        /// </summary>
        /// <param name="textPosition">
        /// Position to query.
        /// </param>
        /// <param name="direction">
        /// Direction of content to query.
        /// </param>
        /// <returns>
        /// If the following symbol is TextPointerContext.EmbeddedElement,
        /// TextPointerContext.ElementBegin, or TextPointerContext.ElementEnd, returns
        /// a TextPointer exactly one symbol distant.
        ///
        /// If the following symbol is TextPointerContext.Text, the distance
        /// of the returned TextPointer is the minimum of the value returned
        /// by textPosition.GetTextLength and the distance to any highlight
        /// start or end edge.
        ///
        /// If the following symbol is TextPointerContext.None, returns null.
        /// </returns>
        internal virtual StaticTextPointer GetNextPropertyChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            StaticTextPointer changePosition;
            StaticTextPointer characterRunEndPosition;

            switch (textPosition.GetPointerContext(direction))
            {
            case TextPointerContext.None:
                changePosition = StaticTextPointer.Null;
                break;

            case TextPointerContext.Text:
                changePosition          = GetNextHighlightChangePosition(textPosition, direction);
                characterRunEndPosition = textPosition.GetNextContextPosition(LogicalDirection.Forward);

                if (changePosition.IsNull ||
                    characterRunEndPosition.CompareTo(changePosition) < 0)
                {
                    changePosition = characterRunEndPosition;
                }

                break;

            case TextPointerContext.EmbeddedElement:
            case TextPointerContext.ElementStart:
            case TextPointerContext.ElementEnd:
            default:
                changePosition = textPosition.CreatePointer(+1);
                break;
            }

            return(changePosition);
        }
        // Returns true iff the indicated content has scoping highlights.
        internal override bool IsContentHighlighted(StaticTextPointer textPosition, LogicalDirection direction)
        {
            int         segmentCount;
            TextSegment textSegment;

            // No highlight when the selection is for interim character.
            if (_selection.IsInterimSelection)
            {
                return(false);
            }

            // Check all segments of selection
            List <TextSegment> textSegments = _selection.TextSegments;

            segmentCount = textSegments.Count;
            for (int segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
            {
                textSegment = textSegments[segmentIndex];

                if ((direction == LogicalDirection.Forward && textSegment.Start.CompareTo(textPosition) <= 0 && textPosition.CompareTo(textSegment.End) < 0) || //
                    (direction == LogicalDirection.Backward && textSegment.Start.CompareTo(textPosition) < 0 && textPosition.CompareTo(textSegment.End) <= 0))
                {
                    return(true);
                }
            }
            return(false);
        }
        // Token: 0x06003006 RID: 12294 RVA: 0x000D8010 File Offset: 0x000D6210
        internal virtual StaticTextPointer GetNextHighlightChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            StaticTextPointer staticTextPointer = StaticTextPointer.Null;

            for (int i = 0; i < this.LayerCount; i++)
            {
                StaticTextPointer nextChangePosition = this.GetLayer(i).GetNextChangePosition(textPosition, direction);
                if (!nextChangePosition.IsNull)
                {
                    if (staticTextPointer.IsNull)
                    {
                        staticTextPointer = nextChangePosition;
                    }
                    else if (direction == LogicalDirection.Forward)
                    {
                        staticTextPointer = StaticTextPointer.Min(staticTextPointer, nextChangePosition);
                    }
                    else
                    {
                        staticTextPointer = StaticTextPointer.Max(staticTextPointer, nextChangePosition);
                    }
                }
            }
            return(staticTextPointer);
        }
            /// <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);
            }
        // Returns the position of the next highlight start or end in an
        // indicated direction, or null if there is no such position.
        internal override StaticTextPointer GetNextChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            StaticTextPointer transitionPosition;
            AttributeRange attributeRange;
            int i;

            transitionPosition = StaticTextPointer.Null;

            // Use a simple iterative search since we don't ever have
            // more than a handful of attributes in a composition.

            if (direction == LogicalDirection.Forward)
            {
                for (i = 0; i < _attributeRanges.Count; i++)
                {
                    attributeRange = (AttributeRange)_attributeRanges[i];

                    if (attributeRange.Start.CompareTo(attributeRange.End) != 0)
                    {
                        if (textPosition.CompareTo(attributeRange.Start) < 0)
                        {
                            transitionPosition = attributeRange.Start.CreateStaticPointer();
                            break;
                        }
                        else if (textPosition.CompareTo(attributeRange.End) < 0)
                        {
                            transitionPosition = attributeRange.End.CreateStaticPointer();
                            break;
                        }
                    }
                }
            }
            else
            {
                for (i = _attributeRanges.Count - 1; i >= 0; i--)
                {
                    attributeRange = (AttributeRange)_attributeRanges[i];

                    if (attributeRange.Start.CompareTo(attributeRange.End) != 0)
                    {
                        if (textPosition.CompareTo(attributeRange.End) > 0)
                        {
                            transitionPosition = attributeRange.End.CreateStaticPointer();
                            break;
                        }
                        else if (textPosition.CompareTo(attributeRange.Start) > 0)
                        {
                            transitionPosition = attributeRange.Start.CreateStaticPointer();
                            break;
                        }
                    }
                }
            }

            return transitionPosition;
        }
Esempio n. 12
0
        // Returns the position of the next highlight start or end in an
        // indicated direction, or null if there is no such position.
        internal override StaticTextPointer GetNextChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            StaticTextPointer transitionPosition;
            AttributeRange    attributeRange;
            int i;

            transitionPosition = StaticTextPointer.Null;

            // Use a simple iterative search since we don't ever have
            // more than a handful of attributes in a composition.

            if (direction == LogicalDirection.Forward)
            {
                for (i = 0; i < _attributeRanges.Count; i++)
                {
                    attributeRange = (AttributeRange)_attributeRanges[i];

                    if (attributeRange.Start.CompareTo(attributeRange.End) != 0)
                    {
                        if (textPosition.CompareTo(attributeRange.Start) < 0)
                        {
                            transitionPosition = attributeRange.Start.CreateStaticPointer();
                            break;
                        }
                        else if (textPosition.CompareTo(attributeRange.End) < 0)
                        {
                            transitionPosition = attributeRange.End.CreateStaticPointer();
                            break;
                        }
                    }
                }
            }
            else
            {
                for (i = _attributeRanges.Count - 1; i >= 0; i--)
                {
                    attributeRange = (AttributeRange)_attributeRanges[i];

                    if (attributeRange.Start.CompareTo(attributeRange.End) != 0)
                    {
                        if (textPosition.CompareTo(attributeRange.End) > 0)
                        {
                            transitionPosition = attributeRange.End.CreateStaticPointer();
                            break;
                        }
                        else if (textPosition.CompareTo(attributeRange.Start) > 0)
                        {
                            transitionPosition = attributeRange.Start.CreateStaticPointer();
                            break;
                        }
                    }
                }
            }

            return(transitionPosition);
        }
        // Token: 0x06003005 RID: 12293 RVA: 0x000D7FD8 File Offset: 0x000D61D8
        internal virtual bool IsContentHighlighted(StaticTextPointer textPosition, LogicalDirection direction)
        {
            int num = 0;

            while (num < this.LayerCount && !this.GetLayer(num).IsContentHighlighted(textPosition, direction))
            {
                num++;
            }
            return(num < this.LayerCount);
        }
Esempio n. 14
0
            // Token: 0x06008477 RID: 33911 RVA: 0x00248284 File Offset: 0x00246484
            internal override object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction, Type highlightLayerOwnerType)
            {
                StaticTextPointer textPosition2;

                if (this.EnsureParentPosition(textPosition, direction, out textPosition2))
                {
                    return(base.GetHighlightValue(textPosition2, direction, highlightLayerOwnerType));
                }
                return(DependencyProperty.UnsetValue);
            }
Esempio n. 15
0
        // Returns the AttributeRange covering specified content, or null
        // if no such range exists.
        private AttributeRange GetRangeAtPosition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            int            i;
            AttributeRange attributeRange;
            AttributeRange attributeRangeAtPosition;

            // Use a simple iterative search since we don't ever have
            // more than a handful of attributes in a composition.

            attributeRangeAtPosition = null;

            if (direction == LogicalDirection.Forward)
            {
                for (i = 0; i < _attributeRanges.Count; i++)
                {
                    attributeRange = (AttributeRange)_attributeRanges[i];

                    if (attributeRange.Start.CompareTo(attributeRange.End) != 0)
                    {
                        if (textPosition.CompareTo(attributeRange.Start) < 0)
                        {
                            break;
                        }
                        else if (textPosition.CompareTo(attributeRange.End) < 0)
                        {
                            attributeRangeAtPosition = attributeRange;
                            break;
                        }
                    }
                }
            }
            else
            {
                for (i = _attributeRanges.Count - 1; i >= 0; i--)
                {
                    attributeRange = (AttributeRange)_attributeRanges[i];

                    if (attributeRange.Start.CompareTo(attributeRange.End) != 0)
                    {
                        if (textPosition.CompareTo(attributeRange.End) > 0)
                        {
                            break;
                        }
                        else if (textPosition.CompareTo(attributeRange.Start) > 0)
                        {
                            attributeRangeAtPosition = attributeRange;
                            break;
                        }
                    }
                }
            }

            return(attributeRangeAtPosition);
        }
            /// <summary>
            /// Returns true iff the indicated content has scoping highlights.
            /// </summary>
            /// <param name="textPosition">
            /// Position to query.
            /// </param>
            /// <param name="direction">
            /// Direction of content to query.
            /// </param>
            internal override bool IsContentHighlighted(StaticTextPointer textPosition, LogicalDirection direction)
            {
                StaticTextPointer parentPosition;

                if (EnsureParentPosition(textPosition, direction, out parentPosition))
                {
                    return(base.IsContentHighlighted(parentPosition, direction));
                }

                return(false);
            }
        // Returns true if the specified character is part of a run of the specified type.
        internal bool IsRunType(StaticTextPointer textPosition, LogicalDirection direction, RunType runType)
        {
            int index = FindIndex(textPosition, direction);

            if (index < 0)
            {
                return(false);
            }

            return(GetRun(index).RunType == runType);
        }
Esempio n. 18
0
        // Token: 0x060035AB RID: 13739 RVA: 0x000F3A30 File Offset: 0x000F1C30
        internal bool GetError(StaticTextPointer textPosition, LogicalDirection direction, out ITextPointer start, out ITextPointer end)
        {
            start = null;
            end   = null;
            int errorIndex = this.GetErrorIndex(textPosition, direction);

            if (errorIndex >= 0)
            {
                start = this.GetRun(errorIndex).Position;
                end   = this.GetRunEndPositionDynamic(errorIndex);
            }
            return(start != null);
        }
Esempio n. 19
0
        // Token: 0x06003C67 RID: 15463 RVA: 0x0011732C File Offset: 0x0011552C
        internal override StaticTextPointer GetNextChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            StaticTextPointer result = StaticTextPointer.Null;

            if (!this.IsTextRangeEmpty(this._selection) && !this._selection.IsInterimSelection)
            {
                List <TextSegment> textSegments = this._selection.TextSegments;
                int count = textSegments.Count;
                if (direction == LogicalDirection.Forward)
                {
                    for (int i = 0; i < count; i++)
                    {
                        TextSegment textSegment = textSegments[i];
                        if (textSegment.Start.CompareTo(textSegment.End) != 0)
                        {
                            if (textPosition.CompareTo(textSegment.Start) < 0)
                            {
                                result = textSegment.Start.CreateStaticPointer();
                                break;
                            }
                            if (textPosition.CompareTo(textSegment.End) < 0)
                            {
                                result = textSegment.End.CreateStaticPointer();
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (int j = count - 1; j >= 0; j--)
                    {
                        TextSegment textSegment = textSegments[j];
                        if (textSegment.Start.CompareTo(textSegment.End) != 0)
                        {
                            if (textPosition.CompareTo(textSegment.End) > 0)
                            {
                                result = textSegment.End.CreateStaticPointer();
                                break;
                            }
                            if (textPosition.CompareTo(textSegment.Start) > 0)
                            {
                                result = textSegment.Start.CreateStaticPointer();
                                break;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 20
0
        // Token: 0x06003C65 RID: 15461 RVA: 0x00117274 File Offset: 0x00115474
        internal override object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction)
        {
            object result;

            if (this.IsContentHighlighted(textPosition, direction))
            {
                result = TextSelectionHighlightLayer._selectedValue;
            }
            else
            {
                result = DependencyProperty.UnsetValue;
            }
            return(result);
        }
Esempio n. 21
0
        // Token: 0x060035AD RID: 13741 RVA: 0x000F3ACC File Offset: 0x000F1CCC
        private int GetErrorIndex(StaticTextPointer textPosition, LogicalDirection direction)
        {
            int num = this.FindIndex(textPosition, direction);

            if (num >= 0)
            {
                SpellerStatusTable.Run run = this.GetRun(num);
                if (run.RunType == SpellerStatusTable.RunType.Clean || run.RunType == SpellerStatusTable.RunType.Dirty)
                {
                    num = -1;
                }
            }
            return(num);
        }
Esempio n. 22
0
        /// <summary>
        /// Returns true iff the indicated content has scoping highlights.
        /// </summary>
        /// <param name="textPosition">
        /// Position to query.
        /// </param>
        /// <param name="direction">
        /// Direction of content to query.
        /// </param>
        internal virtual bool IsContentHighlighted(StaticTextPointer textPosition, LogicalDirection direction)
        {
            int i;

            for (i = 0; i < this.LayerCount; i++)
            {
                if (GetLayer(i).IsContentHighlighted(textPosition, direction))
                {
                    break;
                }
            }

            return(i < this.LayerCount);
        }
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Returns the value of a property stored on scoping highlight, if any.
        //
        // If no property value is set, returns DependencyProperty.UnsetValue.
        internal override object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction)
        {
            AttributeRange attributeRange;
            object value;

            value = DependencyProperty.UnsetValue;

            attributeRange = GetRangeAtPosition(textPosition, direction);
            if (attributeRange != null)
            {
                value = attributeRange.TextDecorations;
            }

            return value;
        }
Esempio n. 24
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Returns the value of a property stored on scoping highlight, if any.
        //
        // If no property value is set, returns DependencyProperty.UnsetValue.
        internal override object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction)
        {
            object value;

            if (IsContentHighlighted(textPosition, direction))
            {
                value = _selectedValue;
            }
            else
            {
                value = DependencyProperty.UnsetValue;
            }

            return value;
        }
Esempio n. 25
0
            // Token: 0x0600847A RID: 33914 RVA: 0x00248314 File Offset: 0x00246514
            internal override StaticTextPointer GetNextPropertyChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
            {
                StaticTextPointer staticTextPointer = StaticTextPointer.Null;
                StaticTextPointer textPosition2;

                if (this.EnsureParentPosition(textPosition, direction, out textPosition2))
                {
                    staticTextPointer = base.GetNextPropertyChangePosition(textPosition2, direction);
                    if (textPosition.TextContainer.Highlights != this)
                    {
                        staticTextPointer = this.GetStaticPositionInChildContainer(staticTextPointer, direction, textPosition);
                    }
                }
                return(staticTextPointer);
            }
Esempio n. 26
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);
 }
Esempio n. 27
0
        // Token: 0x060035AC RID: 13740 RVA: 0x000F3A70 File Offset: 0x000F1C70
        internal bool GetRun(StaticTextPointer position, LogicalDirection direction, out SpellerStatusTable.RunType runType, out StaticTextPointer end)
        {
            int num = this.FindIndex(position, direction);

            runType = SpellerStatusTable.RunType.Clean;
            end     = StaticTextPointer.Null;
            if (num < 0)
            {
                return(false);
            }
            SpellerStatusTable.Run run = this.GetRun(num);
            runType = run.RunType;
            end     = ((direction == LogicalDirection.Forward) ? this.GetRunEndPosition(num) : run.Position.CreateStaticPointer());
            return(true);
        }
Esempio n. 28
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Returns a TextDecorationCollection used to tag spelling errors,
        // or DependencyProperty.UnsetValue if there's no error at the specified position.
        internal override object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction)
        {
            object value;

            if (IsContentHighlighted(textPosition, direction))
            {
                value = _errorTextDecorations;
            }
            else
            {
                value = DependencyProperty.UnsetValue;
            }

            return(value);
        }
Esempio n. 29
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Returns the value of a property stored on scoping highlight, if any.
        //
        // If no property value is set, returns DependencyProperty.UnsetValue.
        internal override object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction)
        {
            AttributeRange attributeRange;
            object         value;

            value = DependencyProperty.UnsetValue;

            attributeRange = GetRangeAtPosition(textPosition, direction);
            if (attributeRange != null)
            {
                value = attributeRange.TextDecorations;
            }

            return(value);
        }
        // Finds the index of a run containing the specified content.
        // Returns -1 if there is no run in the indicated direction -- when
        // position is at the document edge pointing to nothing.
        private int FindIndex(StaticTextPointer position, LogicalDirection direction)
        {
            Run run;
            int index;
            int minIndex;
            int maxIndex;

            index    = -1;
            minIndex = 0;
            maxIndex = _runList.Count;

            while (minIndex < maxIndex)
            {
                index = (minIndex + maxIndex) / 2;

                run = GetRun(index);

                if (direction == LogicalDirection.Forward && position.CompareTo(run.Position) < 0 ||
                    direction == LogicalDirection.Backward && position.CompareTo(run.Position) <= 0)
                {
                    // Search to the left.
                    maxIndex = index;
                }
                else if (direction == LogicalDirection.Forward && position.CompareTo(GetRunEndPosition(index)) >= 0 ||
                         direction == LogicalDirection.Backward && position.CompareTo(GetRunEndPosition(index)) > 0)
                {
                    // Search to the right.
                    minIndex = index + 1;
                }
                else
                {
                    // Got a match.
                    break;
                }
            }

            if (minIndex >= maxIndex)
            {
                // We walked off the document edge searching.
                // position is at document start or end, and direction
                // points off into space, so there's no associated run.
                index = -1;
            }

            return(index);
        }
        // Token: 0x06003004 RID: 12292 RVA: 0x000D7F8C File Offset: 0x000D618C
        internal virtual object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction, Type highlightLayerOwnerType)
        {
            object obj = DependencyProperty.UnsetValue;

            for (int i = 0; i < this.LayerCount; i++)
            {
                HighlightLayer layer = this.GetLayer(i);
                if (layer.OwnerType == highlightLayerOwnerType)
                {
                    obj = layer.GetHighlightValue(textPosition, direction);
                    if (obj != DependencyProperty.UnsetValue)
                    {
                        break;
                    }
                }
            }
            return(obj);
        }
            /// <summary>
            /// Returns the closest neighboring TextPointer in an indicated
            /// direction where a property value calculated from an embedded
            /// object, scoping text element, or scoping highlight could
            /// change.
            /// </summary>
            /// <param name="textPosition">
            /// Position to query.
            /// </param>
            /// <param name="direction">
            /// Direction of content to query.
            /// </param>
            /// <returns>
            /// If the following symbol is TextPointerContext.EmbeddedElement,
            /// TextPointerContext.ElementBegin, or TextPointerContext.ElementEnd, returns
            /// a TextPointer exactly one symbol distant.
            ///
            /// If the following symbol is TextPointerContext.Text, the distance
            /// of the returned TextPointer is the minimum of the value returned
            /// by textPosition.GetTextLength and the distance to any highlight
            /// start or end edge.
            ///
            /// If the following symbol is TextPointerContext.None, returns null.
            /// </returns>
            internal override StaticTextPointer GetNextPropertyChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
            {
                StaticTextPointer parentPosition;
                StaticTextPointer returnPointer = StaticTextPointer.Null;

                if (EnsureParentPosition(textPosition, direction, out parentPosition))
                {
                    returnPointer = base.GetNextPropertyChangePosition(parentPosition, direction);

                    // If we were passed a child position, we need to convert the result back to a child position
                    if (textPosition.TextContainer.Highlights != this)
                    {
                        returnPointer = GetStaticPositionInChildContainer(returnPointer, direction, textPosition);
                    }
                }

                return(returnPointer);
            }
Esempio n. 33
0
        // Token: 0x060035AA RID: 13738 RVA: 0x000F3964 File Offset: 0x000F1B64
        internal StaticTextPointer GetNextErrorTransition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            StaticTextPointer staticTextPointer = StaticTextPointer.Null;
            int num = this.FindIndex(textPosition, direction);

            if (num != -1)
            {
                if (direction == LogicalDirection.Forward)
                {
                    if (this.IsErrorRun(num))
                    {
                        staticTextPointer = this.GetRunEndPosition(num);
                    }
                    else
                    {
                        for (int i = num + 1; i < this._runList.Count; i++)
                        {
                            if (this.IsErrorRun(i))
                            {
                                staticTextPointer = this.GetRun(i).Position.CreateStaticPointer();
                                break;
                            }
                        }
                    }
                }
                else if (this.IsErrorRun(num))
                {
                    staticTextPointer = this.GetRun(num).Position.CreateStaticPointer();
                }
                else
                {
                    for (int i = num - 1; i > 0; i--)
                    {
                        if (this.IsErrorRun(i))
                        {
                            staticTextPointer = this.GetRunEndPosition(i);
                            break;
                        }
                    }
                }
            }
            Invariant.Assert(staticTextPointer.IsNull || textPosition.CompareTo(staticTextPointer) != 0);
            return(staticTextPointer);
        }
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // Returns the index in _runList of an error covering the specified
        // content, or -1 if no such error exists.
        private int GetErrorIndex(StaticTextPointer textPosition, LogicalDirection direction)
        {
            int index;
            Run run;

            index = FindIndex(textPosition, direction);

            if (index >= 0)
            {
                run = GetRun(index);

                if (run.RunType == RunType.Clean || run.RunType == RunType.Dirty)
                {
                    index = -1;
                }
            }

            return(index);
        }
Esempio n. 35
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        /// <summary>
        /// Returns the value of a property stored on scoping highlight, if any.
        /// </summary>
        /// <param name="textPosition">
        /// Position to query.
        /// </param>
        /// <param name="direction">
        /// Direction of content to query.
        /// </param>
        /// <param name="highlightLayerOwnerType">
        /// Type of the matching highlight layer owner.
        /// </param>
        /// <returns>
        /// The highlight value if set on any scoping highlight.  If no property
        /// value is set, returns DependencyProperty.UnsetValue.
        /// </returns>
        internal virtual object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction, Type highlightLayerOwnerType)
        {
            int layerIndex;
            object value;
            HighlightLayer layer;

            value = DependencyProperty.UnsetValue;

            // Take the value on the closest layer.  "Closest" == added first.
            for (layerIndex = 0; layerIndex < this.LayerCount; layerIndex++)
            {
                layer = GetLayer(layerIndex);

                if (layer.OwnerType == highlightLayerOwnerType)
                {
                    value = layer.GetHighlightValue(textPosition, direction);
                    if (value != DependencyProperty.UnsetValue)
                        break;
                }
            }

            return value;
        }
Esempio n. 36
0
 object ITextContainer.GetAdjacentElement(StaticTextPointer position, LogicalDirection direction)
 {
     return ((ITextPointer)position.Handle0).GetAdjacentElement(direction);
 }
 // Returns the next change position starting from the passed in StaticTextPointer.  Determines this by checking 
 // the highlights of the DocumentSequence. 
 internal override StaticTextPointer GetNextChangePosition(StaticTextPointer staticTextPointer, LogicalDirection direction)
 { 
     return this._docSeqContainer.Highlights.GetNextHighlightChangePosition(staticTextPointer, direction);
 }
Esempio n. 38
0
        /// <summary>
        /// Fetch the next run at embedded object position. 
        /// </summary>
        /// <param name="dcp">
        /// Character offset of this run.
        /// </param>
        /// <param name="position">
        /// Current position in the text array.
        /// </param>
        protected TextRun HandleEmbeddedObject(int dcp, StaticTextPointer position)
        {
            Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.EmbeddedElement, "TextPointer does not point to embedded object.");

            TextRun run = null;
            DependencyObject embeddedObject = position.GetAdjacentElement(LogicalDirection.Forward) as DependencyObject;
            if (embeddedObject is UIElement)
            {
                // Extract the aggregated properties into something that the textrun can use.
                TextRunProperties textProps = new TextProperties(embeddedObject, position, true /* inline objects */, true /* get background */);

                // Create inline object run.
                run = new InlineObjectRun(TextContainerHelper.EmbeddedObjectLength, (UIElement)embeddedObject, textProps, _paraClient.Paragraph as TextParagraph);
            }
            else
            {
                // If the embedded object is of an unknown type, treat it as hidden content.
                run = new TextHidden(TextContainerHelper.EmbeddedObjectLength);
            }
            return run;
        }
Esempio n. 39
0
        /// <summary>
        /// Return next TextRun at element edge start position
        /// </summary>
        /// <param name="position">
        /// Current position in text array
        /// </param>
        protected TextRun HandleElementStartEdge(StaticTextPointer position)
        {
            Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart, "TextPointer does not point to element start edge.");

            // 

            TextRun run = null;
            TextElement element = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward);
            Debug.Assert(element != null, "Cannot use ITextContainer that does not provide TextElement instances.");

            Invariant.Assert(!(element is Block), "We do not expect any Blocks inside Paragraphs");

            // Treat figure and floaters as special hidden runs.
            if (element is Figure || element is Floater)
            {
                // Get the length of the element
                int cch = TextContainerHelper.GetElementLength(_paraClient.Paragraph.StructuralCache.TextContainer, element);
                // Create special hidden run.
                run = new FloatingRun(cch, element is Figure);
                if (element is Figure)
                {
                    _hasFigures = true;
                }
                else
                {
                    _hasFloaters = true;
                }
            }
            else if (element is LineBreak)
            {
                int cch = TextContainerHelper.GetElementLength(_paraClient.Paragraph.StructuralCache.TextContainer, element);
                run = new LineBreakRun(cch, PTS.FSFLRES.fsflrSoftBreak);
            }
            else if (element.IsEmpty)
            {
                // Empty TextElement should affect line metrics.
                // TextFormatter does not support this feature right now, so as workaround
                // TextRun with ZERO WIDTH SPACE is used.
                TextProperties textProps = new TextProperties(element, position, false /* inline objects */, true /* get background */);

                char[] textBuffer = new char[_elementEdgeCharacterLength * 2];
                
                // Assert that _elementEdgeCharacterLength is 1 before we use hard-coded indices
                Invariant.Assert(_elementEdgeCharacterLength == 1, "Expected value of _elementEdgeCharacterLength is 1");

                textBuffer[0] = (char)0x200B;
                textBuffer[1] = (char)0x200B;

                run = new TextCharacters(textBuffer, 0, textBuffer.Length, textProps);
            }
            else
            {
                Inline inline = (Inline) element;
                DependencyObject parent = inline.Parent;

                FlowDirection inlineFlowDirection = inline.FlowDirection;
                FlowDirection parentFlowDirection = inlineFlowDirection;

                TextDecorationCollection inlineTextDecorations = DynamicPropertyReader.GetTextDecorations(inline);

                if(parent != null)
                {
                    parentFlowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                }

                if (inlineFlowDirection != parentFlowDirection)
                {
                    // Inline's flow direction is different from its parent. Need to create new TextSpanModifier with flow direction
                    if (inlineTextDecorations == null || inlineTextDecorations.Count == 0)
                    {
                        run = new TextSpanModifier(
                            _elementEdgeCharacterLength,
                            null,
                            null,
                            inlineFlowDirection
                            );
                    }
                    else
                    {
                        run = new TextSpanModifier(
                            _elementEdgeCharacterLength,
                            inlineTextDecorations,
                            inline.Foreground,
                            inlineFlowDirection
                            );
                    }
                }
                else
                {
                    if (inlineTextDecorations == null || inlineTextDecorations.Count == 0)
                    {
                        run = new TextHidden(_elementEdgeCharacterLength);
                    }
                    else
                    {
                        run = new TextSpanModifier(
                            _elementEdgeCharacterLength,
                            inlineTextDecorations,
                            inline.Foreground
                            );
                    }
                }
            }
            return run;
        }
Esempio n. 40
0
 object ITextContainer.GetValue(StaticTextPointer position, DependencyProperty formattingProperty)
 {
     return ((ITextPointer)position.Handle0).GetValue(formattingProperty);
 }
Esempio n. 41
0
 StaticTextPointer ITextContainer.GetNextContextPosition(StaticTextPointer position, LogicalDirection direction)
 {
     return new StaticTextPointer(this, ((ITextPointer)position.Handle0).GetNextContextPosition(direction));
 }
        // Returns the type and end of the Run intersecting position.
        internal bool GetRun(StaticTextPointer position, LogicalDirection direction, out RunType runType, out StaticTextPointer end)
        {
            int index = FindIndex(position, direction);

            runType = RunType.Clean;
            end = StaticTextPointer.Null;

            if (index < 0)
            {
                return false;
            }

            Run run = GetRun(index);

            runType = run.RunType;
            end = (direction == LogicalDirection.Forward) ? GetRunEndPosition(index) : run.Position.CreateStaticPointer();

            return true;
        }
        // Returns the position and suggested replacement list of an error covering
        // the specified content.
        // If no error exists, return false.
        internal bool GetError(StaticTextPointer textPosition, LogicalDirection direction,
            out ITextPointer start, out ITextPointer end)
        {
            int index;

            start = null;
            end = null;

            index = GetErrorIndex(textPosition, direction);

            if (index >= 0)
            {
                start = GetRun(index).Position;
                end = GetRunEndPositionDynamic(index);
            }

            return (start != null);
        }
        // Returns the position of the next error start or end in an
        // indicated direction, or null if there is no such position.
        // Called by the SpellerHighlightLayer.
        internal StaticTextPointer GetNextErrorTransition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            StaticTextPointer transitionPosition;
            int index;
            int i;

            transitionPosition = StaticTextPointer.Null;

            index = FindIndex(textPosition, direction);

            if (index == -1)
            {
                // textPosition is at the document edge.
                // leave transitionPosition null.
            }
            else if (direction == LogicalDirection.Forward)
            {
                if (IsErrorRun(index))
                {
                    transitionPosition = GetRunEndPosition(index);
                }
                else
                {
                    for (i = index+1; i < _runList.Count; i++)
                    {
                        if (IsErrorRun(i))
                        {
                            transitionPosition = GetRun(i).Position.CreateStaticPointer();
                            break;
                        }
                    }
                }
            }
            else // direction == LogicalDirection.Backward
            {
                if (IsErrorRun(index))
                {
                    transitionPosition = GetRun(index).Position.CreateStaticPointer();
                }
                else
                {
                    for (i = index - 1; i > 0; i--)
                    {
                        if (IsErrorRun(i))
                        {
                            transitionPosition = GetRunEndPosition(i);
                            break;
                        }
                    }
                }
            }

            // If we ever had two consecuative errors (with touching borders)
            // we could return a transitionPosition == textPosition, which is illegal.
            // We rely on the fact that consecutive errors are always separated
            // by a word break to avoid this.
            // 
            Invariant.Assert(transitionPosition.IsNull || textPosition.CompareTo(transitionPosition) != 0);

            return transitionPosition;
        }
        // Returns true if the specified character is part of a run of the specified type.
        internal bool IsRunType(StaticTextPointer textPosition, LogicalDirection direction, RunType runType)
        {
            int index = FindIndex(textPosition, direction);

            if (index < 0)
            {
                return false;
            }

            return GetRun(index).RunType == runType;
        }
        //------------------------------------------------------
        //
        //  Internal Methods 
        //
        //----------------------------------------------------- 
 
        #region Internal Methods
 
        // Method is not implemented.  Should not need to be called for constructing the event args.
        internal override object GetHighlightValue(StaticTextPointer staticTextPointer, LogicalDirection direction)
        {
            Debug.Assert(false, "This method is not implemented and not expected to be called."); 
            return null;
        } 
 // Returns whether or not this text pointer has a highlight on it.  Determines this by checking
 // the highlights of the DocumentSequence. 
 internal override bool IsContentHighlighted(StaticTextPointer staticTextPointer, LogicalDirection direction)
 {
     return this._docSeqContainer.Highlights.IsContentHighlighted(staticTextPointer, direction);
 } 
Esempio n. 48
0
 DependencyObject ITextContainer.GetParent(StaticTextPointer position)
 {
     return null;
 }
Esempio n. 49
0
 StaticTextPointer ITextContainer.CreatePointer(StaticTextPointer position, int offset)
 {
     return new StaticTextPointer(this, ((ITextPointer)position.Handle0).CreatePointer(offset));
 }
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // Returns the index in _runList of an error covering the specified
        // content, or -1 if no such error exists.
        private int GetErrorIndex(StaticTextPointer textPosition, LogicalDirection direction)
        {
            int index;
            Run run;

            index = FindIndex(textPosition, direction);

            if (index >= 0)
            {
                run = GetRun(index);

                if (run.RunType == RunType.Clean || run.RunType == RunType.Dirty)
                {
                    index = -1;
                }
            }

            return index;
        }
Esempio n. 51
0
 int ITextContainer.CompareTo(StaticTextPointer position1, ITextPointer position2)
 {
     return ((ITextPointer)position1.Handle0).CompareTo(position2);
 }
        // Finds the index of a run containing the specified content.
        // Returns -1 if there is no run in the indicated direction -- when
        // position is at the document edge pointing to nothing.
        private int FindIndex(StaticTextPointer position, LogicalDirection direction)
        {
            Run run;
            int index;
            int minIndex;
            int maxIndex;

            index = -1;
            minIndex = 0;
            maxIndex = _runList.Count;

            while (minIndex < maxIndex)
            {
                index = (minIndex + maxIndex) / 2;

                run = GetRun(index);

                if (direction == LogicalDirection.Forward && position.CompareTo(run.Position) < 0 ||
                    direction == LogicalDirection.Backward && position.CompareTo(run.Position) <= 0)
                {
                    // Search to the left.
                    maxIndex = index;
                }
                else if (direction == LogicalDirection.Forward && position.CompareTo(GetRunEndPosition(index)) >= 0 ||
                         direction == LogicalDirection.Backward && position.CompareTo(GetRunEndPosition(index)) > 0)
                {
                    // Search to the right.
                    minIndex = index + 1;
                }
                else
                {
                    // Got a match.
                    break;
                }
            }

            if (minIndex >= maxIndex)
            {
                // We walked off the document edge searching.
                // position is at document start or end, and direction
                // points off into space, so there's no associated run.
                index = -1;
            }

            return index;
        }
Esempio n. 53
0
        // Returns the position of the next highlight start or end in an
        // indicated direction, or null if there is no such position.
        internal override StaticTextPointer GetNextChangePosition(StaticTextPointer textPosition, LogicalDirection direction)
        {
            StaticTextPointer transitionPosition;

            transitionPosition = StaticTextPointer.Null;

            if (!IsTextRangeEmpty(_selection) && !_selection.IsInterimSelection)
            {
                int segmentCount;
                List<TextSegment> textSegments = _selection.TextSegments;
                TextSegment textSegment;

                segmentCount = textSegments.Count;

                if (direction == LogicalDirection.Forward)
                {
                    for (int segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
                    {
                        textSegment = textSegments[segmentIndex];

                        // Ignore empty segments.
                        // 












                        if (textSegment.Start.CompareTo(textSegment.End) != 0)
                        {
                            if (textPosition.CompareTo(textSegment.Start) < 0)
                            {
                                transitionPosition = textSegment.Start.CreateStaticPointer();
                                break;
                            }
                            else if (textPosition.CompareTo(textSegment.End) < 0)
                            {
                                transitionPosition = textSegment.End.CreateStaticPointer();
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (int segmentIndex = segmentCount - 1; segmentIndex >= 0; segmentIndex--)
                    {
                        textSegment = textSegments[segmentIndex];

                        if (textSegment.Start.CompareTo(textSegment.End) != 0)
                        {
                            if (textPosition.CompareTo(textSegment.End) > 0)
                            {
                                transitionPosition = textSegment.End.CreateStaticPointer();
                                break;
                            }
                            else if (textPosition.CompareTo(textSegment.Start) > 0)
                            {
                                transitionPosition = textSegment.Start.CreateStaticPointer();
                                break;
                            }
                        }
                    }
                }
            }

            return transitionPosition;
        }
Esempio n. 54
0
 ITextPointer ITextContainer.CreateDynamicTextPointer(StaticTextPointer position, LogicalDirection direction)
 {
     return ((ITextPointer)position.Handle0).CreatePointer(direction);
 }
Esempio n. 55
0
 TextPointerContext ITextContainer.GetPointerContext(StaticTextPointer pointer, LogicalDirection direction)
 {
     return ((ITextPointer)pointer.Handle0).GetPointerContext(direction);
 }
Esempio n. 56
0
 int ITextContainer.GetOffsetToPosition(StaticTextPointer position1, StaticTextPointer position2)
 {
     return ((ITextPointer)position1.Handle0).GetOffsetToPosition((ITextPointer)position2.Handle0);
 }
Esempio n. 57
0
        /// <summary>
        /// Fetch the next run at element end edge position.
        /// ElementEndEdge; we can have 2 possibilities:
        /// (1) Close edge of element associated with the text paragraph,
        ///     create synthetic LineBreak run to end the current line.
        /// (2) End of inline element, hide CloseEdge character and continue
        /// </summary>
        /// <param name="position"></param>
        /// Position in current text array
        protected TextRun HandleElementEndEdge(StaticTextPointer position)
        {
            Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd, "TextPointer does not point to element end edge.");

            TextRun run;
            if (position.Parent == _paraClient.Paragraph.Element)
            {
                // (1) Close edge of element associated with the text paragraph,
                //     create synthetic LineBreak run to end the current line.
                run = new ParagraphBreakRun(_syntheticCharacterLength, PTS.FSFLRES.fsflrEndOfParagraph);
            }
            else
            {
                TextElement element = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward);
                Debug.Assert(element != null, "Element should be here.");
                Inline inline = (Inline) element;
                DependencyObject parent = inline.Parent;
                FlowDirection parentFlowDirection = inline.FlowDirection;

                if(parent != null)
                {
                    parentFlowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                }

                if (inline.FlowDirection != parentFlowDirection)
                {
                    run = new TextEndOfSegment(_elementEdgeCharacterLength);
                }
                else
                {
                    TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline);
                    if (textDecorations == null || textDecorations.Count == 0)
                    {
                        // (2) End of inline element, hide CloseEdge character and continue
                        run = new TextHidden(_elementEdgeCharacterLength);
                    }
                    else
                    {
                        run = new TextEndOfSegment(_elementEdgeCharacterLength);
                    }
                }
            }
            return run;
        }
Esempio n. 58
0
 int ITextContainer.GetTextInRun(StaticTextPointer position, LogicalDirection direction, char[] textBuffer, int startIndex, int count)
 {
     return ((ITextPointer)position.Handle0).GetTextInRun(direction, textBuffer, startIndex, count);
 }
Esempio n. 59
0
        //-------------------------------------------------------------------
        //
        //  Protected Methods
        //
        //-------------------------------------------------------------------

        #region Protected Methods

        /// <summary>
        /// Fetch the next run at text position. 
        /// </summary>
        /// <param name="position">
        /// Current position in text array
        /// </param>
        /// <returns></returns>
        protected TextRun HandleText(StaticTextPointer position)
        {
            DependencyObject element;
            StaticTextPointer endOfRunPosition;

            Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text, "TextPointer does not point to characters.");

            if (position.Parent != null)
            {
                element = position.Parent;
            }
            else
            {
                element = _paraClient.Paragraph.Element;
            }

            // Extract the aggregated properties into something that the textrun can use.
            // 


            TextProperties textProps = new TextProperties(element, position, false /* inline objects */, true /* get background */);

            // Calculate the end of the run by finding either:
            //      a) the next intersection of highlight ranges, or
            //      b) the natural end of this textrun
            endOfRunPosition = position.TextContainer.Highlights.GetNextPropertyChangePosition(position, LogicalDirection.Forward);

            // Clamp the text run at an arbitrary limit, so we don't make
            // an unbounded allocation.
            if (position.GetOffsetToPosition(endOfRunPosition) > 4096)
            {
                endOfRunPosition = position.CreatePointer(4096);
            }

            // Get character buffer for the text run.
            char[] textBuffer = new char[position.GetOffsetToPosition(endOfRunPosition)];

            // Copy characters from text run into buffer. Note the actual number of characters copied,
            // which may be different than the buffer's length. Buffer length only specifies the maximum
            // number of characters
            int charactersCopied = position.GetTextInRun(LogicalDirection.Forward, textBuffer, 0, textBuffer.Length);

            // Create text run using the actual number of characters copied
            return new TextCharacters(textBuffer, 0, charactersCopied, textProps);
        }
 int ITextPointer.CompareTo(StaticTextPointer position)
 {
     // There is single position in the container.
     return 0;
 }