IDE.StartupForm.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. unit IDE.StartupForm;
  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. Compiler IDE Startup form
  8. }
  9. interface
  10. uses
  11. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  12. UIStateForm, StdCtrls, ExtCtrls, BitmapButton, BitmapImage;
  13. type
  14. TStartupFormResult = (srNone, srEmpty, srWizard, srOpenFile, srOpenDialog,
  15. srOpenDialogExamples);
  16. TStartupForm = class(TUIStateForm)
  17. OKButton: TButton;
  18. CancelButton: TButton;
  19. GroupBox1: TGroupBox;
  20. GroupBox2: TGroupBox;
  21. EmptyRadioButton: TRadioButton;
  22. WizardRadioButton: TRadioButton;
  23. OpenRadioButton: TRadioButton;
  24. OpenListBox: TListBox;
  25. StartupCheck: TCheckBox;
  26. NewImage: TImage;
  27. OpenImage: TImage;
  28. DonateBitBtn: TBitmapButton;
  29. MailingListBitBtn: TBitmapButton;
  30. DonateImageDark: TBitmapImage;
  31. MailingListImageDark: TBitmapImage;
  32. procedure RadioButtonClick(Sender: TObject);
  33. procedure FormCreate(Sender: TObject);
  34. procedure DblClick_(Sender: TObject);
  35. procedure OpenListBoxClick(Sender: TObject);
  36. procedure OKButtonClick(Sender: TObject);
  37. procedure FormAfterMonitorDpiChanged(Sender: TObject; OldDPI,
  38. NewDPI: Integer);
  39. procedure DonateBitBtnClick(Sender: TObject);
  40. procedure MailingListBitBtnClick(Sender: TObject);
  41. private
  42. FResult: TStartupFormResult;
  43. FResultMainFileName: TFileName;
  44. procedure SetMRUFilesList(const MRUFilesList: TStringList);
  45. procedure UpdateImages;
  46. protected
  47. procedure CreateWnd; override;
  48. procedure CreateParams(var Params: TCreateParams); override;
  49. public
  50. property MRUFilesList: TStringList write SetMRUFilesList;
  51. property Result: TStartupFormResult read FResult;
  52. property ResultMainFileName: TFileName read FResultMainFileName;
  53. end;
  54. implementation
  55. uses
  56. ComCtrls,
  57. Shared.LicenseFunc, Shared.CommonFunc.Vcl, Shared.CommonFunc,
  58. IDE.Messages, IDE.HelperFunc, IDE.MainForm, IDE.ImagesModule;
  59. {$R *.DFM}
  60. procedure TStartupForm.SetMRUFilesList(const MRUFilesList: TStringList);
  61. begin
  62. if MRUFilesList.Count > 0 then begin
  63. const NDefault = OpenListBox.Items.Count;
  64. OpenListBox.Items.AddStrings(MRUFilesList);
  65. UpdateHorizontalExtent(OpenListBox);
  66. OpenListBox.ItemIndex := NDefault;
  67. end;
  68. end;
  69. procedure TStartupForm.UpdateImages;
  70. function GetImage(const Button: TToolButton; const WH: Integer): TWICImage;
  71. begin
  72. Result := ImagesModule.LightToolBarImageCollection.GetSourceImage(Button.ImageIndex, WH, WH)
  73. end;
  74. begin
  75. { After a DPI change the button's Width and Height isn't yet updated, so calculate it ourselves }
  76. var WH := MulDiv(16, CurrentPPI, 96);
  77. NewImage.Picture.Graphic:= GetImage(MainForm.NewMainFileButton, WH);
  78. OpenImage.Picture.Graphic := GetImage(MainForm.OpenMainFileButton, WH);
  79. end;
  80. procedure TStartupForm.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI,
  81. NewDPI: Integer);
  82. begin
  83. UpdateImages;
  84. end;
  85. procedure TStartupForm.FormCreate(Sender: TObject);
  86. begin
  87. FResult := srNone;
  88. InitFormFont(Self);
  89. InitFormTheme(Self);
  90. if IsLicensed then begin
  91. DonateBitBtn.Visible := False;
  92. const DiffX = MailingListBitBtn.Left - DonateBitBtn.Left;
  93. MailingListBitBtn.Left := MailingListBitBtn.Left - DiffX;
  94. StartupCheck.Left := StartupCheck.Left - DiffX;
  95. end else
  96. DonateBitBtn.Hint := MainForm.UpdatePanelDonateBitBtn.Hint;
  97. if InitFormThemeIsDark then begin
  98. if DonateBitBtn.Visible then
  99. DonateBitBtn.Bitmap := DonateImageDark.Bitmap;
  100. MailingListBitBtn.Bitmap := MailingListImageDark.Bitmap;
  101. end;
  102. UpdateImages;
  103. OpenListBox.Items.Add(SCompilerExampleScripts);
  104. OpenListBox.Items.Add(SCompilerMoreFiles);
  105. OpenListBox.ItemIndex := 0;
  106. UpdateHorizontalExtent(OpenListBox);
  107. OpenRadioButton.Checked := True;
  108. ActiveControl := OpenRadioButton;
  109. end;
  110. { This and CreateParams make bsSizeable (which has an unwanted icon) look like bsDialog, see:
  111. https://stackoverflow.com/questions/32096482/delphi-resizable-bsdialog-form/32098633 }
  112. procedure TStartupForm.CreateWnd;
  113. begin
  114. inherited;
  115. SendMessage(Handle, WM_SETICON, ICON_BIG, 0);
  116. end;
  117. procedure TStartupForm.CreateParams(var Params: TCreateParams);
  118. begin
  119. inherited CreateParams(Params);
  120. Params.ExStyle := Params.ExStyle or WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE;
  121. end;
  122. procedure TStartupForm.RadioButtonClick(Sender: TObject);
  123. begin
  124. EmptyRadioButton.Checked := Sender = EmptyRadioButton;
  125. WizardRadioButton.Checked := Sender = WizardRadioButton;
  126. OpenRadioButton.Checked := Sender = OpenRadioButton;
  127. if Sender = OpenRadioButton then begin
  128. if OpenListBox.ItemIndex = -1 then
  129. OpenListBox.ItemIndex := 0;
  130. end
  131. else
  132. OpenListBox.ItemIndex := -1;
  133. end;
  134. procedure TStartupForm.DblClick_(Sender: TObject);
  135. begin
  136. if OkButton.Enabled then
  137. OkButton.Click;
  138. end;
  139. procedure TStartupForm.OpenListBoxClick(Sender: TObject);
  140. begin
  141. OpenRadioButton.Checked := True;
  142. end;
  143. procedure TStartupForm.DonateBitBtnClick(Sender: TObject);
  144. begin
  145. OpenDonateSite;
  146. end;
  147. procedure TStartupForm.MailingListBitBtnClick(Sender: TObject);
  148. begin
  149. OpenMailingListSite;
  150. end;
  151. procedure TStartupForm.OKButtonClick(Sender: TObject);
  152. begin
  153. if EmptyRadioButton.Checked then
  154. FResult := srEmpty
  155. else if WizardRadioButton.Checked then
  156. FResult := srWizard
  157. else { if OpenRadioButton.Checked then } begin
  158. if OpenListBox.ItemIndex = 0 then
  159. FResult := srOpenDialogExamples
  160. else if OpenListBox.ItemIndex > 1 then begin
  161. FResult := srOpenFile;
  162. FResultMainFileName := OpenListBox.Items[OpenListBox.ItemIndex];
  163. end else
  164. FResult := srOpenDialog;
  165. end;
  166. end;
  167. end.