Implement a TaskDialog window for LCL.

lcltaskdialog.pas implements a task dialog . It is implemented natively on Windows Vista and Windows 7 (or later). On Windows XP, it is emulated.

This unit was originally a part of the freeware Synopse mORMot framework, licensed under a MPL/GPL/LGPL tri-license; version 1.19. It has been relicensed with permission from Arnaud Bouchez, the original author, and all contributors.

The original file name is SynTaskDialog.pas.

Filled once in the initialization block. You can set this reference to Nil to force Delphi dialogs even on Windows Vista/Seven (e.g. make sense if TaskDialogBiggerButtons=true).

The standard common buttons handled by the Task Dialog.
Set of standard common buttons handled by the Task Dialog.
The available main icons for the Task Dialog.
The available footer icons for the Task Dialog.

The available configuration flags for the Task Dialog. Most are standard TDF_* flags used for Vista/Seven native API (see http://msdn.microsoft.com/en-us/library/bb787473(v=vs.85).aspx for TASKDIALOG_FLAGS).

tdfQuery and tdfQueryMasked are custom flags, implemented in pure Delphi code to handle input query.

Our emulation code will handle only tdfUseCommandLinks, tdfUseCommandLinksNoIcon, and tdfQuery options.

Set of available configuration flags for the Task Dialog.

This callback will be triggerred when a task dialog button is clicked. To prevent the task dialog from closing, the application must set ACanClose to FALSE. Otherwise, the task dialog is closed and the button ID is returned via the original TTaskDialog.Execute() result.

The visual components of this Task Dialog. Maps low-level TDE_CONTENT...TDE_MAIN_INSTRUCTION constants, the query editor and checkbox. tdeEdit is for the query editor. tdeVerif is for the checkbox.

The actual form class used for emulation.
The Task Dialog structure which created the form.
The labels corresponding to the Task Dialog main elements.
The Task Dialog selection list.
The Task Dialog optional query editor.
The Task Dialog optional checkbox.

Structure for low-level access to the task dialog implementation. Points either to the HWND handle of the new TaskDialog API or to the emulation dialog.

Implements a TaskDialog. Uses the new TaskDialog API under Vista/Seven, and emulate it with pure Pascal code and standard themed components under XP or 2K. Creating a TTaskDialog object/record on the stack will initialize all of its string parameters to ''. Set the appropriate string parameters, then call Execute() with all additional parameters.

RadioRes/SelectionRes/VerifyChecked will be used to reflect the state after dialog execution.

Typical usage:

var Task: TTaskDialog; begin Task.Inst := 'Saving application settings'; Task.Content := 'This is the content'; Task.Radios := 'Store settings in registry' +#10+ ' Store settings in XML file'; Task.Verify := 'Do no ask for this setting next time'; Task.VerifyChecked := true; Task.Footer := 'XML file is perhaps a better choice'; Task.Execute([],0,[],tiQuestion,tfiInformation,200); ShowMessage(IntToStr(Task.RadioRes)); // 200=Registry, 201=XML if Task.VerifyChecked then ShowMessage(Task.Verify); end;
The main title of the dialog window. If left void, the title of the application main form is used.

The main instruction (first line displayed at the top of dialog). If not assigned (contains ''), the text is taken from resource strings for the message type defined in LCLStrConsts.

The text dispalyed as the primary content for the dialog. The value is used in the Execute method to add a label displayed in the dialog.

In previous LCL versions, '\n' characters sequences were converted to LineEnding characters. This action is no longer performed as of revision 64975.

A #13#10 or #10 separated list of custom buttons. They will be identified with an ID number starting at 100. By default, the buttons will be created at the dialog bottom, just like the common buttons. If tdfUseCommandLinks flag is set, the custom buttons will be created as big button in the middle of the dialog window; in this case, any '\n' will be converted as note text (shown with smaller text under native Vista/Seven TaskDialog, or as popup hint within Delphi emulation).

A #13#10 or #10 delimited list of custom radio buttons. They will be identified with an ID number starting at 200. aRadioDef parameter can be set to define the default selected value. '\n' will be converted as note text (shown with smaller text under native Vista/Seven TaskDialog, or as popup hint within Delphi emulation).

The expanded information content text. The Delphi emulation will always show the Info content (there is no collapse/expand button).

The button caption to be displayed when the information is expanded. Not used under XP: the Delphi emulation will always show the Info content.

The button caption to be displayed when the information is collapsed. Not used under XP. The Delphi emulation will always show the Info content.

The footer content text.

The text of the bottom most optional checkbox.

A #13#10 or #10 separated list of items to be selected. If set, a Combo Box will be displayed to select. If tdfQuery is in the flags, the combo box will be in addition mode and the user will be able to edit the Query text or fill the field with one item of the selection. This selection is not handled via the Vista/Seven TaskDialog, but with our Delphi emulation code (via a TComboBox).

Text to be edited. If tdfQuery is in the flags, will contain the default query text.

The selected radio item; the first is numbered 0.

After execution, contains the selected item from the Selection list.

Reflect the bottom-most optional checkbox state. If Verify is not '', should be set before execution. After execution, will contain the final checkbox state.

Low-level access to the task dialog implementation.

Launches the TaskDialog form.

Some common buttons can be set via aCommonButtons. In emulation mode, aFlags will handle only tdfUseCommandLinks, tdfUseCommandLinksNoIcon, and tdfQuery options.

Will return 0 on error, or the Button ID (e.g. mrOk for the OK button or 100 for the first custom button defined in Buttons string).

If Buttons was defined, aButtonDef can set the selected Button ID. If Radios was defined, aRadioDef can set the selected Radio ID.

aDialogIcon and aFooterIcon are used to specify the displayed icons.

aWidth can be used to force a custom form width (in pixels).

aParent can be set to any HWND - by default, Application.DialogHandle.

If aNonNative is TRUE, the Delphi emulation code will always be used. aEmulateClassicStyle can be set to enforce conformity with the non themed user interface - see @http://synopse.info/forum/viewtopic.php?pid=2867#p2867.

aOnButtonClicked can be set to a callback executed when a button is clicked.

Allow a OnButtonClicked callback to change the Task Dialog main elements. Note that tdeVerif could be modified only in emulation mode, since the API does not give any runtime access to the checkbox caption. Other elements will work in both emulated and native modes.

A wrapper around the TTaskDialog.Execute method. Used to provide a "flat" access to task dialog parameters.

The associated main TTaskDialog instance.

Some common buttons to be displayed.

The default button ID.

The associated configuration flags for this Task Dialog. In emulation mode, aFlags will handle only tdfUseCommandLinks, tdfUseCommandLinksNoIcon, and tdfQuery options.

Used to specify the dialog icon.
Used to specify the footer icon.
The default radio button ID.
Can be used to force a custom form width (in pixels).
If TRUE, the Delphi emulation code will always be used.
Can be used to enforce conformity with the non-themed user interface.
This event handler will be fired on a button dialog click.

Will initialize the dialog parameters. Can be used to display some information with less parameters. For example:

var TaskEx: TTaskDialogEx; // ... TaskEx.Init; TaskEx.Base.Title := 'Task Dialog Test'; TaskEx.Base.Inst := 'Callback Test'; TaskEx.Execute;

Main (and unique) method used to show the dialog. It is a wrapper around the TTaskDialog.Execute method.

Return the text without '&' (Ampersand) characters.

A default Task Dialog wrapper instance. Can be used to display some information with fewer parameters, just like the TTaskDialogEx.Init method. For example:

var TaskEx: TTaskDialogEx; // ... TaskEx := DefaultTaskDialog; TaskEx.Base.Title := 'Task Dialog Test'; TaskEx.Base.Inst := 'Callback Test'; TaskEx.Execute;
Function used to translate captions.

Will map a default font, according to the available fonts. If Calibri is installed, it will be used by default. Falls back to Tahoma otherwise.