From e4fc107b5092ddfcde7fe1615d656fc92d2d6892 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 25 Aug 2011 22:58:14 +0000 Subject: [PATCH] SynEdit: Clean up ScreenCaret.ClipRect calculation; Fix ClipRect by 1 pixel to small. Partly fixes issue #0020053 git-svn-id: trunk@32056 - --- components/synedit/synedit.pp | 37 +++++++++++----------- components/synedit/syneditpointclasses.pas | 4 +++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index 45774061d7..980df5bae5 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -4334,9 +4334,6 @@ begin inherited CreateHandle; //SizeOrFontChanged will be called FLeftGutter.RecalcBounds; FRightGutter.RecalcBounds; - FScreenCaret.ClipRect := Rect(TextLeftPixelOffset(False), 0, - ClientWidth - TextRightPixelOffset - ScrollBarWidth, - ClientHeight - ScrollBarWidth); UpdateScrollBars; finally DoDecPaintLock(nil); @@ -4671,7 +4668,7 @@ begin case Msg.ScrollCode of // Scrolls to start / end of the line SB_TOP: LeftChar := 1; - SB_BOTTOM: LeftChar := Max(FTheLinesView.LengthOfLongestLine, MaxLeftChar); + SB_BOTTOM: LeftChar := CurrentMaxLeftChar; // Scrolls one char left / right SB_LINEDOWN: LeftChar := LeftChar + 1; SB_LINEUP: LeftChar := LeftChar - 1; @@ -4736,9 +4733,6 @@ begin if sfEnsureCursorPosAtResize in fStateFlags then EnsureCursorPosVisible; Exclude(fStateFlags, sfEnsureCursorPosAtResize); - FScreenCaret.ClipRect := Rect(TextLeftPixelOffset(False), 0, - ClientWidth - TextRightPixelOffset - ScrollBarWidth, - ClientHeight - ScrollBarWidth); finally FScreenCaret.UnLock; dec(FScrollBarUpdateLock); @@ -7011,16 +7005,12 @@ end; procedure TCustomSynEdit.GutterResized(Sender: TObject); begin if (csLoading in ComponentState) then exit; - FScreenCaret.ClipRect := Rect(TextLeftPixelOffset(False), 0, - ClientWidth - TextRightPixelOffset - ScrollBarWidth, - ClientHeight - ScrollBarWidth); + GutterChanged(Sender); fTextOffset := TextLeftPixelOffset - (LeftChar - 1) * fCharWidth; + if HandleAllocated then begin - FCharsInWindow := Max(1, (ClientWidth - - TextLeftPixelOffset - TextRightPixelOffset - - ScrollBarWidth) div fCharWidth); - //debugln('TCustomSynEdit.SetGutterWidth A ClientWidth=',dbgs(ClientWidth),' FLeftGutter.Width=',dbgs(FLeftGutter.Width),' ScrollBarWidth=',dbgs(ScrollBarWidth),' fCharWidth=',dbgs(fCharWidth)); + RecalcCharsAndLinesInWin(False); UpdateScrollBars; Invalidate; end; @@ -7500,14 +7490,25 @@ begin end; procedure TCustomSynEdit.RecalcCharsAndLinesInWin(CheckCaret: Boolean); +var + NewLinesInWindow: Integer; begin FCharsInWindow := Max(1, (ClientWidth - TextLeftPixelOffset - TextRightPixelOffset - ScrollBarWidth) div fCharWidth); - FLinesInWindow := Max(0,ClientHeight - ScrollBarWidth) div Max(1,fTextHeight); - FFoldedLinesView.LinesInWindow := fLinesInWindow; - FMarkupManager.LinesInWindow:= fLinesInWindow; - StatusChanged([scLinesInWindow]); + + NewLinesInWindow := Max(0,ClientHeight - ScrollBarWidth) div Max(1,fTextHeight); + if NewLinesInWindow <> FLinesInWindow then begin + FLinesInWindow := NewLinesInWindow; + FFoldedLinesView.LinesInWindow := fLinesInWindow; + FMarkupManager.LinesInWindow:= fLinesInWindow; + StatusChanged([scLinesInWindow]); + end; + + FScreenCaret.ClipRect := Rect(TextLeftPixelOffset(False), 0, + ClientWidth - TextRightPixelOffset - ScrollBarWidth + 1, + ClientHeight - ScrollBarWidth); + if CheckCaret then begin if not (eoScrollPastEol in Options) then LeftChar := LeftChar; diff --git a/components/synedit/syneditpointclasses.pas b/components/synedit/syneditpointclasses.pas index f24702f98d..efe754b179 100644 --- a/components/synedit/syneditpointclasses.pas +++ b/components/synedit/syneditpointclasses.pas @@ -1734,6 +1734,10 @@ end; procedure TSynEditScreenCaret.SetClipRect(const AValue: TRect); begin + if (FClipLeft = AValue.Left) and (FClipRight = AValue.Right) and + (FClipTop = AValue.Top) and (FClipBottom = AValue.Bottom) + then + exit; {$IFDeF SynCaretDebug} debugln(['SynEditCaret ClipRect for HandleOwner=',FHandleOwner, ' Rect=', dbgs(AValue)]); {$ENDIF}