choice_page.iss.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. var
  2. ChoicePagePrepare: array of TNotifyEvent;
  3. ChoicePageSelectionChange: array of TNotifyEvent;
  4. ChoicePageValidate: array of TWizardPageButtonEvent;
  5. ChoicePageMaxTag: Integer;
  6. ChoicePages: array of TInputOptionWizardPage;
  7. procedure ChoicePageOnClickCheck(Sender: TObject);
  8. var
  9. ListBox: TNewCheckListBox;
  10. Id: Integer;
  11. begin
  12. ListBox := TNewCheckListBox(Sender);
  13. Id := Integer(ListBox.Tag);
  14. ChoicePageSelectionChange[Id](ChoicePages[Id]);
  15. end;
  16. function ChoicePageGetInput(Page: TInputOptionWizardPage): TNewEdit;
  17. begin
  18. Result := TNewEdit(Page.FindComponent('ChoicePageInput'));
  19. end;
  20. function ChoicePageGetLabel(Page: TInputOptionWizardPage): TNewStaticText;
  21. begin
  22. Result := TNewStaticText(Page.FindComponent('ChoicePageLabel'));
  23. end;
  24. function ChoicePageGetButton(Page: TInputOptionWizardPage): TNewButton;
  25. begin
  26. Result := TNewButton(Page.FindComponent('ChoicePageBrowseButton'));
  27. end;
  28. procedure ChoicePageSetEditLabel(Page: TInputOptionWizardPage; Caption: String);
  29. var
  30. InputLabel: TNewStaticText;
  31. begin
  32. InputLabel := ChoicePageGetLabel(Page);
  33. InputLabel.Caption := Caption;
  34. end;
  35. function ChoicePageGetInputText(Page: TInputOptionWizardPage): String;
  36. begin
  37. Result := ChoicePageGetInput(Page).Text;
  38. end;
  39. procedure ChoicePageSetInputText(Page: TInputOptionWizardPage; Text: String);
  40. begin
  41. ChoicePageGetInput(Page).Text := Text;
  42. end;
  43. procedure ChoicePageSetInputEnabled(Page: TInputOptionWizardPage; Enabled: Boolean);
  44. begin
  45. ChoicePageGetLabel(Page).Enabled := Enabled;
  46. ChoicePageGetInput(Page).Enabled := Enabled;
  47. ChoicePageGetButton(Page).Enabled := Enabled;
  48. end;
  49. procedure ChoicePageOnBrowseButtonClick(Sender: TObject);
  50. var
  51. Button: TNewButton;
  52. Page: TInputOptionWizardPage;
  53. InputLabel: TNewStaticText;
  54. Input: TNewEdit;
  55. Dir: String;
  56. begin
  57. Button := TNewButton(Sender);
  58. Page := TInputOptionWizardPage(Button.Owner);
  59. Input := ChoicePageGetInput(Page);
  60. InputLabel := ChoicePageGetLabel(Page);
  61. Dir := Input.Text;
  62. if BrowseForFolder(InputLabel.Caption, Dir, True) then
  63. begin
  64. Input.Text := Dir;
  65. end;
  66. end;
  67. <event('CurPageChanged')>
  68. procedure ChoicePageOnCurPageChanged(CurPageID: Integer);
  69. var
  70. i: Integer;
  71. begin
  72. for i := 1 to ChoicePageMaxTag do
  73. begin
  74. if ChoicePages[i].ID = CurPageID then
  75. begin
  76. ChoicePagePrepare[i](ChoicePages[i]);
  77. break;
  78. end;
  79. end;
  80. end;
  81. <event('NextButtonClick')>
  82. function ChoicePageOnNextButtonClick(CurPageID: Integer): Boolean;
  83. var
  84. i: Integer;
  85. begin
  86. Result := True;
  87. for i := 1 to ChoicePageMaxTag do
  88. begin
  89. if ChoicePages[i].ID = CurPageID then
  90. begin
  91. Result := ChoicePageValidate[i](ChoicePages[i]);
  92. break;
  93. end;
  94. end;
  95. end;
  96. <event('InitializeWizard')>
  97. procedure InitChoicePages();
  98. begin
  99. ChoicePages := [ ];
  100. ChoicePagePrepare := [ ];
  101. ChoicePageSelectionChange := [ ];
  102. ChoicePageValidate := [ ];
  103. end;
  104. function FindLinkInText(Text: String): String;
  105. var
  106. Tmp: String;
  107. LinkStartPos, LinkEndPos: Integer;
  108. begin
  109. Result := '';
  110. Tmp := Text;
  111. LinkStartPos := Pos('https://', Tmp);
  112. if LinkStartPos = 0 then exit;
  113. Delete(Tmp, 1, LinkStartPos - 1);
  114. { Try to find the end of the link }
  115. LinkEndPos := 0
  116. if LinkEndPos = 0 then LinkEndPos := Pos(' ', Tmp);
  117. if LinkEndPos = 0 then LinkEndPos := Pos(',', Tmp);
  118. if LinkEndPos = 0 then LinkEndPos := Pos('.', Tmp);
  119. if LinkEndPos = 0 then LinkEndPos := Length(Tmp);
  120. Delete(Text, LinkEndPos, Length(Tmp));
  121. Log('Found link in "' + Text + '": "' + Tmp + '"');
  122. Result := Tmp;
  123. end;
  124. procedure OnStaticTextClick(Sender: TObject);
  125. var
  126. StaticText: TNewStaticText;
  127. Link: String;
  128. Err: Integer;
  129. begin
  130. StaticText := TNewStaticText(Sender);
  131. Link := FindLinkInText(StaticText.Caption);
  132. if Link = '' then
  133. exit;
  134. ShellExec('open', Link, '', '', SW_SHOWNORMAL, ewNoWait, Err);
  135. end;
  136. procedure MakeStaticTextClickable(StaticText: TNewStaticText);
  137. begin
  138. if FindLinkInText(StaticText.Caption) = '' then
  139. exit;
  140. StaticText.OnClick := @OnStaticTextClick;
  141. StaticText.Cursor := crHand;
  142. end;
  143. function ChoicePageCreate(
  144. const AfterID: Integer;
  145. const Caption, Description, SubCaption, EditCaption: String;
  146. HasDirectoryChooser: Boolean;
  147. Prepare: TNotifyEvent;
  148. SelectionChange: TNotifyEvent;
  149. Validate: TWizardPageButtonEvent): TInputOptionWizardPage;
  150. var
  151. VSpace, Y : Integer;
  152. ChoicePage: TInputOptionWizardPage;
  153. InputLabel: TNewStaticText;
  154. Input: TNewEdit;
  155. Button: TNewButton;
  156. begin
  157. ChoicePageMaxTag := ChoicePageMaxTag + 1;
  158. VSpace := ScaleY(8);
  159. ChoicePage := CreateInputOptionPage(AfterID, Caption,
  160. Description, SubCaption, True, True);
  161. MakeStaticTextClickable(ChoicePage.SubCaptionLabel);
  162. ChoicePage.Tag := ChoicePageMaxTag;
  163. ChoicePage.CheckListBox.OnClickCheck := @ChoicePageOnClickCheck;
  164. ChoicePage.CheckListBox.Tag := ChoicePageMaxTag;
  165. if HasDirectoryChooser then
  166. begin
  167. ChoicePage.CheckListBox.Anchors := [ akLeft, akTop, akRight ];
  168. ChoicePage.CheckListBox.Height := ChoicePage.CheckListBox.Height - ScaleY(60);
  169. Y := ChoicePage.CheckListBox.Top + ChoicePage.CheckListBox.Height + VSpace;
  170. InputLabel := TNewStaticText.Create(ChoicePage);
  171. with InputLabel do
  172. begin
  173. Top := Y;
  174. Anchors := [akTop, akLeft, akRight];
  175. Caption := EditCaption;
  176. AutoSize := True;
  177. Parent := ChoicePage.Surface;
  178. Name := 'ChoicePageLabel';
  179. end;
  180. MakeStaticTextClickable(InputLabel);
  181. Y := Y + InputLabel.Height + VSpace;
  182. Input := TNewEdit.Create(ChoicePage);
  183. with Input do
  184. begin
  185. Top := Y;
  186. Anchors := [akTop, akLeft, akRight];
  187. Parent := ChoicePage.Surface;
  188. Name := 'ChoicePageInput';
  189. Text := '';
  190. end;
  191. Button := TNewButton.Create(ChoicePage);
  192. with Button do
  193. begin
  194. Anchors := [akTop, akRight];
  195. Parent := ChoicePage.Surface;
  196. Width := WizardForm.NextButton.Width;
  197. Height := WizardForm.NextButton.Height;
  198. Top := Y - (Height - Input.Height) / 2;
  199. Left := ChoicePage.SurfaceWidth - Button.Width;
  200. Name := 'ChoicePageBrowseButton';
  201. Caption := SetupMessage(msgButtonWizardBrowse);
  202. OnClick := @ChoicePageOnBrowseButtonClick;
  203. end;
  204. Input.Width := Button.Left - ScaleX(8);
  205. end;
  206. SetArrayLength(ChoicePages, ChoicePageMaxTag+1);
  207. SetArrayLength(ChoicePagePrepare, ChoicePageMaxTag+1);
  208. SetArrayLength(ChoicePageSelectionChange, ChoicePageMaxTag+1);
  209. SetArrayLength(ChoicePageValidate, ChoicePageMaxTag+1);
  210. ChoicePages[ChoicePageMaxTag] := ChoicePage;
  211. ChoicePagePrepare[ChoicePageMaxTag] := Prepare;
  212. ChoicePageSelectionChange[ChoicePageMaxTag] := SelectionChange;
  213. ChoicePageValidate[ChoicePageMaxTag] := Validate;
  214. Result := ChoicePage;
  215. end;