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;
31 Point _CaretLocation = new Point();
32 TextPoint _CaretPostion = new TextPoint();
34 bool _CaretBlink,_HideRuler = true;
35 internal const int LineNumberLength = 6;
36 const int UpdateAreaPaddingWidth = 2;
37 const int UpdateAreaWidth = 4;
38 const int UpdateAreaTotalWidth = UpdateAreaWidth + UpdateAreaPaddingWidth;
43 public EditView(Document doc, IEditorRender r,int MarginLeftAndRight = 5)
44 : this(doc,r,new Padding(MarginLeftAndRight, 0, MarginLeftAndRight, 0))
51 /// <param name="doc">ドキュメント</param>
52 /// <param name="r">レンダー</param>
53 /// <param name="margin">マージン(1番目:左、2番目:上、3番目:右、4番目:下)</param>
54 public EditView(Document doc, IEditorRender r, Padding margin)
57 this.CaretBlinkTime = 500;
58 this.CaretWidthOnInsertMode = 1;
59 this.CalculateClipRect();
60 this._CaretLocation.X = this.render.TextArea.X;
61 this._CaretLocation.Y = this.render.TextArea.Y;
62 this.LayoutLines.FoldingCollection.StatusChanged += FoldingCollection_StatusChanged;
63 this.InsertPoint = null;
64 this.HideLineMarker = true;
65 this.IsFocused = false;
66 this.Selections = new SelectCollection();
72 internal SelectCollection Selections
79 /// ラインマーカーを描くなら偽。そうでなければ真
81 public bool HideLineMarker
88 /// キャレットを描くなら偽。そうでなければ真
97 /// 挿入モードなら真を返し、上書きモードなら偽を返す
99 public bool InsertMode
108 public int CaretBlinkTime
117 public double CaretWidthOnInsertMode
124 /// フォーカスがあるなら真をセットする
126 public bool IsFocused
133 /// キャレットを点滅させるなら真。そうでないなら偽
135 /// <remarks>キャレット点滅タイマーもリセットされます</remarks>
136 public bool CaretBlink
138 get { return this._CaretBlink; }
141 this._CaretBlink = value;
143 this.tickCount = DateTime.Now.Ticks + this.To100nsTime(this.CaretBlinkTime);
148 /// 一ページの高さに収まる行数を返す(こちらは表示されていない行も含みます)
150 public int LineCountOnScreenWithInVisible
159 public double ScrollMarginWidth
161 get { return this.PageBound.Width * 20 / 100; }
165 /// ルーラーを表示しないなら真、そうでないなら偽
167 public bool HideRuler
169 get { return this._HideRuler; }
172 this._HideRuler = value;
173 this.LayoutLines.ClearLayoutCache();
175 CalculateLineCountOnScreen();
180 /// 矩形選択モード中に文字列が挿入される位置を表す
182 public SelectCollection InsertPoint
191 public Point CaretLocation
193 get { return this._CaretLocation; }
197 /// レイアウト行のどこにキャレットがあるかを表す
199 public TextPoint CaretPostion
201 get { return this._CaretPostion; }
207 /// <param name="x">x座標</param>
208 /// <param name="y">y座標</param>
209 /// <returns>テキストエリア内にあれば真。そうでなければ偽</returns>
210 public bool HitTextArea(double x, double y)
212 if (x >= this.render.TextArea.X && x <= this.render.TextArea.Right &&
213 y >= this.render.TextArea.Y && y <= this.render.TextArea.Bottom)
222 /// <param name="x">x座標</param>
223 /// <param name="row">行</param>
224 /// <returns>ヒットした場合はFoldingDataオブジェクトが返され、そうでない場合はnullが返る</returns>
225 public FoldingItem HitFoldingData(double x, int row)
227 IEditorRender render = (IEditorRender)base.render;
229 if (x >= this.GetRealtiveX(AreaType.FoldingArea) && x <= this.GetRealtiveX(AreaType.FoldingArea) + render.FoldingWidth)
231 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(row);
232 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
233 FoldingItem foldingData = this.LayoutLines.FoldingCollection.Get(lineHeadIndex, lineLength);
234 if (foldingData != null && foldingData.IsFirstLine(this.LayoutLines,row))
241 /// Rectで指定された範囲にドキュメントを描く
243 /// <param name="updateRect">描写する範囲</param>
244 /// <remarks>キャレットを点滅させる場合、定期的のこのメソッドを呼び出してください</remarks>
245 public override void Draw(Rectangle updateRect)
247 if (this.LayoutLines.Count == 0)
250 IEditorRender render = (IEditorRender)base.render;
252 if ((updateRect.Height < this.PageBound.Height ||
253 updateRect.Width < this.PageBound.Width) &&
254 render.IsVaildCache())
256 render.DrawCachedBitmap(updateRect);
260 Rectangle background = this.PageBound;
261 render.FillBackground(background);
263 if (this.HideRuler == false)
266 this.DrawLineMarker(this.CaretPostion.row);
268 Point pos = this.render.TextArea.TopLeft;
270 double endposy = this.render.TextArea.Bottom;
271 Size lineNumberSize = new Size(this.render.LineNemberWidth,this.render.TextArea.Height);
272 for (int i = this.Src.Row; i < this.LayoutLines.Count; i++)
274 int lineIndex = this.LayoutLines.GetIndexFromLineNumber(i);
275 int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
276 ITextLayout layout = this.LayoutLines.GetLayout(i);
278 if (pos.Y + layout.Height > endposy)
281 FoldingItem foldingData = this.LayoutLines.FoldingCollection.Get(lineIndex, lineLength);
283 if (foldingData != null)
285 if ((!this.LayoutLines.FoldingCollection.IsHasParent(foldingData) ||
286 !this.LayoutLines.FoldingCollection.IsParentHidden(foldingData))
287 && foldingData.IsFirstLine(this.LayoutLines, i))
288 render.DrawFoldingMark(foldingData.Expand, this.PageBound.X + this.GetRealtiveX(AreaType.FoldingArea), pos.Y);
289 if (this.LayoutLines.FoldingCollection.IsHidden(lineIndex))
293 var selectRange = from s in this.Selections.Get(lineIndex, lineLength)
294 let n = Util.ConvertAbsIndexToRelIndex(s, lineIndex, lineLength)
297 this.render.DrawOneLine(this.LayoutLines, i, pos.X, pos.Y, selectRange);
299 if (this.DrawLineNumber)
301 this.render.DrawString((i + 1).ToString(), this.PageBound.X + this.GetRealtiveX(AreaType.LineNumberArea), pos.Y, StringAlignment.Right, lineNumberSize,StringColorType.LineNumber);
304 DrawUpdateArea(i, pos.Y);
306 pos.Y += this.LayoutLines.GetLayout(i).Height;
309 if (this.InsertPoint != null)
310 this.DrawInsertPoint();
312 render.CacheContent();
318 void DrawUpdateArea(int row,double ypos)
320 IEditorRender render = (IEditorRender)base.render;
321 if(this.LayoutLines.GetDirtyFlag(row))
323 Point pos = new Point(this.PageBound.X + this.GetRealtiveX(AreaType.UpdateArea), ypos);
324 Rectangle rect = new Rectangle(pos.X, pos.Y, UpdateAreaWidth, this.LayoutLines.GetLayout(row).Height);
325 render.FillRectangle(rect, FillRectType.UpdateArea);
331 IEditorRender render = (IEditorRender)base.render;
334 Size emSize = render.emSize;
335 Rectangle clipRect = this.render.TextArea;
337 double markerHeight = emSize.Height / 2;
338 if (this.render.RightToLeft)
340 pos = new Point(clipRect.TopRight.X, clipRect.TopRight.Y - emSize.Height - LineMarkerThickness);
341 for (; pos.X >= clipRect.TopLeft.X; pos.X -= emSize.Width, count++)
344 to = new Point(pos.X, pos.Y + emSize.Height);
345 int mod = count % 10;
348 string countStr = (count / 10).ToString();
349 double counterWidth = emSize.Width * countStr.Length;
350 this.render.DrawString(countStr, pos.X - counterWidth, pos.Y, StringAlignment.Right, new Size(counterWidth, double.MaxValue));
353 from.Y = from.Y + emSize.Height / 2;
355 from.Y = from.Y + emSize.Height * 3 / 4;
356 render.DrawLine(from, to);
357 if (this.CaretLocation.X >= pos.X && this.CaretLocation.X < pos.X + emSize.Width)
358 render.FillRectangle(new Rectangle(pos.X, pos.Y + markerHeight, emSize.Width, markerHeight), FillRectType.OverwriteCaret);
363 pos = new Point(clipRect.TopLeft.X, clipRect.TopLeft.Y - emSize.Height - LineMarkerThickness);
364 for (; pos.X < clipRect.TopRight.X; pos.X += emSize.Width, count++)
367 to = new Point(pos.X, pos.Y + emSize.Height);
368 int mod = count % 10;
370 this.render.DrawString((count / 10).ToString(), pos.X, pos.Y, StringAlignment.Left, new Size(double.MaxValue, double.MaxValue));
372 from.Y = from.Y + emSize.Height / 2;
374 from.Y = from.Y + emSize.Height * 3 / 4;
375 render.DrawLine(from, to);
376 if (this.CaretLocation.X >= pos.X && this.CaretLocation.X < pos.X + emSize.Width)
377 render.FillRectangle(new Rectangle(pos.X, pos.Y + markerHeight, emSize.Width, markerHeight), FillRectType.OverwriteCaret);
380 from = clipRect.TopLeft;
381 from.Y -= LineMarkerThickness;
382 to = clipRect.TopRight;
383 to.Y -= LineMarkerThickness;
384 render.DrawLine(from, to);
387 void DrawInsertPoint()
389 IEditorRender render = (IEditorRender)base.render;
390 foreach (Selection sel in this.InsertPoint)
394 TextPoint tp = this.GetLayoutLineFromIndex(sel.start);
395 Point left = this.GetPostionFromTextPoint(tp);
396 double lineHeight = this.LayoutLines.GetLayout(tp.row).Height;
397 Rectangle InsertRect = new Rectangle(left.X,
399 CaretWidthOnInsertMode,
401 render.FillRectangle(InsertRect, FillRectType.InsertPoint);
408 if (this.HideCaret || !this.IsFocused)
411 long diff = DateTime.Now.Ticks - this.tickCount;
412 long blinkTime = this.To100nsTime(this.CaretBlinkTime);
414 if (this._CaretBlink && diff % blinkTime >= blinkTime / 2)
417 Rectangle CaretRect = new Rectangle();
419 IEditorRender render = (IEditorRender)base.render;
421 int row = this.CaretPostion.row;
422 double lineHeight = this.LayoutLines.GetLayout(row).Height;
423 double charWidth = this.LayoutLines.GetLayout(row).GetWidthFromIndex(this.CaretPostion.col);
425 if (this.InsertMode || charWidth == 0)
427 CaretRect.Size = new Size(CaretWidthOnInsertMode, lineHeight);
428 CaretRect.Location = new Point(this.CaretLocation.X, this.CaretLocation.Y);
429 render.FillRectangle(CaretRect, FillRectType.InsertCaret);
433 double height = lineHeight / 3;
434 CaretRect.Size = new Size(charWidth, height);
435 CaretRect.Location = new Point(this.CaretLocation.X, this.CaretLocation.Y + lineHeight - height);
436 render.FillRectangle(CaretRect, FillRectType.OverwriteCaret);
440 long To100nsTime(int ms)
445 public void DrawLineMarker(int row)
447 if (this.HideLineMarker || !this.IsFocused)
449 IEditorRender render = (IEditorRender)base.render;
450 Point p = this.CaretLocation;
451 double height = this.LayoutLines.GetLayout(this.CaretPostion.row).Height;
452 double width = this.render.TextArea.Width;
453 render.FillRectangle(new Rectangle(this.PageBound.X + this.render.TextArea.X, this.CaretLocation.Y, width, height), FillRectType.LineMarker);
457 /// 指定した座標の一番近くにあるTextPointを取得する
459 /// <param name="p">テキストエリアを左上とする相対位置</param>
460 /// <returns>レイアウトラインを指し示すTextPoint</returns>
461 public TextPoint GetTextPointFromPostion(Point p)
463 if (p.Y < this.render.TextArea.TopLeft.Y ||
464 p.Y > this.render.TextArea.BottomRight.Y)
465 return TextPoint.Null;
466 TextPoint tp = new TextPoint();
468 if (this.LayoutLines.Count == 0)
471 p.Y -= this.render.TextArea.Y;
473 int lineHeadIndex, lineLength;
475 tp.row = this.LayoutLines.Count - 1;
476 for (int i = this.Src.Row; i < this.LayoutLines.Count; i++)
478 double height = this.LayoutLines.GetLayout(i).Height;
480 lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
481 lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
483 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
486 if (y + height > p.Y)
494 if (p.X < this.render.TextArea.X)
497 tp.col = GetIndexFromColPostion(tp.row, p.X);
499 lineLength = this.LayoutLines.GetLengthFromLineNumber(tp.row);
500 if (tp.col > lineLength)
507 /// 桁方向の座標に対応するインデックスを取得する
509 /// <param name="row">対象となる行</param>
510 /// <param name="x">テキストエリアからの相対位置</param>
511 /// <returns></returns>
512 public int GetIndexFromColPostion(int row, double x)
514 x -= this.render.TextArea.X;
515 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
518 int index = this.LayoutLines.GetLayout(row).GetIndexFromColPostion(this.Src.X + x);
523 /// インデックスに対応する桁方向の座標を得る
525 /// <param name="row">対象となる行</param>
526 /// <param name="index">インデックス</param>
527 /// <returns>テキストエリアからの相対位置を返す</returns>
528 public double GetColPostionFromIndex(int row, int index)
530 double x = this.LayoutLines.GetLayout(row).GetColPostionFromIndex(index);
531 return x - Src.X + this.render.TextArea.X;
535 /// TextPointに対応する座標を得る
537 /// <param name="tp">レイアウトライン上の位置</param>
538 /// <returns>テキストエリアを左上とする相対位置</returns>
539 public Point GetPostionFromTextPoint(TextPoint tp)
541 Point p = new Point();
542 for (int i = this.Src.Row; i < tp.row; i++)
544 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
545 int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
546 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
548 p.Y += this.LayoutLines.GetLayout(i).Height;
550 p.X = this.GetColPostionFromIndex(tp.row, tp.col);
551 p.Y += this.render.TextArea.Y;
556 /// キャレットを指定した位置に移動させる
558 /// <param name="row"></param>
559 /// <param name="col"></param>
560 /// <param name="autoExpand">折り畳みを展開するなら真</param>
561 public void JumpCaret(int row, int col, bool autoExpand = true)
565 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(row);
566 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
567 FoldingItem foldingData = this.LayoutLines.FoldingCollection.Get(lineHeadIndex, lineLength);
568 if(foldingData != null)
570 if (this.LayoutLines.FoldingCollection.IsParentHidden(foldingData) || !foldingData.IsFirstLine(this.LayoutLines, row))
572 this.LayoutLines.FoldingCollection.Expand(foldingData);
577 this._CaretPostion.row = row;
578 this._CaretPostion.col = col;
582 /// index上の文字が表示されるようにSrcを調整する
584 /// <param name="index">インデックス</param>
585 /// <returns>調整されたら真。そうでなければ偽</returns>
586 public bool AdjustSrc(int index)
588 TextPoint startTextPoint = this.GetLayoutLineFromIndex(index);
589 double x = this.LayoutLines.GetLayout(startTextPoint.row).GetColPostionFromIndex(startTextPoint.col);
590 if (x < this.Src.X ||
591 x > this.Src.X + this.PageBound.Width)
593 this.TryScroll(x, this.Src.Row);
596 if (startTextPoint.row < this.Src.Row ||
597 startTextPoint.row > this.Src.Row + this.LineCountOnScreenWithInVisible)
599 this.TryScroll(this.Src.X, startTextPoint.row);
606 /// キャレットがあるところまでスクロールする
608 /// <return>再描写する必要があるなら真を返す</return>
609 /// <remarks>Document.Update(type == UpdateType.Clear)イベント時に呼び出した場合、例外が発生します</remarks>
610 public bool AdjustCaretAndSrc(AdjustFlow flow = AdjustFlow.Both)
612 IEditorRender render = (IEditorRender)base.render;
614 if (this.PageBound.Width == 0 || this.PageBound.Height == 0)
616 this.SetCaretPostion(this.Padding.Left + render.FoldingWidth, 0);
621 TextPoint tp = this.CaretPostion;
622 double x = this.CaretLocation.X;
623 double y = this.CaretLocation.Y;
625 if (flow == AdjustFlow.Col || flow == AdjustFlow.Both)
627 x = this.LayoutLines.GetLayout(tp.row).GetColPostionFromIndex(tp.col);
629 double left = this.Src.X;
630 double right = this.Src.X + this.render.TextArea.Width;
632 if (x >= left && x <= right) //xは表示領域にないにある
636 else if (x > right) //xは表示領域の右側にある
638 this._Src.X = x - this.render.TextArea.Width + this.ScrollMarginWidth;
639 if (this.render.RightToLeft && this._Src.X > 0)
641 System.Diagnostics.Debug.Assert(x > 0);
646 x = this.render.TextArea.Width - this.ScrollMarginWidth;
650 else if (x < left) //xは表示領域の左側にある
652 this._Src.X = x - this.ScrollMarginWidth;
653 if (!this.render.RightToLeft && this._Src.X < this.render.TextArea.X)
659 x = this.ScrollMarginWidth;
663 x += this.render.TextArea.X;
666 if (flow == AdjustFlow.Row || flow == AdjustFlow.Both)
669 int lineCount = this.LineCountOnScreenWithInVisible;
670 if (tp.row >= this.Src.Row && tp.row < this.Src.Row + lineCount)
671 caretRow = tp.row - this.Src.Row;
672 else if (tp.row >= this.Src.Row + lineCount)
674 this._Src.Row = this.GetSrcRow(tp.row, this.LineCountOnScreen);
675 caretRow = tp.row - this._Src.Row;
677 CalculateLineCountOnScreen();
679 else if (tp.row < this.Src.Row)
681 this._Src.Row = tp.row;
683 CalculateLineCountOnScreen();
690 for (int i = 0; i < caretRow; i++)
692 int currentRow = this.Src.Row + i;
693 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(currentRow);
694 int lineLength = this.LayoutLines.GetLengthFromLineNumber(currentRow);
696 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
699 y += this.LayoutLines.GetLayout(currentRow).Height;
702 y += this.render.TextArea.Y;
705 this.SetCaretPostion(x, y);
708 this.OnSrcChanged(null);
713 int GetSrcRow(int row,int count)
715 if (this.LayoutLines.FoldingStrategy == null)
717 for (int i = row; i >= 0; i--)
719 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
720 int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
721 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
731 /// レイアウト行をテキストポイントからインデックスに変換する
733 /// <param name="tp">テキストポイント表す</param>
734 /// <returns>インデックスを返す</returns>
735 public int GetIndexFromLayoutLine(TextPoint tp)
737 return this.LayoutLines.GetIndexFromTextPoint(tp);
741 /// インデックスからレイアウト行を指し示すテキストポイントに変換する
743 /// <param name="index">インデックスを表す</param>
744 /// <returns>テキストポイント返す</returns>
745 public TextPoint GetLayoutLineFromIndex(int index)
747 return this.LayoutLines.GetTextPointFromIndex(index);
753 /// <param name="x"></param>
754 /// <param name="row"></param>
756 /// 範囲外の座標を指定した場合、範囲内に収まるように調整されます
758 public void Scroll(double x, int row)
764 int endRow = this.LayoutLines.Count - 1 - this.LineCountOnScreen;
769 base.TryScroll(x, row);
775 /// <param name="row">行</param>
776 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
777 public void ScrollIntoView(int row, bool alignTop)
782 double y = this.render.TextArea.Height;
783 for (int i = row; i >= 0; i--)
785 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
786 int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
787 double height = this.LayoutLines.GetLayout(i).Height;
792 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
798 public int AdjustRow(int row, bool isMoveNext)
800 if (this.LayoutLines.FoldingStrategy == null)
802 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(row);
803 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
804 FoldingItem foldingData = this.LayoutLines.FoldingCollection.GetFarestHiddenFoldingData(lineHeadIndex, lineLength);
805 if (foldingData != null && !foldingData.Expand)
807 if (foldingData.End == this.Document.Length)
809 if (isMoveNext && lineHeadIndex > foldingData.Start)
810 row = this.LayoutLines.GetLineNumberFromIndex(foldingData.End) + 1;
812 row = this.LayoutLines.GetLineNumberFromIndex(foldingData.Start);
813 if(row > this.LayoutLines.Count - 1)
814 row = this.LayoutLines.GetLineNumberFromIndex(foldingData.Start);
819 protected override void CalculateClipRect()
821 IEditorRender render = (IEditorRender)base.render;
822 double x, y, width, height;
824 if (this.DrawLineNumber)
826 if (this.render.RightToLeft)
827 x = this.Padding.Left;
829 x = this.Padding.Left + UpdateAreaTotalWidth + this.render.LineNemberWidth + this.LineNumberMargin + render.FoldingWidth;
830 width = this.PageBound.Width - this.render.LineNemberWidth - this.LineNumberMargin - this.Padding.Left - this.Padding.Right - render.FoldingWidth - UpdateAreaTotalWidth;
834 if (this.render.RightToLeft)
835 x = this.Padding.Left;
837 x = this.Padding.Left + UpdateAreaTotalWidth + render.FoldingWidth;
838 width = this.PageBound.Width - this.Padding.Left - this.Padding.Right - render.FoldingWidth - UpdateAreaTotalWidth;
841 y = this.Padding.Top;
842 height = this.PageBound.Height - this.Padding.Top - this.Padding.Bottom;
844 if (this.HideRuler == false)
846 double rulerHeight = this.render.emSize.Height + LineMarkerThickness;
848 height -= rulerHeight;
857 this.render.TextArea = new Rectangle(x, y, width, height);
859 this.LineBreakingMarginWidth = width * 5 / 100;
862 public override void CalculateLineCountOnScreen()
864 if (this.LayoutLines.Count == 0 || this.PageBound.Height == 0)
868 int i = this.Src.Row;
869 int visualCount = this.Src.Row;
872 int row = i < this.LayoutLines.Count ? i : this.LayoutLines.Count - 1;
874 int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(row);
875 int lineLength = this.LayoutLines.GetLengthFromLineNumber(row);
877 if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex) && row < this.LayoutLines.Count - 1)
880 ITextLayout layout = this.LayoutLines.GetLayout(row);
882 double width = layout.Width;
884 if (width > this._LongestWidth)
885 this._LongestWidth = width;
887 double lineHeight = layout.Height;
891 if (y >= this.render.TextArea.Height)
895 this.LineCountOnScreen = Math.Max(visualCount - this.Src.Row - 1, 0);
896 this.LineCountOnScreenWithInVisible = Math.Max(i - this.Src.Row - 1, 0);
899 void SetCaretPostion(double x, double y)
901 this._CaretLocation = new Point(x + this.PageBound.X, y + this.PageBound.Y);
904 void FoldingCollection_StatusChanged(object sender, FoldingItemStatusChangedEventArgs e)
906 this.CalculateLineCountOnScreen();
917 double GetRealtiveX(AreaType type)
919 IEditorRender render = (IEditorRender)base.render;
922 case AreaType.UpdateArea:
923 if (this.render.RightToLeft)
924 return this.PageBound.TopRight.X - UpdateAreaTotalWidth;
925 if (this.DrawLineNumber)
926 return this.render.TextArea.X - this.render.LineNemberWidth - this.LineNumberMargin - render.FoldingWidth - UpdateAreaTotalWidth;
928 return this.render.TextArea.X - render.FoldingWidth - UpdateAreaTotalWidth;
929 case AreaType.FoldingArea:
930 if (this.render.RightToLeft)
931 return this.PageBound.TopRight.X - render.FoldingWidth;
932 if (this.DrawLineNumber)
933 return this.render.TextArea.X - this.render.LineNemberWidth - this.LineNumberMargin - render.FoldingWidth;
935 return this.render.TextArea.X - render.FoldingWidth;
936 case AreaType.LineNumberArea:
937 if (this.DrawLineNumber == false)
938 throw new InvalidOperationException();
939 if (this.render.RightToLeft)
940 return this.PageBound.TopRight.X - UpdateAreaTotalWidth - render.FoldingWidth - this.render.LineNemberWidth;
942 return this.render.TextArea.X - this.render.LineNemberWidth - this.LineNumberMargin;
943 case AreaType.TextArea:
944 return this.render.TextArea.X;
946 throw new ArgumentOutOfRangeException();