Skip to content

Commit

Permalink
Mantis #6615: JvProgramVersionCheck and JvParameterList are not DPI a…
Browse files Browse the repository at this point in the history
…ware
  • Loading branch information
ahausladen committed Jan 30, 2018
1 parent 6232ba1 commit 4dc565b
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 74 deletions.
78 changes: 44 additions & 34 deletions jvcl/run/JvParameterList.pas
Expand Up @@ -532,6 +532,14 @@ implementation
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_');


//=== { Support function for DPI Aware apps } ================================

function PPIScale(Value: Integer): Integer;
begin
Result := MulDiv(Value, Screen.PixelsPerInch, 96);
end;

//=== { TJvParameterListMessages } ===========================================

constructor TJvParameterListMessages.Create;
Expand Down Expand Up @@ -1241,15 +1249,15 @@ constructor TJvParameterList.Create(AOwner: TComponent);
FArrangeSettings.AutoArrange := True;
FArrangeSettings.WrapControls := True;
FArrangeSettings.AutoSize := asBoth;
FArrangeSettings.DistanceVertical := 3;
FArrangeSettings.DistanceHorizontal := 3;
FArrangeSettings.BorderLeft := 5;
FArrangeSettings.BorderTop := 5;
FArrangeSettings.DistanceVertical := PPIScale(3);
FArrangeSettings.DistanceHorizontal := PPIScale(3);
FArrangeSettings.BorderLeft := PPIScale(5);
FArrangeSettings.BorderTop := PPIScale(5);
ScrollBox := nil;
RightPanel := nil;
ArrangePanel := nil;
FMaxWidth := 600;
FMaxHeight := 400;
FMaxWidth := PPIScale(600);
FMaxHeight := PPIScale(400);
FDefaultParameterHeight := 0;
FDefaultParameterWidth := 0;
FDefaultParameterLabelWidth := 0;
Expand Down Expand Up @@ -1507,7 +1515,7 @@ procedure TJvParameterList.CreateParameterDialog;
TForm(ParameterDialog).Position := poOwnerFormCenter;
{$ELSE}
TForm(ParameterDialog).Position := poScreenCenter;
{$ENDIF COMPILER7_UP};
{$ENDIF COMPILER7_UP};
TForm(ParameterDialog).ShowHint := True;
TForm(ParameterDialog).OnShow := DialogShow;

Expand All @@ -1524,7 +1532,7 @@ procedure TJvParameterList.CreateParameterDialog;
MainPanel := DynControlEngine.CreatePanelControl(Self, ParameterDialog, 'MainPanel', '', alClient);
if not Supports(MainPanel, IJvDynControlPanel, ITmpPanel) then
raise EIntfCastError.CreateRes(@RsEIntfCastError);
ITmpPanel.ControlSetBorder(bvNone, bvRaised, 1, bsNone, 3);
ITmpPanel.ControlSetBorder(bvNone, bvRaised, 1, bsNone, PPIScale(3));

ButtonPanel := DynControlEngine.CreatePanelControl(Self, BottomPanel, 'BottonPanel', '',
alRight);
Expand All @@ -1538,26 +1546,28 @@ procedure TJvParameterList.CreateParameterDialog;
Messages.CancelButton, '',
OnCancelButtonClick, False, True);

BottomPanel.Height := OkButton.Height + 6 + 2;
BottomPanel.Height := PPIScale(22) + PPIScale(6 + 2);

OkButton.Top := 3;
OkButton.Left := 3;
OkButton.Top := PPIScale(3);
OkButton.Left := PPIScale(3);
OkButton.Visible := OkButtonVisible;
OkButton.Enabled := OkButtonVisible;
OkButton.Height := PPIScale(22);
if OkButton.Visible then
ButtonLeft := OkButton.Left + OkButton.Width + 3
ButtonLeft := OkButton.Left + OkButton.Width + PPIScale(3)
else
ButtonLeft := 0;

CancelButton.Top := 3;
CancelButton.Left := ButtonLeft + 3;
CancelButton.Top := PPIScale(3);
CancelButton.Left := ButtonLeft + PPIScale(3);
CancelButton.Visible := CancelButtonVisible;
CancelButton.Enabled := CancelButtonVisible;
CancelButton.Height := PPIScale(22);
if CancelButton.Visible then
ButtonLeft := ButtonLeft + 3 + CancelButton.Width + 3;
ButtonLeft := ButtonLeft + PPIScale(3) + CancelButton.Width + PPIScale(3);

ButtonPanel.Width := ButtonLeft + 3;
OrgButtonPanelWidth := ButtonLeft + 3;
ButtonPanel.Width := ButtonLeft + PPIScale(3);
OrgButtonPanelWidth := ButtonLeft + PPIScale(3);

OkButton.Anchors := [akTop, akRight];
CancelButton.Anchors := [akTop, akRight];
Expand All @@ -1569,35 +1579,35 @@ procedure TJvParameterList.CreateParameterDialog;
if not Supports(HistoryPanel, IJvDynControlPanel, ITmpPanel) then
raise EIntfCastError.CreateRes(@RsEIntfCastError);
ITmpPanel.ControlSetBorder(bvNone, bvNone, 0, bsNone, 0);
HistoryPanel.Height := 25;
HistoryPanel.Height := PPIScale(25);
LoadButton := DynControlEngine.CreateButton(Self, HistoryPanel, 'LoadButton',
Messages.HistoryLoadButton, '',
HistoryLoadClick, False, False);
LoadButton.Left := 6;
LoadButton.Top := 5;
LoadButton.Height := 20;
LoadButton.Left := PPIScale(6);
LoadButton.Top := PPIScale(5);
LoadButton.Height := PPIScale(20);
LoadButton.Width :=
TCustomControlAccessProtected(HistoryPanel).Canvas.TextWidth(Messages.HistoryLoadButton) + 5;
ButtonLeft := LoadButton.Left + LoadButton.Width + 5;
SaveButton := DynControlEngine.CreateButton(Self, HistoryPanel, 'SaveButton',
Messages.HistorySaveButton, '',
HistorySaveClick, False, False);
SaveButton.Left := ButtonLeft;
SaveButton.Top := 5;
SaveButton.Height := 20;
SaveButton.Top := PPIScale(5);
SaveButton.Height := PPIScale(20);
SaveButton.Width :=
TCustomControlAccessProtected(HistoryPanel).Canvas.TextWidth(Messages.HistorySaveButton) + 5;
ButtonLeft := SaveButton.Left + SaveButton.Width + 5;
ClearButton := DynControlEngine.CreateButton(Self, HistoryPanel, 'ClearButton',
Messages.HistoryClearButton, '',
HistoryClearClick, False, False);
ClearButton.Left := ButtonLeft;
ClearButton.Top := 5;
ClearButton.Height := 20;
ClearButton.Top := PPIScale(5);
ClearButton.Height := PPIScale(20);
ClearButton.Width :=
TCustomControlAccessProtected(HistoryPanel).Canvas.TextWidth(Messages.HistoryClearButton) +
5;
ButtonLeft := ClearButton.Left + ClearButton.Width + 5;
PPIScale(5);
ButtonLeft := ClearButton.Left + ClearButton.Width + PPIScale(5);
HistoryPanel.Width := ButtonLeft;
OrgHistoryPanelWidth := ButtonLeft;
end
Expand All @@ -1618,9 +1628,9 @@ procedure TJvParameterList.ResizeDialogAfterArrange(Sender: TObject; nLeft, nTop
if ArrangePanel.Width > MaxWidth then
TForm(ParameterDialog).ClientWidth := MaxWidth
else
TForm(ParameterDialog).ClientWidth := ArrangePanel.Width + 5
TForm(ParameterDialog).ClientWidth := ArrangePanel.Width + PPIScale(5)
else
TForm(ParameterDialog).ClientWidth := ArrangePanel.Width + 5;
TForm(ParameterDialog).ClientWidth := ArrangePanel.Width + PPIScale(5);
if Assigned(HistoryPanel) and
(TForm(ParameterDialog).ClientWidth < HistoryPanel.Width) then
TForm(ParameterDialog).ClientWidth := HistoryPanel.Width
Expand All @@ -1631,17 +1641,17 @@ procedure TJvParameterList.ResizeDialogAfterArrange(Sender: TObject; nLeft, nTop
if ArrangePanel.Height + BottomPanel.Height > MaxHeight then
TForm(ParameterDialog).ClientHeight := MaxHeight + 10
else
TForm(ParameterDialog).ClientHeight := ArrangePanel.Height + BottomPanel.Height + 10
TForm(ParameterDialog).ClientHeight := ArrangePanel.Height + BottomPanel.Height + PPIScale(10)
else
TForm(ParameterDialog).ClientHeight := ArrangePanel.Height + BottomPanel.Height + 10;
TForm(ParameterDialog).ClientHeight := ArrangePanel.Height + BottomPanel.Height + PPIScale(10);
end;

if Assigned(HistoryPanel) then
if (OrgButtonPanelWidth + OrgHistoryPanelWidth) > BottomPanel.Width then
begin
ButtonPanel.Align := alBottom;
ButtonPanel.Height := OkButton.Height + 6 + 2;
BottomPanel.Height := ButtonPanel.Height * 2 + 1;
ButtonPanel.Height := OkButton.Height + PPIScale(6 + 2);
BottomPanel.Height := ButtonPanel.Height * 2 + PPIScale(1);
HistoryPanel.Align := alClient;
end
else
Expand All @@ -1650,7 +1660,7 @@ procedure TJvParameterList.ResizeDialogAfterArrange(Sender: TObject; nLeft, nTop
ButtonPanel.Width := OrgButtonPanelWidth;
HistoryPanel.Align := alLeft;
HistoryPanel.Width := OrgHistoryPanelWidth;
BottomPanel.Height := OkButton.Height + 6 + 2;
BottomPanel.Height := OkButton.Height + PPIScale(6 + 2);
end;
CheckScrollBoxAutoScroll;
end;
Expand Down
55 changes: 32 additions & 23 deletions jvcl/run/JvParameterListParameter.pas
Expand Up @@ -29,6 +29,7 @@
interface

uses
Windows,
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Expand Down Expand Up @@ -661,6 +662,13 @@ implementation
uses
JvResources, JvJVCLUtils, JclSysUtils;

//=== { Support function for DPI Aware apps } ================================

function PPIScale(Value: Integer): Integer;
begin
Result := MulDiv(Value, Screen.PixelsPerInch, 96);
end;

function DSADialogsMessageDlg(const Msg: string; const DlgType: TMsgDlgType; const Buttons: TMsgDlgButtons;
const HelpCtx: Longint; const Center: TDlgCenterKind = dckScreen; const Timeout: Integer = 0;
const DefaultButton: TMsgDlgBtn = mbDefault; const CancelButton: TMsgDlgBtn = mbDefault;
Expand Down Expand Up @@ -730,6 +738,7 @@ procedure TJvButtonParameter.CreateWinControlOnParent(ParameterParent: TWinContr
GetParameterName, Caption, Hint, Click, False, False);
Button.Action := Action;
SetWinControl (Button);
WinControl.Height := PPIScale(WinControl.Height);
if Height > 0 then
WinControl.Height := Height;
if Width > 0 then
Expand Down Expand Up @@ -862,7 +871,7 @@ procedure TJvBasePanelEditParameter.ArrangeLabelAndWinControlOnPanelBefore;
DynCtrlFont.ControlFont, Caption+'X');

t := LabelControl.Top;
l := LabelControl.Left + LabelControl.Width + 4;
l := LabelControl.Left + LabelControl.Width + PPIScale(4);

if Height > 0 then
h := Height
Expand All @@ -889,25 +898,25 @@ procedure TJvBasePanelEditParameter.ArrangeLabelAndWinControlOnPanelGroupBox;
var
l, t, w, h: Integer;
begin
t := 16;
l := 5;
t := PPIScale(16);
l := PPIScale(5);

if Height > 0 then
h := Height - 20
h := Height - PPIScale(20)
else
h := fOrgWinControlHeight;

if EditWidth > 0 then
w := EditWidth
else if Width > 0 then
w := Width - 9
w := Width - PPIScale(9)
else
w := 0;

ArrangeWinControlsonPanel(l, t, w, h);

FrameControl.Height := h + 20;
FrameControl.Width := w + 9;
FrameControl.Height := h + PPIScale(20);
FrameControl.Width := w + PPIScale(9);
end;

procedure TJvBasePanelEditParameter.ArrangeLabelAndWinControlOnPanelNone;
Expand Down Expand Up @@ -949,8 +958,8 @@ procedure TJvBasePanelEditParameter.ArrangeWinControlsonPanel(iLeft, iTop:
FBeforeParameterControl.Left := l;
FBeforeParameterControl.Top := iTop;
FBeforeParameterControl.Height := iHeight;
l := FBeforeParameterControl.Left + FBeforeParameterControl.Width+ Space;
w := w + FBeforeParameterControl.Width+ Space;
l := FBeforeParameterControl.Left + FBeforeParameterControl.Width+ PPIScale(Space);
w := w + FBeforeParameterControl.Width+ PPIScale(Space);
end;
WinControl.Left := l;
WinControl.Top := iTop;
Expand All @@ -959,18 +968,18 @@ procedure TJvBasePanelEditParameter.ArrangeWinControlsonPanel(iLeft, iTop:
begin
WinControl.Width := iWidth-l+iLeft;
if Assigned (FAfterParameterControl) then
WinControl.Width := WinControl.Width - (FAfterParameterControl.Width + Space);
WinControl.Width := WinControl.Width - (FAfterParameterControl.Width + PPIScale(Space));
end
else
WinControl.Width := FOrgWinControlWidth;
w := w + WinControl.Width;
if Assigned(FAfterParameterControl) then
begin
l := WinControl.Left + WinControl.Width + Space;
l := WinControl.Left + WinControl.Width + PPIScale(Space);
FAfterParameterControl.Left := l;
FAfterParameterControl.Top := iTop;
FAfterParameterControl.Height := iHeight;
w := w + FAfterParameterControl.Width+ Space;
w := w + FAfterParameterControl.Width+ PPIScale(Space);
end;
iWidth := w;
end;
Expand Down Expand Up @@ -1066,7 +1075,7 @@ procedure TJvBasePanelEditParameter.CreateLabelControl(AParameterParent: TWinCon
IDynAutoSize.ControlSetAutosize(False);
end
else
LabelControl.Height := 16;
LabelControl.Height := PPIScale(16);

end;

Expand Down Expand Up @@ -1252,10 +1261,10 @@ constructor TJvArrangeParameter.Create(AParameterList: TJvParameterList);
begin
inherited Create(AParameterList);
FArrangeSettings := TJvArrangeSettings.Create(Self);
FArrangeSettings.BorderLeft := 2;
FArrangeSettings.BorderTop := 2;
FArrangeSettings.DistanceVertical := 2;
FArrangeSettings.DistanceHorizontal := 2;
FArrangeSettings.BorderLeft := PPIScale(2);
FArrangeSettings.BorderTop := PPIScale(2);
FArrangeSettings.DistanceVertical := PPIScale(2);
FArrangeSettings.DistanceHorizontal := PPIScale(2);
FArrangeSettings.AutoArrange := True;
end;

Expand Down Expand Up @@ -1395,9 +1404,9 @@ procedure TJvGroupBoxParameter.CreateWinControlOnParent(ParameterParent: TWinCon
procedure TJvGroupBoxParameter.ReArrangeGroupbox(Sender: TObject; nLeft, nTop, nWidth, nHeight: Integer);
begin
if ArrangeSettings.AutoSize in [asWidth, asBoth] then
WinControl.Width := nWidth + 5;
WinControl.Width := nWidth + PPIScale(5);
if ArrangeSettings.AutoSize in [asHeight, asBoth] then
WinControl.Height := nHeight + 22;
WinControl.Height := nHeight + PPIScale(22);
end;

procedure TJvGroupBoxParameter.SetWinControlProperties;
Expand Down Expand Up @@ -2678,11 +2687,11 @@ procedure TJvPageControlParameter.RearrangePageControl(Sender: TObject; nLeft,
if Assigned(Sender) and (Sender is TWinControl) then
begin
if (ArrangeSettings.AutoSize in [asWidth, asBoth])
and (TWinControl(Sender).Width <> nWidth + 5) then
TWinControl(Sender).Width := nWidth + 5;
and (TWinControl(Sender).Width <> nWidth + PPIScale(5)) then
TWinControl(Sender).Width := nWidth + PPIScale(5);
if (ArrangeSettings.AutoSize in [asHeight, asBoth])
and (TWinControl(Sender).Height <> nHeight + 45) then
TWinControl(Sender).Height := nHeight + 45;
and (TWinControl(Sender).Height <> nHeight + PPIScale(45)) then
TWinControl(Sender).Height := nHeight + PPIScale(45);
end;
end;

Expand Down

2 comments on commit 4dc565b

@AndyTheFactory
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JvProgramVersionCheck.pas has now a BOM and therefore it does not compile in Delphi 7

totalcmd64_2018-03-05_15-52-16

@ahausladen
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now fixed.

Please sign in to comment.