/// <summary> /// </summary> public CaretElement(EditorView editorView) { SizeChangedEventHandler handler = null; _editorView = editorView; _caretPlacement = CaretPlacement.LeftOfCharacter; _insertionPoint = new TextPoint(editorView.TextBuffer, 0); _preferredVerticalPosition = _preferredHorizontalPosition = 0; _textViewHelper = new TextViewHelper(_editorView); this.ConstructCaretGeometry(); TextLine line = TextFormatter.Create().FormatLine(new DefaultLineGutterTextSource("W", TextFormattingRunProperties.DefaultProperties), 0, 10, new TextFormattingParagraphProperties(), null); _defaultOverwriteCaretWidth = line.Width; _overwriteCaretBrush = new SolidColorBrush(Colors.Gray); _overwriteCaretBrush.Opacity = 0.5; DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); frames.BeginTime = new TimeSpan((long)0); frames.RepeatBehavior = RepeatBehavior.Forever; frames.KeyFrames.Add(new DiscreteDoubleKeyFrame(1, KeyTime.FromPercent(0))); Int32 caretBlinkTime = User32.GetCaretBlinkTime(); if (caretBlinkTime > 0) { frames.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromPercent(0.5))); } else { caretBlinkTime = 500; } frames.Duration = new Duration(new TimeSpan(0, 0, 0, 0, caretBlinkTime * 2)); _blinkAnimationClock = frames.CreateClock(); base.ApplyAnimationClock(UIElement.OpacityProperty, _blinkAnimationClock); this.PositionChanged = (EventHandler<CaretPositionChangedEventArgs>)Delegate.Combine(this.PositionChanged, new EventHandler<CaretPositionChangedEventArgs>(this.CaretElement_PositionChanged)); if (handler == null) { handler = delegate { this.ConstructCaretGeometry(); }; } base.SizeChanged += handler; base.IsVisibleChanged += new DependencyPropertyChangedEventHandler(this.UIElement_VisibleChanged); this.OverwriteMode = false; }
public void AddLine(TextPoint start, Double width) { if (width > _maxWidth) { _maxWidth = width; } foreach (LineWidth width2 in _cachedLines) { if (width2.Start != start) { continue; } if ((width2.Width == _maxWidth) && (width < width2.Width)) { _maxWidth = Double.MaxValue; } width2.Width = width; return; } if (_cachedLines.Count < 50) { _cachedLines.Add(new LineWidth(start, width)); } else { Int32 num = 0; for (var i = 1; i < _cachedLines.Count; i++) { if (_cachedLines[i].Width < _cachedLines[num].Width) { num = i; } } if (width > _cachedLines[num].Width) { _cachedLines[num] = new LineWidth(start, width); } } }
/// <summary> /// Initializes a new instance of the <see cref="TextLineVisual"/> class. /// </summary> /// <exception cref="ArgumentNullException"> /// <para><paramref name="textView"/> is <see langword="null"/>.</para> /// </exception> public TextLineVisual(ITextView textView, IList<TextLine> textLines, TextSpan lineSpan, Int32 newLineLength, IList<Int32> virtualCharacters) { if (textView == null) { throw new ArgumentNullException("textView"); } _textView = textView; _textLines = textLines; _newLineLength = newLineLength; _horizontalOffset = 0; _verticalOffset = 0; _startPoint = new TextPoint(lineSpan.TextBuffer, lineSpan.Start); _length = lineSpan.Length; _transform = new TranslateTransform(this.HorizontalOffset, this.VerticalOffset); base.Transform = _transform; if (virtualCharacters != null) { this.CreateVirtualCharacterLookup(virtualCharacters); } this.ComputeLineProperties(); this.RenderText(); }
/// <summary> /// </summary> public LineWidth(TextPoint start, Double width) { _start = start; _width = width; }
/// <summary> /// Initializes a new instance of the <see cref="SpaceNegotiation"/> class. /// </summary> /// <exception cref="ArgumentNullException"> /// <paramref name="textPosition"/> is <see langword="null"/>. /// </exception> public SpaceNegotiation(TextPoint textPosition, Size size) { if (textPosition == null) { throw new ArgumentNullException("textPosition"); } _textPosition = textPosition; _size = size; }
/// <summary> /// </summary> public ICaretPosition MoveTo(Int32 characterIndex, CaretPlacement caretPlacement) { if (_overwriteMode) { caretPlacement = CaretPlacement.LeftOfCharacter; } ICaretPosition oldPosition = this.Position; Span textElementSpan = _editorView.GetTextElementSpan(characterIndex); if (textElementSpan == null) { return oldPosition; } _caretPlacement = caretPlacement; if ((_caretPlacement == CaretPlacement.RightOfCharacter) && (characterIndex < _editorView.TextBuffer.Length)) { _insertionPoint = new TextPoint(_editorView.TextBuffer, textElementSpan.End); } else { _insertionPoint = new TextPoint(_editorView.TextBuffer, textElementSpan.Start); } ICaretPosition position = this.Position; this.PositionChanged(this, new CaretPositionChangedEventArgs(oldPosition, position)); return position; }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para><paramref name="p1"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="p2"/> is <see langword="null"/>.</para> /// </exception> public static Int32 Compare(TextPoint p1, TextPoint p2) { if (p1 == null) { throw new ArgumentNullException("p1"); } if (p2 == null) { throw new ArgumentNullException("p2"); } return (p1.Position - p2.Position); }