TTaskDialog: start implementing TTaskDialogProgressBar: skeleton only, does not communicate with the dialog yet.

This commit is contained in:
Bart 2023-08-23 13:10:42 +02:00
parent 2885935b2d
commit fe0ed266ce
3 changed files with 104 additions and 0 deletions

View File

@ -1792,6 +1792,9 @@ type
TProgressBarStyle = (pbstNormal, pbstMarquee); TProgressBarStyle = (pbstNormal, pbstMarquee);
//used by TTaskDialogProgressBar, but Delphi defines it in ComCtrls unit
TProgressBarState = (pbsNormal, pbsError, pbsPaused);
{ TCustomProgressBar } { TCustomProgressBar }
{ {
@abstract(Simple progressbar.) @abstract(Simple progressbar.)

View File

@ -27,6 +27,7 @@ uses
LMessages, LResources, LCLIntf, InterfaceBase, LCLStrConsts, LCLType, LMessages, LResources, LCLIntf, InterfaceBase, LCLStrConsts, LCLType,
Forms, Controls, Themes, Graphics, Buttons, ButtonPanel, StdCtrls, Forms, Controls, Themes, Graphics, Buttons, ButtonPanel, StdCtrls,
ExtCtrls, LCLClasses, ClipBrd, Menus, {LCLTaskDialog,} DialogRes, ExtCtrls, LCLClasses, ClipBrd, Menus, {LCLTaskDialog,} DialogRes,
ComCtrls,
// LazUtils // LazUtils
GraphType, FileUtil, LazFileUtils, LazStringUtils, LazLoggerBase; GraphType, FileUtil, LazFileUtils, LazStringUtils, LazLoggerBase;
@ -634,6 +635,35 @@ type
property Items[Index: Integer]: TTaskDialogBaseButtonItem read GetItem write SetItem; default; property Items[Index: Integer]: TTaskDialogBaseButtonItem read GetItem write SetItem; default;
end; end;
TProgressBarState = ComCtrls.TProgressBarState; //it's where Delphi defines this type, so we need to follow
{ TTaskDialogProgressBar }
TTaskDialogProgressBar = class(TPersistent)
private
Dlg: TCustomTaskDialog;
FMarqueeSpeed: Cardinal;
FMax: Integer;
FMin: Integer;
FPosition: Integer;
FState: TProgressBarState;
procedure SetMarqueeSpeed(AValue: Cardinal);
procedure SetMax(AValue: Integer);
procedure SetMin(AValue: Integer);
procedure SetPosition(AValue: Integer);
procedure SetState(AValue: TProgressBarState);
public
constructor Create(ADialog: TCustomTaskDialog);
procedure Initialize; //call after dialog has been instatiated to send message to the dialog window
published
property MarqueeSpeed: Cardinal read FMarqueeSpeed write SetMarqueeSpeed default 0;
property Max: Integer read FMax write SetMax default 100;
property Min: Integer read FMin write SetMin default 0;
property Position: Integer read FPosition write SetPosition default 0;
property State: TProgressBarState read FState write SetState default pbsNormal;
end;
{ TCustomTaskDialog } { TCustomTaskDialog }
TCustomTaskDialog = class(TLCLComponent) TCustomTaskDialog = class(TLCLComponent)
@ -665,6 +695,7 @@ type
FOnRadioButtonClicked: TNotifyEvent; FOnRadioButtonClicked: TNotifyEvent;
FOnTimer: TTaskDlgTimerEvent; FOnTimer: TTaskDlgTimerEvent;
FOnVerificationClicked: TNotifyEvent; FOnVerificationClicked: TNotifyEvent;
FProgressBar: TTaskDialogProgressBar;
FQueryChoices: TStrings; FQueryChoices: TStrings;
FQueryResult: String; FQueryResult: String;
FQueryItemIndex: Integer; FQueryItemIndex: Integer;
@ -729,6 +760,7 @@ type
property MainIcon: TTaskDialogIcon read FMainIcon write FMainIcon default tdiInformation; property MainIcon: TTaskDialogIcon read FMainIcon write FMainIcon default tdiInformation;
property Handle: THandle read FHandle; //Handle to the dialog window property Handle: THandle read FHandle; //Handle to the dialog window
property ModalResult: TModalResult read FModalResult write FModalResult; property ModalResult: TModalResult read FModalResult write FModalResult;
property ProgressBar: TTaskDialogProgressBar read FProgressBar write FProgressBar;
property QueryChoices: TStrings read FQueryChoices write SetQueryChoices; property QueryChoices: TStrings read FQueryChoices write SetQueryChoices;
property QueryItemIndex: Integer read FQueryItemIndex write FQueryItemIndex; property QueryItemIndex: Integer read FQueryItemIndex write FQueryItemIndex;
property QueryResult: String read FQueryResult write FQueryResult; property QueryResult: String read FQueryResult write FQueryResult;
@ -770,6 +802,7 @@ type
property FooterIcon; property FooterIcon;
property FooterText; property FooterText;
property MainIcon; property MainIcon;
property ProgressBar;
property RadioButtons; property RadioButtons;
property QueryChoices; property QueryChoices;
property QueryItemIndex; property QueryItemIndex;

View File

@ -61,6 +61,71 @@ begin
inherited SetItem(Index, Value); inherited SetItem(Index, Value);
end; end;
{ TTaskDialogProgressBar }
procedure TTaskDialogProgressBar.SetMarqueeSpeed(AValue: Cardinal);
begin
if FMarqueeSpeed = AValue then Exit;
FMarqueeSpeed := AValue;
//ToDo: send TDM_SET_PROGRESS_BAR_MARQUEE to Dlg
end;
procedure TTaskDialogProgressBar.SetMax(AValue: Integer);
begin
if FMax = AValue then Exit;
FMax := AValue;
if (FMin > FMax) then
FMin := FMax;
//ToDo: send TDM_SET_PROGRESS_BAR_RANGE to Dlg
end;
procedure TTaskDialogProgressBar.SetMin(AValue: Integer);
begin
if FMin = AValue then Exit;
FMin := AValue;
if (FMin > FMax) then
FMin := FMax;
//ToDo: send TDM_SET_PROGRESS_BAR_RANGE to Dlg
end;
procedure TTaskDialogProgressBar.SetPosition(AValue: Integer);
begin
if FPosition = AValue then Exit;
FPosition := AValue;
if (FPosition < FMin) then
FPosition := FMIn
else
if (FPosition > FMax) then
FPosition := FMax;
//ToDo: send TDM_SET_PROGRESS_BAR_POS to Dlg
//Todo 2: test if Delphi raises an excpetion if FPosition is out of range
end;
procedure TTaskDialogProgressBar.SetState(AValue: TProgressBarState);
begin
if FState = AValue then Exit;
FState := AValue;
//ToDo: send TDM_SET_PROGRESS_BAR_STATE to Dlg
end;
constructor TTaskDialogProgressBar.Create(ADialog: TCustomTaskDialog);
begin
inherited Create;
Dlg := ADialog;
FMin := 0;
FMax := 100;
FMarqueeSpeed := 0;
end;
procedure TTaskDialogProgressBar.Initialize;
//this should be invoked as soon as the dialog has been instatiated (so Dlg.Handle <> 0),
//so probably in Dlg.DoOnConstructed??
begin
//ToDo:
// send TDM_SET_MARQUEE_PROGRESS_BAR to Dlg (differentiates between "normal" and marguee)
// send range, position and state to dialog.
end;
{ TTaskDialogRadioButtonItem } { TTaskDialogRadioButtonItem }
constructor TTaskDialogRadioButtonItem.Create(ACollection: TCollection); constructor TTaskDialogRadioButtonItem.Create(ACollection: TCollection);
@ -98,6 +163,7 @@ begin
FCustomFooterIcon := TIcon.Create; FCustomFooterIcon := TIcon.Create;
FCustomMainIcon := TIcon.Create; FCustomMainIcon := TIcon.Create;
FProgressBar := TTaskDialogProgressBar.Create(Self);
FHandle := 0; FHandle := 0;
end; end;
@ -139,6 +205,7 @@ begin
FQueryChoices.Free; FQueryChoices.Free;
FCustomFooterIcon.Free; FCustomFooterIcon.Free;
FCustomMainIcon.Free; FCustomMainIcon.Free;
FProgressBar.Free;
inherited Destroy; inherited Destroy;
end; end;
@ -188,6 +255,7 @@ end;
procedure TCustomTaskDialog.DoOnDialogConstructed; procedure TCustomTaskDialog.DoOnDialogConstructed;
begin begin
FProgressBar.Initialize;
if Assigned(FOnDialogConstructed) then if Assigned(FOnDialogConstructed) then
FOnDialogConstructed(Self); FOnDialogConstructed(Self);
end; end;