TaskDialog: start implementing CommandLinkHint property for TTaskDialog.Buttons.

For now only functional on Windows Vista+ (native dialog).
This commit is contained in:
Bart 2023-07-31 14:42:06 +02:00
parent d4693029bc
commit fff6152dde
2 changed files with 16 additions and 21 deletions

View File

@ -557,10 +557,13 @@ type
TTaskDialogButtons = class; TTaskDialogButtons = class;
{ TTaskDialogBaseButtonItem }
TTaskDialogBaseButtonItem = class(TCollectionItem) TTaskDialogBaseButtonItem = class(TCollectionItem)
private private
FCaption: TTranslateString; FCaption: TTranslateString;
FClient: TCustomTaskDialog; FClient: TCustomTaskDialog;
FCommandLinkHint: TTranslateString;
FModalResult: TModalResult; FModalResult: TModalResult;
function GetDefault: Boolean; function GetDefault: Boolean;
procedure SetCaption(const ACaption: TTranslateString); procedure SetCaption(const ACaption: TTranslateString);
@ -572,6 +575,7 @@ type
public public
constructor Create(ACollection: TCollection); override; constructor Create(ACollection: TCollection); override;
property ModalResult: TModalResult read FModalResult write FModalResult; property ModalResult: TModalResult read FModalResult write FModalResult;
property CommandLinkHint: TTranslateString read FCommandLinkHint write FCommandLinkHint;
published published
property Caption: TTranslateString read FCaption write SetCaption; property Caption: TTranslateString read FCaption write SetCaption;
property Default: Boolean read GetDefault write SetDefault default False; property Default: Boolean read GetDefault write SetDefault default False;
@ -581,6 +585,7 @@ type
public public
constructor Create(ACollection: TCollection); override; constructor Create(ACollection: TCollection); override;
published published
property CommandLinkHint;
property ModalResult; property ModalResult;
end; end;

View File

@ -1692,8 +1692,6 @@ var
Footer: WideString; Footer: WideString;
DefRB, DefBtn, RUCount: Integer; DefRB, DefBtn, RUCount: Integer;
CommonButtons: TTaskDialogCommonButtons; CommonButtons: TTaskDialogCommonButtons;
B: TTaskDialogBaseButtonItem;
List: TStringList;
Flags: TTaskDialogFlags; Flags: TTaskDialogFlags;
Res: HRESULT; Res: HRESULT;
@ -1706,21 +1704,24 @@ var
TD_FOOTERICONS: array[TLCLTaskDialogFooterIcon] of integer = ( TD_FOOTERICONS: array[TLCLTaskDialogFooterIcon] of integer = (
0, 84, 99, 98, 65533, 65532); 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 var
P: PChar;
i: Integer; i: Integer;
begin begin
if (List.Count = 0) then if (Btns.Count = 0) then
Exit; Exit;
for i := 0 to List.Count - 1 do for i := 0 to Btns.Count - 1 do
begin begin
if length(ButtonCaptions)<=RUCount then if Length(ButtonCaptions)<=RUCount then
begin begin
SetLength(ButtonCaptions,RUCount+16); SetLength(ButtonCaptions,RUCount+16);
SetLength(Buttons,RUCount+16); SetLength(Buttons,RUCount+16);
end; 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].nButtonID := n+firstID;
Buttons[RUCount].pszButtonText := PWideChar(ButtonCaptions[RUCount]); Buttons[RUCount].pszButtonText := PWideChar(ButtonCaptions[RUCount]);
inc(n); inc(n);
@ -1786,19 +1787,8 @@ var
Config.nDefaultButton := DefBtn; Config.nDefaultButton := DefBtn;
RUCount := 0; RUCount := 0;
List := TStringList.Create; AddTaskDiakogButton(ADlg.Buttons,Config.cButtons,TaskDialogFirstButtonIndex);
try AddTaskDiakogButton(ADlg.RadioButtons,Config.cRadioButtons,TaskDialogFirstRadioButtonIndex);
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;
if (Config.cButtons > 0) then if (Config.cButtons > 0) then
Config.pButtons := @Buttons[0]; Config.pButtons := @Buttons[0];