home *** CD-ROM | disk | FTP | other *** search
Wrap
MODULE Demo; (********************************** * * * reqtools.library (V37) * * * * Release 1.0 * * * * (c) 1991 Nico François * * * * Modula-2 Version 1.0 * * (c) 1992 Michael Griebling * * * * Demo.mod * * * * This source is public domain * * in all respects. * * * *********************************) FROM SYSTEM IMPORT ADR, ADDRESS; FROM DOSProcess IMPORT Delay; FROM Hooks IMPORT Hook; FROM InOut IMPORT WriteString, WriteLn; FROM Intuition IMPORT IDCMPFlagSet, IDCMPFlags; FROM ReqTools IMPORT rtFileRequesterPtr, rtFontRequesterPtr, OpenReqToolsLib, vEZRequest, EZRequest, GetString, GetLong, AllocRequest, FileRequest, FreeRequest, PaletteRequest, EZRequestA, RTFILEREQ, RTFONTREQ, RTFIFlags, FReqFlagSet, RTReqPos, FReqFlags, FileRequestA, RTEZDefaultResponse, RTIDCMPFlags, REQPOSTOPLEFTSCR, REQPOSCENTERSCR, EZRequestTags, FontRequest; FROM TagItem IMPORT Tag, TagIs1; FROM VarCallArgs IMPORT ArgIs, ArgIs2; VAR filereq : rtFileRequesterPtr; fontreq : rtFontRequesterPtr; myhook : Hook; filename : ARRAY [0..34] OF CHAR; directory: ARRAY [0..34] OF CHAR; buffer : ARRAY [0..128] OF CHAR; ret : LONGINT; longnum : LONGINT; color : LONGINT; PROCEDURE myputs (str : ARRAY OF CHAR); BEGIN WriteString(str); WriteLn; END myputs; BEGIN IF NOT OpenReqToolsLib() THEN myputs ("You need reqtools.library V37 or higher!"); myputs ("Please install it in your Libs: drirectory."); ELSE myputs (""); myputs ("ReqTools Demo"); myputs ("¯¯¯¯¯¯¯¯¯¯¯¯¯"); myputs ("This program demonstrates what 'reqtools.library' "); myputs ("has to offer."); Delay (60); vEZRequest("`reqtools.library' offers several\ndifferent types of requesters:", "Let's see them", NIL, NIL); vEZRequest ("NUMBER 1:\nThe larch :-)", "Be serious!", NIL, NIL); vEZRequest ("NUMBER 1:\nString requester\nfunction: GetString()", "Show me", NIL, NIL); buffer := "A bit of text"; IF NOT GetString (buffer, 127, "Enter anything:", NIL) THEN vEZRequest ("You entered nothing :-(", "I'm sorry", NIL, NIL); ELSE vEZRequest ("You entered this string:\n'%s'.", "So I did", NIL, ArgIs(ADR(buffer))); END; vEZRequest ("NUMBER 2:\nNumber requester\nfunction: GetLong()", "Show me", NIL, NIL); IF NOT GetLong (longnum, "Enter a number:", NIL) THEN vEZRequest ("You entered nothing :-(", "I'm sorry", NIL, NIL); ELSE vEZRequest ("The number you entered was:\n%ld", "So it was", NIL, ArgIs(longnum)); END; vEZRequest ("NUMBER 3:\nNotification requester, the requester\nyou've been using all the time!\nfunction:EZRequest()", "Show me more", NIL, NIL); vEZRequest ("Simplest usage: some body text and\na single centered gadget.", "Got it", NIL, NIL); WHILE EZRequest ( "You can also use two gadgets to\nask the user something.\nDo you understand?", "Of course|Not really", NIL, NIL) = 0 DO vEZRequest ("You are not one of the brightest are you?\nWe'll try again...", "Ok", NIL, NIL); END; vEZRequest ("Great, we'll continue then.", "Fine", NIL, NIL); CASE INTEGER(EZRequest ( "You can also put up a requester with\nthree choices.\nHow do you like the demo so far?", "Great|So so|Rubbish", NIL, NIL)) OF 0 : vEZRequest ("Too bad, I really hoped you\nwould like it better.", "So what", NIL, NIL) | 1 : vEZRequest ("I'm glad you like it so much.", "Fine", NIL, NIL) | 2 : vEZRequest ("Maybe if you run the demo again\nyou'll REALLY like it.", "Perhaps", NIL, NIL) | END; ret := EZRequestTags ( "The number of responses is not limited to three\nas you can see. The gadgets are labeled with\nthe return code from EZRequest().\nPressing Return will choose 4, note that\n4's button text is printed in boldface.", "1|2|3|4|5|0", NIL, NIL, TagIs1(RTEZDefaultResponse, 4)); vEZRequest ("You picked '%ld'.", "How true", NIL, ArgIs(ret)); vEZRequest ( "You may also use C-style formatting codes in the body text.\nLike this:\n\n'The number %%ld is written %%s.' will give:\n\nThe number %ld is written %s.\n\nif you also pass '5' and '\"five\"' to EZRequest().", "Proceed", NIL, ArgIs2(5, ADR("five"))); IF EZRequestTags ( "It is also possible to pass extra IDCMP flags\nthat will satisfy EZRequest(). This requester\nhas had DISKINSERTED passed to it.\n(Try inserting a disk).", "Continue", NIL, NIL, TagIs1(RTIDCMPFlags, LONGCARD(IDCMPFlagSet{DiskInserted}))) = LONGINT(IDCMPFlagSet{DiskInserted}) THEN vEZRequest ("You inserted a disk.", "I did", NIL, NIL); ELSE vEZRequest ("You used the 'Continue' gadget\nto satisfy the requester.", "I did", NIL, NIL); END; ret := EZRequestTags ( "Finally, it is possible to specify the position\nof the requester.\nE.g. at the top left of the screen, like this.\nThis works for all requesters, not just EZRequest()!", "Amazing", NIL, NIL, TagIs1(RTReqPos, REQPOSTOPLEFTSCR)); ret := EZRequestTags ( "Alternatively, you can center the\nrequester on the screen.\nCheck out 'reqtools.doc' for all the possibilities.", "I'll do that", NIL, NIL, TagIs1(RTReqPos, REQPOSCENTERSCR)); vEZRequest ("NUMBER 4:\nFile requester\nfunction: FileRequest()", "Demonstrate", NIL, NIL); filereq := AllocRequest (RTFILEREQ); IF filereq # NIL THEN filename := ""; directory := ""; IF FileRequest (filereq, filename, directory, "Pick a file") THEN vEZRequest ( "You picked the file:\n'%s'\nin directory:\n'%s'", "Right", NIL, ArgIs2(ADR(filename), LONGCARD(filereq^.Dir))); ELSE vEZRequest ("You didn't pick a file.", "No", NIL, NIL); END; FreeRequest (filereq); ELSE vEZRequest ("Out of memory!", "Oh boy!", NIL, NIL); END; vEZRequest ( "The file requester can be used\nas a directory requester as well.", "Let's see that", NIL, NIL); filereq := AllocRequest (RTFILEREQ); IF filereq # NIL THEN IF FileRequestA (filereq, filename, ADR("Pick a directory"), TagIs1(RTFIFlags, LONGCARD(FReqFlagSet{NoFiles}))) THEN vEZRequest ("You picked the directory:\n'%s'", "Right", NIL, ArgIs(LONGCARD(filereq^.Dir))); ELSE vEZRequest ("You didn't pick a directory.", "No", NIL, NIL); END; FreeRequest (filereq); ELSE vEZRequest ("Out of memory!", "Oh boy!", NIL, NIL); END; vEZRequest ("NUMBER 5:\nFont requester\nfunction: FontRequest()", "Show", NIL, NIL); fontreq := AllocRequest (RTFONTREQ); IF fontreq # NIL THEN fontreq^.Flags := FReqFlagSet{Style, ColorFonts}; (* (* sorry - I haven't implemented the hooks for M2 *) myhook.h_Entry = hookfunc; fontreq->Hook = &myhook; fontreq->Flags |= FREQF_DOWILDFUNC; *) IF FontRequest (fontreq, "Pick a font") THEN vEZRequest ("You picked the font:\n'%s'\nwith size:\n'%ld'", "Right", NIL, ArgIs2(LONGCARD(fontreq^.Attr.taName), fontreq^.Attr.taYSize)); ELSE vEZRequest ("You canceled.\nWas there no font you liked ?", "Nope", NIL, NIL); END; FreeRequest (fontreq); ELSE vEZRequest ("Out of memory!", "Oh boy!", NIL, NIL); END; vEZRequest ("NUMBER 6:\nPalette requester\nfunction: PaletteRequest()", "Proceed", NIL, NIL); color := PaletteRequest ("Change palette", NIL); IF (color = -1) THEN vEZRequest ("You canceled.\nNo nice colors to be picked ?", "Nah", NIL, NIL); ELSE vEZRequest ("You picked color number %ld.", "Sure did", NIL, ArgIs(color)); END; (* free all resources *) myputs ("\nFinished, hope you enjoyed the demo :-)\n"); END; END Demo.