2 * Copyright (C) 2013 FooProject
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
13 using System.Collections.Generic;
15 namespace FooEditEngine
25 /// キャレットとドキュメントの表示を担当します。レイアウト関連もこちらで行います
27 sealed class EditView : ViewBase
30 internal const float LineMarkerThickness = 2;
32 bool _CaretBlink, _HideRuler = true;
33 internal const int LineNumberLength = 6;
34 const int UpdateAreaPaddingWidth = 2;
35 const int UpdateAreaWidth = 4;
36 const int UpdateAreaTotalWidth = UpdateAreaWidth + UpdateAreaPaddingWidth;
41 public EditView(Document doc, IEditorRender r, int MarginLeftAndRight = 5)
42 : this(doc, r, new Padding(MarginLeftAndRight, 0, MarginLeftAndRight, 0))
49 /// <param name="doc">ドキュメント</param>
50 /// <param name="r">レンダー</param>
51 /// <param name="margin">マージン(1番目:左、2番目:上、3番目:右、4番目:下)</param>
52 public EditView(Document doc, IEditorRender r, Padding margin)
53 : base(doc, r, margin)
55 this.CaretBlinkTime = 500;
56 this.CaretWidthOnInsertMode = 1;
57 this.CalculateClipRect();
58 this.CaretLocation = new Point(this.render.TextArea.X, this.render.TextArea.Y);
59 this.LayoutLines.FoldingCollection.StatusChanged += FoldingCollection_StatusChanged;
60 this.IsFocused = false;
66 internal SelectCollection Selections
68 get { return this.Document.Selections; }
69 set { this.Document.Selections = value; }
73 /// ラインマーカーを描くなら偽。そうでなければ真
75 public bool HideLineMarker
77 get { return this.Document.HideLineMarker; }
78 set { this.Document.HideLineMarker = value; }
82 /// キャレットを描くなら偽。そうでなければ真
86 get { return this.Document.HideCaret; }
87 set { this.Document.HideCaret = value; }
91 /// 挿入モードなら真を返し、上書きモードなら偽を返す
93 public bool InsertMode
95 get { return this.Document.InsertMode; }
96 set { this.Document.InsertMode = value; }
102 public int CaretBlinkTime
111 public double CaretWidthOnInsertMode
118 /// フォーカスがあるなら真をセットする
120 public bool IsFocused
127 /// キャレットを点滅させるなら真。そうでないなら偽
129 /// <remarks>キャレット点滅タイマーもリセットされます</remarks>
130 public bool CaretBlink
132 get { return this._CaretBlink; }
135 this._CaretBlink = value;
137 this.tickCount = DateTime.Now.Ticks + this.To100nsTime(this.CaretBlinkTime);
142 /// 一ページの高さに収まる行数を返す(こちらは表示されていない行も含みます)
144 public int LineCountOnScreenWithInVisible
153 public double ScrollMarginWidth
155 get { return this.PageBound.Width * 20 / 100; }
161 public Point CaretLocation
170 /// <param name="x">x座標</param>
171 /// <param name="y">y座標</param>
172 /// <returns>テキストエリア内にあれば真。そうでなければ偽</returns>
173 public bool HitTextArea(double x, double y)
175 if (x >= this.render.TextArea.X && x <= this.render.TextArea.Right &&
176 y >= this.render.TextArea.Y && y <= this.render.TextArea.Bottom)
185 /// <param name="x">x座標</param>
186 /// <param name="row">行</param>
187 /// <returns>ヒットした場合はFoldingDataオブジェクトが返され、そうでない場合はnullが返る</returns>
188 public FoldingItem HitFoldingData(double x, int row)
190 IEditorRender render = (IEditorRender)base.render;
192 if (x >= this.GetRealtiveX(AreaType.FoldingArea) && x <= this.GetRealtiveX(AreaType.FoldingArea) + render.FoldingWidth)
194 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(row);
195 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
196 FoldingItem foldingData = this.LayoutLines.FoldingCollection.Get(lineHeadIndex, lineLength);
197 if (foldingData != null && foldingData.IsFirstLine(this.LayoutLines,row))
204 /// Rectで指定された範囲にドキュメントを描く
206 /// <param name="updateRect">描写する範囲</param>
207 /// <returns>キャッシュしてはならない場合は真を返し、そうでない場合は偽を返します</returns>
208 /// <remarks>描写する範囲がPageBoundより小さい場合、キャッシュされた内容を使用することがあります。なお、レタリング後にrender.CacheContent()を呼び出さなかった場合は更新範囲にかかわらずキャッシュを使用しません</remarks>
209 public override bool Draw(Rectangle updateRect)
211 if (this.LayoutLines.Count == 0)
214 IEditorRender render = (IEditorRender)base.render;
216 if ((updateRect.Height < this.PageBound.Height ||
217 updateRect.Width < this.PageBound.Width) &&
218 render.IsVaildCache())
220 render.DrawCachedBitmap(updateRect);
224 Rectangle background = this.PageBound;
225 render.FillBackground(background);
227 if (this.Document.HideRuler == false)
230 this.DrawLineMarker(this.Document.CaretPostion.row);
232 Point pos = this.render.TextArea.TopLeft;
233 //画面上では(X,Y)が開始位置になるが、開始する行が決まっているのでオフセットを求める
234 pos.Y -= this.Src.GetOffsetY(this.render.emSize.Height);
236 double endposy = this.render.TextArea.Bottom;
237 Size lineNumberSize = new Size(this.render.LineNemberWidth, this.render.TextArea.Height);
239 this.render.BeginClipRect(new Rectangle(this.PageBound.X, this.render.TextArea.Y, this.PageBound.Width, this.render.TextArea.Height));
241 //パフォーマンス向上のため行番号などを先に描く
242 for (int i = this.Src.Row; i < this.LayoutLines.Count; i++)
244 int lineIndex = this.LayoutLines.GetIndexFromLineNumber(i);
245 int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
246 ITextLayout layout = this.LayoutLines.GetLayout(i);
251 FoldingItem foldingData = this.LayoutLines.FoldingCollection.Get(lineIndex, lineLength);
253 if (foldingData != null)
255 if ((!this.LayoutLines.FoldingCollection.IsHasParent(foldingData) ||
256 !this.LayoutLines.FoldingCollection.IsParentHidden(foldingData))
257 && foldingData.IsFirstLine(this.LayoutLines, i))
258 render.DrawFoldingMark(foldingData.Expand, this.PageBound.X + this.GetRealtiveX(AreaType.FoldingArea), pos.Y);
259 if (this.LayoutLines.FoldingCollection.IsHidden(lineIndex))
263 if (this.Document.DrawLineNumber)
265 this.render.DrawString((i + 1).ToString(), this.PageBound.X + this.GetRealtiveX(AreaType.LineNumberArea), pos.Y, StringAlignment.Right, lineNumberSize,StringColorType.LineNumber);
268 DrawUpdateArea(i, pos.Y);
270 pos.Y += this.LayoutLines.GetLayout(i).Height;
273 this.render.EndClipRect();
276 pos = this.render.TextArea.TopLeft;
278 pos.Y -= this.Src.GetOffsetY(this.render.emSize.Height);
280 this.render.BeginClipRect(this.render.TextArea);
282 for (int i = this.Src.Row; i < this.LayoutLines.Count; i++)
284 int lineIndex = this.LayoutLines.GetIndexFromLineNumber(i);
285 int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
286 ITextLayout layout = this.LayoutLines.GetLayout(i);
291 var selectRange = from s in this.Selections.Get(lineIndex, lineLength)
292 let n = Util.ConvertAbsIndexToRelIndex(s, lineIndex, lineLength)
295 this.render.DrawOneLine(this.LayoutLines, i, pos.X, pos.Y, selectRange);
297 pos.Y += this.LayoutLines.GetLayout(i).Height;
300 this.render.EndClipRect();
302 this.DrawInsertPoint();
304 this.Document.SelectGrippers.BottomLeft.Draw(this.render);
305 this.Document.SelectGrippers.BottomRight.Draw(this.render);
307 return this.DrawCaret(); //キャレットを描いた場合はキャッシュしてはならない
310 void DrawUpdateArea(int row,double ypos)
312 IEditorRender render = (IEditorRender)base.render;
313 if(this.LayoutLines.GetDirtyFlag(row))
315 Point pos = new Point(this.PageBound.X + this.GetRealtiveX(AreaType.UpdateArea), ypos);
316 Rectangle rect = new Rectangle(pos.X, pos.Y, UpdateAreaWidth, this.LayoutLines.GetLayout(row).Height);
317 render.FillRectangle(rect, FillRectType.UpdateArea);
323 IEditorRender render = (IEditorRender)base.render;
326 Size emSize = render.emSize;
327 Rectangle clipRect = this.render.TextArea;
329 double markerHeight = emSize.Height / 2;
330 if (this.Document.RightToLeft)
332 pos = new Point(clipRect.TopRight.X, clipRect.TopRight.Y - emSize.Height - LineMarkerThickness);
333 for (; pos.X >= clipRect.TopLeft.X; pos.X -= emSize.Width, count++)
336 to = new Point(pos.X, pos.Y + emSize.Height);
337 int mod = count % 10;
340 string countStr = (count / 10).ToString();
341 double counterWidth = emSize.Width * countStr.Length;
342 this.render.DrawString(countStr, pos.X - counterWidth, pos.Y, StringAlignment.Right, new Size(counterWidth, double.MaxValue));
345 from.Y = from.Y + emSize.Height / 2;
347 from.Y = from.Y + emSize.Height * 3 / 4;
348 render.DrawLine(from, to);
349 if (this.CaretLocation.X >= pos.X && this.CaretLocation.X < pos.X + emSize.Width)
350 render.FillRectangle(new Rectangle(pos.X, pos.Y + markerHeight, emSize.Width, markerHeight), FillRectType.OverwriteCaret);
355 pos = new Point(clipRect.TopLeft.X, clipRect.TopLeft.Y - emSize.Height - LineMarkerThickness);
356 for (; pos.X < clipRect.TopRight.X; pos.X += emSize.Width, count++)
359 to = new Point(pos.X, pos.Y + emSize.Height);
360 int mod = count % 10;
362 this.render.DrawString((count / 10).ToString(), pos.X, pos.Y, StringAlignment.Left, new Size(double.MaxValue, double.MaxValue));
364 from.Y = from.Y + emSize.Height / 2;
366 from.Y = from.Y + emSize.Height * 3 / 4;
367 render.DrawLine(from, to);
368 if (this.CaretLocation.X >= pos.X && this.CaretLocation.X < pos.X + emSize.Width)
369 render.FillRectangle(new Rectangle(pos.X, pos.Y + markerHeight, emSize.Width, markerHeight), FillRectType.OverwriteCaret);
372 from = clipRect.TopLeft;
373 from.Y -= LineMarkerThickness;
374 to = clipRect.TopRight;
375 to.Y -= LineMarkerThickness;
376 render.DrawLine(from, to);
379 void DrawInsertPoint()
381 //一つしかない場合は行選択の可能性がある
382 if (this.Selections.Count <= 1)
384 IEditorRender render = (IEditorRender)base.render;
385 foreach (Selection sel in this.Selections)
389 TextPoint tp = this.GetLayoutLineFromIndex(sel.start);
390 Point left = this.GetPostionFromTextPoint(tp);
391 double lineHeight = this.LayoutLines.GetLayout(tp.row).Height;
392 Rectangle InsertRect = new Rectangle(left.X,
394 CaretWidthOnInsertMode,
396 render.FillRectangle(InsertRect, FillRectType.InsertPoint);
403 if (this.HideCaret || !this.IsFocused)
406 long diff = DateTime.Now.Ticks - this.tickCount;
407 long blinkTime = this.To100nsTime(this.CaretBlinkTime);
409 if (this.CaretBlink && diff % blinkTime >= blinkTime / 2)
412 Rectangle CaretRect = new Rectangle();
414 IEditorRender render = (IEditorRender)base.render;
416 int row = this.Document.CaretPostion.row;
417 double lineHeight = this.LayoutLines.GetLayout(row).Height;
418 double charWidth = this.LayoutLines.GetLayout(row).GetWidthFromIndex(this.Document.CaretPostion.col);
420 if (this.InsertMode || charWidth == 0)
422 CaretRect.Size = new Size(CaretWidthOnInsertMode, lineHeight);
423 CaretRect.Location = new Point(this.CaretLocation.X, this.CaretLocation.Y);
424 render.FillRectangle(CaretRect, FillRectType.InsertCaret);
428 double height = lineHeight / 3;
429 CaretRect.Size = new Size(charWidth, height);
430 CaretRect.Location = new Point(this.CaretLocation.X, this.CaretLocation.Y + lineHeight - height);
431 render.FillRectangle(CaretRect, FillRectType.OverwriteCaret);
436 long To100nsTime(int ms)
441 public void DrawLineMarker(int row)
443 if (this.HideLineMarker || !this.IsFocused)
445 IEditorRender render = (IEditorRender)base.render;
446 Point p = this.CaretLocation;
447 double height = this.LayoutLines.GetLayout(this.Document.CaretPostion.row).Height;
448 double width = this.render.TextArea.Width;
449 render.FillRectangle(new Rectangle(this.PageBound.X + this.render.TextArea.X, this.CaretLocation.Y, width, height), FillRectType.LineMarker);
455 /// <returns>矩形領域を表すRectangle</returns>
456 public Rectangle GetCurrentCaretRect()
458 ITextLayout layout = this.LayoutLines.GetLayout(this.Document.CaretPostion.row);
459 double width = layout.GetWidthFromIndex(this.Document.CaretPostion.col);
461 width = this.CaretWidthOnInsertMode;
462 double height = layout.Height;
463 Rectangle updateRect = new Rectangle(
464 this.CaretLocation.X,
465 this.CaretLocation.Y,
472 /// 指定した座標の一番近くにあるTextPointを取得する
474 /// <param name="p">テキストエリアを左上とする相対位置</param>
475 /// <returns>レイアウトラインを指し示すTextPoint</returns>
476 public TextPoint GetTextPointFromPostion(Point p)
478 if (p.Y < this.render.TextArea.TopLeft.Y ||
479 p.Y > this.render.TextArea.BottomRight.Y)
480 return TextPoint.Null;
481 TextPoint tp = new TextPoint();
483 if (this.LayoutLines.Count == 0)
486 p.Y -= this.render.TextArea.Y;
488 int lineHeadIndex, lineLength;
490 tp.row = this.LayoutLines.Count - 1;
491 for (int i = this.Src.Row; i < this.LayoutLines.Count; i++)
493 double height = this.LayoutLines.GetLayout(i).Height;
495 lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
496 lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
498 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
501 if (y + height > p.Y)
509 if (p.X < this.render.TextArea.X)
512 tp.col = GetIndexFromColPostion(tp.row, p.X);
514 lineLength = this.LayoutLines.GetLengthFromLineNumber(tp.row);
515 if (tp.col > lineLength)
522 /// 桁方向の座標に対応するインデックスを取得する
524 /// <param name="row">対象となる行</param>
525 /// <param name="x">テキストエリアからの相対位置</param>
526 /// <returns></returns>
527 public int GetIndexFromColPostion(int row, double x)
529 x -= this.render.TextArea.X;
530 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
533 int index = this.LayoutLines.GetLayout(row).GetIndexFromColPostion(this.Src.X + x);
538 /// インデックスに対応する桁方向の座標を得る
540 /// <param name="row">対象となる行</param>
541 /// <param name="index">インデックス</param>
542 /// <returns>テキストエリアからの相対位置を返す</returns>
543 public double GetColPostionFromIndex(int row, int index)
545 double x = this.LayoutLines.GetLayout(row).GetColPostionFromIndex(index);
546 return x - Src.X + this.render.TextArea.X;
550 /// TextPointに対応する座標を得る
552 /// <param name="tp">レイアウトライン上の位置</param>
553 /// <returns>テキストエリアを左上とする相対位置</returns>
554 public Point GetPostionFromTextPoint(TextPoint tp)
556 Point p = new Point();
557 for (int i = this.Src.Row; i < tp.row; i++)
559 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
560 int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
561 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
563 p.Y += this.LayoutLines.GetLayout(i).Height;
565 p.X = this.GetColPostionFromIndex(tp.row, tp.col);
566 p.Y += this.render.TextArea.Y;
570 public Gripper HitGripperFromPoint(Point p)
572 if (this.Document.SelectGrippers.BottomLeft.IsHit(p))
573 return this.Document.SelectGrippers.BottomLeft;
574 if (this.Document.SelectGrippers.BottomRight.IsHit(p))
575 return this.Document.SelectGrippers.BottomRight;
579 public Rectangle GetRectFromIndex(int index,int width,int height)
581 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(index);
582 return this.GetRectFromTextPoint(tp, width, height);
585 public Rectangle GetRectFromTextPoint(TextPoint tp, int width, int height)
587 double radius = width / 2;
588 Point point = this.GetPostionFromTextPoint(tp);
589 double lineHeight = this.LayoutLines.GetLayout(tp.row).Height;
590 double srcOffsetY = this.Src.GetOffsetY(this.render.emSize.Height); //画面上ではずれているので引く必要がある
592 return new Rectangle(point.X - radius, point.Y + lineHeight - srcOffsetY, width, height);
596 /// キャレットを指定した位置に移動させる
598 /// <param name="row"></param>
599 /// <param name="col"></param>
600 /// <param name="autoExpand">折り畳みを展開するなら真</param>
601 public void JumpCaret(int row, int col, bool autoExpand = true)
605 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(row);
606 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
607 FoldingItem foldingData = this.LayoutLines.FoldingCollection.Get(lineHeadIndex, lineLength);
608 if(foldingData != null)
610 if (this.LayoutLines.FoldingCollection.IsParentHidden(foldingData) || !foldingData.IsFirstLine(this.LayoutLines, row))
612 this.LayoutLines.FoldingCollection.Expand(foldingData);
617 this.Document.CaretPostion = new TextPoint(row, col);
621 /// index上の文字が表示されるようにSrcを調整する
623 /// <param name="index">インデックス</param>
624 /// <returns>調整されたら真。そうでなければ偽</returns>
625 public bool AdjustSrc(int index)
627 TextPoint startTextPoint = this.GetLayoutLineFromIndex(index);
628 double x = this.LayoutLines.GetLayout(startTextPoint.row).GetColPostionFromIndex(startTextPoint.col);
629 if (x < this.Src.X ||
630 x > this.Src.X + this.PageBound.Width)
632 this.TryScroll(x, this.Src.Row);
635 if (startTextPoint.row < this.Src.Row ||
636 startTextPoint.row > this.Src.Row + this.LineCountOnScreenWithInVisible)
638 this.TryScroll(this.Src.X, startTextPoint.row);
645 /// キャレットがあるところまでスクロールする
647 /// <return>再描写する必要があるなら真を返す</return>
648 /// <remarks>Document.Update(type == UpdateType.Clear)イベント時に呼び出した場合、例外が発生します</remarks>
649 public bool AdjustCaretAndSrc(AdjustFlow flow = AdjustFlow.Both)
651 IEditorRender render = (IEditorRender)base.render;
653 if (this.PageBound.Width == 0 || this.PageBound.Height == 0)
655 this.SetCaretPostion(this.Padding.Left + render.FoldingWidth, 0);
660 TextPoint tp = this.Document.CaretPostion;
661 double x = this.CaretLocation.X;
662 double y = this.CaretLocation.Y;
664 if (flow == AdjustFlow.Col || flow == AdjustFlow.Both)
666 x = this.LayoutLines.GetLayout(tp.row).GetColPostionFromIndex(tp.col);
668 double left = this.Src.X;
669 double right = this.Src.X + this.render.TextArea.Width;
671 if (x >= left && x <= right) //xは表示領域にないにある
675 else if (x > right) //xは表示領域の右側にある
677 this.Document.Src = new SrcPoint(x - this.render.TextArea.Width + this.ScrollMarginWidth,this.Document.Src.Row,this.Document.Src.Y);
678 if (this.Document.RightToLeft && this.Document.Src.X > 0)
680 System.Diagnostics.Debug.Assert(x > 0);
681 this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Document.Src.Y);
685 x = this.render.TextArea.Width - this.ScrollMarginWidth;
689 else if (x < left) //xは表示領域の左側にある
691 this.Document.Src = new SrcPoint(x - this.ScrollMarginWidth, this.Document.Src.Row, this.Document.Src.Y);
692 if (!this.Document.RightToLeft && this.Document.Src.X < this.render.TextArea.X)
694 this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Document.Src.Y);
698 x = this.ScrollMarginWidth;
702 x += this.render.TextArea.X;
705 if (flow == AdjustFlow.Row || flow == AdjustFlow.Both)
708 int lineCount = this.LineCountOnScreenWithInVisible;
709 if (tp.row >= this.Src.Row && tp.row < this.Src.Row + lineCount)
711 caretRow = tp.row - this.Src.Row;
712 y = -this.Src.GetOffsetY(this.render.emSize.Height); //画面上ではずれているので引く必要がある
714 else if (tp.row >= this.Src.Row + lineCount)
716 int srcRow = this.GetSrcRow(tp.row, this.LineCountOnScreen);
717 this.Document.Src = new SrcPoint(this.Document.Src.X, srcRow, srcRow * this.render.emSize.Height);
718 caretRow = tp.row - this.Document.Src.Row;
721 CalculateLineCountOnScreen();
723 else if (tp.row < this.Src.Row)
725 this.Document.Src = new SrcPoint(this.Document.Src.X, tp.row, tp.row * this.render.emSize.Height);
728 CalculateLineCountOnScreen();
733 for (int i = 0; i < caretRow; i++)
735 int currentRow = this.Src.Row + i;
736 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(currentRow);
737 int lineLength = this.LayoutLines.GetLengthFromLineNumber(currentRow);
739 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
742 y += this.LayoutLines.GetLayout(currentRow).Height;
745 y += this.render.TextArea.Y;
748 this.SetCaretPostion(x, y);
752 this.OnSrcChanged(null);
758 int GetSrcRow(int row,int count)
760 if (this.LayoutLines.FoldingStrategy == null)
762 for (int i = row; i >= 0; i--)
764 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
765 int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
766 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
776 /// レイアウト行をテキストポイントからインデックスに変換する
778 /// <param name="tp">テキストポイント表す</param>
779 /// <returns>インデックスを返す</returns>
780 public int GetIndexFromLayoutLine(TextPoint tp)
782 return this.LayoutLines.GetIndexFromTextPoint(tp);
786 /// インデックスからレイアウト行を指し示すテキストポイントに変換する
788 /// <param name="index">インデックスを表す</param>
789 /// <returns>テキストポイント返す</returns>
790 public TextPoint GetLayoutLineFromIndex(int index)
792 return this.LayoutLines.GetTextPointFromIndex(index);
798 /// <param name="x"></param>
799 /// <param name="row"></param>
801 /// 範囲外の座標を指定した場合、範囲内に収まるように調整されます
803 public void Scroll(double x, int row)
809 int endRow = this.LayoutLines.Count - 1 - this.LineCountOnScreen;
814 base.TryScroll(x, row);
820 /// <param name="x"></param>
821 /// <param name="row"></param>
823 /// 範囲外の座標を指定した場合、範囲内に収まるように調整されます
825 public void Scroll(double x, double y)
831 double totalHeight = this.LayoutLines.Count * this.render.emSize.Height;
833 y = totalHeight - this.render.TextArea.Height;
834 base.TryScroll(x, y);
840 /// <param name="row">行</param>
841 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
842 public void ScrollIntoView(int row, bool alignTop)
847 double y = this.render.TextArea.Height;
848 for (int i = row; i >= 0; i--)
850 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
851 int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
852 double height = this.LayoutLines.GetLayout(i).Height;
857 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
863 public int AdjustRow(int row, bool isMoveNext)
865 if (this.LayoutLines.FoldingStrategy == null)
867 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(row);
868 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
869 FoldingItem foldingData = this.LayoutLines.FoldingCollection.GetFarestHiddenFoldingData(lineHeadIndex, lineLength);
870 if (foldingData != null && !foldingData.Expand)
872 if (foldingData.End == this.Document.Length)
874 if (isMoveNext && lineHeadIndex > foldingData.Start)
875 row = this.LayoutLines.GetLineNumberFromIndex(foldingData.End) + 1;
877 row = this.LayoutLines.GetLineNumberFromIndex(foldingData.Start);
878 if(row > this.LayoutLines.Count - 1)
879 row = this.LayoutLines.GetLineNumberFromIndex(foldingData.Start);
884 protected override void CalculateClipRect()
886 IEditorRender render = (IEditorRender)base.render;
887 double x, y, width, height;
889 if (this.Document.DrawLineNumber)
891 if (this.Document.RightToLeft)
892 x = this.Padding.Left;
894 x = this.Padding.Left + UpdateAreaTotalWidth + this.render.LineNemberWidth + this.LineNumberMargin + render.FoldingWidth;
895 width = this.PageBound.Width - this.render.LineNemberWidth - this.LineNumberMargin - this.Padding.Left - this.Padding.Right - render.FoldingWidth - UpdateAreaTotalWidth;
899 if (this.Document.RightToLeft)
900 x = this.Padding.Left;
902 x = this.Padding.Left + UpdateAreaTotalWidth + render.FoldingWidth;
903 width = this.PageBound.Width - this.Padding.Left - this.Padding.Right - render.FoldingWidth - UpdateAreaTotalWidth;
906 y = this.Padding.Top;
907 height = this.PageBound.Height - this.Padding.Top - this.Padding.Bottom;
909 if (this.Document.HideRuler == false)
911 double rulerHeight = this.render.emSize.Height + LineMarkerThickness;
913 height -= rulerHeight;
922 this.render.TextArea = new Rectangle(x, y, width, height);
924 this.LineBreakingMarginWidth = width * 5 / 100;
927 public override void CalculateLineCountOnScreen()
929 if (this.LayoutLines.Count == 0 || this.PageBound.Height == 0)
933 int i = this.Src.Row;
934 int visualCount = this.Src.Row;
937 int row = i < this.LayoutLines.Count ? i : this.LayoutLines.Count - 1;
939 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(row);
940 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
942 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex) && row < this.LayoutLines.Count - 1)
945 ITextLayout layout = this.LayoutLines.GetLayout(row);
947 double width = layout.Width;
949 if (width > this._LongestWidth)
950 this._LongestWidth = width;
952 double lineHeight = layout.Height;
956 if (y >= this.render.TextArea.Height)
960 this.LineCountOnScreen = Math.Max(visualCount - this.Src.Row - 1, 0);
961 this.LineCountOnScreenWithInVisible = Math.Max(i - this.Src.Row - 1, 0);
964 void SetCaretPostion(double x, double y)
966 this.CaretLocation = new Point(x + this.PageBound.X, y + this.PageBound.Y);
969 void FoldingCollection_StatusChanged(object sender, FoldingItemStatusChangedEventArgs e)
971 this.CalculateLineCountOnScreen();
982 double GetRealtiveX(AreaType type)
984 IEditorRender render = (IEditorRender)base.render;
987 case AreaType.UpdateArea:
988 if (this.Document.RightToLeft)
989 return this.PageBound.TopRight.X - UpdateAreaTotalWidth;
990 if (this.Document.DrawLineNumber)
991 return this.render.TextArea.X - this.render.LineNemberWidth - this.LineNumberMargin - render.FoldingWidth - UpdateAreaTotalWidth;
993 return this.render.TextArea.X - render.FoldingWidth - UpdateAreaTotalWidth;
994 case AreaType.FoldingArea:
995 if (this.Document.RightToLeft)
996 return this.PageBound.TopRight.X - render.FoldingWidth;
997 if (this.Document.DrawLineNumber)
998 return this.render.TextArea.X - this.render.LineNemberWidth - this.LineNumberMargin - render.FoldingWidth;
1000 return this.render.TextArea.X - render.FoldingWidth;
1001 case AreaType.LineNumberArea:
1002 if (this.Document.DrawLineNumber == false)
1003 throw new InvalidOperationException();
1004 if (this.Document.RightToLeft)
1005 return this.PageBound.TopRight.X - UpdateAreaTotalWidth - render.FoldingWidth - this.render.LineNemberWidth;
1007 return this.render.TextArea.X - this.render.LineNemberWidth - this.LineNumberMargin;
1008 case AreaType.TextArea:
1009 return this.render.TextArea.X;
1011 throw new ArgumentOutOfRangeException();