Setup.UninstallProgressForm.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. unit Setup.UninstallProgressForm;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2025 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Uninstaller progress form
  8. }
  9. interface
  10. uses
  11. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  12. Setup.SetupForm, StdCtrls, ExtCtrls, BitmapImage, NewProgressBar, NewStaticText,
  13. NewNotebook, NewCtrls;
  14. type
  15. TUninstallProgressForm = class(TSetupForm)
  16. FOuterNotebook: TNewNotebook;
  17. FInnerPage: TNewNotebookPage;
  18. FInnerNotebook: TNewNotebook;
  19. FInstallingPage: TNewNotebookPage;
  20. FMainPanel: TPanel;
  21. FPageNameLabel: TNewStaticText;
  22. FPageDescriptionLabel: TNewStaticText;
  23. FWizardSmallBitmapImage: TBitmapImage;
  24. FBevel1: TBevel;
  25. FStatusLabel: TNewStaticText;
  26. FProgressBar: TNewProgressBar;
  27. FBeveledLabel: TNewStaticText;
  28. FBevel: TBevel;
  29. FCancelButton: TNewButton;
  30. protected
  31. procedure CreateParams(var Params: TCreateParams); override;
  32. public
  33. constructor Create(AOwner: TComponent); override;
  34. destructor Destroy; override;
  35. procedure Initialize(const ATitle, AAppName: String);
  36. procedure UpdateProgress(const AProgress, ARange: Integer);
  37. published
  38. property OuterNotebook: TNewNotebook read FOuterNotebook;
  39. property InnerPage: TNewNotebookPage read FInnerPage;
  40. property InnerNotebook: TNewNotebook read FInnerNotebook;
  41. property InstallingPage: TNewNotebookPage read FInstallingPage;
  42. property MainPanel: TPanel read FMainPanel;
  43. property PageNameLabel: TNewStaticText read FPageNameLabel;
  44. property PageDescriptionLabel: TNewStaticText read FPageDescriptionLabel;
  45. property WizardSmallBitmapImage: TBitmapImage read FWizardSmallBitmapImage;
  46. property Bevel1: TBevel read FBevel1;
  47. property StatusLabel: TNewStaticText read FStatusLabel;
  48. property ProgressBar: TNewProgressBar read FProgressBar;
  49. property BeveledLabel: TNewStaticText read FBeveledLabel;
  50. property Bevel: TBevel read FBevel;
  51. property CancelButton: TNewButton read FCancelButton;
  52. end;
  53. var
  54. UninstallProgressForm: TUninstallProgressForm;
  55. implementation
  56. uses
  57. Themes,
  58. TaskbarProgressFunc,
  59. Shared.SetupMessageIDs, Shared.CommonFunc.Vcl, Shared.Struct,
  60. SetupLdrAndSetup.Messages,
  61. Setup.MainForm, Setup.MainFunc, Setup.InstFunc;
  62. {$R *.DFM}
  63. { TUninstallProgressForm }
  64. procedure UninstallMessageBoxCallback(const Flags: Cardinal; const After: Boolean;
  65. const Param: NativeInt);
  66. const
  67. States: array [TNewProgressBarState] of TTaskbarProgressState =
  68. (tpsNormal, tpsError, tpsPaused);
  69. var
  70. UninstallProgressForm: TUninstallProgressForm;
  71. NewState: TNewProgressBarState;
  72. begin
  73. UninstallProgressForm := TUninstallProgressForm(Param);
  74. if After then
  75. NewState := npbsNormal
  76. else if (Flags and MB_ICONSTOP) <> 0 then
  77. NewState := npbsError
  78. else
  79. NewState := npbsPaused;
  80. with UninstallProgressForm.ProgressBar do begin
  81. State := NewState;
  82. Invalidate;
  83. end;
  84. SetAppTaskbarProgressState(States[NewState]);
  85. end;
  86. constructor TUninstallProgressForm.Create(AOwner: TComponent);
  87. begin
  88. inherited;
  89. SetMessageBoxCallbackFunc(UninstallMessageBoxCallback, NativeInt(Self));
  90. var LStyle := StyleServices(Self);
  91. if not LStyle.Enabled or LStyle.IsSystemStyle then
  92. LStyle := nil;
  93. if not CustomWizardBackground or (SetupHeader.WizardBackColor = clWindow) then
  94. MainPanel.ParentBackGround := False;
  95. InitializeFont;
  96. PageNameLabel.Font.Style := [fsBold];
  97. PageNameLabel.Caption := SetupMessages[msgWizardUninstalling];
  98. { Initialize wizard style: not done here but in TUninstallProgressForm.Initialize }
  99. { Adjust page name and description label - also see TWizardForm.Create }
  100. const I = FPageNameLabel.AdjustHeight;
  101. FPageDescriptionLabel.Top := FPageDescriptionLabel.Top + I;
  102. { Initialize BeveledLabel }
  103. if SetupMessages[msgBeveledLabel] <> '' then begin
  104. BeveledLabel.Caption := ' ' + SetupMessages[msgBeveledLabel] + ' ';
  105. BeveledLabel.Top := Bevel.Top - ((BeveledLabel.Height - 1) div 2);
  106. if not CustomWizardBackground then begin
  107. if LStyle <> nil then
  108. BeveledLabel.Color := LStyle.GetStyleColor(scWindow);
  109. end else
  110. BeveledLabel.Color := TBitmapImageImplementation.AdjustColorForStyle(Self, SetupHeader.WizardBackColor);
  111. BeveledLabel.Visible := True;
  112. end;
  113. CancelButton.Caption := SetupMessages[msgButtonCancel];
  114. end;
  115. destructor TUninstallProgressForm.Destroy;
  116. begin
  117. SetMessageBoxCallbackFunc(nil, 0);
  118. SetAppTaskbarProgressState(tpsNoProgress);
  119. inherited;
  120. end;
  121. procedure TUninstallProgressForm.Initialize(const ATitle, AAppName: String);
  122. begin
  123. var LStyle := StyleServices(Self);
  124. if not LStyle.Enabled or LStyle.IsSystemStyle then
  125. LStyle := nil;
  126. Caption := ATitle;
  127. PageDescriptionLabel.Caption := FmtSetupMessage1(msgUninstallStatusLabel, AAppName);
  128. StatusLabel.Caption := FmtSetupMessage1(msgStatusUninstalling, AAppName);
  129. { Initialize wizard style - also see TWizardForm.Create }
  130. if not CustomWizardBackground then begin
  131. if LStyle <> nil then begin
  132. { TNewNotebook ignores VCL Styles so it needs a bit of help }
  133. OuterNotebook.ParentColor := True;
  134. Color := LStyle.GetStyleColor(scWindow);
  135. end;
  136. end else begin
  137. OuterNotebook.ParentBackground := True;
  138. for var I := 0 to OuterNotebook.PageCount-1 do
  139. OuterNotebook.Pages[I].ParentBackground := True;
  140. InnerNotebook.ParentBackground := True;
  141. for var I := 0 to InnerNotebook.PageCount-1 do
  142. InnerNotebook.Pages[I].ParentBackground := True;
  143. end;
  144. if lfWizardModern in MessagesLangOptions.Flags then begin
  145. if LStyle = nil then begin
  146. if CustomWizardBackground then
  147. InternalError('Unexpected CustomWizardBackground value');
  148. OuterNotebook.Color := clWindow;
  149. end;
  150. Bevel1.Visible := False;
  151. end;
  152. if lfWizardBevelsHidden in MessagesLangOptions.Flags then begin
  153. Bevel1.Visible := False;
  154. Bevel.Visible := False;
  155. end;
  156. { Initialize image }
  157. if not WizardSmallBitmapImage.InitializeFromIcon(HInstance, PChar('Z_UNINSTALLICON' + WizardIconsPostfix), clNone, [32, 48, 64]) then {don't localize}
  158. WizardSmallBitmapImage.InitializeFromIcon(HInstance, PChar('MAINICON' + MainIconPostfix), clNone, [32, 48, 64]); {don't localize}
  159. end;
  160. procedure TUninstallProgressForm.CreateParams(var Params: TCreateParams);
  161. begin
  162. inherited;
  163. Params.WindowClass.style := Params.WindowClass.style or CS_NOCLOSE;
  164. end;
  165. procedure TUninstallProgressForm.UpdateProgress(const AProgress, ARange: Integer);
  166. var
  167. NewPos: Integer;
  168. begin
  169. NewPos := MulDiv(AProgress, ProgressBar.Max, ARange);
  170. if ProgressBar.Position <> NewPos then begin
  171. ProgressBar.Position := NewPos;
  172. SetAppTaskbarProgressValue(UInt64(NewPos), UInt64(ProgressBar.Max));
  173. end;
  174. end;
  175. end.