SynCompletion: Fix div by zero, due to resize during creation (Issue #15964). Patch by Aleksa Todorovic

Added extra code, to prevent unnecessary calculations.

git-svn-id: trunk@23948 -
This commit is contained in:
martin 2010-03-11 19:34:54 +00:00
parent 5270532363
commit 2749b31b1e

View File

@ -104,6 +104,7 @@ type
FPosition: Integer; FPosition: Integer;
FNbLinesInWindow: Integer; FNbLinesInWindow: Integer;
FFontHeight: integer; FFontHeight: integer;
FResizeLock: Integer;
Scroll: TScrollBar; Scroll: TScrollBar;
FOnValidate: TValidateEvent; FOnValidate: TValidateEvent;
FOnCancel: TNotifyEvent; FOnCancel: TNotifyEvent;
@ -383,6 +384,7 @@ uses
constructor TSynBaseCompletionForm.Create(AOwner: TComponent); constructor TSynBaseCompletionForm.Create(AOwner: TComponent);
begin begin
FResizeLock := 1; // prevent DoResize (on Handle Creation) do reset LinesInWindow
{$IFDEF SYN_LAZARUS} {$IFDEF SYN_LAZARUS}
inherited Create(AOwner); inherited Create(AOwner);
{$ELSE} {$ELSE}
@ -429,6 +431,7 @@ begin
{$ELSE} {$ELSE}
ShowHint := False; ShowHint := False;
{$ENDIF} {$ENDIF}
FResizeLock := 0;
end; end;
procedure TSynBaseCompletionForm.Deactivate; procedure TSynBaseCompletionForm.Deactivate;
@ -837,7 +840,9 @@ begin
or (Bitmap=nil) or (Scroll=nil) then exit; or (Bitmap=nil) or (Scroll=nil) then exit;
OldHeight:=Bitmap.Height+2; OldHeight:=Bitmap.Height+2;
OldWidth:=Bitmap.Width+Scroll.Width; OldWidth:=Bitmap.Width+Scroll.Width;
if (OldHeight<>Height) or (OldWidth<>Width) then begin if ((OldHeight<>Height) or (OldWidth<>Width)) and
(fFontHeight > 0) and (FResizeLock = 0) then
begin
FNbLinesInWindow := (Height-2+(fFontHeight-1)) div fFontHeight; FNbLinesInWindow := (Height-2+(fFontHeight-1)) div fFontHeight;
Invalidate; Invalidate;
end; end;
@ -857,11 +862,16 @@ procedure TSynBaseCompletionForm.FontChanged(Sender: TObject);
var var
TextMetric: TTextMetric; TextMetric: TTextMetric;
begin begin
inherited; inc(FResizeLock); // prevent DoResize from recalculating NbLinesInWindow
FillChar(TextMetric,SizeOf(TextMetric),0); try
GetTextMetrics(Canvas.Handle, TextMetric); inherited;
FFontHeight := TextMetric.tmHeight+2; FillChar(TextMetric,SizeOf(TextMetric),0);
SetNblinesInWindow(FNbLinesInWindow); GetTextMetrics(Canvas.Handle, TextMetric);
FFontHeight := TextMetric.tmHeight+2;
SetNblinesInWindow(FNbLinesInWindow);
finally
dec(FResizeLock);
end;
end; end;
{$ENDIF} {$ENDIF}
@ -878,16 +888,21 @@ end;
procedure TSynBaseCompletionForm.SetNbLinesInWindow( procedure TSynBaseCompletionForm.SetNbLinesInWindow(
const Value: Integer); const Value: Integer);
begin begin
FNbLinesInWindow := Value; inc(FResizeLock); // prevent DoResize from recalculating NbLinesInWindow
Height := fFontHeight * NbLinesInWindow + 2; try
{$IFNDEF SYN_LAZARUS} FNbLinesInWindow := Value;
Scroll.Top := 1; Height := fFontHeight * NbLinesInWindow + 2;
Scroll.Left := ClientWidth - Scroll.Width - 1; {$IFNDEF SYN_LAZARUS}
Scroll.Height := Height - 2; Scroll.Top := 1;
{$ELSE} Scroll.Left := ClientWidth - Scroll.Width - 1;
Bitmap.Width := Scroll.Left; Scroll.Height := Height - 2;
Bitmap.Height := Height - 2; {$ELSE}
{$ENDIF} Bitmap.Width := Scroll.Left;
Bitmap.Height := Height - 2;
{$ENDIF}
finally
dec(FResizeLock);
end;
end; end;
procedure TSynBaseCompletionForm.SetPosition(const Value: Integer); procedure TSynBaseCompletionForm.SetPosition(const Value: Integer);