Refactoring TTaskDialog: move (and rename) constants for first radio/button index to Dialogs unit and use them there as well.

This commit is contained in:
Bart 2023-07-22 15:55:17 +02:00
parent b3995a78df
commit 85c1fff32d
3 changed files with 14 additions and 13 deletions

View File

@ -696,6 +696,9 @@ type
property OnButtonClicked;
end;
const
TaskDialogFirstButtonIndex = 100;
TaskDialogFirstRadioButtonIndex = 200;
var
MinimumDialogButtonWidth: Integer = 75;

View File

@ -98,7 +98,7 @@ end;
function TCustomTaskDialog.ButtonIDToModalResult(const AButtonID: Integer
): TModalResult;
begin
if AButtonID<100 then
if AButtonID<TaskDialogFirstButtonIndex then
begin
case AButtonID of
IDOK: Result := mrOK;
@ -112,8 +112,8 @@ begin
else Result := AButtonID
end;
end
else if (AButtonID-100<Buttons.Count) then
Result := Buttons[AButtonID-100].ModalResult
else if (AButtonID-TaskDialogFirstButtonIndex<Buttons.Count) then
Result := Buttons[AButtonID-TaskDialogFirstButtonIndex].ModalResult
else
Result := mrNone;
end;
@ -276,10 +276,10 @@ begin
FModalResult := ButtonIDToModalResult(ButtonID);
debugln(['Old: FModalResult=',FModalResult]);
//ToDo move FirstButtonIndex and FirstRadioButtonIndex to interface section Dialogs unit.
//ToDo move TaskDialogFirstButtonIndex and TaskDialogFirstRadioButtonIndex to interface section Dialogs unit.
debugln(['Old: TaskDlg.RadioRes=',TaskDlg.RadioRes]);
if (TaskDlg.RadioRes>=200) and (TaskDlg.RadioRes-200<RadioButtons.Count) then
FRadioButton := RadioButtons[TaskDlg.RadioRes-200] as TTaskDialogRadioButtonItem
if (TaskDlg.RadioRes>=TaskDialogFirstRadioButtonIndex) and (TaskDlg.RadioRes-TaskDialogFirstRadioButtonIndex<RadioButtons.Count) then
FRadioButton := RadioButtons[TaskDlg.RadioRes-TaskDialogFirstRadioButtonIndex] as TTaskDialogRadioButtonItem
else
FRadioButton := nil;
if TaskDlg.VerifyChecked then
@ -331,7 +331,7 @@ begin
inherited Create(ACollection);
FClient := Collection.Owner as TCustomTaskDialog;
FModalResult := 100 + ID;
FModalResult := TaskDialogFirstButtonIndex + ID;
end;
function TTaskDialogBaseButtonItem.GetDefault: Boolean;

View File

@ -115,8 +115,6 @@ const
0, idDialogWarning, idDialogConfirm, idDialogError, idDialogInfo, idDialogShield);
const
FirstButtonIndex = 100;
FirstRadioButtonIndex = 200;
TD_BTNMOD: array[TTaskDialogCommonButton] of Integer = (
mrOk, mrYes, mrNo, mrCancel, mrRetry, mrAbort);
@ -311,7 +309,7 @@ begin
ARadioRes := 0;
for i := 0 to high(RadioButtonArray) do
if RadioButtonArray[i].Checked then
ARadioRes := i+FirstRadioButtonIndex;
ARadioRes := i+TaskDialogFirstRadioButtonIndex;
end;
@ -416,7 +414,7 @@ begin
Hint := aHint; // note shown as Hint
end;
inc(Y,Height+2);
ModalResult := i+FirstButtonIndex;
ModalResult := i+TaskDialogFirstButtonIndex;
OnClick := @HandleEmulatedButtonClicked;
if ModalResult=aButtonDef then
ActiveControl := CommandLink;
@ -487,7 +485,7 @@ begin
XB := aWidth;
if not (tfUseCommandLinks in FDlg.Flags) then
for i := CustomButtons.Count-1 downto 0 do
AddButton(CustomButtons[i],i+FirstButtonIndex);
AddButton(CustomButtons[i],i+TaskDialogFirstButtonIndex);
for Btn := high(TTaskDialogCommonButton) downto low(TTaskDialogCommonButton) do
begin
if (Btn in CommonButtons) then
@ -701,7 +699,7 @@ begin
if (aWidth < 120) then aWidth := 120;
ClientWidth := aWidth;
Height := FirstRadioButtonIndex;
Height := TaskDialogFirstRadioButtonIndex;
Caption := DialogCaption;
// create a white panel for the main dialog part