// Token: 0x06003836 RID: 14390 RVA: 0x000FAA28 File Offset: 0x000F8C28
        private static void OnResetFormat(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(target);

            if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection.Start is TextPointer))
            {
                return;
            }
            TextEditorTyping._FlushPendingInputItems(textEditor);
            using (textEditor.Selection.DeclareChangeBlock())
            {
                TextPointer start = (TextPointer)textEditor.Selection.Start;
                TextPointer end   = (TextPointer)textEditor.Selection.End;
                if (textEditor.Selection.IsEmpty)
                {
                    TextSegment autoWord = TextRangeBase.GetAutoWord(textEditor.Selection);
                    if (autoWord.IsNull)
                    {
                        ((TextSelection)textEditor.Selection).ClearSpringloadFormatting();
                        return;
                    }
                    start = (TextPointer)autoWord.Start;
                    end   = (TextPointer)autoWord.End;
                }
                TextEditorSelection._ClearSuggestedX(textEditor);
                TextRangeEdit.CharacterResetFormatting(start, end);
            }
        }
Beispiel #2
0
            // Token: 0x060085BD RID: 34237 RVA: 0x0024AA08 File Offset: 0x00248C08
            private ITextPointer GetDropPosition(Visual target, Point point)
            {
                Invariant.Assert(target != null);
                Invariant.Assert(this._textEditor.TextView.IsValid);
                if (target != this._textEditor.TextView.RenderScope && target != null && this._textEditor.TextView.RenderScope.IsAncestorOf(target))
                {
                    GeneralTransform generalTransform = target.TransformToAncestor(this._textEditor.TextView.RenderScope);
                    generalTransform.TryTransform(point, out point);
                }
                ITextPointer textPointer = this.TextView.GetTextPositionFromPoint(point, true);

                if (textPointer != null)
                {
                    textPointer = textPointer.GetInsertionPosition(textPointer.LogicalDirection);
                    if (this._textEditor.AcceptsRichContent)
                    {
                        TextSegment normalizedLineRange = TextEditorSelection.GetNormalizedLineRange(this.TextView, textPointer);
                        if (!normalizedLineRange.IsNull && textPointer.CompareTo(normalizedLineRange.End) < 0 && !TextPointerBase.IsAtWordBoundary(textPointer, LogicalDirection.Forward) && this._dragSourceTextRange != null && TextPointerBase.IsAtWordBoundary(this._dragSourceTextRange.Start, LogicalDirection.Forward) && TextPointerBase.IsAtWordBoundary(this._dragSourceTextRange.End, LogicalDirection.Forward))
                        {
                            TextSegment wordRange        = TextPointerBase.GetWordRange(textPointer);
                            string      textInternal     = TextRangeBase.GetTextInternal(wordRange.Start, wordRange.End);
                            int         offsetToPosition = wordRange.Start.GetOffsetToPosition(textPointer);
                            textPointer = ((offsetToPosition < textInternal.Length / 2) ? wordRange.Start : wordRange.End);
                        }
                    }
                }
                return(textPointer);
            }
 // Token: 0x06003AFD RID: 15101 RVA: 0x0010A660 File Offset: 0x00108860
 internal virtual void InsertEmbeddedUIElementVirtual(FrameworkElement embeddedElement)
 {
     Invariant.Assert(this.HasConcreteTextContainer, "Can't insert embedded object to non-TextContainer range!");
     Invariant.Assert(embeddedElement != null);
     TextRangeBase.BeginChange(this);
     try
     {
         this.Text = string.Empty;
         TextPointer textPointer = TextRangeEditTables.EnsureInsertionPosition(this.Start);
         Paragraph   paragraph   = textPointer.Paragraph;
         if (paragraph != null)
         {
             if (Paragraph.HasNoTextContent(paragraph))
             {
                 BlockUIContainer blockUIContainer = new BlockUIContainer(embeddedElement);
                 blockUIContainer.TextAlignment = TextRangeEdit.GetTextAlignmentFromHorizontalAlignment(embeddedElement.HorizontalAlignment);
                 paragraph.SiblingBlocks.InsertAfter(paragraph, blockUIContainer);
                 paragraph.SiblingBlocks.Remove(paragraph);
                 this.Select(blockUIContainer.ContentStart, blockUIContainer.ContentEnd);
             }
             else
             {
                 InlineUIContainer inlineUIContainer = new InlineUIContainer(embeddedElement);
                 TextPointer       textPointer2      = TextRangeEdit.SplitFormattingElements(this.Start, false);
                 textPointer2.InsertTextElement(inlineUIContainer);
                 this.Select(inlineUIContainer.ElementStart, inlineUIContainer.ElementEnd);
             }
         }
     }
     finally
     {
         TextRangeBase.EndChange(this);
     }
 }
Beispiel #4
0
        // Token: 0x0600350D RID: 13581 RVA: 0x000F0444 File Offset: 0x000EE644
        private string GetText()
        {
            double    top       = this._selectionRect.Top;
            double    bottom    = this._selectionRect.Bottom;
            double    left      = this._selectionRect.Left;
            double    right     = this._selectionRect.Right;
            double    num       = 0.0;
            double    num2      = 0.0;
            int       count     = this._page.Children.Count;
            ArrayList arrayList = new ArrayList();

            FixedNode[] array = this._panel.FixedContainer.FixedTextBuilder.GetFirstLine(this._pageIndex);
            while (array != null && array.Length != 0)
            {
                RubberbandSelector.TextPositionPair textPositionPair = null;
                foreach (FixedNode node in array)
                {
                    Glyphs glyphsElement = this._page.GetGlyphsElement(node);
                    if (glyphsElement != null)
                    {
                        int  num3;
                        int  charIndex;
                        bool flag;
                        if (this.IntersectGlyphs(glyphsElement, top, left, bottom, right, out num3, out charIndex, out flag, out num, out num2))
                        {
                            if (textPositionPair == null || num3 > 0)
                            {
                                textPositionPair       = new RubberbandSelector.TextPositionPair();
                                textPositionPair.first = this._GetTextPosition(node, num3);
                                arrayList.Add(textPositionPair);
                            }
                            textPositionPair.second = this._GetTextPosition(node, charIndex);
                            if (!flag)
                            {
                                textPositionPair = null;
                            }
                        }
                        else
                        {
                            textPositionPair = null;
                        }
                    }
                }
                int num4 = 1;
                array = this._panel.FixedContainer.FixedTextBuilder.GetNextLine(array[0], true, ref num4);
            }
            string text = "";

            foreach (object obj in arrayList)
            {
                RubberbandSelector.TextPositionPair textPositionPair2 = (RubberbandSelector.TextPositionPair)obj;
                text = text + TextRangeBase.GetTextInternal(textPositionPair2.first, textPositionPair2.second) + "\r\n";
            }
            return(text);
        }
        // Token: 0x06004A4F RID: 19023 RVA: 0x0014F910 File Offset: 0x0014DB10
        internal override object GetValue(BaseValueSourceInternal valueSource)
        {
            string  textInternal = TextRangeBase.GetTextInternal(this._textContainer.Start, this._textContainer.End);
            TextBox textBox      = this._textContainer.Parent as TextBox;

            if (textBox != null)
            {
                textBox.OnDeferredTextReferenceResolved(this, textInternal);
            }
            return(textInternal);
        }
 // Token: 0x06003AFF RID: 15103 RVA: 0x0010A8DC File Offset: 0x00108ADC
 internal virtual void ClearAllPropertiesVirtual()
 {
     TextRangeBase.BeginChange(this);
     try
     {
         TextRangeEdit.CharacterResetFormatting(this.Start, this.End);
     }
     finally
     {
         TextRangeBase.EndChange(this);
     }
 }
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Does the real work to calculate the current TextProperty value.
        internal override object GetValue(BaseValueSourceInternal valueSource)
        {
            string s = TextRangeBase.GetTextInternal(_textContainer.Start, _textContainer.End);

            TextBox tb = _textContainer.Parent as TextBox;

            if (tb != null)
            {
                tb.OnDeferredTextReferenceResolved(this, s);
            }

            return(s);
        }
 // Token: 0x06003AA4 RID: 15012 RVA: 0x00109EE4 File Offset: 0x001080E4
 internal TextRange(ITextPointer position1, ITextPointer position2, bool ignoreTextUnitBoundaries)
 {
     if (position1 == null)
     {
         throw new ArgumentNullException("position1");
     }
     if (position2 == null)
     {
         throw new ArgumentNullException("position2");
     }
     this.SetFlags(ignoreTextUnitBoundaries, TextRange.Flags.IgnoreTextUnitBoundaries);
     ValidationHelper.VerifyPosition(position1.TextContainer, position1, "position1");
     ValidationHelper.VerifyPosition(position1.TextContainer, position2, "position2");
     TextRangeBase.Select(this, position1, position2);
 }
        // Token: 0x06003B00 RID: 15104 RVA: 0x0010A91C File Offset: 0x00108B1C
        internal virtual Table InsertTableVirtual(int rowCount, int columnCount)
        {
            TextRangeBase.BeginChange(this);
            Table result;

            try
            {
                result = TextRangeEditTables.InsertTable(this.End, rowCount, columnCount);
            }
            finally
            {
                TextRangeBase.EndChange(this);
            }
            return(result);
        }
        // Token: 0x06003B05 RID: 15109 RVA: 0x0010AA30 File Offset: 0x00108C30
        internal virtual TextRange MergeCellsVirtual()
        {
            TextRangeBase.BeginChange(this);
            TextRange result;

            try
            {
                result = TextRangeEditTables.MergeCells(this);
            }
            finally
            {
                TextRangeBase.EndChange(this);
            }
            return(result);
        }
        // Token: 0x06003B06 RID: 15110 RVA: 0x0010AA64 File Offset: 0x00108C64
        internal virtual TextRange SplitCellVirtual(int splitCountHorizontal, int splitCountVertical)
        {
            TextRangeBase.BeginChange(this);
            TextRange result;

            try
            {
                result = TextRangeEditTables.SplitCell(this, splitCountHorizontal, splitCountVertical);
            }
            finally
            {
                TextRangeBase.EndChange(this);
            }
            return(result);
        }
        // Token: 0x06003B04 RID: 15108 RVA: 0x0010A9FC File Offset: 0x00108BFC
        internal virtual bool DeleteColumnsVirtual()
        {
            TextRangeBase.BeginChange(this);
            bool result;

            try
            {
                result = TextRangeEditTables.DeleteColumns(this);
            }
            finally
            {
                TextRangeBase.EndChange(this);
            }
            return(result);
        }
        // Token: 0x06003B03 RID: 15107 RVA: 0x0010A9C4 File Offset: 0x00108BC4
        internal virtual TextRange InsertColumnsVirtual(int columnCount)
        {
            TextRangeBase.BeginChange(this);
            TextRange result;

            try
            {
                result = TextRangeEditTables.InsertColumns(this, columnCount);
            }
            finally
            {
                TextRangeBase.EndChange(this);
            }
            return(result);
        }
            /// <summary>
            /// Calculates a TextPointer indended for dropping the text.
            /// </summary>
            /// <param name="target"></param>
            /// <param name="point"></param>
            /// <returns>
            /// ITextPointer intended for dropping the selected text.
            /// Adjusts the dropping point to a word boundary (beginning of word)
            /// in case if source range contains whole words.
            /// The position returned is oriented towards a character
            /// under the mouse pointer.
            /// </returns>
            private ITextPointer GetDropPosition(Visual target, Point point)
            {
                Invariant.Assert(target != null);
                Invariant.Assert(_textEditor.TextView.IsValid); // caller must guarantee this.

                // Convert point to RenderScope
                if (target != _textEditor.TextView.RenderScope && target != null && (_textEditor.TextView.RenderScope).IsAncestorOf(target))
                {
                    GeneralTransform transform = target.TransformToAncestor(_textEditor.TextView.RenderScope);
                    transform.TryTransform(point, out point);
                }

                ITextPointer dropPosition = this.TextView.GetTextPositionFromPoint(point, /*snapToText:*/ true);

                // For rich text content we adjust drop position to word boundary
                if (dropPosition != null)
                {
                    // Normalize drop position
                    dropPosition = dropPosition.GetInsertionPosition(dropPosition.LogicalDirection);

                    if (_textEditor.AcceptsRichContent)
                    {
                        TextSegment lineRange = TextEditorSelection.GetNormalizedLineRange(this.TextView, dropPosition);

                        if (!lineRange.IsNull &&
                            // The drop position must be before of end of line
                            dropPosition.CompareTo(lineRange.End) < 0 &&
                            // We check if we are not at word boundary already:
                            !TextPointerBase.IsAtWordBoundary(dropPosition, /*insideWordDirection:*/ LogicalDirection.Forward) &&
                            // We do not do it if the source range was not on word boundaries from both ends
                            _dragSourceTextRange != null &&                                                           //
                            TextPointerBase.IsAtWordBoundary(_dragSourceTextRange.Start, LogicalDirection.Forward) && //
                            TextPointerBase.IsAtWordBoundary(_dragSourceTextRange.End, LogicalDirection.Forward))
                        {
                            // Move to word boundary. Select closest one to a dropPosition.
                            TextSegment wordSegment = TextPointerBase.GetWordRange(dropPosition);
                            string      wordText    = TextRangeBase.GetTextInternal(wordSegment.Start, wordSegment.End);
                            int         indexInWord = wordSegment.Start.GetOffsetToPosition(dropPosition);
                            dropPosition = (indexInWord < (wordText.Length / 2)) ? wordSegment.Start : wordSegment.End;
                        }
                    }
                }

                return(dropPosition);
            }
Beispiel #15
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // ................................................................
        //
        // Editing Commands: Character Editing
        //
        // ................................................................

        private static void OnResetFormat(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor This = TextEditor._GetTextEditor(target);

            if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection.Start is TextPointer))
            {
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

            using (This.Selection.DeclareChangeBlock())
            {
                // Positions to clear all inline formatting properties
                TextPointer startResetFormatPosition = (TextPointer)This.Selection.Start;
                TextPointer endResetFormatPosition   = (TextPointer)This.Selection.End;

                if (This.Selection.IsEmpty)
                {
                    TextSegment autoWordRange = TextRangeBase.GetAutoWord(This.Selection);
                    if (autoWordRange.IsNull)
                    {
                        // Clear springloaded formatting
                        ((TextSelection)This.Selection).ClearSpringloadFormatting();
                        return;
                    }
                    else
                    {
                        // If we have a word, apply reset format to it
                        startResetFormatPosition = (TextPointer)autoWordRange.Start;
                        endResetFormatPosition   = (TextPointer)autoWordRange.End;
                    }
                }

                // Forget previously suggested horizontal position
                TextEditorSelection._ClearSuggestedX(This);

                // Clear all inline formattings
                TextRangeEdit.CharacterResetFormatting(startResetFormatPosition, endResetFormatPosition);
            }
        }
 // Token: 0x06003AFE RID: 15102 RVA: 0x0010A744 File Offset: 0x00108944
 internal virtual void ApplyPropertyToTextVirtual(DependencyProperty formattingProperty, object value, bool applyToParagraphs, PropertyValueAction propertyValueAction)
 {
     TextRangeBase.BeginChange(this);
     try
     {
         for (int i = 0; i < this._textSegments.Count; i++)
         {
             TextSegment textSegment = this._textSegments[i];
             if (formattingProperty == FrameworkElement.FlowDirectionProperty)
             {
                 if (applyToParagraphs || this.IsEmpty || TextRangeBase.IsParagraphBoundaryCrossed(this))
                 {
                     TextRangeEdit.SetParagraphProperty((TextPointer)textSegment.Start, (TextPointer)textSegment.End, formattingProperty, value, propertyValueAction);
                 }
                 else
                 {
                     TextRangeEdit.SetInlineProperty((TextPointer)textSegment.Start, (TextPointer)textSegment.End, formattingProperty, value, propertyValueAction);
                 }
             }
             else if (TextSchema.IsCharacterProperty(formattingProperty))
             {
                 TextRangeEdit.SetInlineProperty((TextPointer)textSegment.Start, (TextPointer)textSegment.End, formattingProperty, value, propertyValueAction);
             }
             else if (TextSchema.IsParagraphProperty(formattingProperty))
             {
                 if (formattingProperty.PropertyType == typeof(Thickness) && (FlowDirection)textSegment.Start.GetValue(Block.FlowDirectionProperty) == FlowDirection.RightToLeft)
                 {
                     value = new Thickness(((Thickness)value).Right, ((Thickness)value).Top, ((Thickness)value).Left, ((Thickness)value).Bottom);
                 }
                 TextRangeEdit.SetParagraphProperty((TextPointer)textSegment.Start, (TextPointer)textSegment.End, formattingProperty, value, propertyValueAction);
             }
         }
     }
     finally
     {
         TextRangeBase.EndChange(this);
     }
 }
 // Token: 0x06003AA6 RID: 15014 RVA: 0x00109F56 File Offset: 0x00108156
 bool ITextRange.Contains(ITextPointer position)
 {
     return(TextRangeBase.Contains(this, position));
 }
 // Token: 0x06004A49 RID: 19017 RVA: 0x0014F8B4 File Offset: 0x0014DAB4
 internal override object GetValue(BaseValueSourceInternal valueSource)
 {
     return(TextRangeBase.GetTextInternal(this._run.ContentStart, this._run.ContentEnd));
 }
 // Token: 0x06003AA7 RID: 15015 RVA: 0x00109F5F File Offset: 0x0010815F
 void ITextRange.Select(ITextPointer position1, ITextPointer position2)
 {
     TextRangeBase.Select(this, position1, position2);
 }
 // Token: 0x06003AE3 RID: 15075 RVA: 0x0010A44C File Offset: 0x0010864C
 internal virtual void LoadVirtual(Stream stream, string dataFormat)
 {
     TextRangeBase.Load(this, stream, dataFormat);
 }
 // Token: 0x06003AAB RID: 15019 RVA: 0x00109F84 File Offset: 0x00108184
 object ITextRange.GetPropertyValue(DependencyProperty formattingProperty)
 {
     return(TextRangeBase.GetPropertyValue(this, formattingProperty));
 }
 // Token: 0x06003AAD RID: 15021 RVA: 0x00109F95 File Offset: 0x00108195
 bool ITextRange.CanSave(string dataFormat)
 {
     return(TextRangeBase.CanSave(this, dataFormat));
 }
 // Token: 0x06003AAC RID: 15020 RVA: 0x00109F8D File Offset: 0x0010818D
 UIElement ITextRange.GetUIElementSelected()
 {
     return(TextRangeBase.GetUIElementSelected(this));
 }
 // Token: 0x06003AA9 RID: 15017 RVA: 0x00109F72 File Offset: 0x00108172
 void ITextRange.SelectParagraph(ITextPointer position)
 {
     TextRangeBase.SelectParagraph(this, position);
 }
Beispiel #25
0
        //gets text within selected area
        private string GetText()
        {
            double top    = _selectionRect.Top;
            double bottom = _selectionRect.Bottom;
            double left   = _selectionRect.Left;
            double right  = _selectionRect.Right;

            double lastBaseline = 0;
            double baseline     = 0;
            double lastHeight   = 0;
            double height       = 0;

            int       nChildren = _page.Children.Count;
            ArrayList ranges    = new ArrayList(); //text ranges in area

            FixedNode[] nodesInLine = _panel.FixedContainer.FixedTextBuilder.GetFirstLine(_pageIndex);

            while (nodesInLine != null && nodesInLine.Length > 0)
            {
                TextPositionPair textRange = null; //current text range

                foreach (FixedNode node in nodesInLine)
                {
                    Glyphs g = _page.GetGlyphsElement(node);
                    if (g != null)
                    {
                        int  begin, end; //first and last index in range
                        bool includeEnd; //is the end of this glyphs included in selection?
                        if (IntersectGlyphs(g, top, left, bottom, right, out begin, out end, out includeEnd, out baseline, out height))
                        {
                            if (textRange == null || begin > 0)
                            {
                                //begin new text range
                                textRange       = new TextPositionPair();
                                textRange.first = _GetTextPosition(node, begin);
                                ranges.Add(textRange);
                            }

                            textRange.second = _GetTextPosition(node, end);

                            if (!includeEnd)
                            {
                                // so future textRanges aren't concatenated with this one
                                textRange = null;
                            }
                        }
                        else
                        {
                            //this Glyphs completely outside selected region
                            textRange = null;
                        }
                        lastBaseline = baseline;
                        lastHeight   = height;
                    }
                }
                int count = 1;
                nodesInLine = _panel.FixedContainer.FixedTextBuilder.GetNextLine(nodesInLine[0], true, ref count);
            }

            string text = "";

            foreach (TextPositionPair range in ranges)
            {
                Debug.Assert(range.first != null && range.second != null);
                text = text + TextRangeBase.GetTextInternal(range.first, range.second) + "\r\n"; //CRLF
            }

            return(text);
        }
 // Token: 0x06003AA8 RID: 15016 RVA: 0x00109F69 File Offset: 0x00108169
 void ITextRange.SelectWord(ITextPointer position)
 {
     TextRangeBase.SelectWord(this, position);
 }
 /// <summary>Checks whether the current selection can be loaded with content in a specified data format.</summary>
 /// <param name="dataFormat">A data format to check for load-compatibility into the current selection.  See <see cref="T:System.Windows.DataFormats" /> for a list of predefined data formats.</param>
 /// <returns>
 ///     <see langword="true" /> if the current selection can be loaded with content in the specified data format; otherwise, <see langword="false" />.</returns>
 // Token: 0x06003ADC RID: 15068 RVA: 0x0010A34E File Offset: 0x0010854E
 public bool CanLoad(string dataFormat)
 {
     return(TextRangeBase.CanLoad(this, dataFormat));
 }
 /// <summary>Instructs the control to ignore this error and any duplicates for the remainder of the lifetime of the control.</summary>
 // Token: 0x06005B57 RID: 23383 RVA: 0x0019C184 File Offset: 0x0019A384
 public void IgnoreAll()
 {
     this._speller.IgnoreAll(TextRangeBase.GetTextInternal(this._start, this._end));
 }
 /// <summary>
 /// Instructs the control to ignore this error and any duplicates for
 /// the remainder of its lifetime.
 /// </summary>
 public void IgnoreAll()
 {
     _speller.IgnoreAll(TextRangeBase.GetTextInternal(_start, _end));
 }
 // Token: 0x06003AAA RID: 15018 RVA: 0x00109F7B File Offset: 0x0010817B
 void ITextRange.ApplyTypingHeuristics(bool overType)
 {
     TextRangeBase.ApplyTypingHeuristics(this, overType);
 }