SynEdit: fixed defer any actions that need the true ClientRect, until AutoSize was done. (required after recent IDE change, to defer All-AutoSizing)

This commit is contained in:
Martin 2024-07-26 18:51:26 +02:00
parent d7d77c934e
commit 98ff9dab59

View File

@ -220,6 +220,7 @@ type
sfScrollbarChanged, sfHorizScrollbarVisible, sfVertScrollbarVisible, sfScrollbarChanged, sfHorizScrollbarVisible, sfVertScrollbarVisible,
sfGutterResized, sfGutterResized,
sfAfterLoadFromFileNeeded, sfAfterLoadFromFileNeeded,
sfAfterHandleCreatedNeeded,
// Mouse-states // Mouse-states
sfLeftGutterClick, sfRightGutterClick, sfLeftGutterClick, sfRightGutterClick,
sfInClick, sfDblClicked, sfTripleClicked, sfQuadClicked, sfInClick, sfDblClicked, sfTripleClicked, sfQuadClicked,
@ -772,6 +773,9 @@ type
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double); override; const AXProportion, AYProportion: Double); override;
protected protected
function WaitingForInitialSize: boolean; inline;
procedure DoHandleInitialSizeFinished;
procedure DoAllAutoSize; override;
procedure CreateHandle; override; procedure CreateHandle; override;
procedure CreateParams(var Params: TCreateParams); override; procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override; procedure CreateWnd; override;
@ -2596,7 +2600,7 @@ begin
// FTrimmedLinesView sets the highlighter to modified. Until fixed, must be done before ScanRanges // FTrimmedLinesView sets the highlighter to modified. Until fixed, must be done before ScanRanges
FTrimmedLinesView.UnLock; // Must be unlocked after caret // May Change lines FTrimmedLinesView.UnLock; // Must be unlocked after caret // May Change lines
if (FPaintLock=1) and HandleAllocated then begin if (FPaintLock=1) and (not WaitingForInitialSize) then begin
ScanRanges(FLastTextChangeStamp <> TSynEditStringList(FLines).TextChangeStamp); ScanRanges(FLastTextChangeStamp <> TSynEditStringList(FLines).TextChangeStamp);
if sfAfterLoadFromFileNeeded in fStateFlags then if sfAfterLoadFromFileNeeded in fStateFlags then
AfterLoadFromFile; AfterLoadFromFile;
@ -2621,7 +2625,7 @@ begin
*) *)
Dec(FPaintLock); Dec(FPaintLock);
if (FPaintLock = 0) and HandleAllocated then begin if (FPaintLock = 0) and (not WaitingForInitialSize) then begin
ScrollAfterTopLineChanged; ScrollAfterTopLineChanged;
if sfScrollbarChanged in fStateFlags then if sfScrollbarChanged in fStateFlags then
UpdateScrollbars; UpdateScrollbars;
@ -3703,7 +3707,16 @@ end;
procedure TCustomSynEdit.UpdateShowing; procedure TCustomSynEdit.UpdateShowing;
begin begin
if (sfAfterHandleCreatedNeeded in fStateFlags) and (not AutoSizeDelayed) and HandleAllocated then begin
DoIncPaintLock(nil); // prevent calculations during inherited and ONLY during inherited
try
DoHandleInitialSizeFinished;
finally
DoDecPaintLock(nil); // run UpdateScrollBars
end;
end;
inherited UpdateShowing; inherited UpdateShowing;
if fMarkupManager <> nil then if fMarkupManager <> nil then
fMarkupManager.DoVisibleChanged(IsVisible); fMarkupManager.DoVisibleChanged(IsVisible);
if HandleAllocated then if HandleAllocated then
@ -4849,7 +4862,7 @@ end;
function TCustomSynEdit.CurrentMaxLeftChar(AIncludeCharsInWin: Boolean function TCustomSynEdit.CurrentMaxLeftChar(AIncludeCharsInWin: Boolean
): Integer; ): Integer;
begin begin
if not HandleAllocated then // don't know chars in window yet if WaitingForInitialSize then // don't know chars in window yet
exit(MaxInt); exit(MaxInt);
Result := FTheLinesView.LengthOfLongestLine + 1; Result := FTheLinesView.LengthOfLongestLine + 1;
@ -4870,7 +4883,7 @@ end;
function TCustomSynEdit.CurrentMaxLineLen: Integer; // called by TSynEditCaret function TCustomSynEdit.CurrentMaxLineLen: Integer; // called by TSynEditCaret
begin begin
if not HandleAllocated then // don't know chars in window yet if WaitingForInitialSize then // don't know chars in window yet
exit(MaxInt); exit(MaxInt);
if (eoScrollPastEolAutoCaret in Options2) then if (eoScrollPastEolAutoCaret in Options2) then
exit(MaxInt); exit(MaxInt);
@ -4889,7 +4902,7 @@ begin
//{BUG21996} DebugLn(['TCustomSynEdit.SetLeftChar=',Value,' Caret=',dbgs(CaretXY),', BlockBegin=',dbgs(BlockBegin),' BlockEnd=',dbgs(BlockEnd), ' StateFlags=',dbgs(fStateFlags), ' paintlock', FPaintLock]); //{BUG21996} DebugLn(['TCustomSynEdit.SetLeftChar=',Value,' Caret=',dbgs(CaretXY),', BlockBegin=',dbgs(BlockBegin),' BlockEnd=',dbgs(BlockEnd), ' StateFlags=',dbgs(fStateFlags), ' paintlock', FPaintLock]);
Value := Min(Value, CurrentMaxLeftChar); Value := Min(Value, CurrentMaxLeftChar);
Value := Max(Value, 1); Value := Max(Value, 1);
if not HandleAllocated then if WaitingForInitialSize then
Include(fStateFlags, sfExplicitLeftChar); Include(fStateFlags, sfExplicitLeftChar);
if Value <> FTextArea.LeftChar then begin if Value <> FTextArea.LeftChar then begin
FTextArea.LeftChar := Value; FTextArea.LeftChar := Value;
@ -4931,32 +4944,64 @@ begin
Text := Value; Text := Value;
end; end;
function TCustomSynEdit.WaitingForInitialSize: boolean;
begin
Result := (sfAfterHandleCreatedNeeded in fStateFlags) or AutoSizeDelayed or (not HandleAllocated);
end;
procedure TCustomSynEdit.DoHandleInitialSizeFinished;
begin
Exclude(fStateFlags, sfAfterHandleCreatedNeeded);
Application.RemoveOnIdleHandler(@IdleScanRanges);
fStateFlags := fStateFlags - [sfHorizScrollbarVisible, sfVertScrollbarVisible];
UpdateScrollBars; // just set sfScrollbarChanged
inc(FDoingResizeLock);
try
FLeftGutter.RecalcBounds;
FRightGutter.RecalcBounds;
finally
dec(FDoingResizeLock);
if sfGutterResized in fStateFlags then begin
Exclude(fStateFlags, sfGutterResized);
RecalcCharsAndLinesInWin(False);
UpdateScrollBars;
end
else
if sfScrollbarChanged in fStateFlags then
UpdateScrollBars;
end;
end;
procedure TCustomSynEdit.DoAllAutoSize;
begin
if (sfAfterHandleCreatedNeeded in fStateFlags) and (not AutoSizeDelayed) and HandleAllocated then begin
DoIncPaintLock(nil); // prevent calculations during inherited and ONLY during inherited
try
inherited DoAllAutoSize;
DoHandleInitialSizeFinished;
finally
DoDecPaintLock(nil); // run UpdateScrollBars
end;
end
else
inherited DoAllAutoSize;
end;
procedure TCustomSynEdit.CreateHandle; procedure TCustomSynEdit.CreateHandle;
begin begin
Application.RemoveOnIdleHandler(@IdleScanRanges); if (not AutoSizeDelayed) then begin
DoIncPaintLock(nil); // prevent calculations during inherited and ONLY during inherited DoIncPaintLock(nil); // prevent calculations during inherited and ONLY during inherited
try
inherited CreateHandle; //SizeOrFontChanged will be called
fStateFlags := fStateFlags - [sfHorizScrollbarVisible, sfVertScrollbarVisible];
UpdateScrollBars; // just set sfScrollbarChanged
finally
DoDecPaintLock(nil); // run UpdateScrollBars
inc(FDoingResizeLock);
try try
FLeftGutter.RecalcBounds; inherited CreateHandle; //SizeOrFontChanged will be called
FRightGutter.RecalcBounds; DoHandleInitialSizeFinished;
finally finally
dec(FDoingResizeLock); DoDecPaintLock(nil); // run UpdateScrollBars
if sfGutterResized in fStateFlags then begin
Exclude(fStateFlags, sfGutterResized);
RecalcCharsAndLinesInWin(False);
UpdateScrollBars;
end
else
if sfScrollbarChanged in fStateFlags then
UpdateScrollBars;
end; end;
end
else begin
Include(fStateFlags, sfAfterHandleCreatedNeeded);
inherited CreateHandle; //SizeOrFontChanged will be called
end; end;
end; end;
@ -5025,7 +5070,7 @@ begin
if not FTheLinesView.IsTextIdxVisible(ToIdx(Value)) then if not FTheLinesView.IsTextIdxVisible(ToIdx(Value)) then
Value := FindNextUnfoldedLine(Value, False); Value := FindNextUnfoldedLine(Value, False);
if not HandleAllocated then if WaitingForInitialSize then
Include(fStateFlags, sfExplicitTopLine); Include(fStateFlags, sfExplicitTopLine);
NewTopView := ToPos(FTheLinesView.TextToViewIndex(ToIdx(Value))); NewTopView := ToPos(FTheLinesView.TextToViewIndex(ToIdx(Value)));
if NewTopView <> TopView then begin if NewTopView <> TopView then begin
@ -5038,7 +5083,7 @@ var
Delta: Integer; Delta: Integer;
srect: TRect; srect: TRect;
begin begin
if (sfPainting in fStateFlags) or (fPaintLock <> 0) or (not HandleAllocated) then if (sfPainting in fStateFlags) or (fPaintLock <> 0) or WaitingForInitialSize then
exit; exit;
Delta := FOldTopView - TopView; Delta := FOldTopView - TopView;
{$IFDEF SYNSCROLLDEBUG} {$IFDEF SYNSCROLLDEBUG}
@ -5095,7 +5140,7 @@ begin
if (sfEnsureCursorPos in fStateFlags) then if (sfEnsureCursorPos in fStateFlags) then
debugln('SynEdit. skip MoveCaretToVisibleArea'); debugln('SynEdit. skip MoveCaretToVisibleArea');
{$ENDIF} {$ENDIF}
if (not HandleAllocated) or (sfEnsureCursorPos in fStateFlags) then if WaitingForInitialSize or (sfEnsureCursorPos in fStateFlags) then
exit; exit;
NewCaretXY:=CaretXY; NewCaretXY:=CaretXY;
@ -5133,7 +5178,7 @@ procedure TCustomSynEdit.UpdateCaret(IgnorePaintLock: Boolean = False);
var var
p: TPoint; p: TPoint;
begin begin
if ( (PaintLock <> 0) and not IgnorePaintLock ) or (not HandleAllocated) if ( (PaintLock <> 0) and not IgnorePaintLock ) or WaitingForInitialSize
then begin then begin
Include(fStateFlags, sfCaretChanged); Include(fStateFlags, sfCaretChanged);
end else begin end else begin
@ -5151,7 +5196,7 @@ procedure TCustomSynEdit.UpdateScrollBars;
var var
ScrollInfo: TScrollInfo; ScrollInfo: TScrollInfo;
begin begin
if (not HandleAllocated) or (PaintLock <> 0) or (FDoingResizeLock <> 0) then if WaitingForInitialSize or (PaintLock <> 0) or (FDoingResizeLock <> 0) then
Include(fStateFlags, sfScrollbarChanged) Include(fStateFlags, sfScrollbarChanged)
else begin else begin
Exclude(fStateFlags, sfScrollbarChanged); Exclude(fStateFlags, sfScrollbarChanged);
@ -5369,7 +5414,7 @@ end;
procedure TCustomSynEdit.DoOnResize; procedure TCustomSynEdit.DoOnResize;
begin begin
inherited; inherited;
if (not HandleAllocated) then if WaitingForInitialSize then
exit; exit;
inc(FDoingResizeLock); inc(FDoingResizeLock);
FScreenCaret.Lock; FScreenCaret.Lock;
@ -5513,7 +5558,7 @@ end;
procedure TCustomSynEdit.ScanRanges(ATextChanged: Boolean = True); procedure TCustomSynEdit.ScanRanges(ATextChanged: Boolean = True);
begin begin
if not HandleAllocated then begin if WaitingForInitialSize then begin
Application.RemoveOnIdleHandler(@IdleScanRanges); // avoid duplicate add Application.RemoveOnIdleHandler(@IdleScanRanges); // avoid duplicate add
if assigned(FHighlighter) then if assigned(FHighlighter) then
Application.AddOnIdleHandler(@IdleScanRanges, False); Application.AddOnIdleHandler(@IdleScanRanges, False);
@ -5674,7 +5719,7 @@ begin
AValue := Min(AValue, CurrentMaxTopView); AValue := Min(AValue, CurrentMaxTopView);
AValue := Max(AValue, 1); AValue := Max(AValue, 1);
if not HandleAllocated then if WaitingForInitialSize then
Include(fStateFlags, sfExplicitTopLine); Include(fStateFlags, sfExplicitTopLine);
(* ToDo: FFoldedLinesView.TopLine := AValue; (* ToDo: FFoldedLinesView.TopLine := AValue;
@ -6788,7 +6833,7 @@ begin
then then
exit; exit;
if (not HandleAllocated) or (fPaintLock > 0) or if WaitingForInitialSize or (fPaintLock > 0) or
(FWinControlFlags * [wcfInitializing, wcfCreatingHandle] <> []) (FWinControlFlags * [wcfInitializing, wcfCreatingHandle] <> [])
then begin then begin
include(fStateFlags, sfEnsureCursorPos); include(fStateFlags, sfEnsureCursorPos);
@ -7831,7 +7876,7 @@ end;
procedure TCustomSynEdit.AfterLoadFromFile; procedure TCustomSynEdit.AfterLoadFromFile;
begin begin
if (not HandleAllocated) or if WaitingForInitialSize or
( (FPaintLock > 0) and not((FPaintLock = 1) and FIsInDecPaintLock) ) ( (FPaintLock > 0) and not((FPaintLock = 1) and FIsInDecPaintLock) )
then begin then begin
Include(fStateFlags, sfAfterLoadFromFileNeeded); Include(fStateFlags, sfAfterLoadFromFileNeeded);
@ -8056,7 +8101,7 @@ begin
exit exit
end; end;
if HandleAllocated then begin if not WaitingForInitialSize then begin
RecalcCharsAndLinesInWin(False); RecalcCharsAndLinesInWin(False);
UpdateScrollBars; UpdateScrollBars;
Invalidate; Invalidate;
@ -8483,9 +8528,9 @@ begin
TopView := TopView; TopView := TopView;
end; end;
// (un)register HWND as drop target // (un)register HWND as drop target
if (eoDropFiles in ChangedOptions) and not (csDesigning in ComponentState) and HandleAllocated then if (eoDropFiles in ChangedOptions) and not (csDesigning in ComponentState) and (not WaitingForInitialSize) then
; // ToDo DragAcceptFiles ; // ToDo DragAcceptFiles
if (ChangedOptions * [eoPersistentCaret, eoNoCaret] <> []) and HandleAllocated then begin if (ChangedOptions * [eoPersistentCaret, eoNoCaret] <> []) and (not WaitingForInitialSize) then begin
UpdateCaret; UpdateCaret;
UpdateScreenCaret; UpdateScreenCaret;
end; end;
@ -8610,7 +8655,7 @@ end;
procedure TCustomSynEdit.SizeOrFontChanged(bFont: boolean); procedure TCustomSynEdit.SizeOrFontChanged(bFont: boolean);
begin begin
if HandleAllocated then begin if not WaitingForInitialSize then begin
LastMouseCaret:=Point(-1,-1); LastMouseCaret:=Point(-1,-1);
//DebugLn('TCustomSynEdit.SizeOrFontChanged LinesInWindow=',dbgs(LinesInWindow),' ClientHeight=',dbgs(ClientHeight),' ',dbgs(LineHeight)); //DebugLn('TCustomSynEdit.SizeOrFontChanged LinesInWindow=',dbgs(LinesInWindow),' ClientHeight=',dbgs(ClientHeight),' ',dbgs(LineHeight));
//debugln('TCustomSynEdit.SizeOrFontChanged A ClientWidth=',dbgs(ClientWidth),' FLeftGutter.Width=',dbgs(FLeftGutter.Width),' ScrollBarWidth=',dbgs(ScrollBarWidth),' CharWidth=',dbgs(CharWidth),' CharsInWindow=',dbgs(CharsInWindow),' Width=',dbgs(Width)); //debugln('TCustomSynEdit.SizeOrFontChanged A ClientWidth=',dbgs(ClientWidth),' FLeftGutter.Width=',dbgs(FLeftGutter.Width),' ScrollBarWidth=',dbgs(ScrollBarWidth),' CharWidth=',dbgs(CharWidth),' CharsInWindow=',dbgs(CharsInWindow),' Width=',dbgs(Width));
@ -8992,7 +9037,7 @@ begin
{$ENDIF} {$ENDIF}
SurrenderPrimarySelection; SurrenderPrimarySelection;
if FFoldedLinesView <> nil then if FFoldedLinesView <> nil then
FFoldedLinesView.LinesInWindow := -1; // Mark as "not HandleAllocated" FFoldedLinesView.LinesInWindow := -1; // Mark as "not HandleAllocated" / WaitingForInitialSize;
inherited DestroyWnd; inherited DestroyWnd;
end; end;