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; property OnButtonClicked;
end; end;
const
TaskDialogFirstButtonIndex = 100;
TaskDialogFirstRadioButtonIndex = 200;
var var
MinimumDialogButtonWidth: Integer = 75; MinimumDialogButtonWidth: Integer = 75;

View File

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

View File

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