mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 13:50:06 +02:00
SynCompletion: added optional ability to resize form. issue #0016835
git-svn-id: trunk@27998 -
This commit is contained in:
parent
916a04d8ec
commit
165f3a6807
@ -88,6 +88,20 @@ type
|
|||||||
sclpExtendUnlimitedLeft
|
sclpExtendUnlimitedLeft
|
||||||
);
|
);
|
||||||
|
|
||||||
|
{ TSynBaseCompletionFormSizeDrag }
|
||||||
|
|
||||||
|
TSynBaseCompletionFormSizeDrag = class(TPanel)
|
||||||
|
private
|
||||||
|
FMouseDownPos, FMouseLastPos, FWinSize: TPoint;
|
||||||
|
protected
|
||||||
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
||||||
|
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
||||||
|
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
||||||
|
public
|
||||||
|
constructor Create(TheOwner: TComponent); override;
|
||||||
|
procedure Paint; override;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TSynBaseCompletionForm }
|
{ TSynBaseCompletionForm }
|
||||||
|
|
||||||
TSynBaseCompletionForm = class(TForm)
|
TSynBaseCompletionForm = class(TForm)
|
||||||
@ -102,6 +116,7 @@ type
|
|||||||
FFontHeight: integer;
|
FFontHeight: integer;
|
||||||
FResizeLock: Integer;
|
FResizeLock: Integer;
|
||||||
Scroll: TScrollBar;
|
Scroll: TScrollBar;
|
||||||
|
SizeDrag: TSynBaseCompletionFormSizeDrag;
|
||||||
FOnValidate: TValidateEvent;
|
FOnValidate: TValidateEvent;
|
||||||
FOnCancel: TNotifyEvent;
|
FOnCancel: TNotifyEvent;
|
||||||
FClSelect: TColor;
|
FClSelect: TColor;
|
||||||
@ -143,12 +158,15 @@ type
|
|||||||
private
|
private
|
||||||
fCurrentEditor: TComponent;
|
fCurrentEditor: TComponent;
|
||||||
FDrawBorderWidth: Integer;
|
FDrawBorderWidth: Integer;
|
||||||
|
FOnDragResized: TNotifyEvent;
|
||||||
FOnMeasureItem: TSynBaseCompletionMeasureItem;
|
FOnMeasureItem: TSynBaseCompletionMeasureItem;
|
||||||
FOnPositionChanged: TNotifyEvent;
|
FOnPositionChanged: TNotifyEvent;
|
||||||
|
FShowSizeDrag: Boolean;
|
||||||
procedure SetCurrentEditor(const AValue: TComponent);
|
procedure SetCurrentEditor(const AValue: TComponent);
|
||||||
procedure SetDrawBorderWidth(const AValue: Integer);
|
procedure SetDrawBorderWidth(const AValue: Integer);
|
||||||
procedure SetLongLineHintTime(const AValue: Integer);
|
procedure SetLongLineHintTime(const AValue: Integer);
|
||||||
procedure EditorStatusChanged(Sender: TObject; Changes: TSynStatusChanges);
|
procedure EditorStatusChanged(Sender: TObject; Changes: TSynStatusChanges);
|
||||||
|
procedure SetShowSizeDrag(const AValue: Boolean);
|
||||||
protected
|
protected
|
||||||
procedure SetVisible(Value: Boolean); override;
|
procedure SetVisible(Value: Boolean); override;
|
||||||
property DrawBorderWidth: Integer read FDrawBorderWidth write SetDrawBorderWidth;
|
property DrawBorderWidth: Integer read FDrawBorderWidth write SetDrawBorderWidth;
|
||||||
@ -189,6 +207,8 @@ type
|
|||||||
write SetLongLineHintTime default 0;
|
write SetLongLineHintTime default 0;
|
||||||
property LongLineHintType: TSynCompletionLongHintType read FLongLineHintType
|
property LongLineHintType: TSynCompletionLongHintType read FLongLineHintType
|
||||||
write FLongLineHintType default sclpExtendRightOnly;
|
write FLongLineHintType default sclpExtendRightOnly;
|
||||||
|
property ShowSizeDrag: Boolean read FShowSizeDrag write SetShowSizeDrag default False;
|
||||||
|
property OnDragResized: TNotifyEvent read FOnDragResized write FOnDragResized;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TSynBaseCompletion }
|
{ TSynBaseCompletion }
|
||||||
@ -374,6 +394,75 @@ procedure PrettyTextOut(c: TCanvas; x, y: integer; s: string);
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
{ TSynBaseCompletionFormSizeDrag }
|
||||||
|
|
||||||
|
procedure TSynBaseCompletionFormSizeDrag.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
||||||
|
X, Y: Integer);
|
||||||
|
begin
|
||||||
|
inherited MouseDown(Button, Shift, X, Y);
|
||||||
|
FMouseDownPos.x := x + Left;
|
||||||
|
FMouseDownPos.y := y + Top;
|
||||||
|
FMouseLastPos.x := x + Left;
|
||||||
|
FMouseLastPos.y := y + Top;
|
||||||
|
FWinSize.x := TSynBaseCompletionForm(Owner).Width;
|
||||||
|
FWinSize.y := TSynBaseCompletionForm(Owner).Height;
|
||||||
|
MouseCapture := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSynBaseCompletionFormSizeDrag.MouseMove(Shift: TShiftState; X, Y: Integer);
|
||||||
|
var
|
||||||
|
F: TSynBaseCompletionForm;
|
||||||
|
begin
|
||||||
|
inherited MouseMove(Shift, X, Y);
|
||||||
|
x := x + Left;
|
||||||
|
y := y + Top;
|
||||||
|
if (FMouseDownPos.y < 0) or
|
||||||
|
((FMouseLastPos.x = x) and (FMouseLastPos.y = y))
|
||||||
|
then
|
||||||
|
exit;
|
||||||
|
FMouseLastPos.x := x;
|
||||||
|
FMouseLastPos.y := y;
|
||||||
|
|
||||||
|
F := TSynBaseCompletionForm(Owner);
|
||||||
|
F.Width :=
|
||||||
|
Max(FWinSize.x + x - FMouseDownPos.x, 100);
|
||||||
|
F.NbLinesInWindow :=
|
||||||
|
Max((FWinSize.y + y - FMouseDownPos.y) div F.FontHeight, 3);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSynBaseCompletionFormSizeDrag.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
|
||||||
|
Y: Integer);
|
||||||
|
begin
|
||||||
|
inherited MouseUp(Button, Shift, X, Y);
|
||||||
|
FMouseDownPos.y := -1;
|
||||||
|
MouseCapture := False;
|
||||||
|
|
||||||
|
if (FWinSize.x <> TSynBaseCompletionForm(Owner).Width) or
|
||||||
|
(FWinSize.y <> TSynBaseCompletionForm(Owner).Height)
|
||||||
|
then
|
||||||
|
TSynBaseCompletionForm(Owner).OnDragResized(Owner);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TSynBaseCompletionFormSizeDrag.Create(TheOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited Create(TheOwner);
|
||||||
|
FMouseDownPos.y := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSynBaseCompletionFormSizeDrag.Paint;
|
||||||
|
begin
|
||||||
|
Canvas.Brush.Color := clBtnFace;
|
||||||
|
Canvas.Brush.Style := bsSolid;
|
||||||
|
Canvas.FillRect(ClientRect);
|
||||||
|
Canvas.Pen.Color := clBtnShadow;
|
||||||
|
Canvas.MoveTo(ClientRect.Right-2, ClientRect.Bottom-1);
|
||||||
|
Canvas.LineTo(ClientRect.Right-1, ClientRect.Bottom-2);
|
||||||
|
Canvas.MoveTo(ClientRect.Right-5, ClientRect.Bottom-1);
|
||||||
|
Canvas.LineTo(ClientRect.Right-1, ClientRect.Bottom-5);
|
||||||
|
Canvas.MoveTo(ClientRect.Right-8, ClientRect.Bottom-1);
|
||||||
|
Canvas.LineTo(ClientRect.Right-1, ClientRect.Bottom-8);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TSynBaseCompletionForm }
|
{ TSynBaseCompletionForm }
|
||||||
|
|
||||||
constructor TSynBaseCompletionForm.Create(AOwner: TComponent);
|
constructor TSynBaseCompletionForm.Create(AOwner: TComponent);
|
||||||
@ -394,8 +483,33 @@ begin
|
|||||||
Scroll.OnScroll := {$IFDEF FPC}@{$ENDIF}ScrollScroll;
|
Scroll.OnScroll := {$IFDEF FPC}@{$ENDIF}ScrollScroll;
|
||||||
Scroll.TabStop := False;
|
Scroll.TabStop := False;
|
||||||
Scroll.Visible := True;
|
Scroll.Visible := True;
|
||||||
Scroll.Anchors:=[akTop,akRight];
|
//Scroll.Align:=alRight;
|
||||||
Scroll.Align:=alRight;
|
|
||||||
|
SizeDrag := TSynBaseCompletionFormSizeDrag.Create(Self);
|
||||||
|
SizeDrag.Parent := Self;
|
||||||
|
SizeDrag.BevelInner := bvNone;
|
||||||
|
SizeDrag.BevelOuter := bvNone;
|
||||||
|
SizeDrag.Caption := '';
|
||||||
|
SizeDrag.AutoSize := False;
|
||||||
|
SizeDrag.BorderStyle := bsNone;
|
||||||
|
SizeDrag.Anchors := [akBottom, akRight, akLeft];
|
||||||
|
SizeDrag.AnchorSideLeft.Side := asrTop;
|
||||||
|
SizeDrag.AnchorSideLeft.Control := Scroll;
|
||||||
|
SizeDrag.AnchorSideRight.Side := asrBottom;
|
||||||
|
SizeDrag.AnchorSideRight.Control := Self;
|
||||||
|
SizeDrag.AnchorSideBottom.Side := asrBottom;
|
||||||
|
SizeDrag.AnchorSideBottom.Control := Self;
|
||||||
|
SizeDrag.Height := Max(5, abs(Font.Height) * 2 div 3);
|
||||||
|
SizeDrag.Cursor := crSizeNWSE;
|
||||||
|
|
||||||
|
Scroll.Anchors:=[akTop,akRight, akBottom];
|
||||||
|
Scroll.AnchorSide[akTop].Side := asrTop;
|
||||||
|
Scroll.AnchorSide[akTop].Control := self;
|
||||||
|
Scroll.AnchorSide[akRight].Side := asrBottom;
|
||||||
|
Scroll.AnchorSide[akRight].Control := Self;
|
||||||
|
Scroll.AnchorSide[akBottom].Side := asrTop;
|
||||||
|
Scroll.AnchorSide[akBottom].Control := SizeDrag;
|
||||||
|
|
||||||
DrawBorderWidth := 1;
|
DrawBorderWidth := 1;
|
||||||
FTextColor:=clBlack;
|
FTextColor:=clBlack;
|
||||||
FTextSelectedColor:=clWhite;
|
FTextSelectedColor:=clWhite;
|
||||||
@ -433,7 +547,8 @@ end;
|
|||||||
|
|
||||||
destructor TSynBaseCompletionForm.Destroy;
|
destructor TSynBaseCompletionForm.Destroy;
|
||||||
begin
|
begin
|
||||||
Scroll.Free;
|
FreeAndNil(Scroll);
|
||||||
|
FreeAndNil(SizeDrag);
|
||||||
FItemList.Free;
|
FItemList.Free;
|
||||||
FHintTimer.Free;
|
FHintTimer.Free;
|
||||||
FHint.Free;
|
FHint.Free;
|
||||||
@ -599,8 +714,9 @@ end;
|
|||||||
|
|
||||||
procedure TSynBaseCompletionForm.MouseMove(Shift: TShiftState; X,Y: Integer);
|
procedure TSynBaseCompletionForm.MouseMove(Shift: TShiftState; X,Y: Integer);
|
||||||
begin
|
begin
|
||||||
|
if (Scroll.Visible) and (x > Scroll.Left) then
|
||||||
|
exit;
|
||||||
Y := (Y - 1) div FFontHeight;
|
Y := (Y - 1) div FFontHeight;
|
||||||
|
|
||||||
ShowItemHint(Scroll.Position + Y);
|
ShowItemHint(Scroll.Position + Y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -823,6 +939,7 @@ begin
|
|||||||
GetTextMetrics(Canvas.Handle, TextMetric);
|
GetTextMetrics(Canvas.Handle, TextMetric);
|
||||||
FFontHeight := TextMetric.tmHeight+2;
|
FFontHeight := TextMetric.tmHeight+2;
|
||||||
SetNblinesInWindow(FNbLinesInWindow);
|
SetNblinesInWindow(FNbLinesInWindow);
|
||||||
|
SizeDrag.Height := Max(5, Font.Height);
|
||||||
finally
|
finally
|
||||||
dec(FResizeLock);
|
dec(FResizeLock);
|
||||||
end;
|
end;
|
||||||
@ -842,6 +959,13 @@ begin
|
|||||||
OnCancel(Self);
|
OnCancel(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSynBaseCompletionForm.SetShowSizeDrag(const AValue: Boolean);
|
||||||
|
begin
|
||||||
|
if FShowSizeDrag = AValue then exit;
|
||||||
|
FShowSizeDrag := AValue;
|
||||||
|
SizeDrag.Visible := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSynBaseCompletionForm.SetCurrentEditor(const AValue: TComponent);
|
procedure TSynBaseCompletionForm.SetCurrentEditor(const AValue: TComponent);
|
||||||
begin
|
begin
|
||||||
if fCurrentEditor = AValue then exit;
|
if fCurrentEditor = AValue then exit;
|
||||||
@ -859,8 +983,9 @@ begin
|
|||||||
FDrawBorderWidth := AValue;
|
FDrawBorderWidth := AValue;
|
||||||
NbLinesInWindow := NbLinesInWindow;
|
NbLinesInWindow := NbLinesInWindow;
|
||||||
Scroll.BorderSpacing.Top := FDrawBorderWidth;
|
Scroll.BorderSpacing.Top := FDrawBorderWidth;
|
||||||
Scroll.BorderSpacing.Bottom := FDrawBorderWidth;
|
|
||||||
Scroll.BorderSpacing.Right := FDrawBorderWidth;
|
Scroll.BorderSpacing.Right := FDrawBorderWidth;
|
||||||
|
SizeDrag.BorderSpacing.Right := FDrawBorderWidth;
|
||||||
|
SizeDrag.BorderSpacing.Bottom := FDrawBorderWidth;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynBaseCompletionForm.SetVisible(Value: Boolean);
|
procedure TSynBaseCompletionForm.SetVisible(Value: Boolean);
|
||||||
|
Loading…
Reference in New Issue
Block a user