mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-06 14:18:14 +02:00
TaskDialog: TLCLTaskDialog:
- less magic numbers - make GlobalLeftMargin a global vraible for the form (-> less params for some methods) - calculate buttonheights, margins and spacings just once - some comments
This commit is contained in:
parent
d64ce3bd4d
commit
9762393535
@ -25,14 +25,22 @@ type
|
|||||||
const
|
const
|
||||||
RadioIndent = 16;
|
RadioIndent = 16;
|
||||||
ComboBoxHeight = 22;
|
ComboBoxHeight = 22;
|
||||||
|
QueryEditHeight = 22;
|
||||||
LargeImageSize = 32;
|
LargeImageSize = 32;
|
||||||
SmallImageSize = 16;
|
SmallImageSize = 16;
|
||||||
|
CommandLinkButtonHeight = 40;
|
||||||
|
RadioVSpacing = 16;
|
||||||
|
CommandLinkButtonVSpacing = 2;
|
||||||
private
|
private
|
||||||
/// the Task Dialog structure which created the form
|
/// the Task Dialog structure which created the form
|
||||||
FDlg: TTaskDialog;
|
FDlg: TTaskDialog;
|
||||||
FVerifyChecked: Boolean;
|
FVerifyChecked: Boolean;
|
||||||
FExpanded: Boolean;
|
FExpanded: Boolean;
|
||||||
FCommandLinkButtonWidth: Integer;
|
CommandLinkButtonWidth: Integer;
|
||||||
|
CommandLinkButtonMargin: Integer;
|
||||||
|
CommandLinkButtonSpacing: Integer; //Height of TBitBtns
|
||||||
|
ButtonHeight: Integer; //Height of TButtons
|
||||||
|
GlobalLeftMargin: Integer;
|
||||||
Timer: TTimer;
|
Timer: TTimer;
|
||||||
TimerStartTime: TTime;
|
TimerStartTime: TTime;
|
||||||
RadioButtonArray: array of TRadioButton;
|
RadioButtonArray: array of TRadioButton;
|
||||||
@ -69,7 +77,7 @@ type
|
|||||||
procedure AddButtons(const ALeft: Integer; var ATop, AButtonLeft: Integer; AWidth, AButtonDef: Integer; APArent: TWinControl);
|
procedure AddButtons(const ALeft: Integer; var ATop, AButtonLeft: Integer; AWidth, AButtonDef: Integer; APArent: TWinControl);
|
||||||
procedure AddCheckBox(const ALeft: Integer; var ATop, XB: Integer; AWidth: Integer; APArent: TWinControl);
|
procedure AddCheckBox(const ALeft: Integer; var ATop, XB: Integer; AWidth: Integer; APArent: TWinControl);
|
||||||
procedure AddExpandButton(const ALeft: Integer; var ATop, XB: Integer; AWidth: Integer; APArent: TWinControl);
|
procedure AddExpandButton(const ALeft: Integer; var ATop, XB: Integer; AWidth: Integer; APArent: TWinControl);
|
||||||
procedure AddFooter(const ALeft: Integer; var ATop, XB: Integer; AFontHeight, AWidth, AGlobalLeftMargin: Integer; APArent: TWinControl);
|
procedure AddFooter(const ALeft: Integer; var ATop, XB: Integer; AFontHeight, AWidth: Integer; APArent: TWinControl);
|
||||||
function AddLabel(const AText: string; BigFont: Boolean; const ALeft: Integer; var ATop: Integer; AFontHeight, AWidth: Integer; APArent: TWinControl): TLabel;
|
function AddLabel(const AText: string; BigFont: Boolean; const ALeft: Integer; var ATop: Integer; AFontHeight, AWidth: Integer; APArent: TWinControl): TLabel;
|
||||||
procedure AddQueryCombo(const ALeft: Integer; var ATop: Integer; AWidth: Integer; AParent: TWinControl);
|
procedure AddQueryCombo(const ALeft: Integer; var ATop: Integer; AWidth: Integer; AParent: TWinControl);
|
||||||
procedure AddQueryEdit(var X,Y: Integer; AWidth: Integer; AParent: TWinControl);
|
procedure AddQueryEdit(var X,Y: Integer; AWidth: Integer; AParent: TWinControl);
|
||||||
@ -260,7 +268,7 @@ begin
|
|||||||
inherited CreateNew(AOwner, Num);
|
inherited CreateNew(AOwner, Num);
|
||||||
RadioButtonArray := nil;
|
RadioButtonArray := nil;
|
||||||
FExpanded := False;
|
FExpanded := False;
|
||||||
FCommandLinkButtonWidth := -1;
|
CommandLinkButtonWidth := -1;
|
||||||
KeyPreview := True;
|
KeyPreview := True;
|
||||||
DoDialogCreated;
|
DoDialogCreated;
|
||||||
end;
|
end;
|
||||||
@ -392,6 +400,18 @@ begin
|
|||||||
if (aWidth < 120) then aWidth := 120;
|
if (aWidth < 120) then aWidth := 120;
|
||||||
ClientWidth := aWidth;
|
ClientWidth := aWidth;
|
||||||
|
|
||||||
|
if (tfEmulateClassicStyle in FDlg.Flags) then
|
||||||
|
begin
|
||||||
|
CommandLinkButtonMargin := 7;
|
||||||
|
CommandLinkButtonSpacing := 7;
|
||||||
|
ButtonHeight := 22;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
CommandLinkButtonMargin := 24;
|
||||||
|
CommandLinkButtonSpacing := 10;
|
||||||
|
ButtonHeight := 28;
|
||||||
|
end;
|
||||||
Height := 200;
|
Height := 200;
|
||||||
//debugln(['Font: Name=',Font.Name,', Size=',Font.Size,', Height=',Font.Height]);
|
//debugln(['Font: Name=',Font.Name,', Size=',Font.Size,', Height=',Font.Height]);
|
||||||
end;
|
end;
|
||||||
@ -437,8 +457,9 @@ procedure TLCLTaskDialog.AddPanels;
|
|||||||
begin
|
begin
|
||||||
{
|
{
|
||||||
Create 3 different panels:
|
Create 3 different panels:
|
||||||
- the top panel holds main con, title, text and expanded text
|
- the top panel holds main icon, title, text and expanded text
|
||||||
- the mid panel holds radiobuttons, commandlinkbuttons and query's
|
- the mid panel holds radiobuttons, commandlinkbuttons and query's
|
||||||
|
(basically everything that comes after ExpandedText and needs to be on a "colored" panel)
|
||||||
- the bottom panel has the rest of the controls
|
- the bottom panel has the rest of the controls
|
||||||
The top and mid panel have a distinct color (unless tfEmulateClassicStyle is set)
|
The top and mid panel have a distinct color (unless tfEmulateClassicStyle is set)
|
||||||
The reason for the 3 panel setup is that it makes it a lot easier to displace the controls
|
The reason for the 3 panel setup is that it makes it a lot easier to displace the controls
|
||||||
@ -515,16 +536,13 @@ begin
|
|||||||
begin
|
begin
|
||||||
Parent := AParent;
|
Parent := AParent;
|
||||||
Font.Height := AFontHeight-3;
|
Font.Height := AFontHeight-3;
|
||||||
if (tfEmulateClassicStyle in FDlg.Flags) then
|
CommandLinkButtonWidth := aWidth - ALeft - GlobalLeftMargin;
|
||||||
FCommandLinkButtonWidth := aWidth-10-ALeft
|
SetBounds(ALeft,ATop,CommandLinkButtonWidth,CommandLinkButtonHeight);
|
||||||
else
|
|
||||||
FCommandLinkButtonWidth := aWidth-16-ALeft;
|
|
||||||
SetBounds(ALeft,ATop,FCommandLinkButtonWidth,40);
|
|
||||||
Caption := FDlg.Buttons[i].Caption;
|
Caption := FDlg.Buttons[i].Caption;
|
||||||
Hint := FDlg.Buttons[i].CommandLinkHint;
|
Hint := FDlg.Buttons[i].CommandLinkHint;
|
||||||
if (Hint <> '') then
|
if (Hint <> '') then
|
||||||
ShowHint := True;
|
ShowHint := True;
|
||||||
inc(ATop,Height+2);
|
inc(ATop,Height+CommandLinkButtonVSpacing);
|
||||||
ModalResult := i+TaskDialogFirstButtonIndex;
|
ModalResult := i+TaskDialogFirstButtonIndex;
|
||||||
OnClick := @OnButtonClicked;
|
OnClick := @OnButtonClicked;
|
||||||
if ModalResult=aButtonDef then
|
if ModalResult=aButtonDef then
|
||||||
@ -534,16 +552,8 @@ begin
|
|||||||
Font.Height := AFontHeight - 2;
|
Font.Height := AFontHeight - 2;
|
||||||
Font.Style := [fsBold]
|
Font.Style := [fsBold]
|
||||||
end;
|
end;
|
||||||
if (tfEmulateClassicStyle in FDlg.Flags) then
|
Margin := CommandLinkButtonMargin;
|
||||||
begin
|
Spacing := CommandLinkButtonSpacing;
|
||||||
Margin := 7;
|
|
||||||
Spacing := 7;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
Margin := 24;
|
|
||||||
Spacing := 10;
|
|
||||||
end;
|
|
||||||
if not (tfUseCommandLinksNoIcon in FDlg.Flags) then
|
if not (tfUseCommandLinksNoIcon in FDlg.Flags) then
|
||||||
begin
|
begin
|
||||||
Images := LCLGlyphs;
|
Images := LCLGlyphs;
|
||||||
@ -572,10 +582,7 @@ var
|
|||||||
end;
|
end;
|
||||||
Result := TButton.Create(Self);
|
Result := TButton.Create(Self);
|
||||||
Result.Parent := AParent;
|
Result.Parent := AParent;
|
||||||
if (tfEmulateClassicStyle in FDlg.Flags) then
|
Result.SetBounds(AButtonLeft,ATop,WB-10,ButtonHeight);
|
||||||
Result.SetBounds(AButtonLeft,ATop,WB-10,22)
|
|
||||||
else
|
|
||||||
Result.SetBounds(AButtonLeft,ATop,WB-12,28);
|
|
||||||
Result.Caption := s;
|
Result.Caption := s;
|
||||||
Result.ModalResult := AModalResult;
|
Result.ModalResult := AModalResult;
|
||||||
Result.TabOrder := CurrTabOrder;
|
Result.TabOrder := CurrTabOrder;
|
||||||
@ -687,7 +694,7 @@ begin
|
|||||||
Inc(ATop, AHeight+8);
|
Inc(ATop, AHeight+8);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLCLTaskDialog.AddFooter(const ALeft: Integer; var ATop, XB: Integer; AFontHeight, AWidth, AGlobalLeftMargin: Integer; APArent: TWinControl);
|
procedure TLCLTaskDialog.AddFooter(const ALeft: Integer; var ATop, XB: Integer; AFontHeight, AWidth: Integer; APArent: TWinControl);
|
||||||
var
|
var
|
||||||
ALabelLeft: Integer;
|
ALabelLeft: Integer;
|
||||||
|
|
||||||
@ -721,8 +728,8 @@ begin
|
|||||||
Image.StretchOutEnabled := False;
|
Image.StretchOutEnabled := False;
|
||||||
Image.Proportional := True;
|
Image.Proportional := True;
|
||||||
Image.Center := True;
|
Image.Center := True;
|
||||||
Image.SetBounds(AGlobalLeftMargin,ATop,SmallImageSize,SmallImageSize);
|
Image.SetBounds(GlobalLeftMargin,ATop,SmallImageSize,SmallImageSize);
|
||||||
ALabelLeft := AGlobalLeftMargin + Aleft + Image.Width;
|
ALabelLeft := GlobalLeftMargin + Aleft + Image.Width;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -759,14 +766,14 @@ begin
|
|||||||
Result.AutoSize := False;
|
Result.AutoSize := False;
|
||||||
R.Left := 0;
|
R.Left := 0;
|
||||||
R.Top := 0;
|
R.Top := 0;
|
||||||
W := aWidth-ALeft-8;
|
W := aWidth-ALeft-GlobalLeftMargin;
|
||||||
R.Right := W;
|
R.Right := W;
|
||||||
R.Bottom := Result.Height;
|
R.Bottom := Result.Height;
|
||||||
Result.Caption := AText;
|
Result.Caption := AText;
|
||||||
Result.Parent := AParent;
|
Result.Parent := AParent;
|
||||||
LCLIntf.DrawText(Result.Canvas.Handle,PChar(AText),Length(AText),R,DT_CALCRECT or DT_WORDBREAK);
|
LCLIntf.DrawText(Result.Canvas.Handle,PChar(AText),Length(AText),R,DT_CALCRECT or DT_WORDBREAK);
|
||||||
Result.SetBounds(ALeft,ATop,W,R.Bottom);
|
Result.SetBounds(ALeft,ATop,W,R.Bottom);
|
||||||
inc(ATop,R.Bottom+16);
|
inc(ATop,R.Bottom+RadioVSpacing);
|
||||||
//debugln(['TLCLTaskDialog.AddLabel End: X=',ALeft,', Result.Left=',Result.Left]);
|
//debugln(['TLCLTaskDialog.AddLabel End: X=',ALeft,', Result.Left=',Result.Left]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -776,10 +783,10 @@ begin
|
|||||||
with QueryCombo do
|
with QueryCombo do
|
||||||
begin
|
begin
|
||||||
Items.Assign(FDlg.QueryChoices);
|
Items.Assign(FDlg.QueryChoices);
|
||||||
if (FCommandLinkButtonWidth > 0) then
|
if (CommandLinkButtonWidth > 0) then
|
||||||
SetBounds(ALeft,ATop,FCommandLinkButtonWidth,ComboBoxHeight) //right align with the buttons
|
SetBounds(ALeft,ATop,CommandLinkButtonWidth,ComboBoxHeight) //right align with the buttons
|
||||||
else
|
else
|
||||||
SetBounds(ALeft,ATop,aWidth-32-ALeft,ComboBoxHeight);
|
SetBounds(ALeft,ATop,aWidth-2*GlobalLeftMargin-ALeft,ComboBoxHeight);
|
||||||
if (tfQueryFixedChoices in FDlg.Flags) then
|
if (tfQueryFixedChoices in FDlg.Flags) then
|
||||||
Style := csDropDownList
|
Style := csDropDownList
|
||||||
else
|
else
|
||||||
@ -803,8 +810,8 @@ begin
|
|||||||
QueryEdit := TEdit.Create(Self);
|
QueryEdit := TEdit.Create(Self);
|
||||||
with QueryEdit do
|
with QueryEdit do
|
||||||
begin
|
begin
|
||||||
if (FCommandLinkButtonWidth > 0) then
|
if (CommandLinkButtonWidth > 0) then
|
||||||
SetBounds(X,Y,FCommandLinkButtonWidth,22) //right align with the buttons
|
SetBounds(X,Y,CommandLinkButtonWidth,QueryEditHeight) //right align with the buttons
|
||||||
else
|
else
|
||||||
SetBounds(X,Y,aWidth-16-X,22);
|
SetBounds(X,Y,aWidth-16-X,22);
|
||||||
Text := FDlg.SimpleQuery;
|
Text := FDlg.SimpleQuery;
|
||||||
@ -945,7 +952,8 @@ var
|
|||||||
aRadioDef, aButtonDef: TModalResult;
|
aRadioDef, aButtonDef: TModalResult;
|
||||||
B: TTaskDialogBaseButtonItem;
|
B: TTaskDialogBaseButtonItem;
|
||||||
ButtonID: Integer;
|
ButtonID: Integer;
|
||||||
ARadioOffset, FontHeight, aWidth, GlobalLeftMargin, ALeft, ATop, i, XB: integer;
|
ARadioOffset, FontHeight, aWidth, ALeft {Left for controls aligned right to the icon, so on top 2 panels},
|
||||||
|
ATop, i, XB: integer;
|
||||||
CurrParent: TWinControl;
|
CurrParent: TWinControl;
|
||||||
aDialogIcon: TLCLTaskDialogIcon;
|
aDialogIcon: TLCLTaskDialogIcon;
|
||||||
CommandLink: TBitBtn;
|
CommandLink: TBitBtn;
|
||||||
@ -1028,27 +1036,27 @@ begin
|
|||||||
ATop := 0;
|
ATop := 0;
|
||||||
|
|
||||||
XB := 0;
|
XB := 0;
|
||||||
ALeft := GlobalLeftMargin; //Left most margin of the form
|
//ALeft := GlobalLeftMargin; //Left most margin of the form
|
||||||
// add CustomButtons and verification checkbox
|
// add CustomButtons and verification checkbox
|
||||||
if (CommonButtons <> []) or
|
if (CommonButtons <> []) or
|
||||||
((FDlg.Buttons.Count<>0) and not (tfUseCommandLinks in FDlg.Flags)) then
|
((FDlg.Buttons.Count<>0) and not (tfUseCommandLinks in FDlg.Flags)) then
|
||||||
begin
|
begin
|
||||||
AddButtons(ALeft, ATop, XB, aWidth, aButtonDef, CurrParent);
|
AddButtons(GlobalLeftMargin, ATop, XB, aWidth, aButtonDef, CurrParent);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//Add Expand button
|
//Add Expand button
|
||||||
if (ExpandedText <> '') then
|
if (ExpandedText <> '') then
|
||||||
AddExpandButton(ALeft, ATop, XB, aWidth, CurrParent);
|
AddExpandButton(GlobalLeftMargin, ATop, XB, aWidth, CurrParent);
|
||||||
|
|
||||||
if (VerificationText <> '') then
|
if (VerificationText <> '') then
|
||||||
AddCheckBox(ALeft, ATop, XB, aWidth, CurrParent);
|
AddCheckBox(GlobalLeftMargin, ATop, XB, aWidth, CurrParent);
|
||||||
inc(ATop,36);
|
inc(ATop,36);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// add FooterText text with optional icon
|
// add FooterText text with optional icon
|
||||||
if (FooterText <> '') then
|
if (FooterText <> '') then
|
||||||
AddFooter(ALeft, ATop, XB, FontHeight, aWidth, GlobalLeftMargin, CurrParent);
|
AddFooter(GlobalLeftMargin, ATop, XB, FontHeight, aWidth, CurrParent);
|
||||||
|
|
||||||
ClientHeight := TopPanel.Height + MidPanel.Height + ATop;
|
ClientHeight := TopPanel.Height + MidPanel.Height + ATop;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user