rtdemo.pas 16 KB

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