Browse Source

Added mouse-select to TextBox.

pull/10/head
Steven Kirk 12 years ago
parent
commit
9fa861e34b
  1. 33
      Perspex.Controls/TextBox.cs

33
Perspex.Controls/TextBox.cs

@ -49,7 +49,6 @@ namespace Perspex.Controls
this.GotFocus += (s, e) => this.textBoxView.GotFocus();
this.LostFocus += (s, e) => this.textBoxView.LostFocus();
this.KeyDown += this.OnKeyDown;
this.PointerPressed += this.OnPointerPressed;
}
public bool AcceptsReturn
@ -94,6 +93,31 @@ namespace Perspex.Controls
set { this.SetValue(TextWrappingProperty, value); }
}
protected override void OnPointerPressed(PointerEventArgs e)
{
var point = e.GetPosition(this.textBoxView);
this.CaretIndex = this.SelectionStart = this.SelectionEnd =
this.textBoxView.GetCaretIndex(point);
e.Device.Capture(this);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
if (e.Device.Captured == this)
{
var point = e.GetPosition(this.textBoxView);
this.CaretIndex = this.SelectionEnd = this.textBoxView.GetCaretIndex(point);
}
}
protected override void OnPointerReleased(PointerEventArgs e)
{
if (e.Device.Captured == this)
{
e.Device.Capture(null);
}
}
protected override void OnTemplateApplied()
{
Decorator textContainer = this.GetVisualDescendents()
@ -398,12 +422,5 @@ namespace Perspex.Controls
return pos - caretIndex;
}
private void OnPointerPressed(object sender, PointerEventArgs e)
{
var point = e.GetPosition(this.textBoxView);
this.CaretIndex = this.SelectionStart = this.SelectionEnd =
this.textBoxView.GetCaretIndex(point);
}
}
}

Loading…
Cancel
Save