Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
		internal CaretPosition(Int32 characterIndex, Int32 textInsertionIndex, CaretPlacement caretPlacement)
		{
			if (characterIndex < 0)
			{
				throw new ArgumentOutOfRangeException("characterIndex");
			}
			if (textInsertionIndex < 0)
			{
				throw new ArgumentOutOfRangeException("textInsertionIndex");
			}
			_characterIndex = characterIndex;
			_textInsertionIndex = textInsertionIndex;
			_placement = caretPlacement;
		}
Esempio n. 3
0
 internal CaretPosition(Int32 characterIndex, Int32 textInsertionIndex, CaretPlacement caretPlacement)
 {
     if (characterIndex < 0)
     {
         throw new ArgumentOutOfRangeException("characterIndex");
     }
     if (textInsertionIndex < 0)
     {
         throw new ArgumentOutOfRangeException("textInsertionIndex");
     }
     _characterIndex     = characterIndex;
     _textInsertionIndex = textInsertionIndex;
     _placement          = caretPlacement;
 }
Esempio n. 4
0
        /// <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;
        }
Esempio n. 5
0
		/// <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;
		}
Esempio n. 6
0
        private ICaretPosition CreateCaretPosition(Int32 characterIndex, CaretPlacement caretPlacement)
        {
            Span textElementSpan = _editorView.GetTextElementSpan(characterIndex);

            return(new CaretPosition(textElementSpan.Start, (caretPlacement == CaretPlacement.LeftOfCharacter) ? textElementSpan.Start : textElementSpan.End, (textElementSpan.Length == 0) ? CaretPlacement.LeftOfCharacter : caretPlacement));
        }
Esempio n. 7
0
		/// <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;
		}
Esempio n. 8
0
		private ICaretPosition CreateCaretPosition(Int32 characterIndex, CaretPlacement caretPlacement)
		{
			Span textElementSpan = _editorView.GetTextElementSpan(characterIndex);
			return new CaretPosition(textElementSpan.Start, (caretPlacement == CaretPlacement.LeftOfCharacter) ? textElementSpan.Start : textElementSpan.End, (textElementSpan.Length == 0) ? CaretPlacement.LeftOfCharacter : caretPlacement);
		}