TaskDialog: use DoOnXXX methods to call the event handlers.

Also rename some methods of LCLTaskDialog for a bit more consistency.
This commit is contained in:
Bart 2023-08-01 16:39:53 +02:00
parent d31e76a1f6
commit b5f0aca3ea
4 changed files with 124 additions and 60 deletions

View File

@ -664,6 +664,16 @@ type
function DoExecute(ParentWnd: HWND): Boolean; dynamic;
procedure DoOnButtonClicked(AModalResult: Integer; var ACanClose: Boolean); dynamic;
procedure DoOnRadioButtonClicked(ButtonID: Integer); dynamic;
procedure DoOnDialogConstructed; dynamic;
procedure DoOnDialogCreated; dynamic;
procedure DoOnDialogDestroyed; dynamic;
procedure DoOnExpandButtonClicked(Expanded: Boolean); dynamic;
procedure DoOnTimer(TickCount: Cardinal; var Reset: Boolean); dynamic;
procedure DoOnVerificationClicked(Checked: Boolean); dynamic;
//procedure DoOnHelp; dynamic;
//procedure DoOnHyperlinkClicked(const AURL: string); dynamic;
//procedure DoOnNavigated; dynamic;
procedure SetRadioButtonFromRadioIndex(AIndex: Integer);
public
constructor Create(AOwner: TComponent); override;

View File

@ -179,6 +179,42 @@ begin
end;
end;
procedure TCustomTaskDialog.DoOnDialogConstructed;
begin
if Assigned(FOnDialogConstructed) then
FOnDialogConstructed(Self);
end;
procedure TCustomTaskDialog.DoOnDialogCreated;
begin
if Assigned(FOnDialogCreated) then
FOnDialogCreated(Self);
end;
procedure TCustomTaskDialog.DoOnDialogDestroyed;
begin
if Assigned(FOnDialogDestroyed) then
FOnDialogDestroyed(Self);
end;
procedure TCustomTaskDialog.DoOnExpandButtonClicked({%H-}Expanded: Boolean);
begin
if Assigned(FOnExpand) then
FOnExpand(Self)
end;
procedure TCustomTaskDialog.DoOnTimer(TickCount: Cardinal; var Reset: Boolean);
begin
if Assigned(FOnTimer) then
FOnTimer(Self, TickCount, Reset);
end;
procedure TCustomTaskDialog.DoOnVerificationClicked({%H-}Checked: Boolean);
begin
if Assigned(FOnVerificationClicked) then
FOnVerificationClicked(Self);
end;
procedure TCustomTaskDialog.SetRadioButtonFromRadioIndex(AIndex: Integer);
begin
if (AIndex >= TaskDialogFirstRadioButtonIndex) and (AIndex-TaskDialogFirstRadioButtonIndex < RadioButtons.Count) then

View File

@ -1657,7 +1657,7 @@ type
TTaskDialogAccess = class(TCustomTaskDialog)
end;
function TaskDialogCallbackProc(hwnd: HWND; uNotification: UINT;
function TaskDialogCallbackProc({%H-}hwnd: HWND; uNotification: UINT;
wParam: WPARAM; {%H-}lParam: LPARAM; dwRefData: Long_Ptr): HRESULT; stdcall;
var Dlg: TTaskDialog absolute dwRefData;
CanClose, ResetTimer: Boolean;
@ -1667,31 +1667,37 @@ begin
TDN_DIALOG_CONSTRUCTED:
begin
Assert((Dlg is TCustomTaskDialog),'TaskDialogCallbackProc: dwRefData is NOT a TCustomTaskDialog');
if Assigned(Dlg.OnDialogConstructed) then
Dlg.OnDialogConstructed(Dlg);
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(Dlg).DoOnDialogConstructed;
{$POP}
end;
TDN_CREATED:
begin
Assert((Dlg is TCustomTaskDialog),'TaskDialogCallbackProc: dwRefData is NOT a TCustomTaskDialog');
if Assigned(Dlg.OnDialogCreated) then
Dlg.OnDialogCreated(Dlg);
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(Dlg).DoOnDialogCreated;
{$POP}
end;
TDN_DESTROYED:
begin
Assert((Dlg is TCustomTaskDialog),'TaskDialogCallbackProc: dwRefData is NOT a TCustomTaskDialog');
if Assigned(Dlg.OnDialogDestroyed) then
Dlg.OnDialogDestroyed(Dlg);
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(Dlg).DoOnDialogDestroyed;
{$POP}
end;
TDN_BUTTON_CLICKED:
begin
Assert((Dlg is TCustomTaskDialog),'TaskDialogCallbackProc: dwRefData is NOT a TCustomTaskDialog');
if Assigned(Dlg.OnButtonClicked) then
begin
CanClose := True;
Dlg.OnButtonClicked(Dlg, Dlg.ButtonIDToModalResult(wParam), CanClose);
if not CanClose then
Result := S_FALSE;
end;
CanClose := True;
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(Dlg).DoOnButtonClicked(Dlg.ButtonIDToModalResult(wParam), CanClose);
if not CanClose then
Result := S_FALSE;
{$POP}
end;
TDN_HYPERLINK_CLICKED:
begin
@ -1720,25 +1726,29 @@ begin
Return value: To reset the tickcount, the application must return S_FALSE, otherwise the tickcount will continue to increment.
}
Assert((Dlg is TCustomTaskDialog),'TaskDialogCallbackProc: dwRefData is NOT a TCustomTaskDialog');
if Assigned(Dlg.OnTimer) then
begin
ResetTimer := False;
Dlg.OnTimer(Dlg, Cardinal(wParam), ResetTimer);
if ResetTimer then
Result := S_FALSE;
end;
ResetTimer := False;
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(Dlg).DoOnTimer(Cardinal(wParam), ResetTimer);
{$POP}
if ResetTimer then
Result := S_FALSE;
end;
TDN_VERIFICATION_CLICKED:
begin
Assert((Dlg is TCustomTaskDialog),'TaskDialogCallbackProc: dwRefData is NOT a TCustomTaskDialog');
if Assigned(Dlg.OnVerificationClicked) then
Dlg.OnVerificationClicked(Dlg);
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(Dlg).DoOnverificationClicked(BOOL(wParam));
{$POP}
end;
TDN_EXPANDO_BUTTON_CLICKED:
begin
Assert((Dlg is TCustomTaskDialog),'TaskDialogCallbackProc: dwRefData is NOT a TCustomTaskDialog');
if Assigned(Dlg.OnExpand) then
Dlg.OnExpand(Dlg);
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(Dlg).DoOnExpandButtonClicked(BOOL(wParam));
{$POP}
end;
TDN_RADIO_BUTTON_CLICKED:
begin

View File

@ -58,15 +58,15 @@ type
procedure SetupTimer;
procedure ResetTimer;
procedure OnTimer(Sender: TObject);
procedure OnRadioButtonClick(Sender: TObject);
procedure DoDialogConstructed;
procedure DoDialogCreated;
procedure DoDialogDestroyed;
procedure VerifyClicked(Sender: TObject);
procedure OnButtonClicked(Sender: TObject);
procedure OnRadioButtonClick(Sender: TObject);
procedure OnVerifyClicked(Sender: TObject);
procedure OnTimer(Sender: TObject);
protected
procedure HandleEmulatedButtonClicked(Sender: TObject);
procedure SetupControls;
public
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
@ -432,7 +432,7 @@ begin
ShowHint := True;
inc(Y,Height+2);
ModalResult := i+TaskDialogFirstButtonIndex;
OnClick := @HandleEmulatedButtonClicked;
OnClick := @OnButtonClicked;
if ModalResult=aButtonDef then
ActiveControl := CommandLink;
if (tfEmulateClassicStyle in FDlg.Flags) then
@ -485,7 +485,7 @@ var
Result.Caption := s;
Result.ModalResult := AModalResult;
Result.TabOrder := CurrTabOrder;
Result.OnClick := @HandleEmulatedButtonClicked;
Result.OnClick := @OnButtonClicked;
if Assigned(FDlg.Buttons.DefaultButton) then
begin
@ -536,7 +536,7 @@ begin
SetBounds(X,Y,XB-X,24);
Caption := VerificationText;
Checked := FVerifyChecked;
OnClick := @VerifyClicked;
OnClick := @OnVerifyClicked;
end;
end;
inc(Y,36);
@ -669,17 +669,17 @@ var
MSecs: Cardinal;
MSecs64: Int64;
begin
if Assigned(FDlg.OnTimer) then
begin
MSecs64 := MilliSecondsBetween(Now, TimerStartTime);
{$PUSH}{$R-}
MSecs := MSecs64;
{$POP}
AResetTimer := False;
FDlg.OnTimer(FDlg, MSecs, AResetTimer);
if AResetTimer then
ResetTimer;
end;
MSecs64 := MilliSecondsBetween(Now, TimerStartTime);
{$PUSH}{$R-}
MSecs := MSecs64;
{$POP}
AResetTimer := False;
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(FDlg).DoOnTimer(MSecs, AResetTimer);
{$POP}
if AResetTimer then
ResetTimer;
end;
procedure TLCLTaskDialog.OnRadioButtonClick(Sender: TObject);
@ -711,40 +711,48 @@ end;
procedure TLCLTaskDialog.DoDialogConstructed;
begin
if Assigned(FDlg.OnDialogConstructed) then
FDlg.OnDialogDestroyed(FDlg);
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(FDlg).DoOnDialogConstructed;
{$POP}
end;
procedure TLCLTaskDialog.DoDialogCreated;
begin
if Assigned(FDlg.OnDialogCreated) then
FDlg.OnDialogCreated(FDlg);
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(FDlg).DoOnDialogCreated;
{$POP}
end;
procedure TLCLTaskDialog.DoDialogDestroyed;
begin
if Assigned(FDlg.OnDialogDestroyed) then
FDlg.OnDialogDestroyed(FDlg);
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(FDlg).DoOnDialogDestroyed;
{$POP}
end;
procedure TLCLTaskDialog.VerifyClicked(Sender: TObject);
procedure TLCLTaskDialog.OnVerifyClicked(Sender: TObject);
begin
if Assigned(FDlg.OnVerificationClicked) then
FDlg.OnVerificationClicked(FDlg);
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(FDlg).DoOnverificationClicked(VerifyCheckBox.Checked);
{$POP}
end;
procedure TLCLTaskDialog.HandleEmulatedButtonClicked(Sender: TObject);
procedure TLCLTaskDialog.OnButtonClicked(Sender: TObject);
var Btn: TButton absolute Sender;
CanClose: Boolean;
begin
if Assigned(FDlg) and Assigned(FDlg.OnButtonClicked) then
begin
CanClose := True;
FDlg.OnButtonClicked(FDlg, FDlg.ButtonIDToModalResult(Btn.ModalResult),CanClose);
if not CanClose then
ModalResult := mrNone;
end;
CanClose := True;
{$PUSH}
{$ObjectChecks OFF}
TTaskDialogAccess(FDlg).DoOnButtonClicked(FDlg.ButtonIDToModalResult(Btn.ModalResult), CanClose);
if not CanClose then
ModalResult := mrNone;
{$POP}
end;