synedit: high-DPI: implement DoAutoAdjustLayout. issue #31753

git-svn-id: trunk@55675 -
This commit is contained in:
ondrej 2017-08-17 10:39:39 +00:00
parent f215e1f571
commit 3f21545b7d
4 changed files with 62 additions and 18 deletions

View File

@ -784,6 +784,8 @@ type
property PaintLockOwner: TSynEditBase read GetPaintLockOwner write SetPaintLockOwner; property PaintLockOwner: TSynEditBase read GetPaintLockOwner write SetPaintLockOwner;
property TextDrawer: TheTextDrawer read fTextDrawer; property TextDrawer: TheTextDrawer read fTextDrawer;
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double); override;
protected protected
procedure CreateHandle; override; procedure CreateHandle; override;
procedure CreateParams(var Params: TCreateParams); override; procedure CreateParams(var Params: TCreateParams); override;
@ -8229,6 +8231,19 @@ begin
inherited DestroyWnd; inherited DestroyWnd;
end; end;
procedure TCustomSynEdit.DoAutoAdjustLayout(
const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double
);
begin
inherited DoAutoAdjustLayout(AMode, AXProportion, AYProportion);
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin
FLeftGutter.ScalePPI(AXProportion);
FRightGutter.ScalePPI(AXProportion);
end;
end;
procedure TCustomSynEdit.DoBlockIndent; procedure TCustomSynEdit.DoBlockIndent;
var var
BB,BE : TPoint; BB,BE : TPoint;

View File

@ -71,6 +71,7 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure Assign(Source: TPersistent); override; procedure Assign(Source: TPersistent); override;
procedure RecalcBounds; procedure RecalcBounds;
procedure ScalePPI(const AScaleFactor: Double);
function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo; function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean; virtual; HandleActionProc: TSynEditMouseActionHandler): Boolean; virtual;
procedure ResetMouseActions; virtual; // set mouse-actions according to current Options / may clear them procedure ResetMouseActions; virtual; // set mouse-actions according to current Options / may clear them
@ -190,6 +191,7 @@ type
property Height:Integer read FHeight; property Height:Integer read FHeight;
procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer); procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer);
virtual abstract; virtual abstract;
procedure ScalePPI(const AScaleFactor: Double); virtual;
public public
// X/Y are relative to the gutter, not the gutter part // X/Y are relative to the gutter, not the gutter part
function HasCustomPopupMenu(out PopMenu: TPopupMenu): Boolean; virtual; function HasCustomPopupMenu(out PopMenu: TPopupMenu): Boolean; virtual;
@ -322,6 +324,14 @@ begin
FMouseActions.ResetUserActions; FMouseActions.ResetUserActions;
end; end;
procedure TSynGutterBase.ScalePPI(const AScaleFactor: Double);
var
I: Integer;
begin
for I := 0 to PartCount-1 do
Parts[I].ScalePPI(AScaleFactor);
end;
procedure TSynGutterBase.RegisterResizeHandler(AHandler: TNotifyEvent); procedure TSynGutterBase.RegisterResizeHandler(AHandler: TNotifyEvent);
begin begin
FOnResizeHandler.Add(TMethod(AHandler)); FOnResizeHandler.Add(TMethod(AHandler));
@ -745,6 +755,11 @@ begin
FMouseActions.ResetUserActions; FMouseActions.ResetUserActions;
end; end;
procedure TSynGutterPartBase.ScalePPI(const AScaleFactor: Double);
begin
Width := Round(Width*AScaleFactor);
end;
procedure TSynGutterPartBase.DoOnGutterClick(X, Y : integer); procedure TSynGutterPartBase.DoOnGutterClick(X, Y : integer);
begin begin
if Assigned(FOnGutterClick) then if Assigned(FOnGutterClick) then

View File

@ -98,6 +98,7 @@ type
function DoHandleMouseAction(AnAction: TSynEditMouseAction; function DoHandleMouseAction(AnAction: TSynEditMouseAction;
var AnInfo: TSynEditMouseActionInfo): Boolean; override; var AnInfo: TSynEditMouseActionInfo): Boolean; override;
procedure ResetMouseActions; override; // set mouse-actions according to current Options / may clear them procedure ResetMouseActions; override; // set mouse-actions according to current Options / may clear them
procedure ScalePPI(const AScaleFactor: Double); override;
published published
property MarkupInfo; property MarkupInfo;
property MouseActionsExpanded: TSynEditMouseActions property MouseActionsExpanded: TSynEditMouseActions
@ -484,11 +485,17 @@ begin
FMouseActionsCollapsed.ResetUserActions; FMouseActionsCollapsed.ResetUserActions;
end; end;
procedure TSynGutterCodeFolding.ScalePPI(const AScaleFactor: Double);
begin
AutoSize := False;
inherited ScalePPI(AScaleFactor);
end;
procedure TSynGutterCodeFolding.DrawNodeSymbol(Canvas: TCanvas; Rect: TRect; procedure TSynGutterCodeFolding.DrawNodeSymbol(Canvas: TCanvas; Rect: TRect;
NodeType: TSynEditFoldLineCapability; SubType: TDrawNodeSymbolOptions); NodeType: TSynEditFoldLineCapability; SubType: TDrawNodeSymbolOptions);
var var
Points: Array [0..3] of TPoint; Points: Array [0..3] of TPoint;
X, Y: Integer; X, Y, LineBorder: Integer;
AliasMode: TAntialiasingMode; AliasMode: TAntialiasingMode;
OdlCosmetic: Boolean; OdlCosmetic: Boolean;
begin begin
@ -506,6 +513,7 @@ begin
Canvas.Rectangle(Rect); Canvas.Rectangle(Rect);
Canvas.Pen.Style := psSolid; Canvas.Pen.Style := psSolid;
Canvas.Pen.Cosmetic := OdlCosmetic; Canvas.Pen.Cosmetic := OdlCosmetic;
LineBorder := Round((Rect.Right-Rect.Left) / 5);
X := (Rect.Left - 1 + Rect.Right) div 2; X := (Rect.Left - 1 + Rect.Right) div 2;
Y := (Rect.Top - 1 + Rect.Bottom) div 2; Y := (Rect.Top - 1 + Rect.Bottom) div 2;
@ -513,8 +521,8 @@ begin
cfFoldStart: cfFoldStart:
begin begin
// [-] // [-]
Canvas.MoveTo(X - 2, Y); Canvas.MoveTo(Rect.Left + LineBorder, Y);
Canvas.LineTo(X + 3, Y); Canvas.LineTo(Rect.Right - LineBorder, Y);
end; end;
cfHideStart: cfHideStart:
begin begin
@ -525,10 +533,10 @@ begin
cfCollapsedFold: cfCollapsedFold:
begin begin
// [+] // [+]
Canvas.MoveTo(X - 2, Y); Canvas.MoveTo(Rect.Left + LineBorder, Y);
Canvas.LineTo(X + 3, Y); Canvas.LineTo(Rect.Right - LineBorder, Y);
Canvas.MoveTo(X, Y - 2); Canvas.MoveTo(X, Rect.Top + LineBorder);
Canvas.LineTo(X, Y + 3); Canvas.LineTo(X, Rect.Bottom - LineBorder);
end; end;
cfCollapsedHide: cfCollapsedHide:
begin begin
@ -536,24 +544,22 @@ begin
false: begin false: begin
// [v] // [v]
Points[0].X := X; Points[0].X := X;
Points[0].y := Y + 2; Points[0].y := Rect.Bottom - LineBorder - 1;
Points[1].X := X - 2; Points[1].X := Rect.Left + LineBorder;
Points[1].y := Y; Points[1].y := Y;
Points[2].X := X + 2; Points[2].X := Rect.Right - LineBorder - 1;
Points[2].y := Y; Points[2].y := Y;
Points[3].X := X; Points[3] := Points[0];
Points[3].y := Y + 2;
end; end;
true: begin true: begin
// [v] // [v]
Points[0].X := X; Points[0].X := X;
Points[0].y := Y - 2; Points[0].y := Rect.Top + LineBorder;
Points[1].X := X - 2; Points[1].X := Rect.Left + LineBorder;
Points[1].y := Y; Points[1].y := Y;
Points[2].X := X + 2; Points[2].X := Rect.Right - LineBorder - 1;
Points[2].y := Y; Points[2].y := Y;
Points[3].X := X; Points[3] := Points[0];
Points[3].y := Y - 2;
end; end;
end; end;
Canvas.Polygon(Points); Canvas.Polygon(Points);

View File

@ -319,6 +319,7 @@ type
procedure Assign(Source: TPersistent); override; procedure Assign(Source: TPersistent); override;
procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer); override; procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer); override;
procedure AddMark(AMark: TSynGutterLOvMark); procedure AddMark(AMark: TSynGutterLOvMark);
procedure ScalePPI(const AScaleFactor: Double); override;
function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo; function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean; override; HandleActionProc: TSynEditMouseActionHandler): Boolean; override;
@ -1041,7 +1042,7 @@ var
begin begin
if FFirstTextLineChanged > 0 then ReScan; if FFirstTextLineChanged > 0 then ReScan;
AClip.Right := AClip.Left + 3; AClip.Right := Round((AClip.Right - AClip.Left) / 3);
i := AClip.Top - TopOffset; i := AClip.Top - TopOffset;
imax := AClip.Bottom - TopOffset; imax := AClip.Bottom - TopOffset;
if imax > high(FPixLineStates) then imax := high(FPixLineStates); if imax > high(FPixLineStates) then imax := high(FPixLineStates);
@ -1541,6 +1542,13 @@ begin
Result := 10; Result := 10;
end; end;
procedure TSynGutterLineOverview.ScalePPI(const AScaleFactor: Double);
begin
AutoSize := False;
FLineMarks.ItemHeight := Round(FLineMarks.ItemHeight*AScaleFactor);
inherited ScalePPI(AScaleFactor);
end;
procedure TSynGutterLineOverview.Assign(Source : TPersistent); procedure TSynGutterLineOverview.Assign(Source : TPersistent);
begin begin
if Assigned(Source) and (Source is TSynGutterLineOverview) then if Assigned(Source) and (Source is TSynGutterLineOverview) then