void render_ChangedRightToLeft(object sender, EventArgs e) { this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Src.OffsetY); }
/// <summary> /// テキストポイントが含まれるように表示位置を調整します /// </summary> /// <param name="tp">テキストポイント</param> /// <param name="flow">調整方向</param> /// <returns>調整位置が変わったなら真。変わってないなら偽</returns> public (bool, Point) AdjustSrc(TextPoint tp, AdjustFlow flow) { bool result = false; Point tpPoint = new Point(); 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 = relPoint.X; double left = this.Src.X; double right = this.Src.X + this.render.TextArea.Width; if (x >= left && x <= right) //xは表示領域にないにある { x -= left; } else if (x > right) //xは表示領域の右側にある { 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.OffsetY); } else { x = this.render.TextArea.Width - this.ScrollMarginWidth; } result = true; } else if (x < left) //xは表示領域の左側にある { 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.OffsetY); } else { x = this.ScrollMarginWidth; } result = true; } x += this.render.TextArea.X; } if (flow == AdjustFlow.Row || flow == AdjustFlow.Both) { 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++) { 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; } caret_y += relPoint.Y; if (caret_y < 0) { this.Document.Src = new SrcPoint(this.Src.X, tp.row, -relPoint.Y); y = 0; } else if (caret_y >= 0 && caret_y < alignedHeight) { y = caret_y; } else if (caret_y >= alignedHeight) { SrcPoint newsrc = this.GetNearstRowAndOffsetY(tp.row, -(alignedHeight - relPoint.Y)); this.Document.Src = new SrcPoint(this.Src.X, newsrc.Row, -newsrc.OffsetY); y = alignedHeight; } y += this.render.TextArea.Y; result = true; } if (result) { this.OnSrcChanged(null); } tpPoint.X = x; tpPoint.Y = y; return(result, tpPoint); }