Both,
}
+ enum TextPointSearchRange
+ {
+ TextAreaOnly,
+ Full
+ }
+
/// <summary>
/// キャレットとドキュメントの表示を担当します。レイアウト関連もこちらで行います
/// </summary>
{
internal const float LineMarkerThickness = 2;
long tickCount;
- bool _CaretBlink, _HideRuler = true;
+ bool _CaretBlink;
internal const int LineNumberLength = 6;
const int UpdateAreaPaddingWidth = 2;
const int UpdateAreaWidth = 4;
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>
this.DrawLineMarker(this.Document.CaretPostion.row);
Point pos = this.render.TextArea.TopLeft;
- //画面上では(X,Y)が開始位置になるが、開始する行が決まっているのでオフセットを求める
- pos.Y -= this.Src.GetOffsetY(this.render.emSize.Height);
+ //画面上では行をずらして表示する
+ pos.Y += this.Src.OffsetY;
double endposy = this.render.TextArea.Bottom;
Size lineNumberSize = new Size(this.render.LineNemberWidth, this.render.TextArea.Height);
if (foldingData != null)
{
- if ((!this.LayoutLines.FoldingCollection.IsHasParent(foldingData) ||
- !this.LayoutLines.FoldingCollection.IsParentHidden(foldingData))
- && foldingData.IsFirstLine(this.LayoutLines, i))
- render.DrawFoldingMark(foldingData.Expand, this.PageBound.X + this.GetRealtiveX(AreaType.FoldingArea), pos.Y);
if (this.LayoutLines.FoldingCollection.IsHidden(lineIndex))
continue;
+ if (foldingData.IsFirstLine(this.LayoutLines, i) && foldingData.End >= lineIndex + lineLength)
+ render.DrawFoldingMark(foldingData.Expand, this.PageBound.X + this.GetRealtiveX(AreaType.FoldingArea), pos.Y);
}
if (this.Document.DrawLineNumber)
DrawUpdateArea(i, pos.Y);
- pos.Y += this.LayoutLines.GetLayout(i).Height;
+ pos.Y += layout.Height;
//pos.Y += this.render.emSize.Height;
}
//リセットしないと行が正しく描けない
pos = this.render.TextArea.TopLeft;
pos.X -= this.Src.X;
- pos.Y -= this.Src.GetOffsetY(this.render.emSize.Height);
+ pos.Y += this.Src.OffsetY;
this.render.BeginClipRect(this.render.TextArea);
if (pos.Y > endposy)
break;
- var selectRange = from s in this.Selections.Get(lineIndex, lineLength)
- let n = Util.ConvertAbsIndexToRelIndex(s, lineIndex, lineLength)
- select n;
+ FoldingItem foldingData = this.LayoutLines.FoldingCollection.Get(lineIndex, lineLength);
+
+ if (foldingData != null)
+ {
+ if (this.LayoutLines.FoldingCollection.IsHidden(lineIndex))
+ continue;
+ }
- this.render.DrawOneLine(this.LayoutLines, i, pos.X, pos.Y, selectRange);
+ this.render.DrawOneLine(this.Document, this.LayoutLines, i, pos.X, pos.Y);
- pos.Y += this.LayoutLines.GetLayout(i).Height;
- //pos.Y += this.render.emSize.Height;
+ pos.Y += layout.Height;
}
this.render.EndClipRect();
{
TextPoint tp = this.GetLayoutLineFromIndex(sel.start);
Point left = this.GetPostionFromTextPoint(tp);
- double lineHeight = this.LayoutLines.GetLayout(tp.row).Height;
+ double lineHeight = render.emSize.Height;
Rectangle InsertRect = new Rectangle(left.X,
left.Y,
CaretWidthOnInsertMode,
IEditorRender render = (IEditorRender)base.render;
int row = this.Document.CaretPostion.row;
- double lineHeight = this.LayoutLines.GetLayout(row).Height;
- double charWidth = this.LayoutLines.GetLayout(row).GetWidthFromIndex(this.Document.CaretPostion.col);
+ ITextLayout layout = this.LayoutLines.GetLayout(row);
+ double lineHeight = render.emSize.Height;
+ double charWidth = layout.GetWidthFromIndex(this.Document.CaretPostion.col);
if (this.InsertMode || charWidth == 0)
{
return;
IEditorRender render = (IEditorRender)base.render;
Point p = this.CaretLocation;
- double height = this.LayoutLines.GetLayout(this.Document.CaretPostion.row).Height;
+ double height = this.LayoutLines.GetLineHeight(this.Document.CaretPostion);
double width = this.render.TextArea.Width;
render.FillRectangle(new Rectangle(this.PageBound.X + this.render.TextArea.X, this.CaretLocation.Y, width, height), FillRectType.LineMarker);
}
double width = layout.GetWidthFromIndex(this.Document.CaretPostion.col);
if (width == 0.0)
width = this.CaretWidthOnInsertMode;
- double height = layout.Height;
+ double height = this.LayoutLines.GetLineHeight(this.Document.CaretPostion);
Rectangle updateRect = new Rectangle(
this.CaretLocation.X,
this.CaretLocation.Y,
/// <summary>
/// 指定した座標の一番近くにあるTextPointを取得する
/// </summary>
- /// <param name="p">テキストエリアを左上とする相対位置</param>
+ /// <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)
return tp;
+ //表示領域から探索を始めるのでパディングの分だけ引く
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++)
+ //p.Y に最も近い行を調べる
+ var t = this.GetNearstRowAndOffsetY(this.Src.Row, p.Y);
+ double relX = 0, relY;
+ if (t == null)
{
- 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)
+ if(p.Y > 0)
{
- tp.row = i;
- break;
+ tp.row = this.LayoutLines.Count - 1;
+ relY = this.LayoutLines.GetLayout(tp.row).Height - this.render.emSize.Height;
+ }
+ else if(p.Y == 0)
+ {
+ tp.row = this.Src.Row;
+ relY = 0;
+ }
+ else
+ {
+ tp.row = 0;
+ relY = 0;
}
- y += height;
+ }
+ else
+ {
+ tp.row = t.Item1;
+ relY = t.Item2; //相対位置がマイナスなので反転させる
}
- 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);
+ relX = p.X - this.render.TextArea.X;
+ tp.col = this.LayoutLines.GetLayout(tp.row).GetIndexFromPostion(relX,relY);
- lineLength = this.LayoutLines.GetLengthFromLineNumber(tp.row);
+ int lineLength = this.LayoutLines.GetLengthFromLineNumber(tp.row);
if (tp.col > lineLength)
tp.col = lineLength;
}
/// <summary>
- /// 桁方向の座標に対応するインデックスを取得する
- /// </summary>
- /// <param name="row">対象となる行</param>
- /// <param name="x">テキストエリアからの相対位置</param>
- /// <returns></returns>
- public int GetIndexFromColPostion(int row, double x)
- {
- x -= this.render.TextArea.X;
- int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
- if (lineLength == 0)
- return 0;
- int index = this.LayoutLines.GetLayout(row).GetIndexFromColPostion(this.Src.X + x);
- return index;
- }
-
- /// <summary>
- /// インデックスに対応する桁方向の座標を得る
- /// </summary>
- /// <param name="row">対象となる行</param>
- /// <param name="index">インデックス</param>
- /// <returns>テキストエリアからの相対位置を返す</returns>
- public double GetColPostionFromIndex(int row, int index)
- {
- double x = this.LayoutLines.GetLayout(row).GetColPostionFromIndex(index);
- return x - Src.X + this.render.TextArea.X;
- }
-
- /// <summary>
/// TextPointに対応する座標を得る
/// </summary>
/// <param name="tp">レイアウトライン上の位置</param>
continue;
p.Y += this.LayoutLines.GetLayout(i).Height;
}
- p.X = this.GetColPostionFromIndex(tp.row, tp.col);
- p.Y += this.render.TextArea.Y;
+ Point relP = this.LayoutLines.GetLayout(tp.row).GetPostionFromIndex(tp.col);
+ p.X += relP.X - Src.X + this.render.TextArea.X;
+ p.Y += this.render.TextArea.Y + relP.Y;
return p;
}
public Rectangle GetRectFromTextPoint(TextPoint tp, int width, int height)
{
+ if (tp.row < this.Src.Row)
+ return Rectangle.Empty;
+ //画面外にある時は計算する必要がそもそもない
+ if (tp.row - this.Src.Row > this.LineCountOnScreen)
+ return Rectangle.Empty;
double radius = width / 2;
Point point = this.GetPostionFromTextPoint(tp);
- double lineHeight = this.LayoutLines.GetLayout(tp.row).Height;
- double srcOffsetY = this.Src.GetOffsetY(this.render.emSize.Height); //画面上ではずれているので引く必要がある
+ double lineHeight = this.render.emSize.Height;
+ double srcOffsetY = this.Src.OffsetY; //画面上ではずれているので引く必要がある
+
+ Rectangle rect = new Rectangle(point.X - radius, point.Y + lineHeight - srcOffsetY, width, height);
- return new Rectangle(point.X - radius, point.Y + lineHeight - srcOffsetY, width, height);
+ if (rect.BottomLeft.Y >= this.render.TextArea.BottomLeft.Y ||
+ rect.BottomRight.X < this.render.TextArea.BottomLeft.X ||
+ rect.BottomLeft.X > this.render.TextArea.BottomRight.X)
+ return Rectangle.Empty;
+ return rect;
}
/// <summary>
}
}
- this.Document.CaretPostion = new TextPoint(row, col);
+ //イベント呼び出しの再入防止のため
+ this.Document.SetCaretPostionWithoutEvent(new TextPoint(row, col));
}
/// <summary>
public bool AdjustSrc(int index)
{
TextPoint startTextPoint = this.GetLayoutLineFromIndex(index);
- double x = this.LayoutLines.GetLayout(startTextPoint.row).GetColPostionFromIndex(startTextPoint.col);
- if (x < this.Src.X ||
- x > this.Src.X + this.PageBound.Width)
+ Point relP = this.LayoutLines.GetLayout(startTextPoint.row).GetPostionFromIndex(startTextPoint.col);
+ if (relP.X < this.Src.X ||
+ relP.X > this.Src.X + this.PageBound.Width)
{
- this.TryScroll(x, this.Src.Row);
+ this.TryScroll(relP.X, this.Src.Row);
return true;
}
if (startTextPoint.row < this.Src.Row ||
startTextPoint.row > this.Src.Row + this.LineCountOnScreenWithInVisible)
{
- this.TryScroll(this.Src.X, startTextPoint.row);
+ this.TryScroll(this.Src.X, startTextPoint.row, relP.Y);
return true;
}
return false;
TextPoint tp = this.Document.CaretPostion;
double x = this.CaretLocation.X;
double y = this.CaretLocation.Y;
+ Point relPoint = this.LayoutLines.GetLayout(tp.row).GetPostionFromIndex(tp.col);
if (flow == AdjustFlow.Col || flow == AdjustFlow.Both)
{
- x = this.LayoutLines.GetLayout(tp.row).GetColPostionFromIndex(tp.col);
+ x = relPoint.X;
double left = this.Src.X;
double right = this.Src.X + this.render.TextArea.Width;
}
else if (x > right) //xは表示領域の右側にある
{
- this.Document.Src = new SrcPoint(x - this.render.TextArea.Width + this.ScrollMarginWidth,this.Document.Src.Row,this.Document.Src.Y);
+ this.Document.Src = new SrcPoint(x - this.render.TextArea.Width + this.ScrollMarginWidth,this.Document.Src.Row,this.Document.Src.OffsetY);
if (this.Document.RightToLeft && this.Document.Src.X > 0)
{
System.Diagnostics.Debug.Assert(x > 0);
- this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Document.Src.Y);
+ this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Document.Src.OffsetY);
}
else
{
}
else if (x < left) //xは表示領域の左側にある
{
- this.Document.Src = new SrcPoint(x - this.ScrollMarginWidth, this.Document.Src.Row, this.Document.Src.Y);
+ this.Document.Src = new SrcPoint(x - this.ScrollMarginWidth, this.Document.Src.Row, this.Document.Src.OffsetY);
if (!this.Document.RightToLeft && this.Document.Src.X < this.render.TextArea.X)
{
- this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Document.Src.Y);
+ this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Document.Src.OffsetY);
}
else
{
if (flow == AdjustFlow.Row || flow == AdjustFlow.Both)
{
- int caretRow = 0;
- int lineCount = this.LineCountOnScreenWithInVisible;
- if (tp.row >= this.Src.Row && tp.row < this.Src.Row + lineCount)
+ int PhyLineCountOnScreen = (int)(this.render.TextArea.Height / this.render.emSize.Height);
+ //計算量を減らすため
+ if (tp.row < this.Src.Row || this.Src.Row + PhyLineCountOnScreen * 2 < tp.row)
+ this.Document.Src = new SrcPoint(this.Src.X, tp.row, -relPoint.Y);
+
+ //キャレットのY座標を求める
+ double lineHeight = this.render.emSize.Height;
+ double caret_y = this.Src.OffsetY; //src.rowからキャレット位置
+ double alignedHeight = PhyLineCountOnScreen * lineHeight - lineHeight;
+ for (int i = this.Src.Row; i < tp.row; i++)
{
- caretRow = tp.row - this.Src.Row;
- y = -this.Src.GetOffsetY(this.render.emSize.Height); //画面上ではずれているので引く必要がある
+ int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
+ int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
+
+ if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
+ continue;
+ caret_y += this.LayoutLines.GetLayout(i).Height;
}
- else if (tp.row >= this.Src.Row + lineCount)
+ caret_y += relPoint.Y;
+
+ if (caret_y < 0)
{
- int srcRow = this.GetSrcRow(tp.row, this.LineCountOnScreen);
- this.Document.Src = new SrcPoint(this.Document.Src.X, srcRow, srcRow * this.render.emSize.Height);
- caretRow = tp.row - this.Document.Src.Row;
+ this.Document.Src = new SrcPoint(this.Src.X, tp.row, -relPoint.Y);
y = 0;
- result = true;
- CalculateLineCountOnScreen();
}
- else if (tp.row < this.Src.Row)
+ else if (caret_y >= 0 && caret_y < alignedHeight)
{
- this.Document.Src = new SrcPoint(this.Document.Src.X, tp.row, tp.row * this.render.emSize.Height);
- y = 0;
- result = true;
- CalculateLineCountOnScreen();
+ y = caret_y;
}
-
- if (caretRow > 0)
+ else if(caret_y >= alignedHeight)
{
- for (int i = 0; i < caretRow; i++)
- {
- int currentRow = this.Src.Row + i;
- int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(currentRow);
- int lineLength = this.LayoutLines.GetLengthFromLineNumber(currentRow);
-
- if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
- continue;
-
- y += this.LayoutLines.GetLayout(currentRow).Height;
- }
+ var newsrc = this.GetNearstRowAndOffsetY(tp.row, -(alignedHeight - relPoint.Y));
+ if(newsrc == null)
+ this.Document.Src = new SrcPoint(this.Src.X, tp.row, 0);
+ else
+ this.Document.Src = new SrcPoint(this.Src.X, newsrc.Item1, -newsrc.Item2);
+ y = alignedHeight;
}
y += this.render.TextArea.Y;
+ result = true;
}
this.SetCaretPostion(x, y);
return result;
}
- int GetSrcRow(int row,int count)
- {
- if (this.LayoutLines.FoldingStrategy == null)
- return row - count;
- for (int i = row; i >= 0; i--)
- {
- int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
- int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
- if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
- continue;
- if (count <= 0)
- return i;
- count--;
- }
- return 0;
- }
-
/// <summary>
/// レイアウト行をテキストポイントからインデックスに変換する
/// </summary>
}
/// <summary>
- /// 指定した座標までスクロールする
- /// </summary>
- /// <param name="x"></param>
- /// <param name="row"></param>
- /// <remarks>
- /// 範囲外の座標を指定した場合、範囲内に収まるように調整されます
- /// </remarks>
- public void Scroll(double x, double y)
- {
- if (x < 0)
- x = 0;
- if (y < 0)
- y = 0;
- double totalHeight = this.LayoutLines.Count * this.render.emSize.Height;
- if (y > totalHeight)
- y = totalHeight - this.render.TextArea.Height;
- base.TryScroll(x, y);
- }
-
- /// <summary>
/// 指定行までスクロールする
/// </summary>
/// <param name="row">行</param>