From fff6152ddea51bca1c31439a2271e6acc87bbb1e Mon Sep 17 00:00:00 2001 From: Bart <9132501-flyingsheep@users.noreply.gitlab.com> Date: Mon, 31 Jul 2023 14:42:06 +0200 Subject: [PATCH] TaskDialog: start implementing CommandLinkHint property for TTaskDialog.Buttons. For now only functional on Windows Vista+ (native dialog). --- lcl/dialogs.pp | 5 ++++ lcl/interfaces/win32/win32wsdialogs.pp | 32 +++++++++----------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lcl/dialogs.pp b/lcl/dialogs.pp index 124386e51e..f7bd3e71e8 100644 --- a/lcl/dialogs.pp +++ b/lcl/dialogs.pp @@ -557,10 +557,13 @@ type TTaskDialogButtons = class; + { TTaskDialogBaseButtonItem } + TTaskDialogBaseButtonItem = class(TCollectionItem) private FCaption: TTranslateString; FClient: TCustomTaskDialog; + FCommandLinkHint: TTranslateString; FModalResult: TModalResult; function GetDefault: Boolean; procedure SetCaption(const ACaption: TTranslateString); @@ -572,6 +575,7 @@ type public constructor Create(ACollection: TCollection); override; property ModalResult: TModalResult read FModalResult write FModalResult; + property CommandLinkHint: TTranslateString read FCommandLinkHint write FCommandLinkHint; published property Caption: TTranslateString read FCaption write SetCaption; property Default: Boolean read GetDefault write SetDefault default False; @@ -581,6 +585,7 @@ type public constructor Create(ACollection: TCollection); override; published + property CommandLinkHint; property ModalResult; end; diff --git a/lcl/interfaces/win32/win32wsdialogs.pp b/lcl/interfaces/win32/win32wsdialogs.pp index ed31c0d327..64414ced46 100644 --- a/lcl/interfaces/win32/win32wsdialogs.pp +++ b/lcl/interfaces/win32/win32wsdialogs.pp @@ -1692,8 +1692,6 @@ var Footer: WideString; DefRB, DefBtn, RUCount: Integer; CommonButtons: TTaskDialogCommonButtons; - B: TTaskDialogBaseButtonItem; - List: TStringList; Flags: TTaskDialogFlags; Res: HRESULT; @@ -1706,21 +1704,24 @@ var TD_FOOTERICONS: array[TLCLTaskDialogFooterIcon] of integer = ( 0, 84, 99, 98, 65533, 65532); - procedure AddTaskDiakogButton(List: TStringList; var n: longword; firstID: integer); + procedure AddTaskDiakogButton(Btns: TTaskDialogButtons; var n: longword; firstID: integer); var - P: PChar; i: Integer; begin - if (List.Count = 0) then + if (Btns.Count = 0) then Exit; - for i := 0 to List.Count - 1 do + for i := 0 to Btns.Count - 1 do begin - if length(ButtonCaptions)<=RUCount then + if Length(ButtonCaptions)<=RUCount then begin SetLength(ButtonCaptions,RUCount+16); SetLength(Buttons,RUCount+16); end; - ButtonCaptions[RUCount] := Utf8ToUtf16(StringReplace(List[i],'\n',#10,[rfReplaceAll])); + ButtonCaptions[RUCount] := Utf8ToUtf16(StringReplace(Btns.Items[i].Caption,'\n',#10,[rfReplaceAll])); + if (Btns.Items[i] is TTaskDialogButtonItem) and (tfUseCommandLinks in ADlg.Flags) then + begin + ButtonCaptions[RUCount] := ButtonCaptions[RUCount] + Utf8ToUtf16(#10 + Btns.Items[i].CommandLinkHint); + end; Buttons[RUCount].nButtonID := n+firstID; Buttons[RUCount].pszButtonText := PWideChar(ButtonCaptions[RUCount]); inc(n); @@ -1786,19 +1787,8 @@ var Config.nDefaultButton := DefBtn; RUCount := 0; - List := TStringList.Create; - try - for B in ADlg.Buttons do - List.Add(B.Caption); - AddTaskDiakogButton(List,Config.cButtons,TaskDialogFirstButtonIndex); - - List.Clear; - for B in ADlg.RadioButtons do - List.Add(B.Caption); - AddTaskDiakogButton(List,Config.cRadioButtons,TaskDialogFirstRadioButtonIndex); - finally - List.Free; - end; + AddTaskDiakogButton(ADlg.Buttons,Config.cButtons,TaskDialogFirstButtonIndex); + AddTaskDiakogButton(ADlg.RadioButtons,Config.cRadioButtons,TaskDialogFirstRadioButtonIndex); if (Config.cButtons > 0) then Config.pButtons := @Buttons[0];