IDE.MsgBoxDesignerForm.pas 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. unit IDE.MsgBoxDesignerForm;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2024 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. MessageBox Designer form
  8. Originally contributed by leserg73
  9. }
  10. interface
  11. uses
  12. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  13. UIStateForm, StdCtrls, ExtCtrls, NewStaticText, ComCtrls, pngimage;
  14. type
  15. TMsgBoxDesignerForm = class(TUIStateForm)
  16. IMGmbInformation: TImage;
  17. IMGmbConfirmation: TImage;
  18. IMGmbError: TImage;
  19. IMGmbCriticalError: TImage;
  20. Panel1: TPanel;
  21. GroupBox1: TGroupBox;
  22. GroupBox2: TGroupBox;
  23. MSGText: TMemo;
  24. rb_mbInformation: TRadioButton;
  25. rb_mbConfirmation: TRadioButton;
  26. rb_mbError: TRadioButton;
  27. rb_mbCriticalError: TRadioButton;
  28. GroupBox3: TGroupBox;
  29. MBDButtonOK: TButton;
  30. MBDButtonCancel: TButton;
  31. MBDButtonPreview: TButton;
  32. Bevel1: TBevel;
  33. rbMB_OK: TRadioButton;
  34. rbMB_OKCANCEL: TRadioButton;
  35. rbMB_YESNO: TRadioButton;
  36. rbMB_YESNOCANCEL: TRadioButton;
  37. rbMB_RETRYCANCEL: TRadioButton;
  38. rbMB_ABORTRETRYIGNORE: TRadioButton;
  39. GroupBox4: TGroupBox;
  40. cb_IDOK: TCheckBox;
  41. cb_IDCANCEL: TCheckBox;
  42. cb_IDYES: TCheckBox;
  43. cb_IDNO: TCheckBox;
  44. cb_IDABORT: TCheckBox;
  45. cb_IDRETRY: TCheckBox;
  46. cb_IDIGNORE: TCheckBox;
  47. GroupBox5: TGroupBox;
  48. cb_MB_SETFOREGROUND: TCheckBox;
  49. NewStaticText1: TNewStaticText;
  50. NewEdit1: TEdit;
  51. UpDown1: TUpDown;
  52. GroupBox6: TGroupBox;
  53. cb_MsgBox: TRadioButton;
  54. cb_TaskDialogMsgBox: TRadioButton;
  55. rb_IDOK: TCheckBox;
  56. rb_IDCANCEL: TCheckBox;
  57. rb_IDYES: TCheckBox;
  58. rb_IDNO: TCheckBox;
  59. rb_IDABORT: TCheckBox;
  60. rb_IDRETRY: TCheckBox;
  61. rb_IDIGNORE: TCheckBox;
  62. TaskInstructionLabel: TNewStaticText;
  63. TaskMessageLabel: TNewStaticText;
  64. TaskInstructionText: TEdit;
  65. TaskMessageText: TEdit;
  66. Button1Text: TEdit;
  67. Button2Text: TEdit;
  68. Button3Text: TEdit;
  69. Button1Label: TNewStaticText;
  70. Button2Label: TNewStaticText;
  71. Button3Label: TNewStaticText;
  72. cb_Suppressible: TCheckBox;
  73. cb_DefIDOK: TRadioButton;
  74. cb_DefIDCANCEL: TRadioButton;
  75. cb_DefIDYES: TRadioButton;
  76. cb_DefIDNO: TRadioButton;
  77. cb_DefIDABORT: TRadioButton;
  78. cb_DefIDRETRY: TRadioButton;
  79. cb_DefIDIGNORE: TRadioButton;
  80. procedure FormCreate(Sender: TObject);
  81. procedure UpDown1Changing(Sender: TObject; var AllowChange: Boolean);
  82. procedure rbMB_OKClick(Sender: TObject);
  83. procedure rbMB_OKCANCELClick(Sender: TObject);
  84. procedure rbMB_YESNOClick(Sender: TObject);
  85. procedure rbMB_RETRYCANCELClick(Sender: TObject);
  86. procedure rbMB_YESNOCANCELClick(Sender: TObject);
  87. procedure rbMB_ABORTRETRYIGNOREClick(Sender: TObject);
  88. procedure MBDButtonPreviewClick(Sender: TObject);
  89. procedure cb_TaskDialogMsgBoxClick(Sender: TObject);
  90. procedure cb_MsgBoxClick(Sender: TObject);
  91. procedure rb_IDOKClick(Sender: TObject);
  92. procedure rb_IDCANCELClick(Sender: TObject);
  93. procedure rb_IDNOClick(Sender: TObject);
  94. procedure rb_IDYESClick(Sender: TObject);
  95. procedure rb_IDRETRYClick(Sender: TObject);
  96. procedure rb_IDIGNOREClick(Sender: TObject);
  97. procedure rb_IDABORTClick(Sender: TObject);
  98. procedure cb_SuppressibleClick(Sender: TObject);
  99. procedure MSGTextKeyPress(Sender: TObject; var Key: Char);
  100. public
  101. function GetText(TabWidth: Integer; UseTabCharacter: Boolean): String;
  102. end;
  103. implementation
  104. uses
  105. Shared.CommonFunc.Vcl, Shared.CommonFunc, IDE.HelperFunc, Shared.TaskDialogFunc, IDE.Messages;
  106. {$R *.DFM}
  107. procedure TMsgBoxDesignerForm.FormCreate(Sender: TObject);
  108. begin
  109. InitFormFont(Self);
  110. InitFormTheme(Self);
  111. cb_Suppressible.Checked := True;
  112. MSGText.Lines[MSGText.CaretPos.Y] := '<Enter your text here...>';
  113. MSGText.SelStart := MSGText.Perform(EM_LINEINDEX, 0, 0);
  114. MSGText.SelLength := Length(MSGText.Lines[0]);
  115. cb_IDCANCEL.Enabled := False;
  116. cb_IDABORT.Enabled := False;
  117. cb_IDRETRY.Enabled := False;
  118. cb_IDIGNORE.Enabled := False;
  119. cb_IDYES.Enabled := False;
  120. cb_IDNO.Enabled := False;
  121. NewStaticText1.Enabled := False;
  122. NewEdit1.Enabled := False;
  123. UpDown1.Enabled := False;
  124. TaskInstructionLabel.Visible := False;
  125. TaskMessageLabel.Visible := False;
  126. TaskInstructionText.Visible := False;
  127. TaskMessageText.Visible := False;
  128. Button1Text.Visible := False;
  129. Button2Text.Visible := False;
  130. Button3Text.Visible := False;
  131. Button1Label.Visible := False;
  132. Button2Label.Visible := False;
  133. Button3Label.Visible := False;
  134. end;
  135. procedure TMsgBoxDesignerForm.rbMB_OKClick(Sender: TObject);
  136. begin
  137. cb_IDOK.Checked := False;
  138. cb_IDCANCEL.Checked := False;
  139. cb_IDABORT.Checked := False;
  140. cb_IDRETRY.Checked := False;
  141. cb_IDIGNORE.Checked := False;
  142. cb_IDYES.Checked := False;
  143. cb_IDNO.Checked := False;
  144. cb_IDOK.Enabled := False;
  145. cb_IDCANCEL.Enabled := False;
  146. cb_IDABORT.Enabled := False;
  147. cb_IDRETRY.Enabled := False;
  148. cb_IDIGNORE.Enabled := False;
  149. cb_IDYES.Enabled := False;
  150. cb_IDNO.Enabled := False;
  151. NewStaticText1.Enabled := False;
  152. NewEdit1.Enabled := False;
  153. NewEdit1.Text := '1';
  154. UpDown1.Enabled := False;
  155. if cb_TaskDialogMsgBox.Checked then begin
  156. rb_IDOK.Enabled := True;
  157. rb_IDCANCEL.Enabled := False;
  158. rb_IDABORT.Enabled := False;
  159. rb_IDRETRY.Enabled := False;
  160. rb_IDIGNORE.Enabled := False;
  161. rb_IDYES.Enabled := False;
  162. rb_IDNO.Enabled := False;
  163. rb_IDOK.Checked := False;
  164. rb_IDCANCEL.Checked := False;
  165. rb_IDABORT.Checked := False;
  166. rb_IDRETRY.Checked := False;
  167. rb_IDIGNORE.Checked := False;
  168. rb_IDYES.Checked := False;
  169. rb_IDNO.Checked := False;
  170. Button3Text.Enabled := False;
  171. Button3Label.Enabled := False;
  172. Button2Text.Enabled := False;
  173. Button2Label.Enabled := False;
  174. Button1Text.Enabled := True;
  175. Button1Label.Enabled := True;
  176. Button1Text.Text := 'OK';
  177. Button2Text.Text := '';
  178. Button3Text.Text := '';
  179. end;
  180. if cb_Suppressible.Checked then begin
  181. cb_DefIDOK.Checked := True;
  182. cb_DefIDCANCEL.Checked := False;
  183. cb_DefIDYES.Checked := False;
  184. cb_DefIDNO.Checked := False;
  185. cb_DefIDABORT.Checked := False;
  186. cb_DefIDRETRY.Checked := False;
  187. cb_DefIDIGNORE.Checked := False;
  188. cb_DefIDOK.Enabled := True;
  189. cb_DefIDCANCEL.Enabled := False;
  190. cb_DefIDYES.Enabled := False;
  191. cb_DefIDNO.Enabled := False;
  192. cb_DefIDABORT.Enabled := False;
  193. cb_DefIDRETRY.Enabled := False;
  194. cb_DefIDIGNORE.Enabled := False;
  195. end;
  196. end;
  197. procedure TMsgBoxDesignerForm.rbMB_YESNOClick(Sender: TObject);
  198. begin
  199. cb_IDOK.Checked := False;
  200. cb_IDCANCEL.Checked := False;
  201. cb_IDABORT.Checked := False;
  202. cb_IDRETRY.Checked := False;
  203. cb_IDIGNORE.Checked := False;
  204. cb_IDYES.Checked := False;
  205. cb_IDNO.Checked := False;
  206. cb_IDOK.Enabled := False;
  207. cb_IDCANCEL.Enabled := False;
  208. cb_IDABORT.Enabled := False;
  209. cb_IDRETRY.Enabled := False;
  210. cb_IDIGNORE.Enabled := False;
  211. cb_IDYES.Enabled := True;
  212. cb_IDNO.Enabled := True;
  213. if not cb_TaskDialogMsgBox.Checked then begin
  214. NewStaticText1.Enabled := True;
  215. NewEdit1.Enabled := True;
  216. NewEdit1.Text := '1';
  217. UpDown1.Max := 2;
  218. UpDown1.Enabled := True;
  219. end;
  220. if cb_TaskDialogMsgBox.Checked then begin
  221. rb_IDOK.Enabled := False;
  222. rb_IDCANCEL.Enabled := False;
  223. rb_IDABORT.Enabled := False;
  224. rb_IDRETRY.Enabled := False;
  225. rb_IDIGNORE.Enabled := False;
  226. rb_IDYES.Enabled := True;
  227. rb_IDNO.Enabled := True;
  228. rb_IDOK.Checked := False;
  229. rb_IDCANCEL.Checked := False;
  230. rb_IDABORT.Checked := False;
  231. rb_IDRETRY.Checked := False;
  232. rb_IDIGNORE.Checked := False;
  233. rb_IDYES.Checked := False;
  234. rb_IDNO.Checked := False;
  235. Button3Text.Enabled := False;
  236. Button3Label.Enabled := False;
  237. Button2Text.Enabled := True;
  238. Button2Label.Enabled := True;
  239. Button1Text.Enabled := True;
  240. Button1Label.Enabled := True;
  241. Button1Text.Text := 'Yes';
  242. Button2Text.Text := 'No';
  243. Button3Text.Text := '';
  244. end;
  245. if cb_Suppressible.Checked then begin
  246. cb_DefIDOK.Checked := False;
  247. cb_DefIDCANCEL.Checked := False;
  248. cb_DefIDYES.Checked := True;
  249. cb_DefIDNO.Checked := False;
  250. cb_DefIDABORT.Checked := False;
  251. cb_DefIDRETRY.Checked := False;
  252. cb_DefIDIGNORE.Checked := False;
  253. cb_DefIDOK.Enabled := False;
  254. cb_DefIDCANCEL.Enabled := False;
  255. cb_DefIDYES.Enabled := True;
  256. cb_DefIDNO.Enabled := True;
  257. cb_DefIDABORT.Enabled := False;
  258. cb_DefIDRETRY.Enabled := False;
  259. cb_DefIDIGNORE.Enabled := False;
  260. end;
  261. end;
  262. procedure TMsgBoxDesignerForm.rbMB_OKCANCELClick(Sender: TObject);
  263. begin
  264. cb_IDOK.Checked := False;
  265. cb_IDCANCEL.Checked := False;
  266. cb_IDABORT.Checked := False;
  267. cb_IDRETRY.Checked := False;
  268. cb_IDIGNORE.Checked := False;
  269. cb_IDYES.Checked := False;
  270. cb_IDNO.Checked := False;
  271. cb_IDOK.Enabled := True;
  272. cb_IDCANCEL.Enabled := True;
  273. cb_IDABORT.Enabled := False;
  274. cb_IDRETRY.Enabled := False;
  275. cb_IDIGNORE.Enabled := False;
  276. cb_IDYES.Enabled := False;
  277. cb_IDNO.Enabled := False;
  278. if not cb_TaskDialogMsgBox.Checked then begin
  279. NewStaticText1.Enabled := True;
  280. NewEdit1.Enabled := True;
  281. NewEdit1.Text := '1';
  282. UpDown1.Max := 2;
  283. UpDown1.Enabled := True;
  284. end;
  285. if cb_TaskDialogMsgBox.Checked then begin
  286. rb_IDOK.Enabled := True;
  287. rb_IDCANCEL.Enabled := True;
  288. rb_IDABORT.Enabled := False;
  289. rb_IDRETRY.Enabled := False;
  290. rb_IDIGNORE.Enabled := False;
  291. rb_IDYES.Enabled := False;
  292. rb_IDNO.Enabled := False;
  293. rb_IDOK.Checked := False;
  294. rb_IDCANCEL.Checked := False;
  295. rb_IDABORT.Checked := False;
  296. rb_IDRETRY.Checked := False;
  297. rb_IDIGNORE.Checked := False;
  298. rb_IDYES.Checked := False;
  299. rb_IDNO.Checked := False;
  300. Button3Text.Enabled := False;
  301. Button3Label.Enabled := False;
  302. Button2Text.Enabled := True;
  303. Button2Label.Enabled := True;
  304. Button1Text.Enabled := True;
  305. Button1Label.Enabled := True;
  306. Button1Text.Text := 'OK';
  307. Button2Text.Text := 'Cancel';
  308. Button3Text.Text := '';
  309. end;
  310. if cb_Suppressible.Checked then begin
  311. cb_DefIDOK.Checked := True;
  312. cb_DefIDCANCEL.Checked := False;
  313. cb_DefIDYES.Checked := False;
  314. cb_DefIDNO.Checked := False;
  315. cb_DefIDABORT.Checked := False;
  316. cb_DefIDRETRY.Checked := False;
  317. cb_DefIDIGNORE.Checked := False;
  318. cb_DefIDOK.Enabled := True;
  319. cb_DefIDCANCEL.Enabled := True;
  320. cb_DefIDYES.Enabled := False;
  321. cb_DefIDNO.Enabled := False;
  322. cb_DefIDABORT.Enabled := False;
  323. cb_DefIDRETRY.Enabled := False;
  324. cb_DefIDIGNORE.Enabled := False;
  325. end;
  326. end;
  327. procedure TMsgBoxDesignerForm.rbMB_RETRYCANCELClick(Sender: TObject);
  328. begin
  329. cb_IDOK.Checked := False;
  330. cb_IDCANCEL.Checked := False;
  331. cb_IDABORT.Checked := False;
  332. cb_IDRETRY.Checked := False;
  333. cb_IDIGNORE.Checked := False;
  334. cb_IDYES.Checked := False;
  335. cb_IDNO.Checked := False;
  336. cb_IDOK.Enabled := False;
  337. cb_IDCANCEL.Enabled := True;
  338. cb_IDABORT.Enabled := False;
  339. cb_IDRETRY.Enabled := True;
  340. cb_IDIGNORE.Enabled := False;
  341. cb_IDYES.Enabled := False;
  342. cb_IDNO.Enabled := False;
  343. if not cb_TaskDialogMsgBox.Checked then begin
  344. NewStaticText1.Enabled := True;
  345. NewEdit1.Enabled := True;
  346. NewEdit1.Text := '1';
  347. UpDown1.Max := 2;
  348. UpDown1.Enabled := True;
  349. end;
  350. if cb_TaskDialogMsgBox.Checked then begin
  351. rb_IDOK.Enabled := False;
  352. rb_IDCANCEL.Enabled := True;
  353. rb_IDABORT.Enabled := False;
  354. rb_IDRETRY.Enabled := True;
  355. rb_IDIGNORE.Enabled := False;
  356. rb_IDYES.Enabled := False;
  357. rb_IDNO.Enabled := False;
  358. rb_IDOK.Checked := False;
  359. rb_IDCANCEL.Checked := False;
  360. rb_IDABORT.Checked := False;
  361. rb_IDRETRY.Checked := False;
  362. rb_IDIGNORE.Checked := False;
  363. rb_IDYES.Checked := False;
  364. rb_IDNO.Checked := False;
  365. Button3Text.Enabled := False;
  366. Button3Label.Enabled := False;
  367. Button2Text.Enabled := True;
  368. Button2Label.Enabled := True;
  369. Button1Text.Enabled := True;
  370. Button1Label.Enabled := True;
  371. Button1Text.Text := 'Retry';
  372. Button2Text.Text := 'Cancel';
  373. Button3Text.Text := '';
  374. end;
  375. if cb_Suppressible.Checked then begin
  376. cb_DefIDOK.Checked := False;
  377. cb_DefIDCANCEL.Checked := True;
  378. cb_DefIDYES.Checked := False;
  379. cb_DefIDNO.Checked := False;
  380. cb_DefIDABORT.Checked := False;
  381. cb_DefIDRETRY.Checked := False;
  382. cb_DefIDIGNORE.Checked := False;
  383. cb_DefIDOK.Enabled := False;
  384. cb_DefIDCANCEL.Enabled := True;
  385. cb_DefIDYES.Enabled := False;
  386. cb_DefIDNO.Enabled := False;
  387. cb_DefIDABORT.Enabled := False;
  388. cb_DefIDRETRY.Enabled := True;
  389. cb_DefIDIGNORE.Enabled := False;
  390. end;
  391. end;
  392. procedure TMsgBoxDesignerForm.rbMB_YESNOCANCELClick(Sender: TObject);
  393. begin
  394. cb_IDOK.Checked := False;
  395. cb_IDCANCEL.Checked := False;
  396. cb_IDABORT.Checked := False;
  397. cb_IDRETRY.Checked := False;
  398. cb_IDIGNORE.Checked := False;
  399. cb_IDYES.Checked := False;
  400. cb_IDNO.Checked := False;
  401. cb_IDOK.Enabled := False;
  402. cb_IDCANCEL.Enabled := True;
  403. cb_IDABORT.Enabled := False;
  404. cb_IDRETRY.Enabled := False;
  405. cb_IDIGNORE.Enabled := False;
  406. cb_IDYES.Enabled := True;
  407. cb_IDNO.Enabled := True;
  408. if not cb_TaskDialogMsgBox.Checked then begin
  409. NewStaticText1.Enabled := True;
  410. NewEdit1.Enabled := True;
  411. NewEdit1.Text := '1';
  412. UpDown1.Max := 3;
  413. UpDown1.Enabled := True;
  414. end;
  415. if cb_TaskDialogMsgBox.Checked then begin
  416. rb_IDOK.Enabled := False;
  417. rb_IDCANCEL.Enabled := True;
  418. rb_IDABORT.Enabled := False;
  419. rb_IDRETRY.Enabled := False;
  420. rb_IDIGNORE.Enabled := False;
  421. rb_IDYES.Enabled := True;
  422. rb_IDNO.Enabled := True;
  423. rb_IDOK.Checked := False;
  424. rb_IDCANCEL.Checked := False;
  425. rb_IDABORT.Checked := False;
  426. rb_IDRETRY.Checked := False;
  427. rb_IDIGNORE.Checked := False;
  428. rb_IDYES.Checked := False;
  429. rb_IDNO.Checked := False;
  430. Button3Text.Enabled := True;
  431. Button3Label.Enabled := True;
  432. Button2Text.Enabled := True;
  433. Button2Label.Enabled := True;
  434. Button1Text.Enabled := True;
  435. Button1Label.Enabled := True;
  436. Button1Text.Text := 'Yes';
  437. Button2Text.Text := 'No';
  438. Button3Text.Text := 'Cancel';
  439. end;
  440. if cb_Suppressible.Checked then begin
  441. cb_DefIDOK.Checked := False;
  442. cb_DefIDCANCEL.Checked := False;
  443. cb_DefIDYES.Checked := True;
  444. cb_DefIDNO.Checked := False;
  445. cb_DefIDABORT.Checked := False;
  446. cb_DefIDRETRY.Checked := False;
  447. cb_DefIDIGNORE.Checked := False;
  448. cb_DefIDOK.Enabled := False;
  449. cb_DefIDCANCEL.Enabled := True;
  450. cb_DefIDYES.Enabled := True;
  451. cb_DefIDNO.Enabled := True;
  452. cb_DefIDABORT.Enabled := False;
  453. cb_DefIDRETRY.Enabled := False;
  454. cb_DefIDIGNORE.Enabled := False;
  455. end;
  456. end;
  457. procedure TMsgBoxDesignerForm.rbMB_ABORTRETRYIGNOREClick(Sender: TObject);
  458. begin
  459. cb_IDOK.Checked := False;
  460. cb_IDCANCEL.Checked := False;
  461. cb_IDABORT.Checked := False;
  462. cb_IDRETRY.Checked := False;
  463. cb_IDIGNORE.Checked := False;
  464. cb_IDYES.Checked := False;
  465. cb_IDNO.Checked := False;
  466. cb_IDOK.Enabled := False;
  467. cb_IDCANCEL.Enabled := False;
  468. cb_IDABORT.Enabled := True;
  469. cb_IDRETRY.Enabled := True;
  470. cb_IDIGNORE.Enabled := True;
  471. cb_IDYES.Enabled := False;
  472. cb_IDNO.Enabled := False;
  473. if not cb_TaskDialogMsgBox.Checked then begin
  474. NewStaticText1.Enabled := True;
  475. NewEdit1.Enabled := True;
  476. NewEdit1.Text := '1';
  477. UpDown1.Max := 3;
  478. UpDown1.Enabled := True;
  479. end;
  480. if cb_TaskDialogMsgBox.Checked then begin
  481. rb_IDOK.Enabled := False;
  482. rb_IDCANCEL.Enabled := False;
  483. rb_IDABORT.Enabled := True;
  484. rb_IDRETRY.Enabled := True;
  485. rb_IDIGNORE.Enabled := True;
  486. rb_IDYES.Enabled := False;
  487. rb_IDNO.Enabled := False;
  488. rb_IDOK.Checked := False;
  489. rb_IDCANCEL.Checked := False;
  490. rb_IDABORT.Checked := False;
  491. rb_IDRETRY.Checked := False;
  492. rb_IDIGNORE.Checked := False;
  493. rb_IDYES.Checked := False;
  494. rb_IDNO.Checked := False;
  495. Button3Text.Enabled := True;
  496. Button3Label.Enabled := True;
  497. Button2Text.Enabled := True;
  498. Button2Label.Enabled := True;
  499. Button1Text.Enabled := True;
  500. Button1Label.Enabled := True;
  501. Button1Text.Text := 'Retry'; //this order is not a mistake
  502. Button2Text.Text := 'Ignore'; //
  503. Button3Text.Text := 'Abort'; //
  504. end;
  505. if cb_Suppressible.Checked then begin
  506. cb_DefIDOK.Checked := False;
  507. cb_DefIDCANCEL.Checked := False;
  508. cb_DefIDYES.Checked := False;
  509. cb_DefIDNO.Checked := False;
  510. cb_DefIDABORT.Checked := False;
  511. cb_DefIDRETRY.Checked := False;
  512. cb_DefIDIGNORE.Checked := True;
  513. cb_DefIDOK.Enabled := False;
  514. cb_DefIDCANCEL.Enabled := False;
  515. cb_DefIDYES.Enabled := False;
  516. cb_DefIDNO.Enabled := False;
  517. cb_DefIDABORT.Enabled := True;
  518. cb_DefIDRETRY.Enabled := True;
  519. cb_DefIDIGNORE.Enabled := True;
  520. end;
  521. end;
  522. procedure TMsgBoxDesignerForm.UpDown1Changing(Sender: TObject; var AllowChange: Boolean);
  523. begin
  524. AllowChange := True;
  525. end;
  526. procedure TMsgBoxDesignerForm.cb_MsgBoxClick(Sender: TObject);
  527. begin
  528. IMGmbConfirmation.Visible := True;
  529. cb_MB_SETFOREGROUND.Enabled := True;
  530. cb_MB_SETFOREGROUND.Checked := False;
  531. GroupBox1.Visible := True;
  532. if not cb_Suppressible.Checked then begin
  533. GroupBox4.Caption := ' Return values ';
  534. cb_DefIDOK.Visible := False;
  535. cb_DefIDCANCEL.Visible := False;
  536. cb_DefIDYES.Visible := False;
  537. cb_DefIDNO.Visible := False;
  538. cb_DefIDABORT.Visible := False;
  539. cb_DefIDRETRY.Visible := False;
  540. cb_DefIDIGNORE.Visible := False;
  541. end
  542. else begin
  543. GroupBox4.Caption := ' Return values / -------- / Default ';
  544. cb_DefIDOK.Visible := True;
  545. cb_DefIDCANCEL.Visible := True;
  546. cb_DefIDYES.Visible := True;
  547. cb_DefIDNO.Visible := True;
  548. cb_DefIDABORT.Visible := True;
  549. cb_DefIDRETRY.Visible := True;
  550. cb_DefIDIGNORE.Visible := True;
  551. end;
  552. cb_IDOK.Checked := False;
  553. cb_IDCANCEL.Checked := False;
  554. cb_IDABORT.Checked := False;
  555. cb_IDRETRY.Checked := False;
  556. cb_IDIGNORE.Checked := False;
  557. cb_IDYES.Checked := False;
  558. cb_IDNO.Checked := False;
  559. rb_IDOK.Visible := False;
  560. rb_IDCANCEL.Visible := False;
  561. rb_IDABORT.Visible := False;
  562. rb_IDRETRY.Visible := False;
  563. rb_IDIGNORE.Visible := False;
  564. rb_IDYES.Visible := False;
  565. rb_IDNO.Visible := False;
  566. rb_mbInformation.Checked := True;
  567. TaskInstructionLabel.Visible := False;
  568. TaskMessageLabel.Visible := False;
  569. TaskInstructionText.Visible := False;
  570. TaskMessageText.Visible := False;
  571. Button1Text.Visible := False;
  572. Button2Text.Visible := False;
  573. Button3Text.Visible := False;
  574. Button1Label.Visible := False;
  575. Button2Label.Visible := False;
  576. Button3Label.Visible := False;
  577. rbMB_OK.Checked := True;
  578. rbMB_OKClick(Self);
  579. end;
  580. procedure TMsgBoxDesignerForm.cb_SuppressibleClick(Sender: TObject);
  581. begin
  582. if cb_Suppressible.Checked then begin
  583. cb_DefIDOK.Visible := True;
  584. cb_DefIDCANCEL.Visible := True;
  585. cb_DefIDYES.Visible := True;
  586. cb_DefIDNO.Visible := True;
  587. cb_DefIDABORT.Visible := True;
  588. cb_DefIDRETRY.Visible := True;
  589. cb_DefIDIGNORE.Visible := True;
  590. if cb_MsgBox.Checked then
  591. GroupBox4.Caption := ' Return values / -------- / Default ';
  592. if cb_TaskDialogMsgBox.Checked then
  593. GroupBox4.Caption := ' Return values / Shield / Default ';
  594. end
  595. else begin
  596. cb_DefIDOK.Checked := False;
  597. cb_DefIDCANCEL.Checked := False;
  598. cb_DefIDYES.Checked := False;
  599. cb_DefIDNO.Checked := False;
  600. cb_DefIDABORT.Checked := False;
  601. cb_DefIDRETRY.Checked := False;
  602. cb_DefIDIGNORE.Checked := False;
  603. cb_DefIDOK.Visible := False;
  604. cb_DefIDCANCEL.Visible := False;
  605. cb_DefIDYES.Visible := False;
  606. cb_DefIDNO.Visible := False;
  607. cb_DefIDABORT.Visible := False;
  608. cb_DefIDRETRY.Visible := False;
  609. cb_DefIDIGNORE.Visible := False;
  610. if cb_MsgBox.Checked then
  611. GroupBox4.Caption := ' Return values ';
  612. if cb_TaskDialogMsgBox.Checked then
  613. GroupBox4.Caption := ' Return values / Shield ';
  614. end;
  615. if rbMB_OK.Checked then rbMB_OKClick(Self);
  616. if rbMB_OKCANCEL.Checked then rbMB_OKCANCELClick(Self);
  617. if rbMB_YESNO.Checked then rbMB_YESNOClick(Self);
  618. if rbMB_YESNOCANCEL.Checked then rbMB_YESNOCANCELClick(Self);
  619. if rbMB_RETRYCANCEL.Checked then rbMB_RETRYCANCELClick(Self);
  620. if rbMB_ABORTRETRYIGNORE.Checked then rbMB_ABORTRETRYIGNOREClick(Self);
  621. end;
  622. procedure TMsgBoxDesignerForm.cb_TaskDialogMsgBoxClick(Sender: TObject);
  623. begin
  624. IMGmbConfirmation.Visible := False;
  625. cb_MB_SETFOREGROUND.Enabled := False;
  626. cb_MB_SETFOREGROUND.Checked := False;
  627. GroupBox1.Visible := False;
  628. if not cb_Suppressible.Checked then begin
  629. GroupBox4.Caption := ' Return values / Shield ';
  630. cb_DefIDOK.Visible := False;
  631. cb_DefIDCANCEL.Visible := False;
  632. cb_DefIDYES.Visible := False;
  633. cb_DefIDNO.Visible := False;
  634. cb_DefIDABORT.Visible := False;
  635. cb_DefIDRETRY.Visible := False;
  636. cb_DefIDIGNORE.Visible := False;
  637. end
  638. else begin
  639. GroupBox4.Caption := ' Return values / Shield / Default ';
  640. cb_DefIDOK.Visible := True;
  641. cb_DefIDCANCEL.Visible := True;
  642. cb_DefIDYES.Visible := True;
  643. cb_DefIDNO.Visible := True;
  644. cb_DefIDABORT.Visible := True;
  645. cb_DefIDRETRY.Visible := True;
  646. cb_DefIDIGNORE.Visible := True;
  647. end;
  648. cb_IDOK.Checked := False;
  649. cb_IDCANCEL.Checked := False;
  650. cb_IDABORT.Checked := False;
  651. cb_IDRETRY.Checked := False;
  652. cb_IDIGNORE.Checked := False;
  653. cb_IDYES.Checked := False;
  654. cb_IDNO.Checked := False;
  655. rb_IDOK.Checked := False;
  656. rb_IDCANCEL.Checked := False;
  657. rb_IDABORT.Checked := False;
  658. rb_IDRETRY.Checked := False;
  659. rb_IDIGNORE.Checked := False;
  660. rb_IDYES.Checked := False;
  661. rb_IDNO.Checked := False;
  662. rb_IDOK.Visible := True;
  663. rb_IDCANCEL.Visible := True;
  664. rb_IDABORT.Visible := True;
  665. rb_IDRETRY.Visible := True;
  666. rb_IDIGNORE.Visible := True;
  667. rb_IDYES.Visible := True;
  668. rb_IDNO.Visible := True;
  669. rb_mbInformation.Checked := True;
  670. TaskInstructionLabel.Visible := True;
  671. TaskMessageLabel.Visible := True;
  672. TaskInstructionText.Visible := True;
  673. TaskMessageText.Visible := True;
  674. Button1Text.Visible := True;
  675. Button2Text.Visible := True;
  676. Button3Text.Visible := True;
  677. Button1Label.Visible := True;
  678. Button2Label.Visible := True;
  679. Button3Label.Visible := True;
  680. TaskInstructionText.Text := 'Instruction Text';
  681. TaskMessageText.Text := 'Message Text';
  682. rbMB_OK.Checked := True;
  683. rbMB_OKClick(Self);
  684. end;
  685. procedure TMsgBoxDesignerForm.rb_IDOKClick(Sender: TObject);
  686. begin
  687. if rb_IDOK.Checked then
  688. rb_IDCANCEL.Checked := False;
  689. end;
  690. procedure TMsgBoxDesignerForm.rb_IDCANCELClick(Sender: TObject);
  691. begin
  692. if rb_IDCANCEL.Checked then begin
  693. rb_IDOK.Checked := False;
  694. rb_IDNO.Checked := False;
  695. rb_IDYES.Checked := False;
  696. rb_IDRETRY.Checked := False;
  697. end;
  698. end;
  699. procedure TMsgBoxDesignerForm.rb_IDYESClick(Sender: TObject);
  700. begin
  701. if rb_IDYES.Checked then begin
  702. rb_IDNO.Checked := False;
  703. rb_IDCANCEL.Checked := False;
  704. end;
  705. end;
  706. procedure TMsgBoxDesignerForm.rb_IDNOClick(Sender: TObject);
  707. begin
  708. if rb_IDNO.Checked then begin
  709. rb_IDYES.Checked := False;
  710. rb_IDCANCEL.Checked := False;
  711. end;
  712. end;
  713. procedure TMsgBoxDesignerForm.rb_IDRETRYClick(Sender: TObject);
  714. begin
  715. if rb_IDRETRY.Checked then begin
  716. rb_IDCANCEL.Checked := False;
  717. rb_IDABORT.Checked := False;
  718. rb_IDIGNORE.Checked := False;
  719. end;
  720. end;
  721. procedure TMsgBoxDesignerForm.rb_IDIGNOREClick(Sender: TObject);
  722. begin
  723. if rb_IDIGNORE.Checked then begin
  724. rb_IDABORT.Checked := False;
  725. rb_IDRETRY.Checked := False;
  726. end;
  727. end;
  728. procedure TMsgBoxDesignerForm.rb_IDABORTClick(Sender: TObject);
  729. begin
  730. if rb_IDABORT.Checked then begin
  731. rb_IDIGNORE.Checked := False;
  732. rb_IDRETRY.Checked := False;
  733. end;
  734. end;
  735. procedure TMsgBoxDesignerForm.MBDButtonPreviewClick(Sender: TObject);
  736. begin
  737. { default value }
  738. var Buttons := MB_OK;
  739. var Typ := mbInformation;
  740. { icon and caption set }
  741. var Caption: String;
  742. if rb_mbInformation.Checked then begin
  743. Caption := 'Info';
  744. Typ := mbInformation;
  745. end;
  746. if rb_mbConfirmation.Checked then begin
  747. Caption := 'Confirm';
  748. Typ := mbConfirmation;
  749. end;
  750. if rb_mbError.Checked then begin
  751. Caption := 'Error';
  752. Typ := mbError;
  753. end;
  754. if rb_mbCriticalError.Checked then begin
  755. Caption := 'Fatal Error';
  756. Typ := mbCriticalError;
  757. end;
  758. { button type set }
  759. if rbMB_OK.Checked then Buttons := MB_OK;
  760. if rbMB_OKCANCEL.Checked then Buttons := MB_OKCANCEL;
  761. if rbMB_YESNO.Checked then Buttons := MB_YESNO;
  762. if rbMB_YESNOCANCEL.Checked then Buttons := MB_YESNOCANCEL;
  763. if rbMB_RETRYCANCEL.Checked then Buttons := MB_RETRYCANCEL;
  764. if rbMB_ABORTRETRYIGNORE.Checked then Buttons := MB_ABORTRETRYIGNORE;
  765. if cb_MsgBox.Checked then begin
  766. if MSGText.GetTextLen = 0 then
  767. MSGText.Lines.Add('Your message text.');
  768. { MessageBox with DefButton }
  769. if NewEdit1.Text = '1' then
  770. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons);
  771. if NewEdit1.Text = '2' then
  772. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_DEFBUTTON2);
  773. if NewEdit1.Text = '3' then
  774. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_DEFBUTTON3);
  775. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  776. if (NewEdit1.Text = '1') and (cb_MB_SETFOREGROUND.Checked) then
  777. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_SETFOREGROUND);
  778. if (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  779. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_DEFBUTTON2 or MB_SETFOREGROUND);
  780. if (NewEdit1.Text = '3') and (cb_MB_SETFOREGROUND.Checked) then
  781. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_DEFBUTTON3 or MB_SETFOREGROUND);
  782. end else if cb_TaskDialogMsgBox.Checked then begin
  783. { create ButtonLabels array - also see GetText}
  784. var ButtonLabels: TArray<string>;
  785. if Button3Text.Enabled then
  786. ButtonLabels := TArray<string>.Create(Button1Text.Text, Button2Text.Text, Button3Text.Text)
  787. else if Button2Text.Enabled then
  788. ButtonLabels := TArray<string>.Create(Button1Text.Text, Button2Text.Text)
  789. else
  790. ButtonLabels := TArray<string>.Create(Button1Text.Text);
  791. if rbMB_OKCANCEL.Checked or rbMB_YESNOCANCEL.Checked or rbMB_RETRYCANCEL.Checked then begin
  792. { Specifying a cancel label is optional: if it's missing TaskDialogMsgBox will use a button
  793. at the bottom instead }
  794. const NLabels = Length(ButtonLabels);
  795. if ButtonLabels[NLabels-1] = '' then
  796. SetLength(ButtonLabels, NLabels-1);
  797. end;
  798. { get Shield Flag value }
  799. var ShieldButton := 0;
  800. if rbMB_OK.Checked and rb_IDOK.Checked then ShieldButton := IDOK;
  801. if rbMB_OKCANCEL.Checked and rb_IDOK.Checked then ShieldButton := IDOK;
  802. if rbMB_OKCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := IDCANCEL;
  803. if rbMB_YESNO.Checked and rb_IDYES.Checked then ShieldButton := IDYES;
  804. if rbMB_YESNO.Checked and rb_IDNO.Checked then ShieldButton := IDNO;
  805. if rbMB_YESNOCANCEL.Checked and rb_IDYES.Checked then ShieldButton := IDYES;
  806. if rbMB_YESNOCANCEL.Checked and rb_IDNO.Checked then ShieldButton := IDNO;
  807. if rbMB_YESNOCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := IDCANCEL;
  808. if rbMB_RETRYCANCEL.Checked and rb_IDRETRY.Checked then ShieldButton := IDRETRY;
  809. if rbMB_RETRYCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := IDCANCEL;
  810. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDRETRY.Checked then ShieldButton := IDRETRY;
  811. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDABORT.Checked then ShieldButton := IDABORT;
  812. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDIGNORE.Checked then ShieldButton := IDIGNORE;
  813. { TaskDialogMsgBox(Icon, Instruction, Text, Caption, Typ, Buttons, ButtonLabels, ShieldButton) }
  814. TaskDialogMsgBox('', TaskInstructionText.Text, TaskMessageText.Text, Caption,
  815. Typ, Buttons, ButtonLabels, ShieldButton);
  816. end;
  817. end;
  818. procedure TMsgBoxDesignerForm.MSGTextKeyPress(Sender: TObject; var Key: Char);
  819. begin
  820. if Key = #27 then begin
  821. MBDButtonCancel.Click;
  822. Key := #0;
  823. end;
  824. end;
  825. function TMsgBoxDesignerForm.GetText(TabWidth: Integer; UseTabCharacter: Boolean): String;
  826. function TextTab: String;
  827. begin
  828. if UseTabCharacter then
  829. Result := #9
  830. else
  831. Result := Format('%*s', [TabWidth, '']);
  832. end;
  833. function TextUserClicked(IDButton: String): String;
  834. begin
  835. Result := 'user clicked ' + StringReplace(IDButton, 'ID', '', [])
  836. end;
  837. function TextCase(IDButton: String): String;
  838. begin
  839. Result := TextTab + IDButton +': { ' + TextUserClicked(IDButton) + ' };';
  840. end;
  841. function TextCall(ButtonCount: Integer; SCall, IDButton, IDButton2, IDButton3: String): String;
  842. begin
  843. case ButtonCount of
  844. 0: Result := SCall + ';';
  845. 1: Result := 'if ' + SCall + ' = ' + IDButton + ' then' + SNewLine +
  846. 'begin' + SNewLine +
  847. TextTab + '// ' + TextUserClicked(IDButton) + SNewLine +
  848. 'end;';
  849. 2, 3:
  850. begin
  851. Result := 'case ' + SCall + ' of ' + SNewLine +
  852. TextCase(IDButton) + SNewLine +
  853. TextCase(IDButton2) + SNewLine;
  854. if ButtonCount = 3 then
  855. Result := Result + TextCase(IDButton3) + SNewLine;
  856. Result := Result + 'end;';
  857. end;
  858. end;
  859. end;
  860. { MsgBox / SuppressibleMsgBox }
  861. function TextMsgBox(ButtonCount: Integer; Caption, Typ, Buttons,
  862. IDButton, IDButton2, IDButton3: String): String;
  863. begin
  864. var SMsgBox: String;
  865. if not cb_Suppressible.Checked then
  866. SMsgBox := 'MsgBox'
  867. else
  868. SMsgBox := 'SuppressibleMsgBox';
  869. //Buttons also contains Default if suppressible, pre-separated by a comma (but ButtonCount does *not* include this)
  870. SMsgBox := SMsgBox + '(''' + Caption + ''', ' + Typ + ', ' + Buttons + ')';
  871. Result := TextCall(ButtonCount, SMsgBox, IDButton, IDButton2, IDButton3);
  872. end;
  873. { TaskDialogMsgBox / SuppressibleTaskDialogMsgBox }
  874. function TextTaskDialog(ButtonCount: Integer; InstructionAndText, Typ, Buttons,
  875. ButtonLabels, ShieldButton, IDButton, IDButton2, IDButton3: String): String;
  876. begin
  877. var STaskDialog: String;
  878. if not cb_Suppressible.Checked then
  879. STaskDialog := 'TaskDialogMsgBox'
  880. else
  881. STaskDialog := 'SuppressibleTaskDialogMsgBox';
  882. //InstructionAndText contains both Instruction and Text, pre-separated by a quote, a comma and another quote
  883. //ButtonLabels contains all labels, also pre-separated by the above
  884. //ShieldButton also contains Default if suppressible, pre-separated by a comma (but ButtonCount does *not* include this)
  885. STaskDialog := STaskDialog+ '(''' + InstructionAndText + ''', ' + Typ + ', ' + Buttons + ', [''' + ButtonLabels + '''], ' + ShieldButton + ')';
  886. Result := TextCall(ButtonCount, STaskDialog, IDButton, IDButton2, IDButton3);
  887. end;
  888. begin
  889. { default value }
  890. var ButtonCount := 0;
  891. var Buttons := 'MB_OK';
  892. var Typ := 'mbInformation';
  893. var ShieldButton: String := '0';
  894. var SuppressibleDefault := '';
  895. { make a string with Default parameter for Suppressible* calls }
  896. if cb_Suppressible.Checked then begin
  897. if cb_DefIDOK.Checked then SuppressibleDefault := ', IDOK';
  898. if cb_DefIDCANCEL.Checked then SuppressibleDefault := ', IDCANCEL';
  899. if cb_DefIDYES.Checked then SuppressibleDefault := ', IDYES';
  900. if cb_DefIDNO.Checked then SuppressibleDefault := ', IDNO';
  901. if cb_DefIDABORT.Checked then SuppressibleDefault := ', IDABORT';
  902. if cb_DefIDRETRY.Checked then SuppressibleDefault := ', IDRETRY';
  903. if cb_DefIDIGNORE.Checked then SuppressibleDefault := ', IDIGNORE';
  904. end;
  905. { icon and caption set }
  906. if rb_mbInformation.Checked then begin
  907. Typ := 'mbInformation';
  908. end;
  909. if rb_mbConfirmation.Checked then begin
  910. Typ := 'mbConfirmation';
  911. end;
  912. if rb_mbError.Checked then begin
  913. Typ := 'mbError';
  914. end;
  915. if rb_mbCriticalError.Checked then begin
  916. Typ := 'mbCriticalError';
  917. end;
  918. { button type set }
  919. if rbMB_OK.Checked then Buttons := 'MB_OK';
  920. if rbMB_OKCANCEL.Checked then Buttons := 'MB_OKCANCEL';
  921. if rbMB_YESNO.Checked then Buttons := 'MB_YESNO';
  922. if rbMB_YESNOCANCEL.Checked then Buttons := 'MB_YESNOCANCEL';
  923. if rbMB_RETRYCANCEL.Checked then Buttons := 'MB_RETRYCANCEL';
  924. if rbMB_ABORTRETRYIGNORE.Checked then Buttons := 'MB_ABORTRETRYIGNORE';
  925. var ModeMsg: Integer;
  926. var CaptionOrInstructionAndText: String;
  927. var ButtonLabels: String;
  928. if cb_MsgBox.Checked then begin
  929. { MsgBox(Text, Typ, Buttons); }
  930. ModeMsg := 0;
  931. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  932. if (rbMB_OK.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  933. Buttons := 'MB_OK or MB_SETFOREGROUND';
  934. if (rbMB_OKCANCEL.Checked) and (NewEdit1.Text = '2') then
  935. Buttons := 'MB_OKCANCEL or MB_DEFBUTTON2';
  936. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  937. if (rbMB_OKCANCEL.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  938. Buttons := 'MB_OKCANCEL or MB_SETFOREGROUND';
  939. if (rbMB_OKCANCEL.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  940. Buttons := 'MB_OKCANCEL or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  941. if (rbMB_YESNO.Checked) and (NewEdit1.Text = '2') then
  942. Buttons := 'MB_YESNO or MB_DEFBUTTON2';
  943. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  944. if (rbMB_YESNO.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  945. Buttons := 'MB_YESNO or MB_SETFOREGROUND';
  946. if (rbMB_YESNO.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  947. Buttons := 'MB_YESNO or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  948. if (rbMB_RETRYCANCEL.Checked) and (NewEdit1.Text = '2') then
  949. Buttons := 'MB_RETRYCANCEL or MB_DEFBUTTON2';
  950. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  951. if (rbMB_RETRYCANCEL.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  952. Buttons := 'MB_RETRYCANCEL or MB_SETFOREGROUND';
  953. if (rbMB_RETRYCANCEL.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  954. Buttons := 'MB_RETRYCANCEL or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  955. if (rbMB_YESNOCANCEL.Checked) and (NewEdit1.Text = '2') then
  956. Buttons := 'MB_YESNOCANCEL or MB_DEFBUTTON2';
  957. if (rbMB_YESNOCANCEL.Checked) and (NewEdit1.Text = '3') then
  958. Buttons := 'MB_YESNOCANCEL or MB_DEFBUTTON3';
  959. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  960. if (rbMB_YESNOCANCEL.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  961. Buttons := 'MB_YESNOCANCEL or MB_SETFOREGROUND';
  962. if (rbMB_YESNOCANCEL.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  963. Buttons := 'MB_YESNOCANCEL or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  964. if (rbMB_YESNOCANCEL.Checked) and (NewEdit1.Text = '3') and (cb_MB_SETFOREGROUND.Checked) then
  965. Buttons := 'MB_YESNOCANCEL or MB_DEFBUTTON3 or MB_SETFOREGROUND';
  966. if (rbMB_ABORTRETRYIGNORE.Checked) and (NewEdit1.Text = '2') then
  967. Buttons := 'MB_ABORTRETRYIGNORE or MB_DEFBUTTON2';
  968. if (rbMB_ABORTRETRYIGNORE.Checked) and (NewEdit1.Text = '3') then
  969. Buttons := 'MB_ABORTRETRYIGNORE or MB_DEFBUTTON3';
  970. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  971. if (rbMB_ABORTRETRYIGNORE.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  972. Buttons := 'MB_ABORTRETRYIGNORE or MB_SETFOREGROUND';
  973. if (rbMB_ABORTRETRYIGNORE.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  974. Buttons := 'MB_ABORTRETRYIGNORE or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  975. if (rbMB_ABORTRETRYIGNORE.Checked) and (NewEdit1.Text = '3') and (cb_MB_SETFOREGROUND.Checked) then
  976. Buttons := 'MB_ABORTRETRYIGNORE or MB_DEFBUTTON3 or MB_SETFOREGROUND';
  977. { Suppressible msg }
  978. if cb_Suppressible.Checked then Buttons := Buttons + SuppressibleDefault;
  979. { replace in a message string escape /r/n }
  980. CaptionOrInstructionAndText := StringReplace(MSGText.Lines.GetText, SNewLine, '''#13#10''', [rfReplaceAll]);
  981. end else begin
  982. { TaskDialogMsgBox(TaskInstructionText.Text, TaskMessageText.Text, Typ, Buttons, ButtonLabels, ShieldButton) }
  983. ModeMsg := 1;
  984. { create ButtonLabels array - also see MBDButtonPreviewClick }
  985. var ButtonLabelsArray: TArray<string>;
  986. if Button3Text.Enabled then
  987. ButtonLabelsArray := TArray<string>.Create(Button1Text.Text, Button2Text.Text, Button3Text.Text)
  988. else if Button2Text.Enabled then
  989. ButtonLabelsArray := TArray<string>.Create(Button1Text.Text, Button2Text.Text)
  990. else
  991. ButtonLabelsArray := TArray<string>.Create(Button1Text.Text);
  992. var NLabels := Length(ButtonLabelsArray);
  993. if rbMB_OKCANCEL.Checked or rbMB_YESNOCANCEL.Checked or rbMB_RETRYCANCEL.Checked then begin
  994. { Specifying a cancel label is optional: if it's missing TaskDialogMsgBox will use a button
  995. at the bottom instead }
  996. if ButtonLabelsArray[NLabels-1] = '' then begin
  997. Dec(NLabels);
  998. SetLength(ButtonLabelsArray, NLabels);
  999. end;
  1000. end;
  1001. for var I := 0 to NLabels-1 do begin { NLabels is always > 0 }
  1002. if I = 0 then
  1003. ButtonLabels := ButtonLabelsArray[I]
  1004. else
  1005. ButtonLabels := ButtonLabels + ''', ''' + ButtonLabelsArray[I];
  1006. end;
  1007. { get Shield Flag value }
  1008. if rbMB_OK.Checked and rb_IDOK.Checked then ShieldButton := 'IDOK';
  1009. if rbMB_OKCANCEL.Checked and rb_IDOK.Checked then ShieldButton := 'IDOK';
  1010. if rbMB_OKCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := 'IDCANCEL';
  1011. if rbMB_YESNO.Checked and rb_IDYES.Checked then ShieldButton := 'IDYES';
  1012. if rbMB_YESNO.Checked and rb_IDNO.Checked then ShieldButton := 'IDNO';
  1013. if rbMB_YESNOCANCEL.Checked and rb_IDYES.Checked then ShieldButton := 'IDYES';
  1014. if rbMB_YESNOCANCEL.Checked and rb_IDNO.Checked then ShieldButton := 'IDNO';
  1015. if rbMB_YESNOCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := 'IDCANCEL';
  1016. if rbMB_RETRYCANCEL.Checked and rb_IDRETRY.Checked then ShieldButton := 'IDRETRY';
  1017. if rbMB_RETRYCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := 'IDCANCEL';
  1018. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDRETRY.Checked then ShieldButton := 'IDRETRY';
  1019. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDABORT.Checked then ShieldButton := 'IDABORT';
  1020. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDIGNORE.Checked then ShieldButton := 'IDIGNORE';
  1021. { Suppressible msg }
  1022. if cb_Suppressible.Checked then ShieldButton := ShieldButton + SuppressibleDefault;
  1023. CaptionOrInstructionAndText := TaskInstructionText.Text + ''', ''' + TaskMessageText.Text;
  1024. end;
  1025. var IDButton, IDButton2, IDButton3: String;
  1026. var Text: String;
  1027. { selected button OK }
  1028. if (cb_IDOK.Checked and not cb_IDCANCEL.Checked) then begin
  1029. IDButton := 'IDOK';
  1030. ButtonCount := 1;
  1031. case ModeMsg of
  1032. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1033. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1034. end;
  1035. end
  1036. { selected button CANCEL }
  1037. else if (cb_IDCANCEL.Checked and not cb_IDOK.Checked and not cb_IDRETRY.Checked and not cb_IDYES.Checked and not cb_IDNO.Checked and not cb_IDABORT.Checked and not cb_IDIGNORE.Checked) then begin
  1038. IDButton := 'IDCANCEL';
  1039. ButtonCount := 1;
  1040. case ModeMsg of
  1041. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1042. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1043. end;
  1044. end
  1045. { selected button OK and CANCEL }
  1046. else if (cb_IDCANCEL.Checked and cb_IDOK.Checked and not cb_IDRETRY.Checked and not cb_IDYES.Checked and not cb_IDNO.Checked) then begin
  1047. IDButton := 'IDOK';
  1048. IDButton2 := 'IDCANCEL';
  1049. ButtonCount := 2;
  1050. case ModeMsg of
  1051. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1052. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1053. end;
  1054. end
  1055. { selected button YES }
  1056. else if (cb_IDYES.Checked and not cb_IDNO.Checked and not cb_IDCANCEL.Checked) then begin
  1057. IDButton := 'IDYES';
  1058. ButtonCount := 1;
  1059. case ModeMsg of
  1060. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1061. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1062. end;
  1063. end
  1064. { selected button NO }
  1065. else if (cb_IDNO.Checked and not cb_IDYES.Checked and not cb_IDCANCEL.Checked) then begin
  1066. IDButton := 'IDNO';
  1067. ButtonCount := 1;
  1068. case ModeMsg of
  1069. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1070. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1071. end;
  1072. end
  1073. { selected button YES and NO }
  1074. else if (cb_IDYES.Checked and cb_IDNO.Checked and not cb_IDCANCEL.Checked) then begin
  1075. IDButton := 'IDYES';
  1076. IDButton2 := 'IDNO';
  1077. ButtonCount := 2;
  1078. case ModeMsg of
  1079. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1080. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1081. end;
  1082. end
  1083. { selected button YES and CANCEL }
  1084. else if (cb_IDYES.Checked and not cb_IDNO.Checked and cb_IDCANCEL.Checked) then begin
  1085. IDButton := 'IDYES';
  1086. IDButton2 := 'IDCANCEL';
  1087. ButtonCount := 2;
  1088. case ModeMsg of
  1089. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1090. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1091. end;
  1092. end
  1093. { selected button NO and CANCEL }
  1094. else if (cb_IDNO.Checked and not cb_IDYES.Checked and cb_IDCANCEL.Checked) then begin
  1095. IDButton := 'IDNO';
  1096. IDButton2 := 'IDCANCEL';
  1097. ButtonCount := 2;
  1098. case ModeMsg of
  1099. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1100. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1101. end;
  1102. end
  1103. { selected button YES, NO and CANCEL }
  1104. else if (cb_IDYES.Checked and cb_IDNO.Checked and cb_IDCANCEL.Checked) then begin
  1105. IDButton := 'IDYES';
  1106. IDButton2 := 'IDNO';
  1107. IDButton3 := 'IDCANCEL';
  1108. ButtonCount := 3;
  1109. case ModeMsg of
  1110. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, IDButton3);
  1111. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, IDButton3);
  1112. end;
  1113. end
  1114. { selected button RETRY }
  1115. else if (cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and not cb_IDABORT.Checked and not cb_IDIGNORE.Checked) then begin
  1116. IDButton := 'IDRETRY';
  1117. ButtonCount := 1;
  1118. case ModeMsg of
  1119. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1120. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1121. end;
  1122. end
  1123. { selected button RETRY and CANCEL }
  1124. else if (cb_IDRETRY.Checked and cb_IDCANCEL.Checked and not cb_IDABORT.Checked and not cb_IDIGNORE.Checked) then begin
  1125. IDButton := 'IDRETRY';
  1126. IDButton2 := 'IDCANCEL';
  1127. ButtonCount := 2;
  1128. case ModeMsg of
  1129. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1130. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1131. end;
  1132. end
  1133. { selected button IGNORE }
  1134. else if (cb_IDIGNORE.Checked and not cb_IDCANCEL.Checked and not cb_IDABORT.Checked and not cb_IDRETRY.Checked) then begin
  1135. IDButton := 'IDIGNORE';
  1136. ButtonCount := 1;
  1137. case ModeMsg of
  1138. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1139. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1140. end;
  1141. end
  1142. { selected button ABORT }
  1143. else if (cb_IDABORT.Checked and not cb_IDCANCEL.Checked and not cb_IDRETRY.Checked and not cb_IDIGNORE.Checked) then begin
  1144. IDButton := 'IDABORT';
  1145. ButtonCount := 1;
  1146. case ModeMsg of
  1147. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1148. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1149. end;
  1150. end
  1151. { selected button RETRY and IGNORE }
  1152. else if (cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and not cb_IDABORT.Checked and cb_IDIGNORE.Checked) then begin
  1153. IDButton := 'IDRETRY';
  1154. IDButton2 := 'IDIGNORE';
  1155. ButtonCount := 2;
  1156. case ModeMsg of
  1157. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1158. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1159. end;
  1160. end
  1161. { selected button RETRY and ABORT }
  1162. else if (cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and cb_IDABORT.Checked and not cb_IDIGNORE.Checked) then begin
  1163. IDButton := 'IDRETRY';
  1164. IDButton2 := 'IDABORT';
  1165. ButtonCount := 2;
  1166. case ModeMsg of
  1167. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1168. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1169. end;
  1170. end
  1171. { selected button IGNORE and ABORT }
  1172. else if (not cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and cb_IDABORT.Checked and cb_IDIGNORE.Checked) then begin
  1173. IDButton := 'IDIGNORE';
  1174. IDButton2 := 'IDABORT';
  1175. ButtonCount := 2;
  1176. case ModeMsg of
  1177. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1178. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1179. end;
  1180. end
  1181. { selected button RETRY, IGNORE and ABORT }
  1182. else if (cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and cb_IDABORT.Checked and cb_IDIGNORE.Checked) then begin
  1183. IDButton := 'IDRETRY';
  1184. IDButton2 := 'IDIGNORE';
  1185. IDButton3 := 'IDABORT';
  1186. ButtonCount := 3;
  1187. case ModeMsg of
  1188. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, IDButton3);
  1189. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, IDButton3);
  1190. end;
  1191. end
  1192. { no selected buttons }
  1193. else begin
  1194. case ModeMsg of
  1195. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, '', '', '');
  1196. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, '', '', '');
  1197. end;
  1198. end;
  1199. var SL := TStringList.Create;
  1200. try
  1201. SL.Text := Text;
  1202. SL.Insert(0, '// Display a message box');
  1203. for var I := 0 to SL.Count-1 do
  1204. SL[I] := TextTab + SL[I];
  1205. Result := SL.Text;
  1206. finally
  1207. SL.Free;
  1208. end;
  1209. end;
  1210. end.