SynEdit: Clean up ScreenCaret.ClipRect calculation; Fix ClipRect by 1 pixel to small. Partly fixes issue #0020053

git-svn-id: trunk@32056 -
This commit is contained in:
martin 2011-08-25 22:58:14 +00:00
parent 7f8b9f009e
commit e4fc107b50
2 changed files with 23 additions and 18 deletions

View File

@ -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;

View File

@ -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}