예제 #1
0
        internal static void _OnApplyProperty(TextEditor This, DependencyProperty formattingProperty, object propertyValue, bool applyToParagraphs, PropertyValueAction propertyValueAction)
        {
            if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection))
            {
                return;
            }

            // Check whether the property is known
            if (!TextSchema.IsParagraphProperty(formattingProperty) && !TextSchema.IsCharacterProperty(formattingProperty))
            {
                Invariant.Assert(false, "The property '" + formattingProperty.Name + "' is unknown to TextEditor");
                return;
            }

            TextSelection selection = (TextSelection)This.Selection;

            if (TextSchema.IsStructuralCharacterProperty(formattingProperty) &&
                !TextRangeEdit.CanApplyStructuralInlineProperty(selection.Start, selection.End))
            {
                // Ignore structural commands fires in inappropriate context.
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

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

            // Break merged typing sequence
            TextEditorTyping._BreakTypingSequence(This);

            // Apply property
            selection.ApplyPropertyValue(formattingProperty, propertyValue, applyToParagraphs, propertyValueAction);
        }
 /// <summary>Returns the effective value of a specified formatting property on the current selection.</summary>
 /// <param name="formattingProperty">A formatting property to get the value of with respect to the current selection.</param>
 /// <returns>An object specifying the value of the specified formatting property.</returns>
 /// <exception cref="T:System.ArgumentException">Occurs when <paramref name="formattingProperty" /> does not specify a valid formatting property, or <paramref name="value" /> specifies an invalid value for <paramref name="formattingProperty" />.</exception>
 /// <exception cref="T:System.ArgumentNullException">Occurs when <paramref name="formattingProperty" /> is <see langword="null" />.</exception>
 // Token: 0x06003AD9 RID: 15065 RVA: 0x0010A2EC File Offset: 0x001084EC
 public object GetPropertyValue(DependencyProperty formattingProperty)
 {
     if (formattingProperty == null)
     {
         throw new ArgumentNullException("formattingProperty");
     }
     if (!TextSchema.IsCharacterProperty(formattingProperty) && !TextSchema.IsParagraphProperty(formattingProperty))
     {
         throw new ArgumentException(SR.Get("TextEditorPropertyIsNotApplicableForTextFormatting", new object[]
         {
             formattingProperty.Name
         }));
     }
     return(((ITextRange)this).GetPropertyValue(formattingProperty));
 }
 // Token: 0x06003AD7 RID: 15063 RVA: 0x0010A16C File Offset: 0x0010836C
 internal void ApplyPropertyValue(DependencyProperty formattingProperty, object value, bool applyToParagraphs, PropertyValueAction propertyValueAction)
 {
     Invariant.Assert(this.HasConcreteTextContainer, "Can't apply property to non-TextContainer range!");
     if (formattingProperty == null)
     {
         throw new ArgumentNullException("formattingProperty");
     }
     if (!TextSchema.IsCharacterProperty(formattingProperty) && !TextSchema.IsParagraphProperty(formattingProperty))
     {
         throw new ArgumentException(SR.Get("TextEditorPropertyIsNotApplicableForTextFormatting", new object[]
         {
             formattingProperty.Name
         }));
     }
     if (value is string && formattingProperty.PropertyType != typeof(string))
     {
         TypeConverter converter = TypeDescriptor.GetConverter(formattingProperty.PropertyType);
         Invariant.Assert(converter != null);
         value = converter.ConvertFromString((string)value);
     }
     if (!formattingProperty.IsValidValue(value) && (!(formattingProperty.PropertyType == typeof(Thickness)) || !(value is Thickness)))
     {
         throw new ArgumentException(SR.Get("TextEditorTypeOfParameterIsNotAppropriateForFormattingProperty", new object[]
         {
             (value == null) ? "null" : value.GetType().Name,
             formattingProperty.Name
         }), "value");
     }
     if (propertyValueAction != PropertyValueAction.SetValue && propertyValueAction != PropertyValueAction.IncreaseByAbsoluteValue && propertyValueAction != PropertyValueAction.DecreaseByAbsoluteValue && propertyValueAction != PropertyValueAction.IncreaseByPercentageValue && propertyValueAction != PropertyValueAction.DecreaseByPercentageValue)
     {
         throw new ArgumentException(SR.Get("TextRange_InvalidParameterValue"), "propertyValueAction");
     }
     if (propertyValueAction != PropertyValueAction.SetValue && !TextSchema.IsPropertyIncremental(formattingProperty))
     {
         throw new ArgumentException(SR.Get("TextRange_PropertyCannotBeIncrementedOrDecremented", new object[]
         {
             formattingProperty.Name
         }), "propertyValueAction");
     }
     this.ApplyPropertyToTextVirtual(formattingProperty, value, applyToParagraphs, propertyValueAction);
 }
        // Token: 0x06003835 RID: 14389 RVA: 0x000FA980 File Offset: 0x000F8B80
        internal static void _OnApplyProperty(TextEditor This, DependencyProperty formattingProperty, object propertyValue, bool applyToParagraphs, PropertyValueAction propertyValueAction)
        {
            if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection))
            {
                return;
            }
            if (!TextSchema.IsParagraphProperty(formattingProperty) && !TextSchema.IsCharacterProperty(formattingProperty))
            {
                Invariant.Assert(false, "The property '" + formattingProperty.Name + "' is unknown to TextEditor");
                return;
            }
            TextSelection textSelection = (TextSelection)This.Selection;

            if (TextSchema.IsStructuralCharacterProperty(formattingProperty) && !TextRangeEdit.CanApplyStructuralInlineProperty(textSelection.Start, textSelection.End))
            {
                return;
            }
            TextEditorTyping._FlushPendingInputItems(This);
            TextEditorSelection._ClearSuggestedX(This);
            TextEditorTyping._BreakTypingSequence(This);
            textSelection.ApplyPropertyValue(formattingProperty, propertyValue, applyToParagraphs, propertyValueAction);
        }
 // 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);
     }
 }