Both,
}
+ enum TextPointSearchRange
+ {
+ TextAreaOnly,
+ Full
+ }
+
/// <summary>
/// キャレットとドキュメントの表示を担当します。レイアウト関連もこちらで行います
/// </summary>
return false;
}
+ public bool IsUpperTextArea(double x, double y)
+ {
+ if (x >= this.render.TextArea.X && x <= this.render.TextArea.Right && y < this.render.TextArea.Y)
+ return true;
+ else
+ return false;
+ }
+
+ public bool IsUnderTextArea(double x,double y)
+ {
+ if (x >= this.render.TextArea.X && x <= this.render.TextArea.Right && y > this.render.TextArea.Bottom)
+ return true;
+ else
+ return false;
+ }
+
/// <summary>
/// ヒットテストを行う
/// </summary>
/// 指定した座標の一番近くにあるTextPointを取得する
/// </summary>
/// <param name="p">テキストエリアを左上とする相対位置</param>
+ /// <param name="searchRange">探索範囲</param>
/// <returns>レイアウトラインを指し示すTextPoint</returns>
- public TextPoint GetTextPointFromPostion(Point p)
+ public TextPoint GetTextPointFromPostion(Point p,TextPointSearchRange searchRange = TextPointSearchRange.TextAreaOnly)
{
- if (p.Y < this.render.TextArea.TopLeft.Y ||
- p.Y > this.render.TextArea.BottomRight.Y)
- return TextPoint.Null;
+ if(searchRange == TextPointSearchRange.TextAreaOnly)
+ {
+ if (p.Y < this.render.TextArea.TopLeft.Y ||
+ p.Y > this.render.TextArea.BottomRight.Y)
+ return TextPoint.Null;
+ }
+
TextPoint tp = new TextPoint();
if (this.LayoutLines.Count == 0)
p.Y -= this.render.TextArea.Y;
int lineHeadIndex, lineLength;
- double y = 0;
- tp.row = this.LayoutLines.Count - 1;
- for (int i = this.Src.Row; i < this.LayoutLines.Count; i++)
+
+ if(p.Y >= this.render.TextArea.TopLeft.Y)
{
- double height = this.LayoutLines.GetLayout(i).Height;
+ double y = 0;
+ tp.row = this.LayoutLines.Count - 1;
+ for (int i = this.Src.Row; i < this.LayoutLines.Count; i++)
+ {
+ double height = this.LayoutLines.GetLayout(i).Height;
- lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
- lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
+ lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
+ lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
- if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
- continue;
+ if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
+ continue;
- if (y + height > p.Y)
+ if (y + height > p.Y)
+ {
+ tp.row = i;
+ break;
+ }
+ y += height;
+ }
+ }else
+ {
+ double y = this.render.TextArea.TopLeft.Y;
+ tp.row = 0;
+ for (int i = this.Src.Row; i >= 0; i--)
{
- tp.row = i;
- break;
+ double height = this.LayoutLines.GetLayout(i).Height;
+
+ lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
+ lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
+
+ if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
+ continue;
+
+ if (y - height < p.Y)
+ {
+ tp.row = i;
+ break;
+ }
+ y -= height;
}
- y += height;
}
- if (p.X < this.render.TextArea.X)
- return tp;
+ if (searchRange == TextPointSearchRange.TextAreaOnly)
+ {
+ if (p.X < this.render.TextArea.X)
+ return tp;
+ }
tp.col = GetIndexFromColPostion(tp.row, p.X);
//sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
}
- void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
+ void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
{
if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
{
void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
{
Point p = e.Position;
+ TextPointSearchRange searchRange;
if (this.View.HitTextArea(p.X, p.Y))
- {
- TextPoint tp = this.View.GetTextPointFromPostion(p);
- this._Controller.MoveCaretAndSelect(tp);
- if (this.peer != null)
- this.peer.OnNotifyCaretChanged();
- this.Refresh();
- }
+ searchRange = TextPointSearchRange.TextAreaOnly;
+ else if (this._Controller.SelectionLength > 0)
+ searchRange = TextPointSearchRange.Full;
+ else
+ return;
+ TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
+ this._Controller.MoveCaretAndSelect(tp);
+ if (this.peer != null)
+ this.peer.OnNotifyCaretChanged();
+ this.Refresh();
}
bool IsModiferKeyPressed(VirtualKey key)