mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 12:00:02 +02:00
synedit: fix scroll calculations of the completion box, hide scroll if there is no need in it (bug #0012910)
git-svn-id: trunk@18104 -
This commit is contained in:
parent
274cb5df0a
commit
35fdea5b96
@ -125,11 +125,13 @@ type
|
|||||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||||
procedure KeyPress(var Key: char); override;
|
procedure KeyPress(var Key: char); override;
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
procedure ScrollGetFocus(Sender: TObject);
|
|
||||||
procedure Deactivate; override;
|
procedure Deactivate; override;
|
||||||
procedure SelectPrec;
|
procedure SelectPrec;
|
||||||
procedure SelectNext;
|
procedure SelectNext;
|
||||||
procedure ScrollChange(Sender: TObject);
|
procedure ScrollChange(Sender: TObject);
|
||||||
|
procedure ScrollGetFocus(Sender: TObject);
|
||||||
|
procedure ScrollScroll(Sender: TObject; ScrollCode: TScrollCode;
|
||||||
|
var ScrollPos: Integer);
|
||||||
procedure SetItemList(const Value: TStrings);
|
procedure SetItemList(const Value: TStrings);
|
||||||
procedure SetPosition(const Value: Integer);
|
procedure SetPosition(const Value: Integer);
|
||||||
procedure SetNbLinesInWindow(const Value: Integer);
|
procedure SetNbLinesInWindow(const Value: Integer);
|
||||||
@ -421,6 +423,7 @@ begin
|
|||||||
Scroll.OnChange := {$IFDEF FPC}@{$ENDIF}ScrollChange;
|
Scroll.OnChange := {$IFDEF FPC}@{$ENDIF}ScrollChange;
|
||||||
Scroll.Parent := Self;
|
Scroll.Parent := Self;
|
||||||
Scroll.OnEnter := {$IFDEF FPC}@{$ENDIF}ScrollGetFocus;
|
Scroll.OnEnter := {$IFDEF FPC}@{$ENDIF}ScrollGetFocus;
|
||||||
|
Scroll.OnScroll := {$IFDEF FPC}@{$ENDIF}ScrollScroll;
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
Scroll.Visible := True;
|
Scroll.Visible := True;
|
||||||
Scroll.Anchors:=[akTop,akRight];
|
Scroll.Anchors:=[akTop,akRight];
|
||||||
@ -637,14 +640,22 @@ begin
|
|||||||
//Writeln('[TSynBaseCompletionForm.Paint]');
|
//Writeln('[TSynBaseCompletionForm.Paint]');
|
||||||
|
|
||||||
// update scroll bar
|
// update scroll bar
|
||||||
if ItemList.Count - NbLinesInWindow < 0 then
|
Scroll.Visible := ItemList.Count > NbLinesInWindow;
|
||||||
Scroll.Max := 0
|
|
||||||
|
if Scroll.Visible then
|
||||||
|
begin
|
||||||
|
Scroll.Max := ItemList.Count - 1;
|
||||||
|
Scroll.LargeChange := NbLinesInWindow;
|
||||||
|
Scroll.PageSize := NbLinesInWindow;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Scroll.Max := ItemList.Count - NbLinesInWindow;
|
begin
|
||||||
|
Scroll.PageSize := 0;
|
||||||
|
Scroll.Max := 0;
|
||||||
|
end;
|
||||||
{$IFNDEF SYN_LAZARUS}
|
{$IFNDEF SYN_LAZARUS}
|
||||||
Position := Position;
|
Position := Position;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Scroll.LargeChange := NbLinesInWindow;
|
|
||||||
|
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
bitmap.SetSize(ClientWidth, ClientHeight);
|
bitmap.SetSize(ClientWidth, ClientHeight);
|
||||||
@ -652,15 +663,18 @@ begin
|
|||||||
bitmap.Width:=ClientWidth;
|
bitmap.Width:=ClientWidth;
|
||||||
bitmap.Height:=ClientHeight;
|
bitmap.Height:=ClientHeight;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
with bitmap do begin
|
with bitmap do
|
||||||
|
begin
|
||||||
{$IFNDEF SYN_LAZARUS}
|
{$IFNDEF SYN_LAZARUS}
|
||||||
canvas.pen.color := fbcolor;
|
canvas.pen.color := fbcolor;
|
||||||
canvas.brush.color := color;
|
canvas.brush.color := color;
|
||||||
canvas.Rectangle(0, 0, Width, Height);
|
canvas.Rectangle(0, 0, Width, Height);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
//DebugLn(['TSynBaseCompletionForm.Paint NbLinesInWindow=',NbLinesInWindow,' ItemList.Count=',ItemList.Count]);
|
//DebugLn(['TSynBaseCompletionForm.Paint NbLinesInWindow=',NbLinesInWindow,' ItemList.Count=',ItemList.Count]);
|
||||||
for i := 0 to min(NbLinesInWindow - 1, ItemList.Count - 1) do begin
|
for i := 0 to min(NbLinesInWindow - 1, ItemList.Count - Scroll.Position - 1) do
|
||||||
if i + Scroll.Position = Position then begin
|
begin
|
||||||
|
if i + Scroll.Position = Position then
|
||||||
|
begin
|
||||||
Canvas.Brush.Color := clSelect;
|
Canvas.Brush.Color := clSelect;
|
||||||
Canvas.Pen.Color := clSelect;
|
Canvas.Pen.Color := clSelect;
|
||||||
Canvas.Rectangle(0, (FFontHeight * i), width, (FFontHeight * (i + 1))+1);
|
Canvas.Rectangle(0, (FFontHeight * i), width, (FFontHeight * (i + 1))+1);
|
||||||
@ -673,38 +687,38 @@ begin
|
|||||||
Hint := ItemList[Position];
|
Hint := ItemList[Position];
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Begin
|
begin
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
Canvas.Brush.Color := BackgroundColor;
|
Canvas.Brush.Color := BackgroundColor;
|
||||||
Canvas.Font.Color := TextColor;
|
Canvas.Font.Color := TextColor;
|
||||||
Canvas.FillRect(Rect(0, (FFontHeight * i), width, (FFontHeight * (i + 1))+1));
|
Canvas.FillRect(Rect(0, (FFontHeight * i), width, (FFontHeight * (i + 1))+1));
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Canvas.Brush.Color := Color;
|
Canvas.Brush.Color := Color;
|
||||||
Canvas.Font.Color := clBlack;
|
Canvas.Font.Color := clBlack;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//DebugLn(['TSynBaseCompletionForm.Paint ',i,' ',ItemList[Scroll.Position + i]]);
|
//DebugLn(['TSynBaseCompletionForm.Paint ',i,' ',ItemList[Scroll.Position + i]]);
|
||||||
if not Assigned(OnPaintItem)
|
if not Assigned(OnPaintItem) or
|
||||||
or not OnPaintItem(ItemList[Scroll.Position + i], Canvas,
|
not OnPaintItem(ItemList[Scroll.Position + i], Canvas,
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
0, FFontHeight * i, i + Scroll.Position = Position,
|
0, FFontHeight * i, i + Scroll.Position = Position,
|
||||||
i + Scroll.Position
|
i + Scroll.Position
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
0, FFontHeight * i
|
0, FFontHeight * i
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
)
|
) then
|
||||||
then
|
begin
|
||||||
Begin
|
Canvas.TextOut(2, FFontHeight * i, ItemList[Scroll.Position + i]);
|
||||||
Canvas.TextOut(2, FFontHeight * i, ItemList[Scroll.Position + i]);
|
end;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
// paint the rest of the background
|
// paint the rest of the background
|
||||||
if NbLinesInWindow > ItemList.Count then begin
|
if NbLinesInWindow > ItemList.Count - Scroll.Position then
|
||||||
canvas.brush.color := color;
|
begin
|
||||||
|
Canvas.brush.color := color;
|
||||||
i:=(FFontHeight * ItemList.Count)+1;
|
i:=(FFontHeight * ItemList.Count)+1;
|
||||||
canvas.FillRect(Rect(0, i, Width, Height));
|
Canvas.FillRect(Rect(0, i, Width, Height));
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
@ -726,7 +740,8 @@ procedure TSynBaseCompletionForm.ScrollChange(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
if Position < Scroll.Position then
|
if Position < Scroll.Position then
|
||||||
Position := Scroll.Position
|
Position := Scroll.Position
|
||||||
else if Position > Scroll.Position + NbLinesInWindow - 1 then
|
else
|
||||||
|
if Position > Scroll.Position + NbLinesInWindow - 1 then
|
||||||
Position := Scroll.Position + NbLinesInWindow - 1;
|
Position := Scroll.Position + NbLinesInWindow - 1;
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
@ -736,6 +751,13 @@ begin
|
|||||||
ActiveControl := nil;
|
ActiveControl := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSynBaseCompletionForm.ScrollScroll(Sender: TObject; ScrollCode: TScrollCode;
|
||||||
|
var ScrollPos: Integer);
|
||||||
|
begin
|
||||||
|
if ScrollPos > (Scroll.Max - Scroll.PageSize) + 1 then
|
||||||
|
ScrollPos := Scroll.Max - Scroll.PageSize + 1;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSynBaseCompletionForm.SelectNext;
|
procedure TSynBaseCompletionForm.SelectNext;
|
||||||
begin
|
begin
|
||||||
if Position < ItemList.Count - 1 then
|
if Position < ItemList.Count - 1 then
|
||||||
|
Loading…
Reference in New Issue
Block a user