From 0604893269537fed3e48ccfb57d69be92a4a4057 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Mon, 31 May 2010 10:26:31 +0200 Subject: Textedit: scrolling improvements. --- prototypes/textedit/demo_textedit.lpi | 2 +- prototypes/textedit/fpg_textedit.pas | 44 ++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 10 deletions(-) (limited to 'prototypes') diff --git a/prototypes/textedit/demo_textedit.lpi b/prototypes/textedit/demo_textedit.lpi index 37d7bf3f..09e3125f 100644 --- a/prototypes/textedit/demo_textedit.lpi +++ b/prototypes/textedit/demo_textedit.lpi @@ -14,7 +14,7 @@ - + diff --git a/prototypes/textedit/fpg_textedit.pas b/prototypes/textedit/fpg_textedit.pas index 234b8817..62d6d644 100644 --- a/prototypes/textedit/fpg_textedit.pas +++ b/prototypes/textedit/fpg_textedit.pas @@ -119,6 +119,8 @@ TfpgBaseTextEdit = class(TfpgWidget) procedure SetRightEdgeCol(const AValue: Integer); protected { -- internal events -- } + procedure HandleShow; override; + procedure HandleResize(AWidth, AHeight: TfpgCoord); override; procedure HandlePaint; override; procedure HandleMouseEnter; override; procedure HandleMouseExit; override; @@ -376,6 +378,8 @@ procedure TfpgBaseTextEdit.SetGutterShowLineNumbers(const AValue: Boolean); procedure TfpgBaseTextEdit.SetGutterVisible(const AValue: Boolean); begin FGutterPan.Visible := AValue; + if FGutterPan.Visible then + UpdateGutterCoords; Invalidate; end; @@ -440,18 +444,20 @@ procedure TfpgBaseTextEdit.GetSelBounds(var AStartNo, AEndNo, AStartOffs, procedure TfpgBaseTextEdit.UpdateScrollBars; begin FVScrollBar.Min := 0; - FVScrollBar.PageSize := FVisLines - 2; - FVScrollBar.Max := FLines.Count +1 - FVisLines; // +1 is so the last line is completely visible + FVScrollBar.PageSize := FVisLines - 4; + FVScrollBar.Max := FLines.Count - FVisLines + 1; // +1 is so the last line is completely visible FVScrollBar.Position := VPos; + FVScrollBar.SliderSize := FVisLines / FLines.Count; FVScrollBar.Visible := FLines.Count > FVisLines; FHScrollBar.Min := 0; - FHScrollBar.PageSize := FVisCols div 4; //FMaxScrollH div 4; - FHScrollBar.Max := FMaxScrollH;// div 2; + FHScrollBar.PageSize := FVisCols div 2; //FMaxScrollH div 4; + FHScrollBar.Max := FMaxScrollH - FVisCols + 1;// div 2; FHScrollBar.Position := HPos; + FHScrollBar.SliderSize := FVisCols / FMaxScrollH; FHScrollBar.Visible := FMaxScrollH > FVisCols; - UpdateScrollBarCoords; +// UpdateScrollBarCoords; end; procedure TfpgBaseTextEdit.VScrollBarMove(Sender: TObject; position: integer); @@ -917,10 +923,31 @@ procedure TfpgBaseTextEdit.SetRightEdgeCol(const AValue: Integer); end; end; +procedure TfpgBaseTextEdit.HandleShow; +begin + inherited HandleShow; + HandleResize(Width, Height); +end; + +procedure TfpgBaseTextEdit.HandleResize(AWidth, AHeight: TfpgCoord); +begin + writeln('DEBUG: TfpgBaseTextEdit.HandleResize '); + inherited HandleResize(AWidth, AHeight); + if HasHandle then + begin + UpdateCharBounds; + writeln('DEBUG: TfpgBaseTextEdit.HandleResize - update sb coords'); + UpdateScrollBarCoords; + writeln('DEBUG: TfpgBaseTextEdit.HandleResize - update sb'); + UpdateScrollBars; + UpdateGutterCoords; + end; +end; + procedure TfpgBaseTextEdit.HandlePaint; begin + writeln('DEBUG: TfpgBaseTextEdit.HandlePaint '); // inherited HandlePaint; - UpdateCharBounds; // normal house keeping Canvas.ClearClipRect; Canvas.Clear(clBoxColor); @@ -929,8 +956,6 @@ procedure TfpgBaseTextEdit.HandlePaint; Canvas.SetClipRect(GetClientRect); // do the actual drawing - UpdateScrollBarCoords; - UpdateGutterCoords; DrawVisible; DrawCaret(CaretPos.X, CaretPos.Y); Canvas.ClearClipRect; @@ -1353,7 +1378,7 @@ constructor TfpgBaseTextEdit.Create(AOwner: TComponent); CaretPos.y := 0; FTopLine := 0; FTabWidth := 8; - FMaxScrollH := 0; + FMaxScrollH := 1; VPos := 0; HPos := 0; FTracking := True; @@ -1534,6 +1559,7 @@ procedure TfpgBaseTextEdit.LoadFromFile(const AFileName: TfpgString); Exit; //==> Clear; FLines.LoadFromFile(AFileName); + HandleResize(Width, Height); Invalidate; end; -- cgit v1.2.3-54-g00ecf