rtdemo.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. PROGRAM RTDemo;
  2. (*
  3. ** This is a straight translation from demo.c
  4. ** in the reqtools archive.
  5. **
  6. ** Check this demo for tips on how to use
  7. ** reqtools in FPC Pascal.
  8. **
  9. ** [email protected] (Nils Sjoholm)
  10. **
  11. *)
  12. {
  13. History:
  14. Changed to use the new stuff in unit reqtools.pas.
  15. Removed the array values, will use unit longarray
  16. instead. Cleaned up the code a bit.
  17. 09 Dec 2002.
  18. [email protected]
  19. }
  20. uses reqtools, strings, utility, exec, amigados;
  21. CONST
  22. DISKINSERTED=$00008000;
  23. VAR
  24. filereq : prtFileRequester;
  25. fontreq : prtFontRequester;
  26. scrnreq : prtScreenModeRequester;
  27. filelist : prtFileList;
  28. buffer : PChar;
  29. filename : PChar;
  30. dummy : PChar;
  31. dummy2 : PChar;
  32. longnum : Longword;
  33. ret : Longint;
  34. color : Longint;
  35. undertag : Array [0..1] of tTagItem;
  36. Param : array of PtrUInt;
  37. FUNCTION GetScrollValue(value : INTEGER): STRING;
  38. BEGIN
  39. IF value = 0 THEN GetScrollValue := 'Off'
  40. ELSE GetScrollValue := 'On';
  41. END;
  42. PROCEDURE CleanUp;
  43. BEGIN
  44. if assigned(dummy) then StrDispose(dummy);
  45. if assigned(dummy2) then StrDispose(dummy2);
  46. if assigned(buffer) then StrDispose(buffer);
  47. if assigned(filename) then StrDispose(filename);
  48. END;
  49. BEGIN
  50. if not Assigned(ReqToolsBase) then
  51. begin
  52. writeln('Cannot open ', REQTOOLSNAME);
  53. Halt(5);
  54. end;
  55. dummy:= StrAlloc(400);
  56. dummy2 := StrAlloc(200);
  57. undertag[0].ti_Tag := RT_UnderScore;
  58. undertag[0].ti_Data := Longint(byte('_'));
  59. undertag[1].ti_Tag := TAG_END;
  60. rtEZRequestA('ReqTools 2.0 Demo' + #10 +
  61. '~~~~~~~~~~~~~~~~~' + #10 +
  62. '''reqtools.library'' offers several' + #10 +
  63. 'different types of requesters:','Let''s see them', NIL, NIL, NIL);
  64. rtEZRequestA('NUMBER 1:' + #10 + 'The larch :-)',
  65. 'Be serious!', NIL, NIL, NIL);
  66. rtEZRequestA('NUMBER 1:' + #10 + 'String requester' + #10 + 'function:rtGetString()',
  67. 'Show me', NIL, NIL, NIL);
  68. buffer:= StrAlloc(128); { This should alloc'd to maxchars + 1 }
  69. StrPCopy(buffer, 'A bit of text');
  70. ret := rtGetStringA (buffer, 127, 'Enter anything:', NIL, NIL);
  71. IF (ret=0) THEN
  72. rtEZRequestA('You entered nothing','I''m sorry', NIL, NIL, NIL)
  73. ELSE
  74. rtEZRequestA('You entered this string:' + #10 + '%s','So I did', NIL, @buffer, NIL);
  75. ret := rtGetString(buffer, 127, 'Enter anything:', NIL,[
  76. RTGS_GadFmt, AsTag(' _Ok |New _2.0 feature!|_Cancel'),
  77. RTGS_TextFmt, AsTag('These are two new features of ReqTools 2.0:' + #10
  78. + 'Text above the entry gadget and more than' + #10 + 'one response gadget.'),
  79. TAG_MORE, AsTag(@undertag)]);
  80. IF ret=2 THEN
  81. rtEZRequestA('Yep, this is a new' + #10 + 'ReqTools 2.0 feature!',
  82. 'Oh boy!',NIL,NIL,NIL);
  83. ret := rtGetString(buffer, 127, 'Enter anything:',NIL,[
  84. RTGS_GadFmt, AsTag(' _Ok | _Abort |_Cancel'),
  85. RTGS_TextFmt, AsTag('New is also the ability to switch off the' + #10 +
  86. 'backfill pattern. You can also center the' + #10 +
  87. 'text above the entry gadget.' + #10 +
  88. 'These new features are also available in' + #10 +
  89. 'the rtGetLong() requester.'),
  90. RTGS_BackFill, LFALSE,
  91. RTGS_Flags, GSREQF_CENTERTEXT + GSREQF_HIGHLIGHTTEXT,
  92. TAG_MORE, AsTag(@undertag)]);
  93. IF ret = 2 THEN
  94. rtEZRequestA('What!! You pressed abort!?!' + #10 + 'You must be joking :-)',
  95. 'Ok, Continue',NIL,NIL,NIL);
  96. rtEZRequestA ('NUMBER 2:' + #10 + 'Number requester' + #10 + 'function:rtGetLong()',
  97. 'Show me', NIL, NIL, NIL);
  98. ret := rtGetLong(longnum, 'Enter a number:',NIL,[
  99. RTGL_ShowDefault, LFALSE,
  100. RTGL_Min, 0,
  101. RTGL_Max, 666,
  102. TAG_DONE]);
  103. IF(ret=0) THEN
  104. rtEZRequestA('You entered nothing','I''m sorry', NIL, NIL, NIL)
  105. ELSE
  106. rtEZRequestA('The number You entered was:' + #10 + '%ld' ,
  107. 'So it was', NIL, @longnum, NIL);
  108. rtEZRequestA ('NUMBER 3:' + #10 + 'Notification requester, the requester' + #10 +
  109. 'you''ve been using all the time!' + #10 +
  110. 'function: rtEZRequestA()','Show me more', NIL, NIL, NIL);
  111. rtEZRequestA ('Simplest usage: some body text and' + #10 + 'a single centered gadget.',
  112. 'Got it', NIL, NIL, NIL);
  113. ret := 0;
  114. WHILE ret = 0 DO BEGIN
  115. ret := rtEZRequestA ('You can also use two gadgets to' + #10 +
  116. 'ask the user something' + #10 +
  117. 'Do you understand?',
  118. 'Of course|Not really', NIL, NIL, NIL);
  119. IF ret = 0 THEN rtEZRequestA ('You are not one of the brightest are you?' +
  120. #10 + 'We''ll try again...',
  121. 'Ok', NIL, NIL, NIL);
  122. END;
  123. rtEZRequestA ('Great, we''ll continue then.', 'Fine', NIL, NIL, NIL);
  124. ret:=rtEZRequestA ('You can also put up a requester with' + #10 +
  125. 'three choices.' + #10 +
  126. 'How do you like the demo so far ?',
  127. 'Great|So so|Rubbish', NIL, NIL, NIL);
  128. CASE ret OF
  129. 0: rtEZRequestA ('Too bad, I really hoped you' + #10 + 'would like it better.',
  130. 'So what', NIL, NIL, NIL);
  131. 1: rtEZRequestA ('I''m glad you like it so much.','Fine', NIL, NIL, NIL);
  132. 2: rtEZRequestA ('Maybe if you run the demo again' + #10 + 'you''ll REALLY like it.',
  133. 'Perhaps', NIL, NIL, NIL);
  134. END;
  135. ret := rtEZRequest('The number of responses is not limited to three' + #10 +
  136. 'as you can see. The gadgets are labeled with' + #10 +
  137. 'the ''Return'' code from rtEZRequestA().' + #10 +
  138. 'Pressing ''Return'' will choose 4, note that' + #10 +
  139. '4''s button text is printed in boldface.',
  140. '1|2|3|4|5|0', NIL, NIL,[
  141. RTEZ_DefaultResponse, 4,
  142. TAG_DONE]);
  143. rtEZRequestA('You picked ''%ld''.', 'How true', NIL, @ret, NIL);
  144. {
  145. If i used just a string for this text is will be truncated
  146. after 255 chars. There are no strpcat in strings so we
  147. have to use two buffers and then use strcat.
  148. Could also try ansistring.
  149. }
  150. strpcopy(dummy,'New for Release 2.0 of ReqTools (V38) is' + #10 +
  151. 'the possibility to define characters in the' + #10 +
  152. 'buttons as keyboard shortcuts.' + #10 +
  153. 'As you can see these characters are underlined.' + #10 +
  154. 'Pressing shift while still holding down the key' + #10 +
  155. 'will cancel the shortcut.' + #10);
  156. {
  157. The second buffer.
  158. }
  159. strpcopy(dummy2,'Note that in other requesters a string gadget may' + #10 +
  160. 'be active. To use the keyboard shortcuts there' + #10 +
  161. 'you have to keep the Right Amiga key pressed down.');
  162. {
  163. Now put them together
  164. }
  165. strcat(dummy,dummy2);
  166. rtEZRequestA(dummy,'_Great|_Fantastic|_Swell|Oh _Boy',NIL,NIL,@undertag);
  167. SetLength(Param, 2);
  168. Param[0] := 5;
  169. Param[1] := AsTag('five');
  170. rtEZRequestA('You may also use C-style formatting codes in the body text.' + #10 +
  171. 'Like this:' + #10 + #10 +
  172. 'The number %%ld is written %%s. will give:' + #10 + #10 +
  173. 'The number %ld is written %s.' + #10 + #10 +
  174. 'if you also pass ''5'' and ''five'' to rtEZRequestA().',
  175. '_Proceed',NIL, @Param, @undertag);
  176. ret := rtEZRequest('It is also possible to pass extra IDCMP flags' + #10 +
  177. 'that will satisfy rtEZRequest(). This requester' + #10 +
  178. 'has had DISKINSERTED passed to it.' + #10 +
  179. '(Try inserting a disk).', '_Continue', NIL,NIL,[
  180. RT_IDCMPFlags, DISKINSERTED,
  181. TAG_MORE, AsTag(@undertag)]);
  182. IF ((ret = DISKINSERTED)) THEN
  183. rtEZRequestA('You inserted a disk.', 'I did', NIL, NIL, NIL)
  184. ELSE
  185. rtEZRequestA('You Used the ''Continue'' gadget' + #10 +
  186. 'to satisfy the requester.','I did', NIL, NIL, NIL);
  187. rtEZRequest('Finally, it is possible to specify the position' + #10 +
  188. 'of the requester.' + #10 +
  189. 'E.g. at the top left of the screen, like this.' + #10 +
  190. 'This works for all requesters, not just rtEZRequest()!',
  191. '_Amazing', NIL,NIL,[
  192. RT_ReqPos, REQPOS_TOPLEFTSCR,
  193. TAG_MORE, AsTag(@undertag)]);
  194. rtEZRequest('Alternatively, you can center the' + #10 +
  195. 'requester on the screen.' + #10 +
  196. 'Check out ''reqtools.doc'' for all the possibilities.',
  197. 'I''ll do that', NIL,NIL,[
  198. RT_ReqPos, REQPOS_CENTERSCR,
  199. TAG_MORE, AsTag(@undertag)]);
  200. ret := rtEZRequestA('NUMBER 4:' + #10 + 'File requester' + #10 + 'function: rtFileRequest()',
  201. '_Demonstrate', NIL, NIL, @undertag);
  202. filereq := rtAllocRequestA(RT_FILEREQ, NIL);
  203. IF (filereq<>NIL) THEN BEGIN
  204. filename := StrAlloc(80);
  205. strpcopy (filename, '');
  206. {
  207. We have to cast rtFileRequester to an Longint
  208. to keep the compiler happy.
  209. }
  210. ret := Longint(rtFileRequestA(filereq, filename, 'Pick a file', NIL));
  211. IF (ret)<>0 THEN begin
  212. SetLength(Param, 2);
  213. Param[0] := AsTag(filename);
  214. Param[1] := AsTag(filereq^.Dir);
  215. rtEZRequestA('You picked the file:' + #10 + '%s' + #10 + 'in directory:'
  216. + #10 + '%s', 'Right', NIL, @Param, NIL);
  217. END
  218. ELSE
  219. rtEZRequestA('You didn''t pick a file.', 'No', NIL, NIL, NIL);
  220. rtEZRequestA('The file requester has the ability' + #10 +
  221. 'to allow you to pick more than one' + #10 +
  222. 'file (use Shift to extend-select).' + #10 +
  223. 'Note the extra gadgets you get.',
  224. '_Interesting', NIL,NIL, @undertag);
  225. filelist := rtFileRequest(filereq,filename,'Pick some files',[
  226. RTFI_Flags, FREQF_MULTISELECT,
  227. TAG_END]);
  228. IF filelist <> NIL THEN BEGIN
  229. rtEZRequestA('You selected some files, this is' + #10 +
  230. 'the first one:' + #10 +
  231. '"%s"' + #10 +
  232. 'All the files are returned as a linked' + #10 +
  233. 'list (see demo.c and reqtools.h).',
  234. 'Aha', NIL, @(filelist^.Name),NIL);
  235. (* Traverse all selected files *)
  236. (*
  237. tempflist = flist;
  238. while (tempflist) {
  239. DoSomething (tempflist->Name, tempflist->StrLen);
  240. tempflist = tempflist->Next;
  241. }
  242. *)
  243. (* Free filelist when no longer needed! *)
  244. rtFreeFileList(filelist);
  245. END;
  246. rtFreeRequest(filereq);
  247. END
  248. ELSE
  249. rtEZRequestA('Out of memory!', 'Oh boy!', NIL, NIL, NIL);
  250. rtEZRequestA('The file requester can be used' + #10 + 'as a directory requester as well.',
  251. 'Let''s _see that', NIL, NIL, @undertag);
  252. filereq := rtAllocRequestA(RT_FILEREQ, NIL);
  253. IF (filereq<>NIL) THEN BEGIN
  254. ret := Longint(rtFileRequest(filereq, filename, 'Pick a directory',[
  255. RTFI_Flags, FREQF_NOFILES,
  256. TAG_END]));
  257. IF(ret=1) THEN begin
  258. rtEZRequestA('You picked the directory:' + #10 +'%s',
  259. 'Right', NIL, @(filereq^.Dir), NIL);
  260. end ELSE
  261. rtEZRequestA('You didn''t pick a directory.', 'No', NIL, NIL, NIL);
  262. rtFreeRequest(filereq);
  263. END
  264. ELSE
  265. ret := rtEZRequestA('Out of memory','No',NIL,NIL,NIL);
  266. rtEZRequestA('NUMBER 5:' + #10 +' Font requester' + #10 + 'function:rtFontRequest()',
  267. 'Show', NIL, NIL, NIL);
  268. fontreq := rtAllocRequestA(RT_FONTREQ, NIL);
  269. IF (fontreq<>NIL) THEN BEGIN
  270. fontreq^.Flags := FREQF_STYLE OR FREQF_COLORFONTS;
  271. ret := rtFontRequestA (fontreq, 'Pick a font', NIL);
  272. IF(ret<>0) THEN begin
  273. SetLength(Param, 2);
  274. Param[0] := AsTag(fontreq^.Attr.ta_Name);
  275. Param[1] := AsTag(fontreq^.Attr.ta_YSize);
  276. rtEZRequestA('You picked the font:' + #10 + '%s' + #10 + 'with size:' +
  277. #10 + '%ld',
  278. 'Right', NIL, @Param, NIL);
  279. end ELSE
  280. ret := rtEZRequestA('You didn''t pick a font','I know', NIL, NIL, NIL);
  281. rtFreeRequest(fontreq);
  282. END
  283. ELSE
  284. rtEZRequestA('Out of memory!', 'Oh boy!', NIL, NIL, NIL);
  285. rtEZRequestA('NUMBER 6:' + #10 + 'Palette requester' + #10 + 'function:rtPaletteRequest()',
  286. '_Proceed', NIL,NIL, @undertag);
  287. color := rtPaletteRequestA('Change palette',NIL,NIL);
  288. IF (color = -1) THEN
  289. rtEZRequestA('You canceled.' + #10 + 'No nice colors to be picked ?',
  290. 'Nah', NIL, NIL, NIL)
  291. ELSE begin
  292. rtEZRequestA('You picked color number %ld.', 'Sure did',
  293. NIL, @color, NIL);
  294. END;
  295. rtEZRequestA('NUMBER 7: (ReqTools 2.0)' + #10 +
  296. 'Volume requester' + #10 +
  297. 'function: rtFileRequest() with' + #10 +
  298. 'RTFI_VolumeRequest tag.',
  299. '_Show me', NIL, NIL, @undertag);
  300. filereq := rtAllocRequestA(RT_FILEREQ,NIL);
  301. IF (filereq <> NIL) THEN BEGIN
  302. ret := Longint(rtFileRequest(filereq,NIL,'Pick a volume!',[
  303. RTFI_VolumeRequest,0,
  304. TAG_END]));
  305. IF (ret = 1) THEN begin
  306. rtEZRequestA('You picked the volume:' + #10 + '%s',
  307. 'Right',NIL, @filereq^.Dir,NIL);
  308. end
  309. ELSE
  310. rtEZRequestA('You didn''t pick a volume.','I did not',NIL,NIL,NIL);
  311. rtFreeRequest(filereq);
  312. END
  313. ELSE
  314. rtEZRequestA('Out of memory','Oh boy!',NIL,NIL,NIL);
  315. rtEZRequestA('NUMBER 8: (ReqTools 2.0)' + #10 +
  316. 'Screen mode requester' + #10 +
  317. 'function: rtScreenModeRequest()' + #10 +
  318. 'Only available on Kickstart 2.0!',
  319. '_Proceed', NIL, NIL, @undertag);
  320. scrnreq := rtAllocRequestA (RT_SCREENMODEREQ, NIL);
  321. IF (scrnreq<>NIL) THEN BEGIN
  322. ret := rtScreenModeRequest( scrnreq, 'Pick a screen mode:',[
  323. RTSC_Flags, SCREQF_DEPTHGAD OR SCREQF_SIZEGADS OR
  324. SCREQF_AUTOSCROLLGAD OR SCREQF_OVERSCANGAD,
  325. TAG_END]);
  326. IF(ret=1) THEN BEGIN
  327. SetLength(Param, 6);
  328. Param[0] := scrnreq^.DisplayID;
  329. Param[1] := scrnreq^.DisplayWidth;
  330. Param[2] := scrnreq^.DisplayHeight;
  331. Param[3] := scrnreq^.DisplayDepth;
  332. Param[4] := scrnreq^.OverscanType;
  333. Param[5] := AsTag(PChar(AnsiString(GetScrollValue(scrnreq^.AutoScroll))));
  334. rtEZRequestA('You picked this mode:' + #10 +
  335. 'ModeID : 0x%lx' + #10 +
  336. 'Size : %ld x %ld' + #10 +
  337. 'Depth : %ld' + #10 +
  338. 'Overscan: %ld' + #10 +
  339. 'AutoScroll %s',
  340. 'Right', NIL,
  341. @Param,NIL);
  342. END
  343. ELSE
  344. rtEZRequestA('You didn''t pick a screen mode.', 'Sorry', NIL, NIL, NIL);
  345. rtFreeRequest (scrnreq);
  346. END
  347. ELSE
  348. rtEZRequestA('Out of memory!', 'Oh boy!', NIL, NIL, NIL);
  349. rtEZRequestA('That''s it!' + #10 + 'Hope you enjoyed the demo', '_Sure did', NIL,
  350. NIL,@undertag);
  351. CleanUp;
  352. END.