Implements an emulated task dialog for platforms where the Task Dialog API is not supported.

TaskDlgEmulation.pp contains types, routines, and variable used to implement a non-native, emulated Task Dialog. It is used in widgetset classes for platforms where the task dialog API is not available, or not supported for a specific version of an operating system. It emulates the functionality of TaskDialogIndirect available on Windows Vista and later versions. It adds capabilities that TaskDialogIndirect does not have, including:

  • Query via combo-box.
  • Query via single line edit, which supports masking the input for use with e.g. passwords.

It contains TLCLTaskDialog - a dynamically configured form displayed when a task dialog is executed using its configuration settings. The emulated dialog does not aim to be visually (near) exactly the same as the Vista+ native dialog.

This dialog is invoked by Dialogs.TTaskDialog.Execute on systems that do not support the native Vista+ dialog, and it is also used as a fallback in case the native Vista+ dialog fails (when passed invalid combination of arguments). The dialog therefore uses the Flags property of Dialogs.TTaskDialog, but not all of these flags are supported (yet) in the emulated dialog.

TaskDlgEmulation.pp is part of the Lazarus Component Library (LCL). This unit was originally a part of the freeware Synopse mORMot framework, and 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 name was SynTaskDialog.pas.

Added in LCL version 4.0 as replacement for the deprecated types in the lcltaskdialog.pas unit.
Represents the textual display elements on a task dialog form.

TTaskDialogElement is an enumerated type with values which represent the display areas for elements on an emulated task dialog form. Values in TTaskDialogElement are used in the implementation of TLCLTaskDialog as an index for TLabel instances used on the dialog form.

Content area which contains the text for the task dialog. Area with the expanded text for a task dialog. Area displayed at the bottom of a task dialog with the footer text and icon. Area with the title for a task dialog. Area used to display the query or simple query controls for a task dialog. Area used to display the check box with the verification text for a task dialog. Implements an emulated (non-native) task dialog form.

TLCLTaskDialog is a TForm descendant which implements the dialog form displayed when an emulated (non-native) TTaskDialog is executed. It imitates the content, layout, and behavior for the dialog displayed for the Windows Task Dialog API.

It provides support for use of TTaskDialog on platforms which do not implement the Task Dialog API - including Windows versions prior to Windows Vista. Most of the properties, methods, and members in the class are declared as private and are available to the methods in the class instance. Application do not normally create an instance of TLCLTaskDialog; it is created at run-time when TTaskDialog calls its Execute method.

TLCLTaskDialog allows the dialog form to be configured at run-time using the settings specified in the TTaskDialog passed as the Owner of the form. The Execute methods handles initializing the form instance, displaying the dialog, capturing the modal result value, and returning changes to the TTaskDialog for the emulated task dialog form.

Added in LCL version 4.0. TTaskDialog.Flags TForm
The task dialog instance which created and is the owner of the dialog form. The labels corresponding to the Task Dialog display elements. Combo-box control with the Task Dialog selection list. Edit control with the optional Task Dialog query editor. Check-box control used for optional Task Dialog verification. The expand/collapse button (expando control) for the Task dialog. The progress bar control for the Task dialog. Implements the event handler signalled when the expand/collapse button (expando control) has been clicked on the task dialog.

OnExpandButtonClicked is a method method used to perform actions needed when the expand/collapse button for the task dialog has been clicked. It is assigned during form set-up to the OnClick event handler for the TButton instance used on the form.

OnExpandButtonClicked ensures that the correct private method is called for the button click; the current value in the expanded state is used to determine whether expandable text is changed from expanded to collapsed, or vice versa. It also sets the new value for the private expanded state member.

The DoOnExpandButtonClicked in the TTaskDialog instance for the dialog form is called with the new value for the Expanded property.

Added in LCL version 4.0. TTaskDialog.Expanded TTaskDialog.ExpandedText TTaskDialog.DoOnExpandButtonClicked
Not used in the method. Configures and initializes properties and controls used on the emulated task dialog form.

SetupControls is a method used to configure / initialize controls and content on the emulated task dialog. Values from the TTaskDialog owner are copied to the dialog form, including:

  • Buttons
  • CommonButtons
  • RadioButtons
  • Caption (application title or main form caption when omitted)
  • Title (or the IconMessage when omitted)
  • Text
  • ExpandButtonCaption
  • CollapseButtonCaption
  • ExpandedText
  • FooterText
  • VerificationText

Values from the Flags property in TTaskDIalog are used to determine which content and UI elements are enabled on the dialog form.

SetupControls calls private method in the class to layout and align the elements on the dialog form. This includes setting the border style, border icons, and position for the dialog form. The font typeface and size used on the dialog are assigned in the method.

It creates and populates three (3) panels with the controls needed for the dialog. The top panel holds the main icon, title, text, and expanded text. The middle panel contains any radio buttons, command link buttons, query controls, or the progress bar for the dialog. The bottom panel contains the remainder of the controls on the dialog form including the expand /collapse button, verification check box, and footer text.

A timer enabled for the form is created, initialized, and started in the method.

SetupControls calculates the width needed for the dialog form. It uses the length of common elements (like Title, Text, and the cumlative length for button captions) when an explict Width has not been assigned for the task dialog. A minimum width of 120 pixels is assumed, but common calculated widths include 300, 420, amd 480 pixels. A minimum height of 200 pixels is assumed.

SetupControls is called from the Execute method before the ShowModal method is called for the emulated task dialog.

TCustomTaskDialog TTaskDialog TCustomForm.ShowModal
Implements the OnKeyDown event handler for the task dialog.

KeyDown is an overridden method in TLCLTaskDialog which implements the handler routine for OnKeyDown events in the dialog form. KeyDown ensures that Esc, Alt+F4, and F1 key down events are applied properly for the emulated task dialog.

When BorderIcons indicates that the dialog form can be closed (contains biSystemMenu), the Esc (Escape) key can be used to close the dialog form by calling the Close method. Without the system border icon, the Esc key is not handled in the method.

When Key and Shift indicate that the Alt+F4 key was pressed, the value in Key is digested (set to 0). The native task dialog blocks Alt+F4 to close the dialog, so it is blocked in the emulated task dialog as well.

When Key indicates that F1 was pressed, the DoOnHelp method in the TTaskDialog instance is called to signal an assigned OnHelp event handler in the task dialog. The value in Key is set to 0 to consume the key event.

KeyDown calls the inherited method prior to exit.

TForm.BorderIcons TWinControl.KeyDown TWinControl.OnKeyDown TShiftState
Virtual key code examined in the method. Shift, Control, or Alt modifier for the key. Alternate constructor for the class instance.

CreateNew is an overridden constructor in TLCLTaskDialog. It is the alternate constructor called when creating a form instance which does not have an associated resource file (.lfm). It extends the inherited method to assign the value in AOwner to the internal TTaskDialog member for the class instance.

CreateNew calls the inherited method to configure and initialize the dialog form instance. It sets the default values for internal members and properties like KeyPreview (True).

TCustomForm.CreateNew TForm.KeyPreview
Owner of the class instance. Instance sequence number for the new class instance. Included as a suffix in the Name for the class. Destructor for the class instance.

Destroy is the overridden destructor for the class instance. It ensures that the OnDialogDestroyed event handler in the TCustomTaskDialog instance for the dialog form is signalled (when assigned). Destroy calls the inherited destructor (in TCustomForm) prior to exit.

TCustomTaskDialog.DoOnDialogDestroyed TCustomForm.Destroy
Performs actions needed when a new instance of the class has been created.

AfterConstruction is an overridden method in TLCLTaskDialog used to perform actions needed when the emulated dialog form instance has been created. It calls the inherited method on entry to set the bounds for the form, signal the OnCreate event handler (when assigned), and to perform scaling when enabled in both the application and the form.

Use the OnDialogConstructed event handler in the TTaskDialog instance to perform actions needed when the Handle for the dialog form has been realized.

TCustomTaskDialog.Handle TCustomTaskDialog.OnDialogConstructed TCustomForm.AfterConstruction
Performs actions needed when the dialog form is initially displayed.

DoShow is an overridden method in TLCLTaskDialog used to perform actions needed when the task dialog form is displayed for the first time. DoShow is called when queued OnResize or OnChangeBounds event handlers are executed, or when the Showing property is set to True.

DoShow calls the inherited method on entry to signal the OnShow event handler (when assigned). It ensures that the Handle for the task dialog form is allocated before any dialog-specific event handlers are signalled, like OnDialogConstructed or OnDialogCreated.

TCustomTaskDialog.OnDialogConstructed TCustomTaskDialog.OnDialogCreated TCustomForm.DoShow TCustomForm.OnShow TWinControl.Showing
Configures and displays the emulated task dialog and returns the modal result value.

Execute is an Integer function used to configure, display, and capture the modal result value for the emulated task dialog. The return value contains the modal result for the button used to close the dialog form. No actions are performed in the method when the Owner of the form has not been assigned or is not a TTaskDialog instance. In this situation, the return value is -1.

Execute calls the SetupControls method to configure and layout the elements on the dialog form using the settings provided in the TTaskDialog instance.

AParentWnd contains the handle for the form that is used as the parent for the dialog form. The value is compared to the handles for the forms on the current Screen. When found, the form instance is assigned to the PopupParent property for the dialog form. When not found, the currently active form on the screen is used as the PopupParent.

Execute calls the ShowModal method (in TCustomForm) to manage modal display of the dialog form in the application, and to start the processing loop for the modal form. ShowModal sets the return value for the method.

When ShowModal has been completed, values from the updated form are applied to the TTaskDialog instance which created the dialog. This includes values like:

  • The query result and query item index (when used).
  • The value from the simple query control (when used).
  • The verification check box state (when used).
  • The identifier for the selected radio button returned in the ARadioRes argument.
TTaskDialog.Flags
Modal result value captured when ShowModal is called for the dialog form, or -1 when the owner is not a TTaskDialog instance. Handle for the form which is the parent for the dialog form, or 0 to use the active form on the screen. Returns the identifier for the selected radio button on the form, or 0 when not available. Executes an emulated task dialog for using the specified arguments.

ExecuteLCLTaskDialog is an Integer function used to execute an emulated task dialog form for the specified TCustomTaskDialog instance. It is a convenience routine called from the Execute method in the widgetset class instance for those platforms which do not support the native Task Dialog API.

ExecuteLCLTaskDialog creates a temporary instance of TLCLTaskDialog and calls its Execute method using the arguments to the routine. The return value contains the result from the Execute method in the dialog form; -1 indicates that ADlg did not contain a valid TCustomTaskDialog instance. Otherwise, it contains the modal result from the dialog form.

TCustomTaskDialog.Execute TCustomTaskDialog.ModalResult
Modal result value captured when the emulated task dialog form is executed. TTaskDialog instance with the settings for the task dialog. Handle for the form which is the parent for the task dialog form. Returns the identifier for the selected radio button on the task dialog form. Represents the available main icons for an emulated task dialog.

TLCLTaskDialogIcon is an enumerated type with values which represent the icons available as the main icon on an emulated task dialog form.

TTaskDialogIcon
Indicates that an icon is not used on the dialog form. Represents the Warning icon. Represents the Question Mark icon. Represents the Error icon. Represents the Information icon. This value is not used. Represents the Shield icon. Represents the available footer icons for an emulated task dialog.

TLCLTaskDialogFooterIcon is an enumerated type with values which represent the icons available as the footer icon on an emulated task dialog form.

Indicates that a footer icon is not used. Represents the Warning icon. Represents the Question Mark icon. Represents the Error icon. Represents the Information icon. Represents the Shield icon. Gets the title displayed on the task dialog for the specified main icon.

IconMessage is a String function used to get the title displayed on an emulated task dialog for the specified icon. It is used in the implementation of TLCLTaskDialog to retrieve the title on the emulated task dialog when the value has not already been assigned. The return value contains the translated resource string associated with the index value in the Icon argument. For example:

tiWarning
Returns rsMtWarning.
tiQuestion
Returns rsMtConfirmation.
tiError
Returns rsMtError.
tiInformation, tiShield
Returns rsMtInformation.
Other values
Returns an empty string ('').
TTaskDialogIcon
Translated message content for the specified icon. Specifies the icon used to identify the translated message in the return value.