home *** CD-ROM | disk | FTP | other *** search
- /*********************************
- * *
- * reqtools.library (V37) *
- * *
- * Release 1.0b *
- * *
- * (c) 1991 Nico François *
- * *
- * demo.c *
- * *
- * This source is public domain *
- * in all respects. *
- * *
- *********************************/
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <libraries/dos.h>
- #include <intuition/intuition.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
-
- #include <stdio.h>
-
- #include <libraries/reqtools.h>
- #include <proto/reqtools.h>
-
- struct ReqToolsBase *ReqToolsBase;
-
- ULONG __asm __saveds hookfunc (register __a0 struct Hook *,
- register __a2 APTR, register __a1 ULONG *);
-
- void myputs (char *str)
- {
- Write (Output(), str, strlen(str));
- }
-
- _main()
- {
- struct rtFileRequester *filereq;
- struct rtFontRequester *fontreq;
- struct Hook myhook;
- char buffer[128], filename[34];
- long longnum, ret, color;
-
- if (!(ReqToolsBase = (struct ReqToolsBase *)
- OpenLibrary (REQTOOLSNAME, 37))) {
- myputs ("You need reqtools.library V37 or higher!\n"
- "Please install it in your Libs: drirectory.\n");
- exit (0);
- }
-
- myputs ("\nReqTools Demo\n¯¯¯¯¯¯¯¯¯¯¯¯¯\n"
- "This program demonstrates what 'reqtools.library' "
- "has to offer.\n");
-
- Delay (60);
-
- rtEZRequest ("'reqtools.library' offers several\n"
- "different types of requesters:",
- "Let's see them", NULL, NULL);
-
- rtEZRequest ("NUMBER 1:\nThe larch :-)", "Be serious!", NULL, NULL);
-
- rtEZRequest ("NUMBER 1:\nString requester\nfunction: rtGetString()",
- "Show me", NULL, NULL);
-
- strcpy (buffer, "A bit of text");
- if (!rtGetString (buffer, 127, "Enter anything:", NULL, TAG_END))
- rtEZRequest ("You entered nothing :-(", "I'm sorry", NULL, NULL);
- else
- rtEZRequest ("You entered this string:\n'%s'.",
- "So I did", NULL, NULL, buffer);
-
- rtEZRequest ("NUMBER 2:\nNumber requester\nfunction: rtGetLong()",
- "Show me", NULL, NULL);
-
- if (!rtGetLong (&longnum, "Enter a number:", NULL,
- RTGL_ShowDefault, FALSE, TAG_END))
- rtEZRequest ("You entered nothing :-(",
- "I'm sorry", NULL, NULL);
- else
- rtEZRequest ("The number you entered was:\n%ld",
- "So it was", NULL, NULL, longnum);
-
- rtEZRequest ("NUMBER 3:\nNotification requester, the requester\n"
- "you've been using all the time!\nfunction: rtEZRequest()",
- "Show me more", NULL, NULL);
-
- rtEZRequest ("Simplest usage: some body text and\na single centered gadget.",
- "Got it", NULL, NULL);
-
- while (!rtEZRequest ("You can also use two gadgets to\n"
- "ask the user something.\n"
- "Do you understand?", "Of course|Not really",
- NULL, NULL))
- rtEZRequest ("You are not one of the brightest are you?\n"
- "We'll try again...",
- "Ok", NULL, NULL);
-
- rtEZRequest ("Great, we'll continue then.", "Fine", NULL, NULL);
-
- switch (rtEZRequest ("You can also put up a requester with\n"
- "three choices.\n"
- "How do you like the demo so far ?",
- "Great|So so|Rubbish", NULL, NULL)) {
- case FALSE:
- rtEZRequest ("Too bad, I really hoped you\nwould like it better.",
- "So what", NULL, NULL);
- break;
- case TRUE:
- rtEZRequest ("I'm glad you like it so much.", "Fine", NULL, NULL);
- break;
- case 2:
- rtEZRequest ("Maybe if you run the demo again\n"
- "you'll REALLY like it.",
- "Perhaps", NULL, NULL);
- break;
- }
-
- ret = rtEZRequestTags ("The number of responses is not limited to three\n"
- "as you can see. The gadgets are labeled with\n"
- "the return code from rtEZRequest().\n"
- "Pressing Return will choose 4, note that\n"
- "4's button text is printed in boldface.",
- "1|2|3|4|5|0", NULL, NULL,
- RTEZ_DefaultResponse, 4, TAG_END);
- rtEZRequest ("You picked '%ld'.", "How true", NULL, NULL, ret);
-
- rtEZRequest (
- "You may also use C-style formatting codes in the body text.\n"
- "Like this:\n\n"
- "'The number %%ld is written %%s.' will give:\n\n"
- "The number %ld is written %s.\n\n"
- "if you also pass '5' and '\"five\"' to rtEZRequest().",
- "Proceed", NULL, NULL, 5, "five");
-
- if (rtEZRequestTags ("It is also possible to pass extra IDCMP flags\n"
- "that will satisfy rtEZRequest(). This requester\n"
- "has had DISKINSERTED passed to it.\n"
- "(Try inserting a disk).",
- "Continue", NULL, NULL,
- RT_IDCMPFlags, DISKINSERTED, TAG_END)
- & DISKINSERTED)
- rtEZRequest ("You inserted a disk.", "I did", NULL, NULL);
- else
- rtEZRequest ("You used the 'Continue' gadget\n"
- "to satisfy the requester.", "I did", NULL, NULL);
-
- rtEZRequestTags ("Finally, it is possible to specify the position\n"
- "of the requester.\n"
- "E.g. at the top left of the screen, like this.\n"
- "This works for all requesters, not just rtEZRequest()!",
- "Amazing", NULL, NULL,
- RT_ReqPos, REQPOS_TOPLEFTSCR, TAG_END);
-
- rtEZRequestTags ("Alternatively, you can center the\n"
- "requester on the screen.\n"
- "Check out 'reqtools.doc' for all the possibilities.",
- "I'll do that", NULL, NULL,
- RT_ReqPos, REQPOS_CENTERSCR, TAG_END);
-
- rtEZRequest ("NUMBER 4:\nFile requester\n"
- "function: rtFileRequest()",
- "Demonstrate", NULL, NULL);
-
- if (filereq = rtAllocRequestA (RT_FILEREQ, NULL)) {
-
- /*
- myhook.h_Entry = hookfunc;
- filereq->Hook = &myhook;
- filereq->Flags = FREQF_DOWILDFUNC;
- */
-
- filename[0] = 0;
- if (rtFileRequest (filereq, filename, "Pick a file", TAG_END))
- rtEZRequest ("You picked the file:\n'%s'\nin directory:\n'%s'",
- "Right", NULL, NULL, filename, filereq->Dir);
- else
- rtEZRequest ("You didn't pick a file.", "No", NULL, NULL);
-
- rtFreeRequest (filereq);
- }
- else
- rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
-
-
- rtEZRequest ("The file requester can be used\n"
- "as a directory requester as well.",
- "Let'see that", NULL, NULL);
-
- if (filereq = rtAllocRequestA (RT_FILEREQ, NULL)) {
- if (rtFileRequest (filereq, filename, "Pick a directory",
- RTFI_Flags, FREQF_NOFILES, TAG_END))
- rtEZRequest ("You picked the directory:\n'%s'",
- "Right", NULL, NULL, filereq->Dir);
- else
- rtEZRequest ("You didn't pick a directory.", "No", NULL, NULL);
-
- rtFreeRequest (filereq);
- }
- else
- rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
-
- rtEZRequest ("NUMBER 5:\nFont requester\n"
- "function: rtFontRequest()",
- "Show", NULL, NULL);
-
- if (fontreq = rtAllocRequestA (RT_FONTREQ, NULL)) {
-
- fontreq->Flags = FREQF_STYLE|FREQF_COLORFONTS;
-
- /*
- myhook.h_Entry = hookfunc;
- fontreq->Hook = &myhook;
- fontreq->Flags |= FREQF_DOWILDFUNC;
- */
-
- if (rtFontRequest (fontreq, "Pick a font", TAG_END))
- rtEZRequest ("You picked the font:\n'%s'\nwith size:\n'%ld'",
- "Right", NULL, NULL,
- fontreq->Attr.ta_Name, fontreq->Attr.ta_YSize);
- else
- rtEZRequest ("You canceled.\nWas there no font you liked ?",
- "Nope", NULL, NULL);
-
- rtFreeRequest (fontreq);
- }
- else
- rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
-
- rtEZRequest ("NUMBER 6:\nPalette requester\n"
- "function: rtPaletteRequest()",
- "Proceed", NULL, NULL);
-
- color = rtPaletteRequest ("Change palette", NULL, TAG_END);
- if (color == -1)
- rtEZRequest ("You canceled.\nNo nice colors to be picked ?",
- "Nah", NULL, NULL);
- else
- rtEZRequest ("You picked color number %ld.", "Sure did",
- NULL, NULL, color);
-
- /* free all resources */
- CloseLibrary ((struct Library *)ReqToolsBase);
-
- myputs ("\nFinished, hope you enjoyed the demo :-)\n");
-
- exit (0);
- }
-
- ULONG __asm __saveds hookfunc (register __a0 struct Hook *hook,
- register __a2 APTR req,
- register __a1 ULONG *param)
- {
- struct FileInfoBlock *fib;
- struct TextAttr *ta;
-
- switch (param[0]) {
- case REQHOOK_WILDFILE:
- /* param[1] holds address of a FileInfoBlock */
- fib = (struct FileInfoBlock *)param[1];
- myputs (fib->fib_FileName); myputs ("\n");
- return (FALSE);
- case REQHOOK_WILDFONT:
- /* param[1] holds address of a TextAttr */
- ta = (struct TextAttr *)param[1];
- myputs (ta->ta_Name); myputs ("\n");
- return (FALSE);
- default:
- return (0);
- }
- }
-