1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
{%MainUnit ../forms.pp}
{
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
{ TCustomDesignControl }
constructor TCustomDesignControl.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FScaled := True;
FDesignTimePPI := 96;
FPixelsPerInch := FDesignTimePPI;
if Application.Scaled then
Font.PixelsPerInch := FDesignTimePPI;
end;
procedure TCustomDesignControl.AutoAdjustLayout(AMode: TLayoutAdjustmentPolicy;
const AFromPPI, AToPPI, AOldFormWidth, ANewFormWidth: Integer);
begin
if (AMode = lapAutoAdjustForDPI) and (AToPPI=FPixelsPerInch) then // don't do anything if FPixelsPerInch already is AToPPI
Exit;
// override AFromPPI with FPixelsPerInch - it is needed e.g. when a frame is placed on form
// - the frame can have a different PPI than the parent form.
// See issue #36370
inherited AutoAdjustLayout(AMode, FPixelsPerInch, AToPPI, AOldFormWidth, ANewFormWidth);
if AMode = lapAutoAdjustForDPI then
FPixelsPerInch := AToPPI;
end;
function TCustomDesignControl.DesignTimePPIIsStored: Boolean;
begin
if Assigned(Owner) then
Result := False // inplace frames do not store DesignTimePPI - always the parent's DesignTimePPI is used
else
Result := FDesignTimePPI<>96;
end;
procedure TCustomDesignControl.DoAutoAdjustLayout(
const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double
);
var
NewWidth, NewHeight: Integer;
begin
if Assigned(Parent) then
begin
inherited;
Exit;
end;
// Apply the changes
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin
NewWidth := Round(Width*AXProportion);
NewHeight := Round(Height*AYProportion);
BorderSpacing.AutoAdjustLayout(AXProportion, AYProportion);
Constraints.AutoAdjustLayout(AXProportion, AYProportion);
SetBounds(Left, Top, NewWidth, NewHeight);
end;
end;
procedure TCustomDesignControl.SetDesignTimePPI(const ADesignTimePPI: Integer);
begin
if FDesignTimePPI=ADesignTimePPI then
Exit;
FDesignTimePPI := ADesignTimePPI;
if csLoading in ComponentState then
FPixelsPerInch := FDesignTimePPI; // set FPixelsPerInch in LFM loading
end;
procedure TCustomDesignControl.SetScaled(const AScaled: Boolean);
begin
if FScaled=AScaled then
Exit;
FScaled := AScaled;
if not FScaled then
Font.PixelsPerInch := Screen.PixelsPerInch;
end;
|