home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d575 / reqtools.lha / ReqTools / demo / demo.c < prev    next >
C/C++ Source or Header  |  1991-12-22  |  8KB  |  274 lines

  1. /*********************************
  2. *                                *
  3. *  reqtools.library (V37)        *
  4. *                                *
  5. *  Release 1.0b                  *
  6. *                                *
  7. *  (c) 1991 Nico François        *
  8. *                                *
  9. *  demo.c                        *
  10. *                                *
  11. *  This source is public domain  *
  12. *  in all respects.              *
  13. *                                *
  14. *********************************/
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <libraries/dos.h>
  19. #include <intuition/intuition.h>
  20. #include <proto/exec.h>
  21. #include <proto/dos.h>
  22.  
  23. #include <stdio.h>
  24.  
  25. #include <libraries/reqtools.h>
  26. #include <proto/reqtools.h>
  27.  
  28. struct ReqToolsBase *ReqToolsBase;
  29.  
  30. ULONG __asm __saveds hookfunc (register __a0 struct Hook *,
  31.                                          register __a2 APTR, register __a1 ULONG *);
  32.  
  33. void myputs (char *str)
  34. {
  35.     Write (Output(), str, strlen(str));
  36. }
  37.  
  38. _main()
  39. {
  40.     struct rtFileRequester *filereq;
  41.     struct rtFontRequester *fontreq;
  42.     struct Hook myhook;
  43.     char buffer[128], filename[34];
  44.     long longnum, ret, color;
  45.  
  46.     if (!(ReqToolsBase = (struct ReqToolsBase *)
  47.                                                         OpenLibrary (REQTOOLSNAME, 37))) {
  48.         myputs ("You need reqtools.library V37 or higher!\n"
  49.                   "Please install it in your Libs: drirectory.\n");
  50.         exit (0);
  51.         }
  52.  
  53.     myputs ("\nReqTools Demo\n¯¯¯¯¯¯¯¯¯¯¯¯¯\n"
  54.               "This program demonstrates what 'reqtools.library' "
  55.               "has to offer.\n");
  56.  
  57.     Delay (60);
  58.  
  59.     rtEZRequest ("'reqtools.library' offers several\n"
  60.                      "different types of requesters:",
  61.                      "Let's see them", NULL, NULL);
  62.  
  63.     rtEZRequest ("NUMBER 1:\nThe larch :-)", "Be serious!", NULL, NULL);
  64.  
  65.     rtEZRequest ("NUMBER 1:\nString requester\nfunction: rtGetString()",
  66.                      "Show me", NULL, NULL);
  67.  
  68.     strcpy (buffer, "A bit of text");
  69.     if (!rtGetString (buffer, 127, "Enter anything:", NULL, TAG_END))
  70.         rtEZRequest ("You entered nothing :-(", "I'm sorry", NULL, NULL);
  71.     else
  72.         rtEZRequest ("You entered this string:\n'%s'.",
  73.                          "So I did", NULL, NULL, buffer);
  74.  
  75.     rtEZRequest ("NUMBER 2:\nNumber requester\nfunction: rtGetLong()",
  76.                      "Show me", NULL, NULL);
  77.  
  78.     if (!rtGetLong (&longnum, "Enter a number:", NULL,
  79.                          RTGL_ShowDefault, FALSE, TAG_END))
  80.         rtEZRequest ("You entered nothing :-(",
  81.                          "I'm sorry", NULL, NULL);
  82.     else
  83.         rtEZRequest ("The number you entered was:\n%ld",
  84.                          "So it was", NULL, NULL, longnum);
  85.  
  86.     rtEZRequest ("NUMBER 3:\nNotification requester, the requester\n"
  87.                      "you've been using all the time!\nfunction: rtEZRequest()",
  88.                      "Show me more", NULL, NULL);
  89.  
  90.     rtEZRequest ("Simplest usage: some body text and\na single centered gadget.",
  91.                      "Got it", NULL, NULL);
  92.  
  93.     while (!rtEZRequest ("You can also use two gadgets to\n"
  94.                                 "ask the user something.\n"
  95.                                 "Do you understand?", "Of course|Not really",
  96.                                 NULL, NULL))
  97.         rtEZRequest ("You are not one of the brightest are you?\n"
  98.                          "We'll try again...",
  99.                          "Ok", NULL, NULL);
  100.  
  101.     rtEZRequest ("Great, we'll continue then.", "Fine", NULL, NULL);
  102.  
  103.     switch (rtEZRequest ("You can also put up a requester with\n"
  104.                                 "three choices.\n"
  105.                                 "How do you like the demo so far ?",
  106.                                 "Great|So so|Rubbish", NULL, NULL)) {
  107.         case FALSE:
  108.             rtEZRequest ("Too bad, I really hoped you\nwould like it better.",
  109.                              "So what", NULL, NULL);
  110.             break;
  111.         case TRUE:
  112.             rtEZRequest ("I'm glad you like it so much.", "Fine", NULL, NULL);
  113.             break;
  114.         case 2:
  115.             rtEZRequest ("Maybe if you run the demo again\n"
  116.                              "you'll REALLY like it.",
  117.                              "Perhaps", NULL, NULL);
  118.             break;
  119.         }
  120.  
  121.     ret = rtEZRequestTags ("The number of responses is not limited to three\n"
  122.                                   "as you can see.  The gadgets are labeled with\n"    
  123.                                   "the return code from rtEZRequest().\n"
  124.                                   "Pressing Return will choose 4, note that\n"
  125.                                   "4's button text is printed in boldface.",
  126.                                   "1|2|3|4|5|0", NULL, NULL,
  127.                                   RTEZ_DefaultResponse, 4, TAG_END);
  128.     rtEZRequest ("You picked '%ld'.", "How true", NULL, NULL, ret);
  129.  
  130.     rtEZRequest (
  131.         "You may also use C-style formatting codes in the body text.\n"
  132.         "Like this:\n\n"
  133.         "'The number %%ld is written %%s.' will give:\n\n"
  134.         "The number %ld is written %s.\n\n"
  135.         "if you also pass '5' and '\"five\"' to rtEZRequest().",
  136.         "Proceed", NULL, NULL, 5, "five");
  137.  
  138.     if (rtEZRequestTags ("It is also possible to pass extra IDCMP flags\n"
  139.                                "that will satisfy rtEZRequest(). This requester\n"
  140.                                "has had DISKINSERTED passed to it.\n"
  141.                                "(Try inserting a disk).",
  142.                                "Continue", NULL, NULL,
  143.                                RT_IDCMPFlags, DISKINSERTED, TAG_END)
  144.                                & DISKINSERTED)
  145.         rtEZRequest ("You inserted a disk.", "I did", NULL, NULL);
  146.     else
  147.         rtEZRequest ("You used the 'Continue' gadget\n"
  148.                          "to satisfy the requester.", "I did", NULL, NULL);
  149.  
  150.     rtEZRequestTags ("Finally, it is possible to specify the position\n"
  151.                           "of the requester.\n"
  152.                           "E.g. at the top left of the screen, like this.\n"
  153.                           "This works for all requesters, not just rtEZRequest()!",
  154.                           "Amazing", NULL, NULL,
  155.                           RT_ReqPos, REQPOS_TOPLEFTSCR, TAG_END);
  156.  
  157.     rtEZRequestTags ("Alternatively, you can center the\n"
  158.                           "requester on the screen.\n"
  159.                           "Check out 'reqtools.doc' for all the possibilities.",
  160.                           "I'll do that", NULL, NULL,
  161.                           RT_ReqPos, REQPOS_CENTERSCR, TAG_END);
  162.  
  163.     rtEZRequest ("NUMBER 4:\nFile requester\n"
  164.                      "function: rtFileRequest()",
  165.                      "Demonstrate", NULL, NULL);
  166.  
  167.     if (filereq = rtAllocRequestA (RT_FILEREQ, NULL)) {
  168.  
  169. /*
  170.         myhook.h_Entry = hookfunc;
  171.         filereq->Hook = &myhook;
  172.         filereq->Flags = FREQF_DOWILDFUNC;
  173. */
  174.  
  175.         filename[0] = 0;
  176.         if (rtFileRequest (filereq, filename, "Pick a file", TAG_END))
  177.             rtEZRequest ("You picked the file:\n'%s'\nin directory:\n'%s'",
  178.                              "Right", NULL, NULL, filename, filereq->Dir);
  179.         else
  180.             rtEZRequest ("You didn't pick a file.", "No", NULL, NULL);
  181.  
  182.         rtFreeRequest (filereq);
  183.         }
  184.     else
  185.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  186.  
  187.  
  188.     rtEZRequest ("The file requester can be used\n"
  189.                      "as a directory requester as well.",
  190.                      "Let'see that", NULL, NULL);
  191.  
  192.     if (filereq = rtAllocRequestA (RT_FILEREQ, NULL)) {
  193.         if (rtFileRequest (filereq, filename, "Pick a directory",
  194.                                  RTFI_Flags, FREQF_NOFILES, TAG_END))
  195.             rtEZRequest ("You picked the directory:\n'%s'",
  196.                              "Right", NULL, NULL, filereq->Dir);
  197.         else
  198.             rtEZRequest ("You didn't pick a directory.", "No", NULL, NULL);
  199.  
  200.         rtFreeRequest (filereq);
  201.         }
  202.     else
  203.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  204.  
  205.     rtEZRequest ("NUMBER 5:\nFont requester\n"
  206.                      "function: rtFontRequest()",
  207.                      "Show", NULL, NULL);
  208.  
  209.     if (fontreq = rtAllocRequestA (RT_FONTREQ, NULL)) {
  210.  
  211.         fontreq->Flags = FREQF_STYLE|FREQF_COLORFONTS;
  212.  
  213. /*
  214.         myhook.h_Entry = hookfunc;
  215.         fontreq->Hook = &myhook;
  216.         fontreq->Flags |= FREQF_DOWILDFUNC;
  217. */
  218.  
  219.         if (rtFontRequest (fontreq, "Pick a font", TAG_END))
  220.             rtEZRequest ("You picked the font:\n'%s'\nwith size:\n'%ld'",
  221.                              "Right", NULL, NULL,
  222.                              fontreq->Attr.ta_Name, fontreq->Attr.ta_YSize);
  223.         else
  224.             rtEZRequest ("You canceled.\nWas there no font you liked ?",
  225.                              "Nope", NULL, NULL);
  226.  
  227.         rtFreeRequest (fontreq);
  228.         }
  229.     else
  230.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  231.  
  232.     rtEZRequest ("NUMBER 6:\nPalette requester\n"
  233.                      "function: rtPaletteRequest()",
  234.                      "Proceed", NULL, NULL);
  235.  
  236.     color = rtPaletteRequest ("Change palette", NULL, TAG_END);
  237.     if (color == -1)
  238.         rtEZRequest ("You canceled.\nNo nice colors to be picked ?",
  239.                          "Nah", NULL, NULL);
  240.     else
  241.         rtEZRequest ("You picked color number %ld.", "Sure did",
  242.                          NULL, NULL, color);
  243.  
  244.     /* free all resources */
  245.     CloseLibrary ((struct Library *)ReqToolsBase);
  246.  
  247.     myputs ("\nFinished, hope you enjoyed the demo :-)\n");
  248.  
  249.     exit (0);
  250. }
  251.  
  252. ULONG __asm __saveds hookfunc (register __a0 struct Hook *hook,
  253.                                          register __a2 APTR req,
  254.                                          register __a1 ULONG *param)
  255. {
  256.     struct FileInfoBlock *fib;
  257.     struct TextAttr *ta;
  258.  
  259.     switch (param[0]) {
  260.         case REQHOOK_WILDFILE:
  261.             /* param[1] holds address of a FileInfoBlock */
  262.             fib = (struct FileInfoBlock *)param[1];
  263.             myputs (fib->fib_FileName); myputs ("\n");
  264.             return (FALSE);
  265.         case REQHOOK_WILDFONT:
  266.             /* param[1] holds address of a TextAttr */
  267.             ta = (struct TextAttr *)param[1];
  268.             myputs (ta->ta_Name); myputs ("\n");
  269.             return (FALSE);
  270.         default:
  271.             return (0);
  272.         }
  273. }
  274.