From 892cf32728a0f9e21e0d7cb60ed16efa96051edd Mon Sep 17 00:00:00 2001 From: Bart <9132501-flyingsheep@users.noreply.gitlab.com> Date: Mon, 7 Aug 2023 22:05:30 +0200 Subject: [PATCH] TaskDialog: implement property CollapsButtonCaption. Delphi does not have this, but the Windows TaskDialogIndirect API has it. It controls the text next to the Expand/Collaps button if the dialog is in expanded state. --- lcl/dialogs.pp | 3 +++ lcl/interfaces/win32/win32wsdialogs.pp | 6 +----- lcl/taskdlgemulation.pp | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lcl/dialogs.pp b/lcl/dialogs.pp index c4787f56c4..b5879f43f1 100644 --- a/lcl/dialogs.pp +++ b/lcl/dialogs.pp @@ -627,6 +627,7 @@ type FButton: TTaskDialogButtonItem; FButtons: TTaskDialogButtons; FCaption: TTranslateString; + FCollapsButtonCaption: TTranslateString; FCommonButtons: TTaskDialogCommonButtons; FDefaultButton: TTaskDialogCommonButton; FExpandButtonCaption: TTranslateString; @@ -688,6 +689,7 @@ type property Buttons: TTaskDialogButtons read FButtons write SetButtons; property Caption: TTranslateString read FCaption write FCaption; property CommonButtons: TTaskDialogCommonButtons read FCommonButtons write FCommonButtons default [tcbOk, tcbCancel]; + property CollapsButtonCaption: TTranslateString read FCollapsButtonCaption write FCollapsButtonCaption; property DefaultButton: TTaskDialogCommonButton read FDefaultButton write FDefaultButton default tcbOk; property ExpandButtonCaption: TTranslateString read FExpandButtonCaption write FExpandButtonCaption; property ExpandedText: TTranslateString read FExpandedText write FExpandedText; @@ -725,6 +727,7 @@ type property Buttons; property Caption; property CommonButtons; + property CollapsButtonCaption; property DefaultButton; property ExpandButtonCaption; property ExpandedText; diff --git a/lcl/interfaces/win32/win32wsdialogs.pp b/lcl/interfaces/win32/win32wsdialogs.pp index eaffd40d8b..23c9fb8bc2 100644 --- a/lcl/interfaces/win32/win32wsdialogs.pp +++ b/lcl/interfaces/win32/win32wsdialogs.pp @@ -1846,7 +1846,6 @@ var if (MainInstruction = '') then MainInstruction := Utf8ToUtf16(IconMessage(TF_DIALOGICON(ADlg.MainIcon))); Content := Utf8ToUtf16(ADlg.Text); - CollapsedControlText := Utf8ToUtf16(ADlg.ExpandButtonCaption); VerificationText := Utf8ToUtf16(ADlg.VerificationText); if (AParentWnd = 0) then begin @@ -1857,10 +1856,7 @@ var end; ExpandedInformation := Utf8ToUtf16(ADlg.ExpandedText); CollapsedControlText := Utf8ToUtf16(ADlg.ExpandButtonCaption); - - //Seems to be the caption of the ExpandButton when ExpandedText is displayed - //If it's empty, then the caption of the ExpandButton remains the same - ExpandedControlText := ''; //currently no matching field in TTaskDialog + ExpandedControlText := Utf8ToUtf16(ADlg.CollapsButtonCaption); Footer := Utf8ToUtf16(ADlg.FooterText); diff --git a/lcl/taskdlgemulation.pp b/lcl/taskdlgemulation.pp index a15fe0a701..ec4f75a7c0 100644 --- a/lcl/taskdlgemulation.pp +++ b/lcl/taskdlgemulation.pp @@ -7,7 +7,7 @@ interface uses Classes, SysUtils, LazUTF8, - LCLType, LCLStrConsts, LCLIntf, InterfaceBase, ImgList, LCLProc, DateUtils, + LCLType, LCLStrConsts, LCLIntf, InterfaceBase, ImgList, LCLProc, DateUtils, Math, LResources, Menus, Graphics, Forms, Controls, StdCtrls, ExtCtrls, Buttons, Dialogs, DialogRes; @@ -31,7 +31,7 @@ type //CustomButtons, Radios: TStringList; DialogCaption, DlgTitle, DlgText, - ExpandButtonCaption, ExpandedText, FooterText, + ExpandButtonCaption, CollapsButtonCaption, ExpandedText, FooterText, VerificationText: String; CommonButtons: TTaskDialogCommonButtons; @@ -525,8 +525,18 @@ begin //inc(Y, 16); X := ALeftMargin; if (ExpandButtonCaption = '') then - ExpandButtonCaption := '>>'; - WB := Canvas.TextWidth(ExpandButtonCaption)+32;//52; + begin + if (CollapsButtonCaption = '') then + begin + ExpandButtonCaption := 'Show details'; + CollapsButtonCaption := 'Hide details'; + end + else + ExpandButtonCaption := CollapsButtonCaption; + end; + if (CollapsButtonCaption = '') then + CollapsButtonCaption := ExpandButtonCaption; + WB := Max(Canvas.TextWidth(ExpandButtonCaption), Canvas.TextWidth(CollapsButtonCaption)) +32;//52; debugln([' X+WB=', X+WB]); debugln([' XB=', XB]); debugln([' diff=', X+WB-XB]); @@ -798,6 +808,7 @@ begin DlgTitle := FDlg.Title; DlgText := FDlg.Text; ExpandButtonCaption := FDlg.ExpandButtonCaption; + CollapsButtonCaption := FDlg.CollapsButtonCaption; ExpandedText := FDlg.ExpandedText; FooterText := FDlg.FooterText; VerificationText := FDlg.VerificationText;