mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 23:59:27 +02:00
LCL/TaskDialog: Scaling of TaskDialog (some issues left)
This commit is contained in:
parent
11bb7ce45a
commit
ca1b88b2cf
@ -415,6 +415,10 @@ function DefaultFont: TFont;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
Dialogs,
|
||||||
|
ImgList;
|
||||||
|
|
||||||
var
|
var
|
||||||
LDefaultFont: TFont;
|
LDefaultFont: TFont;
|
||||||
|
|
||||||
@ -631,6 +635,7 @@ function TTaskDialog.Execute(aCommonButtons: TCommonButtons;
|
|||||||
aDialogIcon: TTaskDialogIcon; aFooterIcon: TTaskDialogFooterIcon;
|
aDialogIcon: TTaskDialogIcon; aFooterIcon: TTaskDialogFooterIcon;
|
||||||
aRadioDef, aWidth: integer; aParent: HWND; aNonNative: boolean;
|
aRadioDef, aWidth: integer; aParent: HWND; aNonNative: boolean;
|
||||||
aEmulateClassicStyle: boolean; aOnButtonClicked: TTaskDialogButtonClickedEvent): integer;
|
aEmulateClassicStyle: boolean; aOnButtonClicked: TTaskDialogButtonClickedEvent): integer;
|
||||||
|
|
||||||
function GetNextStringLineToWS(var P: PChar): WS;
|
function GetNextStringLineToWS(var P: PChar): WS;
|
||||||
var S: PChar;
|
var S: PChar;
|
||||||
tmp: string;
|
tmp: string;
|
||||||
@ -648,7 +653,9 @@ begin
|
|||||||
P := nil;
|
P := nil;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var aHint: string;
|
var aHint: string;
|
||||||
|
|
||||||
function NoCR(const aText: string): string;
|
function NoCR(const aText: string): string;
|
||||||
var i: integer;
|
var i: integer;
|
||||||
begin
|
begin
|
||||||
@ -702,13 +709,15 @@ var
|
|||||||
List: TStrings;
|
List: TStrings;
|
||||||
B: TCommonButton;
|
B: TCommonButton;
|
||||||
CommandLink: TBitBtn;
|
CommandLink: TBitBtn;
|
||||||
Rad: array of TRadioButton;
|
Rad: array of TRadioButton = nil;
|
||||||
|
|
||||||
function AddLabel(Text: string; BigFont: boolean): TLabel;
|
function AddLabel(Text: string; BigFont: boolean): TLabel;
|
||||||
var R: TRect;
|
var R: TRect;
|
||||||
W: integer;
|
W: integer;
|
||||||
begin
|
begin
|
||||||
result := TLabel.Create(Dialog.Form);
|
result := TLabel.Create(Dialog.Form);
|
||||||
result.Parent := Par;
|
result.Parent := Par;
|
||||||
|
result.Font.PixelsPerInch := 96;
|
||||||
result.WordWrap := true;
|
result.WordWrap := true;
|
||||||
if BigFont then begin
|
if BigFont then begin
|
||||||
if aEmulateClassicStyle then begin
|
if aEmulateClassicStyle then begin
|
||||||
@ -732,6 +741,7 @@ begin
|
|||||||
result.Caption := Text;
|
result.Caption := Text;
|
||||||
inc(Y,R.Bottom+16);
|
inc(Y,R.Bottom+16);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure AddBevel;
|
procedure AddBevel;
|
||||||
var BX: integer;
|
var BX: integer;
|
||||||
begin
|
begin
|
||||||
@ -744,6 +754,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
inc(Y,16);
|
inc(Y,16);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function AddButton(const s: string; ModalResult: integer): TButton;
|
function AddButton(const s: string; ModalResult: integer): TButton;
|
||||||
var WB: integer;
|
var WB: integer;
|
||||||
begin
|
begin
|
||||||
@ -755,9 +766,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
result := TButton.Create(Dialog.Form);
|
result := TButton.Create(Dialog.Form);
|
||||||
result.Parent := Par;
|
result.Parent := Par;
|
||||||
if aEmulateClassicStyle then
|
result.Font.PixelsPerInch := 96;
|
||||||
result.SetBounds(XB,Y,WB-10,22) else
|
if aEmulateClassicStyle then
|
||||||
result.SetBounds(XB,Y,WB-12,28);
|
result.SetBounds(XB,Y,WB-10,22)
|
||||||
|
else
|
||||||
|
result.SetBounds(XB,Y,WB-12,28);
|
||||||
result.Caption := s;
|
result.Caption := s;
|
||||||
result.ModalResult := ModalResult;
|
result.ModalResult := ModalResult;
|
||||||
result.TabOrder := CurrTabOrder;
|
result.TabOrder := CurrTabOrder;
|
||||||
@ -773,10 +786,50 @@ begin
|
|||||||
if ModalResult=aButtonDef then
|
if ModalResult=aButtonDef then
|
||||||
Dialog.Form.ActiveControl := result;
|
Dialog.Form.ActiveControl := result;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure AddImages(AImgList: TCustomImageList; AResName: String);
|
||||||
|
var
|
||||||
|
img100, img150, img200: TCustomBitmap;
|
||||||
|
begin
|
||||||
|
img100 := TPortableNetworkGraphic.Create;
|
||||||
|
img150 := TPortableNetworkGraphic.Create;
|
||||||
|
img200 := TPortableNetworkGraphic.Create;
|
||||||
|
try
|
||||||
|
img100.LoadFromResourceName(HInstance, AResName);
|
||||||
|
img150.LoadFromResourceName(HInstance, AResName + '_150');
|
||||||
|
img200.LoadFromResourceName(HInstance, AResName + '_200');
|
||||||
|
AImgList.AddMultipleResolutions([img100, img150, img200]);
|
||||||
|
finally
|
||||||
|
img100.Free;
|
||||||
|
img150.Free;
|
||||||
|
img200.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
imgList: TLCLGlyphs;
|
||||||
|
|
||||||
|
procedure PrepareImages;
|
||||||
|
var
|
||||||
|
di: TTaskDialogIcon;
|
||||||
|
begin
|
||||||
|
imgList := TLCLGlyphs.Create(Dialog.Form);
|
||||||
|
imgList.MissingResources := gmrOneMustExist;
|
||||||
|
imgList.Scaled := true;
|
||||||
|
imgList.Width := 32;
|
||||||
|
imgList.Height := 32;
|
||||||
|
imgList.RegisterResolutions([16, 24, 32, 48, 64]);
|
||||||
|
for di in TTaskDialogIcon do
|
||||||
|
if LAZ_ICONS[di] <> '' then
|
||||||
|
AddImages(imgList, LAZ_ICONS[di]);
|
||||||
|
// Since footer icons use the same image resources we do not add them again.
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
PngImg: TPortableNetworkGraphic;
|
|
||||||
IconHandle: HICON;
|
IconHandle: HICON;
|
||||||
ARadioOffset: integer;
|
ARadioOffset: integer;
|
||||||
|
imgIndex: Integer;
|
||||||
|
imgRes: TScaledImageListResolution;
|
||||||
begin
|
begin
|
||||||
if (byte(aCommonButtons)=0) and (Buttons='') then begin
|
if (byte(aCommonButtons)=0) and (Buttons='') then begin
|
||||||
aCommonButtons := [cbOk];
|
aCommonButtons := [cbOk];
|
||||||
@ -835,12 +888,16 @@ begin
|
|||||||
exit; // error (mostly invalid argument) -> execute the VCL emulation
|
exit; // error (mostly invalid argument) -> execute the VCL emulation
|
||||||
end;
|
end;
|
||||||
{$endif MSWINDOWS}
|
{$endif MSWINDOWS}
|
||||||
|
|
||||||
// use our native (naive?) Delphi implementation
|
// use our native (naive?) Delphi implementation
|
||||||
Dialog.Emulated := true;
|
Dialog.Emulated := true;
|
||||||
Dialog.Form := TEmulatedTaskDialog.CreateNew(Application);
|
Dialog.Form := TEmulatedTaskDialog.CreateNew(Application);
|
||||||
try
|
try
|
||||||
Dialog.Form.Owner := @Self;
|
Dialog.Form.Owner := @Self;
|
||||||
|
|
||||||
// initialize form properties
|
// initialize form properties
|
||||||
|
Dialog.Form.PixelsPerInch := 96; // for scaling later
|
||||||
|
Dialog.Form.Font.PixelsPerInch := 96;
|
||||||
Dialog.Form.BorderStyle := bsDialog;
|
Dialog.Form.BorderStyle := bsDialog;
|
||||||
if tdfAllowDialogCancellation in aFlags then
|
if tdfAllowDialogCancellation in aFlags then
|
||||||
Dialog.Form.BorderIcons := [biSystemMenu]
|
Dialog.Form.BorderIcons := [biSystemMenu]
|
||||||
@ -865,6 +922,10 @@ begin
|
|||||||
Dialog.Form.ClientWidth := aWidth;
|
Dialog.Form.ClientWidth := aWidth;
|
||||||
Dialog.Form.Height := 200;
|
Dialog.Form.Height := 200;
|
||||||
Dialog.Form.Caption := Title;
|
Dialog.Form.Caption := Title;
|
||||||
|
|
||||||
|
// Prepare image list
|
||||||
|
PrepareImages;
|
||||||
|
|
||||||
// create a white panel for the main dialog part
|
// create a white panel for the main dialog part
|
||||||
Panel := TPanel.Create(Dialog.Form);
|
Panel := TPanel.Create(Dialog.Form);
|
||||||
Panel.Parent := Dialog.Form;
|
Panel.Parent := Dialog.Form;
|
||||||
@ -875,14 +936,16 @@ begin
|
|||||||
Panel.Color := clWindow;
|
Panel.Color := clWindow;
|
||||||
end;
|
end;
|
||||||
Par := Panel;
|
Par := Panel;
|
||||||
|
|
||||||
// handle main dialog icon
|
// handle main dialog icon
|
||||||
if aEmulateClassicStyle then
|
if aEmulateClassicStyle then
|
||||||
IconBorder := 10 else
|
IconBorder := 10
|
||||||
|
else
|
||||||
IconBorder := 24;
|
IconBorder := 24;
|
||||||
|
|
||||||
if (LAZ_ICONS[aDialogIcon]<>'') {$IFDEF MSWINDOWS}or
|
if (LAZ_ICONS[aDialogIcon]<>'') {$IFDEF MSWINDOWS}or
|
||||||
((WidgetSet.GetLCLCapability(lcNativeTaskDialog) = LCL_CAPABILITY_YES) and (WIN_ICONS[aDialogIcon]<>nil)){$ENDIF} then
|
((WidgetSet.GetLCLCapability(lcNativeTaskDialog) = LCL_CAPABILITY_YES) and (WIN_ICONS[aDialogIcon]<>nil)){$ENDIF} then
|
||||||
begin
|
begin
|
||||||
Image := TImage.Create(Dialog.Form);
|
Image := TImage.Create(Dialog.Form);
|
||||||
Image.Parent := Par;
|
Image.Parent := Par;
|
||||||
{$IFDEF MSWINDOWS}
|
{$IFDEF MSWINDOWS}
|
||||||
@ -898,9 +961,11 @@ begin
|
|||||||
Image.Picture.Icon.Handle := IconHandle
|
Image.Picture.Icon.Handle := IconHandle
|
||||||
else if LAZ_ICONS[aDialogIcon]<>'' then
|
else if LAZ_ICONS[aDialogIcon]<>'' then
|
||||||
begin
|
begin
|
||||||
|
imgRes := imgList.ResolutionForPPI[32, Screen.PixelsPerInch, Dialog.Form.GetCanvasScaleFactor];
|
||||||
|
imgIndex := imgList.GetImageIndex(LAZ_ICONS[aDialogIcon]);
|
||||||
Pic := TPortableNetworkGraphic.Create;
|
Pic := TPortableNetworkGraphic.Create;
|
||||||
try
|
try
|
||||||
Pic.LoadFromResourceName(HINSTANCE, LAZ_ICONS[aDialogIcon]);
|
imgRes.GetBitmap(imgIndex, Pic);
|
||||||
Image.Picture.Assign(Pic);
|
Image.Picture.Assign(Pic);
|
||||||
finally
|
finally
|
||||||
Pic.Free;
|
Pic.Free;
|
||||||
@ -919,6 +984,7 @@ begin
|
|||||||
X := IconBorder;
|
X := IconBorder;
|
||||||
Y := IconBorder;
|
Y := IconBorder;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// add main texts (Instruction, Content, Information)
|
// add main texts (Instruction, Content, Information)
|
||||||
Dialog.Form.Element[tdeMainInstruction] := AddLabel(Inst, true);
|
Dialog.Form.Element[tdeMainInstruction] := AddLabel(Inst, true);
|
||||||
Dialog.Form.Element[tdeContent] := AddLabel(Content, false);
|
Dialog.Form.Element[tdeContent] := AddLabel(Content, false);
|
||||||
@ -999,13 +1065,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
if not (tdfUseCommandLinksNoIcon in aFlags) then
|
if not (tdfUseCommandLinksNoIcon in aFlags) then
|
||||||
begin
|
begin
|
||||||
PngImg := TPortableNetworkGraphic.Create;
|
Images := imgList;
|
||||||
try
|
ImageIndex := imgList.GetImageIndex('btn_arrowright');
|
||||||
PngImg.LoadFromResourceName(HINSTANCE, 'btn_arrowright');
|
|
||||||
Glyph.Assign(PngImg);
|
|
||||||
finally
|
|
||||||
PngImg.Free;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1051,9 +1112,11 @@ begin
|
|||||||
Dialog.Form.ActiveControl := Dialog.Form.Edit;
|
Dialog.Form.ActiveControl := Dialog.Form.Edit;
|
||||||
inc(Y,42);
|
inc(Y,42);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// from now we won't add components to the white panel, but to the form
|
// from now we won't add components to the white panel, but to the form
|
||||||
Panel.Height := Y;
|
Panel.Height := Y;
|
||||||
Par := Dialog.Form;
|
Par := Dialog.Form;
|
||||||
|
|
||||||
// add buttons and verification checkbox
|
// add buttons and verification checkbox
|
||||||
if (byte(aCommonButtons)<>0) or (Verify<>'') or
|
if (byte(aCommonButtons)<>0) or (Verify<>'') or
|
||||||
((Buttons<>'') and not (tdfUseCommandLinks in aFlags)) then begin
|
((Buttons<>'') and not (tdfUseCommandLinks in aFlags)) then begin
|
||||||
@ -1088,10 +1151,12 @@ begin
|
|||||||
inc(Y,36);
|
inc(Y,36);
|
||||||
end else
|
end else
|
||||||
XB := 0;
|
XB := 0;
|
||||||
|
|
||||||
// add footer text with optional icon
|
// add footer text with optional icon
|
||||||
if Footer<>'' then begin
|
if Footer<>'' then begin
|
||||||
if XB<>0 then
|
if XB<>0 then
|
||||||
AddBevel else
|
AddBevel
|
||||||
|
else
|
||||||
inc(Y,16);
|
inc(Y,16);
|
||||||
if (LAZ_FOOTERICONS[aFooterIcon]<>'') {$IFDEF MSWINDOWS}or ((WidgetSet.GetLCLCapability(lcNativeTaskDialog) = LCL_CAPABILITY_YES) and (WIN_FOOTERICONS[aFooterIcon]<>nil)){$ENDIF} then
|
if (LAZ_FOOTERICONS[aFooterIcon]<>'') {$IFDEF MSWINDOWS}or ((WidgetSet.GetLCLCapability(lcNativeTaskDialog) = LCL_CAPABILITY_YES) and (WIN_FOOTERICONS[aFooterIcon]<>nil)){$ENDIF} then
|
||||||
begin
|
begin
|
||||||
@ -1118,9 +1183,11 @@ begin
|
|||||||
if (Ico=nil) and (LAZ_FOOTERICONS[aFooterIcon]<>'') then
|
if (Ico=nil) and (LAZ_FOOTERICONS[aFooterIcon]<>'') then
|
||||||
begin
|
begin
|
||||||
Pic := TPortableNetworkGraphic.Create;
|
Pic := TPortableNetworkGraphic.Create;
|
||||||
Pic.LoadFromResourceName(HINSTANCE, LAZ_FOOTERICONS[aFooterIcon]);
|
imgIndex := imgList.GetImageIndex(LAZ_FOOTERICONS[aFooterIcon]);
|
||||||
Bmp.Width := Pic.Width shr 1;
|
imgRes := imgList.ResolutionForPPI[16, Screen.PixelsPerInch, Dialog.Form.GetCanvasScaleFactor];
|
||||||
Bmp.Height := Pic.Height shr 1;
|
imgRes.GetBitmap(imgIndex, Pic);
|
||||||
|
Bmp.Width := Pic.Width;
|
||||||
|
Bmp.Height := Pic.Height;
|
||||||
end;
|
end;
|
||||||
if (Ico<>nil) or (Pic<>nil) then
|
if (Ico<>nil) or (Pic<>nil) then
|
||||||
begin
|
begin
|
||||||
@ -1169,7 +1236,13 @@ begin
|
|||||||
if Assigned(Dialog.Form.PopupParent) then
|
if Assigned(Dialog.Form.PopupParent) then
|
||||||
Dialog.Form.PopupMode := pmExplicit;
|
Dialog.Form.PopupMode := pmExplicit;
|
||||||
|
|
||||||
|
|
||||||
|
// Scale the dialog
|
||||||
|
// Dialog.Form.AutoAdjustLayout(lapAutoAdjustForDPI, 96, Screen.PixelsPerInch, 0, 0);
|
||||||
|
Dialog.Form.AutoScale;
|
||||||
|
|
||||||
// retrieve the results
|
// retrieve the results
|
||||||
|
|
||||||
result := Dialog.Form.ShowModal;
|
result := Dialog.Form.ShowModal;
|
||||||
if Dialog.Form.Combo<>nil then begin
|
if Dialog.Form.Combo<>nil then begin
|
||||||
SelectionRes := Dialog.Form.Combo.ItemIndex;
|
SelectionRes := Dialog.Form.Combo.ItemIndex;
|
||||||
|
Loading…
Reference in New Issue
Block a user