TaskDialog: fix setting focus when tfQueryFocused is set.

Give some varibales a mor meningfull name and update some comments regarding those.
This commit is contained in:
Bart 2023-08-02 18:00:05 +02:00
parent 89c95847d0
commit a46e62000d

View File

@ -39,10 +39,10 @@ type
Image: TImage; Image: TImage;
/// the labels corresponding to the Task Dialog main elements /// the labels corresponding to the Task Dialog main elements
Element: array[tdeContent..tdeMainInstruction] of TLabel; Element: array[tdeContent..tdeMainInstruction] of TLabel;
/// the Task Dialog selection list /// the Task Dialog query selection list
Combo: TComboBox; QueryCombo: TComboBox;
/// the Task Dialog optional query editor /// the Task Dialog optional query single line editor
Edit: TEdit; QueryEdit: TEdit;
/// the Task Dialog optional checkbox /// the Task Dialog optional checkbox
VerifyCheckBox: TCheckBox; VerifyCheckBox: TCheckBox;
@ -305,15 +305,15 @@ begin
Result := ShowModal; Result := ShowModal;
if Assigned(Combo) then if Assigned(QueryCombo) then
begin begin
FDlg.QueryItemIndex := Combo.ItemIndex; FDlg.QueryItemIndex := QueryCombo.ItemIndex;
FDlg.QueryResult := Combo.Text; FDlg.QueryResult := QueryCombo.Text;
end end
else else
begin begin
if Assigned(Edit) then if Assigned(QueryEdit) then
FDlg.QueryResult := Edit.Text; FDlg.QueryResult := QueryEdit.Text;
end; end;
if VerifyCheckBox<>nil then if VerifyCheckBox<>nil then
@ -623,8 +623,8 @@ end;
procedure TLCLTaskDialog.AddQueryCombo(var X, Y: Integer; AWidth: Integer; AParent: TWinControl); procedure TLCLTaskDialog.AddQueryCombo(var X, Y: Integer; AWidth: Integer; AParent: TWinControl);
begin begin
Combo := TComboBox.Create(Self); QueryCombo := TComboBox.Create(Self);
with Combo do with QueryCombo do
begin begin
Items.Assign(FDlg.QueryChoices); Items.Assign(FDlg.QueryChoices);
SetBounds(X,Y,aWidth-32-X,22); SetBounds(X,Y,aWidth-32-X,22);
@ -641,8 +641,6 @@ begin
else else
ItemIndex := -1; ItemIndex := -1;
end; end;
if (tfQueryFocused in FDlg.Flags) then
ActiveControl := Combo;
Parent := AParent; Parent := AParent;
end; end;
inc(Y,42); inc(Y,42);
@ -650,16 +648,14 @@ end;
procedure TLCLTaskDialog.AddQueryEdit(var X, Y: Integer; AWidth: Integer; AParent: TWinControl); procedure TLCLTaskDialog.AddQueryEdit(var X, Y: Integer; AWidth: Integer; AParent: TWinControl);
begin begin
Edit := TEdit.Create(Self); QueryEdit := TEdit.Create(Self);
with Edit do with QueryEdit do
begin begin
SetBounds(X,Y,aWidth-16-X,22); SetBounds(X,Y,aWidth-16-X,22);
Text := FDlg.SimpleQuery; Text := FDlg.SimpleQuery;
PasswordChar := FDlg.SimpleQueryPasswordChar; PasswordChar := FDlg.SimpleQueryPasswordChar;
Parent := AParent; Parent := AParent;
end; end;
if (tfQueryFocused in FDlg.Flags) then
ActiveControl := Edit;
inc(Y,42); inc(Y,42);
end; end;
@ -874,7 +870,7 @@ begin
AddCommandLinkButtons(X, Y, aWidth, aButtonDef, FontHeight, CurrParent); AddCommandLinkButtons(X, Y, aWidth, aButtonDef, FontHeight, CurrParent);
// add query combobox list or query edit // add query combobox list or QueryEdit
if (tfQuery in FDlg.Flags) and (FDlg.QueryChoices.Count > 0) then if (tfQuery in FDlg.Flags) and (FDlg.QueryChoices.Count > 0) then
AddQueryCombo(X, Y, aWidth, CurrParent) AddQueryCombo(X, Y, aWidth, CurrParent)
else else
@ -903,6 +899,15 @@ begin
if (tfCallBackTimer in FDlg.Flags) then if (tfCallBackTimer in FDlg.Flags) then
SetupTimer; SetupTimer;
//AddButtons (which comes after adding query) may have set ActiveControl
//so do this here and not in AddQueryCombo or AddQueryEdit
if Assigned(QueryCombo) and (tfQueryFocused in FDlg.Flags) then
ActiveControl := QueryCombo
else
if Assigned(QueryEdit) and (tfQueryFocused in FDlg.Flags) then
ActiveControl := QueryEdit;
end; end;
procedure TLCLTaskDialog.KeyDown(var Key: Word; Shift: TShiftState); procedure TLCLTaskDialog.KeyDown(var Key: Word; Shift: TShiftState);