/// <summary> Resolves text effect on a text range to a list of text effect targets. </summary> /// <param name="startPosition">The starting text pointer</param> /// <param name="endPosition">The end text pointer</param> /// <param name="effect">The effect to apply on the text</param> /// <returns>Collection of <see cref="T:System.Windows.Documents.TextEffectTarget" /> objects corresponding to the text range.</returns> // Token: 0x06003920 RID: 14624 RVA: 0x001030F0 File Offset: 0x001012F0 public static TextEffectTarget[] Resolve(TextPointer startPosition, TextPointer endPosition, TextEffect effect) { if (effect == null) { throw new ArgumentNullException("effect"); } ValidationHelper.VerifyPositionPair(startPosition, endPosition); TextPointer textPointer = new TextPointer(startPosition); TextEffectResolver.MoveToFirstCharacterSymbol(textPointer); List <TextEffectTarget> list = new List <TextEffectTarget>(); while (textPointer.CompareTo(endPosition) < 0) { TextEffect textEffect = effect.Clone(); TextPointer textPointer2 = new TextPointer(textPointer); TextEffectResolver.MoveToFirstNonCharacterSymbol(textPointer2, endPosition); textPointer2 = (TextPointer)TextPointerBase.Min(textPointer2, endPosition); textEffect.PositionStart = textPointer.TextContainer.Start.GetOffsetToPosition(textPointer); textEffect.PositionCount = textPointer.GetOffsetToPosition(textPointer2); list.Add(new TextEffectTarget(textPointer.Parent, textEffect)); textPointer = textPointer2; TextEffectResolver.MoveToFirstCharacterSymbol(textPointer); } return(list.ToArray()); }
//--------------------------- // public static methods //--------------------------- /// <summary> /// resolves text effect on a text range to a list of text effect targets. /// The method will walk the text and perform the following task: /// 1) For each continous block of text, create a text effect targeting the scoping element /// 2) For the text effect created, calculate the starting cp index and cp count for the effect /// /// The method will create freezable copy of the TextEffect passed in and fill in /// CharacterIndex and Count for the range. /// </summary> /// <param name="startPosition">starting text pointer</param> /// <param name="endPosition">end text pointer</param> /// <param name="effect">effect that is apply on the text</param> public static TextEffectTarget[] Resolve( TextPointer startPosition, TextPointer endPosition, TextEffect effect ) { if (effect == null) { throw new ArgumentNullException("effect"); } ValidationHelper.VerifyPositionPair(startPosition, endPosition); TextPointer effectStart = new TextPointer(startPosition); // move to the first character symbol at or after Start position MoveToFirstCharacterSymbol(effectStart); TextEffect effectCopy; List <TextEffectTarget> list = new List <TextEffectTarget>(); // we will now traverse the TOM and resolve text effects to the immediate parent // of the characters. We are effectively applying the text effect onto // block of continous text. while (effectStart.CompareTo(endPosition) < 0) { // create a copy of the text effect // so that we can set the CharacterIndex and Count effectCopy = effect.Clone(); // create a position TextPointer continuousTextEnd = new TextPointer(effectStart); // move the position to the end of the continuous text block MoveToFirstNonCharacterSymbol(continuousTextEnd, endPosition); // make sure we are not out of the range continuousTextEnd = (TextPointer)TextPointerBase.Min(continuousTextEnd, endPosition); // set the character index to be the distance from the Start // of this text block to the Start of the text container effectCopy.PositionStart = effectStart.TextContainer.Start.GetOffsetToPosition(effectStart); // count is the distance from the text block start to end effectCopy.PositionCount = effectStart.GetOffsetToPosition(continuousTextEnd); list.Add( new TextEffectTarget( effectStart.Parent, effectCopy ) ); // move the effectStart to the beginning of the next text block. effectStart = continuousTextEnd; MoveToFirstCharacterSymbol(effectStart); } return(list.ToArray()); }
// Token: 0x06003C68 RID: 15464 RVA: 0x0011745C File Offset: 0x0011565C internal void InternalOnSelectionChanged() { ITextPointer textPointer; if (!this._selection.IsInterimSelection) { textPointer = this._selection.Start; } else { textPointer = this._selection.End; } ITextPointer end = this._selection.End; ITextPointer textPointer2; ITextPointer textPointer3; if (this._oldStart.CompareTo(textPointer) < 0) { textPointer2 = this._oldStart; textPointer3 = TextPointerBase.Min(textPointer, this._oldEnd); } else { textPointer2 = textPointer; textPointer3 = TextPointerBase.Min(end, this._oldStart); } ITextPointer textPointer4; ITextPointer textPointer5; if (this._oldEnd.CompareTo(end) < 0) { textPointer4 = TextPointerBase.Max(textPointer, this._oldEnd); textPointer5 = end; } else { textPointer4 = TextPointerBase.Max(end, this._oldStart); textPointer5 = this._oldEnd; } this._oldStart = textPointer; this._oldEnd = end; if (this.Changed != null && (textPointer2.CompareTo(textPointer3) != 0 || textPointer4.CompareTo(textPointer5) != 0)) { TextSelectionHighlightLayer.TextSelectionHighlightChangedEventArgs args = new TextSelectionHighlightLayer.TextSelectionHighlightChangedEventArgs(textPointer2, textPointer3, textPointer4, textPointer5); this.Changed(this, args); } }
// This is actual implementation to make highlight change notification. // This is called when highlight needs to be changed without public TextSelection change event. internal void InternalOnSelectionChanged() { ITextPointer newStart; ITextPointer newEnd; ITextPointer invalidRangeLeftStart; ITextPointer invalidRangeLeftEnd; ITextPointer invalidRangeRightStart; ITextPointer invalidRangeRightEnd; TextSelectionHighlightChangedEventArgs args; // If the current seleciton is interim selection, we do not highlight it // and we make newStart == newEnd. if (!_selection.IsInterimSelection) { newStart = _selection.Start; } else { newStart = _selection.End; } newEnd = _selection.End; // We want to raise an event that tracks the change tightly -- // only identifying content where the selection status actually changed. // This is important for render performance. // // Ex: // Old selection: 012<selection>345</selection>678 // New selection: 0123<selection>456</selection>78 // // Should raise (3-3), (6-6) as deltas, not (3-6). // // Get the left side invalid range. if (_oldStart.CompareTo(newStart) < 0) { invalidRangeLeftStart = _oldStart; invalidRangeLeftEnd = TextPointerBase.Min(newStart, _oldEnd); } else { invalidRangeLeftStart = newStart; invalidRangeLeftEnd = TextPointerBase.Min(newEnd, _oldStart); } // Get the right side invalid range. if (_oldEnd.CompareTo(newEnd) < 0) { invalidRangeRightStart = TextPointerBase.Max(newStart, _oldEnd); invalidRangeRightEnd = newEnd; } else { invalidRangeRightStart = TextPointerBase.Max(newEnd, _oldStart); invalidRangeRightEnd = _oldEnd; } _oldStart = newStart; _oldEnd = newEnd; if (this.Changed != null) { if (invalidRangeLeftStart.CompareTo(invalidRangeLeftEnd) != 0 || invalidRangeRightStart.CompareTo(invalidRangeRightEnd) != 0) { args = new TextSelectionHighlightChangedEventArgs(invalidRangeLeftStart, invalidRangeLeftEnd, invalidRangeRightStart, invalidRangeRightEnd); this.Changed(this, args); } } }