/// <remarks> /// If the caret position is outside the document text bounds /// it is set to the correct position by calling ValidateCaretPos. /// </remarks> public void ValidateCaretPos() { line = Math.Max(0, Math.Min(textArea.Document.TotalNumberOfLines - 1, line)); column = Math.Max(0, column); if (column == int.MaxValue || !textArea.TextEditorProperties.AllowCaretBeyondEOL) { LineSegment lineSegment = textArea.Document.GetLineSegment(line); column = Math.Min(column, lineSegment.Length); } DebuggerData.selectedLine = line; textArea.Invalidate(); }
void VScrollBarValueChanged(object sender, EventArgs e) { textArea.VirtualTop = new Point(textArea.VirtualTop.X, vScrollBar.Value); textArea.Invalidate(); AdjustScrollBars(); }
public void UpdateCaretPosition() { Log("UpdateCaretPosition"); if (textArea.TextEditorProperties.CaretLine) { textArea.Invalidate(); } else { if (caretImplementation.RequireRedrawOnPositionChange) { textArea.UpdateLine(oldLine); if (line != oldLine) { textArea.UpdateLine(line); } } else { if (textArea.MotherTextAreaControl.TextEditorProperties.LineViewerStyle == LineViewerStyle.FullRow && oldLine != line) { textArea.UpdateLine(oldLine); textArea.UpdateLine(line); } } } oldLine = line; if (hidden || textArea.MotherTextEditorControl.IsInUpdate) { outstandingUpdate = true; return; } else { outstandingUpdate = false; } ValidateCaretPos(); int lineNr = this.line; int xpos = textArea.TextView.GetDrawingXPos(lineNr, this.column); //LineSegment lineSegment = textArea.Document.GetLineSegment(lineNr); Point pos = ScreenPosition; if (xpos >= 0) { CreateCaret(); bool success = caretImplementation.SetPosition(pos.X, pos.Y); if (!success) { caretImplementation.Destroy(); caretCreated = false; UpdateCaretPosition(); } } else { caretImplementation.Destroy(); } // set the input method editor location if (ime == null) { ime = new Ime(textArea.Handle, textArea.Document.TextEditorProperties.Font); } else { ime.HWnd = textArea.Handle; ime.Font = textArea.Document.TextEditorProperties.Font; } ime.SetIMEWindowLocation(pos.X, pos.Y); currentPos = pos; }
public void ResizeTextArea(bool forceRedraw = false) { var y = 0; var h = 0; if (_hRuler != null) { _hRuler.Bounds = new Rectangle(0, 0, Width - SystemInformation.HorizontalScrollBarArrowWidth, TextArea.TextView.FontHeight); y = _hRuler.Bounds.Bottom; h = _hRuler.Bounds.Height; } var fontHeight = TextArea.TextView.FontHeight; var totalLineHeight = GetNumberOfVisibleLines() * fontHeight; // If the lines cannot fit the TextArea draw the VScrollBar var drawVScrollBar = totalLineHeight > Height || TextArea.VirtualTop.Y > 0; var width = TextArea.TextView.DrawingPosition.Width; // Measuring string length is not exactly accurate, add 10 as a error margin var drawHScrollBar = width > 0 && GetMaximumVisibleLineWidth() + 10 > TextArea.TextView.DrawingPosition.Width || TextArea.VirtualTop.X > 0; AdjustScrollBars(); if (!forceRedraw && !IsRedrawRequired(drawVScrollBar, drawHScrollBar)) { return; } VScrollBar.ValueChanged -= VScrollBarValueChanged; HScrollBar.ValueChanged -= HScrollBarValueChanged; if (drawHScrollBar && drawVScrollBar) { TextArea.Bounds = new Rectangle(0, y, Width - SystemInformation.HorizontalScrollBarArrowWidth, Height - SystemInformation.VerticalScrollBarArrowHeight - h); Controls.Remove(VScrollBar); Controls.Remove(HScrollBar); Controls.Add(VScrollBar); Controls.Add(HScrollBar); VScrollBar.ValueChanged += VScrollBarValueChanged; HScrollBar.ValueChanged += HScrollBarValueChanged; SetScrollBarBounds(true, true); } else if (drawVScrollBar) { TextArea.Bounds = new Rectangle(0, y, Width - SystemInformation.HorizontalScrollBarArrowWidth, Height); // If VScrollBar was not visible before scroll to the end if (!Controls.Contains(VScrollBar)) { VScrollBar.Value = VScrollBar.Maximum; } else { Controls.Remove(VScrollBar); } Controls.Add(VScrollBar); Controls.Remove(HScrollBar); VScrollBar.ValueChanged += VScrollBarValueChanged; SetScrollBarBounds(true, false); } else if (drawHScrollBar) { TextArea.Bounds = new Rectangle(0, y, Width, Height - SystemInformation.VerticalScrollBarArrowHeight - h); Controls.Remove(HScrollBar); Controls.Add(HScrollBar); Controls.Remove(VScrollBar); HScrollBar.ValueChanged += HScrollBarValueChanged; SetScrollBarBounds(false, true); } else { Controls.Remove(VScrollBar); Controls.Remove(HScrollBar); TextArea.Bounds = new Rectangle(0, y, Width, Height); } TextArea.Invalidate(); }
void HScrollBarValueChanged(object sender, EventArgs e) { TextArea.VirtualTop = new Point(HScrollBar.Value * TextArea.TextView.WideSpaceWidth, TextArea.VirtualTop.Y); TextArea.Invalidate(); }
void VScrollBarValueChanged(object sender, EventArgs e) { textArea.VirtualTop = new Point(textArea.VirtualTop.X, vScrollBar.Value); textArea.Invalidate(); AdjustScrollBars(); /* * HACK for improved scrolling smooothness * by Steve Gray @ 15-Oct-2006 */ /* * Point vtop = textArea.VirtualTop; * * // adjust VirtualTop, but don't auto-Invalidate() * textArea.NoAutoInvalidate = true; * textArea.VirtualTop = new Point(textArea.VirtualTop.X, vScrollBar.Value); * textArea.NoAutoInvalidate = false; * * int yoffset = textArea.VirtualTop.Y - vtop.Y; * if (yoffset == 0) * return; * * if (Math.Abs(yoffset) + 10 >= textArea.ClientSize.Height) * { * // no data to keep * textArea.Invalidate(); * AdjustScrollBars(); * return; * } * * // get screen location of textArea * Point taloc = textArea.PointToScreen(Point.Empty); * * Graphics g = textArea.CreateGraphics(); * Rectangle rect = new Rectangle(taloc, textArea.ClientSize); * * if (yoffset > 0) // scrolled down, move graphics up * { * rect.Y += yoffset; * rect.Height -= yoffset; * g.CopyFromScreen(rect.Location, Point.Empty, rect.Size); * rect.Y = rect.Height; * } * else // scrolled up, move graphics down * { * yoffset = -yoffset; * rect.Height -= yoffset; * g.CopyFromScreen(rect.Location, new Point(0, yoffset), rect.Size); * rect.Y = 0; * } * rect.Height = yoffset; * rect.X = 0; * * // Invalidate region which has been "revealed" * textArea.Invalidate(rect); * //textArea.Invalidate(); * * lock (this) * { // set a timer to invalidate and redraw in full, * // as the above code can cause occasional graphical oddities * if (scrollTimer == null) * scrollTimer = new System.Threading.Timer(new TimerCallback(InvalidateTimer), null, 250, -1); * else * scrollTimer.Change(250, -1); * } * * AdjustScrollBars(); * */ }
public void UpdateCaretPosition() { if (Shared.TEP.CaretLine) { _textArea.Invalidate(); } else { if (_caretImplementation.RequireRedrawOnPositionChange) { _textArea.UpdateLine(_oldLine); if (_line != _oldLine) { _textArea.UpdateLine(_line); } } else { if (Shared.TEP.LineViewerStyle == LineViewerStyle.FullRow && _oldLine != _line) { _textArea.UpdateLine(_oldLine); _textArea.UpdateLine(_line); } } } _oldLine = _line; if (_hidden || _textArea.MotherTextEditorControl.IsInUpdate) { _outstandingUpdate = true; return; } else { _outstandingUpdate = false; } ValidateCaretPos(); int lineNr = _line; int xpos = _textArea.GetDrawingXPos(lineNr, this._column); //LineSegment lineSegment = textArea.Document.GetLineSegment(lineNr); Point pos = ScreenPosition; if (xpos >= 0) { CreateCaret(); bool success = _caretImplementation.SetPosition(pos.X, pos.Y); if (!success) { _caretImplementation.Destroy(); _caretCreated = false; UpdateCaretPosition(); } } else { _caretImplementation.Destroy(); } //// set the input method editor location //if (ime == null) //{ // ime = new Ime(textArea.Handle, Shared.FontContainer.DefaultFont); //} //else //{ // ime.HWnd = textArea.Handle; // ime.Font = Shared.FontContainer.DefaultFont; //} //ime.SetIMEWindowLocation(pos.X, pos.Y); _currentPos = pos; }
private void VScrollBarValueChanged(object sender, EventArgs e) { TextArea.VirtualTop = new Point(TextArea.VirtualTop.X, VScrollBar.Value); TextArea.Invalidate(); UpdateLayout(); }