home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / libs / reqtools.lha / ReqTools / demo / demo.c next >
Encoding:
C/C++ Source or Header  |  1992-06-29  |  12.7 KB  |  406 lines

  1. /*********************************
  2. *                                *
  3. *  reqtools.library (V38)        *
  4. *                                *
  5. *  Release 2.0                   *
  6. *                                *
  7. *  (c) 1991/1992 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 <exec/execbase.h>
  19. #include <libraries/dos.h>
  20. #include <intuition/intuition.h>
  21. #include <proto/exec.h>
  22. #include <proto/dos.h>
  23.  
  24. #include <stdio.h>
  25.  
  26. #include <libraries/reqtools.h>
  27. #include <proto/reqtools.h>
  28.  
  29. extern struct ExecBase *SysBase;
  30. struct ReqToolsBase *ReqToolsBase;
  31.  
  32. #define REG register
  33.  
  34. /* Callback functions
  35.     Define DOHOOKS when you compile to activate these filter functions */
  36.  
  37. BOOL __asm __saveds file_filterfunc (
  38.     REG __a0 struct Hook *, REG __a2 struct rtFileRequester *,
  39.     REG __a1 struct FileInfoBlock *
  40.     );
  41. BOOL __asm __saveds font_filterfunc (
  42.     REG __a0 struct Hook *, REG __a2 struct rtFontRequester *,
  43.     REG __a1 struct TextAttr *
  44.     );
  45. BOOL __asm __saveds vol_filterfunc (
  46.     REG __a0 struct Hook *, REG __a2 struct rtFileRequester *,
  47.     REG __a1 struct rtVolumeEntry *
  48.     );
  49.  
  50. ULONG undertag[] = { RT_Underscore, '_', TAG_END };
  51.  
  52. void myputs (char *str)
  53. {
  54.     Write (Output(), str, strlen(str));
  55. }
  56.  
  57. _main()
  58. {
  59.     struct rtFileRequester *filereq;
  60.     struct rtFontRequester *fontreq;
  61.     struct rtScreenModeRequester *scrmodereq;
  62.     struct Hook filterhook, font_filterhook, vol_filterhook;
  63.     char buffer[128], filename[34];
  64.     long longnum, ret, color;
  65.  
  66.     if (!(ReqToolsBase = (struct ReqToolsBase *)
  67.                                           OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION))) {
  68.         myputs ("You need reqtools.library V38 or higher!\n"
  69.                   "Please install it in your Libs: drirectory.\n");
  70.         exit (0);
  71.         }
  72.  
  73.     rtEZRequest ("ReqTools 2.0 Demo\n"
  74.                  "~~~~~~~~~~~~~~~~~\n"
  75.                      "'reqtools.library' offers several\n"
  76.                      "different types of requesters:",
  77.                      "Let's see them", NULL, NULL);
  78.  
  79.     rtEZRequest ("NUMBER 1:\nThe larch :-)", "Be serious!", NULL, NULL);
  80.  
  81.     rtEZRequest ("NUMBER 1:\nString requester\nfunction: rtGetString()",
  82.                      "Show me", NULL, NULL);
  83.  
  84.     strcpy (buffer, "A bit of text");
  85.     if (!rtGetString (buffer, 127, "Enter anything:", NULL, TAG_END))
  86.         rtEZRequest ("You entered nothing :-(", "I'm sorry", NULL, NULL);
  87.     else
  88.         rtEZRequest ("You entered this string:\n'%s'.",
  89.                          "So I did", NULL, NULL, buffer);
  90.  
  91.     rtGetString (buffer, 127, "Enter anything:", NULL,
  92.                      RTGS_GadFmt, " _Ok |New _2.0 feature!|_Cancel",
  93.                      RTGS_TextFmt, "These are two new features of ReqTools 2.0:\n"
  94.                                          "Text above the entry gadget and more than\n"
  95.                                          "one response gadget.",
  96.                      TAG_MORE, undertag);
  97.  
  98.     rtGetString (buffer, 127, "Enter anything:", NULL,
  99.                      RTGS_GadFmt, " _Ok |_Abort|_Cancel",
  100.                      RTGS_TextFmt, "New is also the ability to switch off the\n"
  101.                                          "backfill pattern.  You can also center the\n"
  102.                                          "text above the entry gadget.\n"
  103.                                          "These new features are also available in\n"
  104.                                          "the rtGetLong() requester.",
  105.                      RTGS_Backfill, FALSE,
  106.                      RTGS_Flags, GSREQF_CENTERTEXT|GSREQF_HIGHLIGHTTEXT,
  107.                      TAG_MORE, undertag);
  108.  
  109.     rtEZRequest ("NUMBER 2:\nNumber requester\nfunction: rtGetLong()",
  110.                      "Show me", NULL, NULL);
  111.  
  112.     if (!rtGetLong (&longnum, "Enter a number:", NULL,
  113.                          RTGL_ShowDefault, FALSE, TAG_END))
  114.         rtEZRequest ("You entered nothing :-(",
  115.                          "I'm sorry", NULL, NULL);
  116.     else
  117.         rtEZRequest ("The number you entered was:\n%ld",
  118.                          "So it was", NULL, NULL, longnum);
  119.  
  120.     rtEZRequest ("NUMBER 3:\nMessage requester, the requester\n"
  121.                      "you've been using all the time!\nfunction: rtEZRequest()",
  122.                      "Show me more", NULL, NULL);
  123.  
  124.     rtEZRequest ("Simplest usage: some body text and\na single centered gadget.",
  125.                      "Got it", NULL, NULL);
  126.  
  127.     while (!rtEZRequest ("You can also use two gadgets to\n"
  128.                                 "ask the user something.\n"
  129.                                 "Do you understand?", "Of course|Not really",
  130.                                 NULL, NULL))
  131.         rtEZRequest ("You are not one of the brightest are you?\n"
  132.                          "We'll try again...",
  133.                          "Ok", NULL, NULL);
  134.  
  135.     rtEZRequest ("Great, we'll continue then.", "Fine", NULL, NULL);
  136.  
  137.     switch (rtEZRequest ("You can also put up a requester with\n"
  138.                                 "three choices.\n"
  139.                                 "How do you like the demo so far ?",
  140.                                 "Great|So so|Rubbish", NULL, NULL)) {
  141.         case FALSE:
  142.             rtEZRequest ("Too bad, I really hoped you\nwould like it better.",
  143.                              "So what", NULL, NULL);
  144.             break;
  145.         case TRUE:
  146.             rtEZRequest ("I'm glad you like it so much.", "Fine", NULL, NULL);
  147.             break;
  148.         case 2:
  149.             rtEZRequest ("Maybe if you run the demo again\n"
  150.                              "you'll REALLY like it.",
  151.                              "Perhaps", NULL, NULL);
  152.             break;
  153.         }
  154.  
  155.     ret = rtEZRequestTags ("The number of responses is not limited to three\n"
  156.                                   "as you can see.  The gadgets are labeled with\n"    
  157.                                   "the return code from rtEZRequest().\n"
  158.                                   "Pressing Return will choose 4, note that\n"
  159.                                   "4's button text is printed in boldface.",
  160.                                   "1|2|3|4|5|0", NULL, NULL,
  161.                                   RTEZ_DefaultResponse, 4, TAG_END);
  162.     rtEZRequest ("You picked '%ld'.", "How true", NULL, NULL, ret);
  163.  
  164.     rtEZRequestTags ("New for Release 2.0 of ReqTools (V38) is\n"
  165.                           "the possibility to define characters in the\n"
  166.                           "buttons as keyboard shortcuts.\n"
  167.                           "As you can see these characters are underlined.\n"
  168.                           "Pressing shift while still holding down the key\n"
  169.                           "will cancel the shortcut.\n"
  170.                           "Note that in other requesters a string gadget may\n"
  171.                           "be active.  To use the keyboard shortcuts there\n"
  172.                           "you have to keep the Right Amiga key pressed down.",
  173.                           "_Great|_Fantastic|_Swell|Oh _Boy",
  174.                           NULL, NULL,
  175.                           RT_Underscore, '_', TAG_END);
  176.  
  177.     rtEZRequest (
  178.         "You may also use C-style formatting codes in the body text.\n"
  179.         "Like this:\n\n"
  180.         "'The number %%ld is written %%s.' will give:\n\n"
  181.         "The number %ld is written %s.\n\n"
  182.         "if you also pass '5' and '\"five\"' to rtEZRequest().",
  183.         "_Proceed", NULL, (struct TagItem *)&undertag, 5, "five");
  184.  
  185.     if (rtEZRequestTags ("It is also possible to pass extra IDCMP flags\n"
  186.                                "that will satisfy rtEZRequest(). This requester\n"
  187.                                "has had DISKINSERTED passed to it.\n"
  188.                                "(Try inserting a disk).",
  189.                                "_Continue", NULL, NULL,
  190.                                RT_IDCMPFlags, DISKINSERTED,
  191.                                 RT_Underscore, '_', TAG_END)
  192.                                & DISKINSERTED)
  193.         rtEZRequest ("You inserted a disk.", "I did", NULL, NULL);
  194.     else
  195.         rtEZRequest ("You used the 'Continue' gadget\n"
  196.                          "to satisfy the requester.", "I did", NULL, NULL);
  197.  
  198.     rtEZRequestTags ("Finally, it is possible to specify the position\n"
  199.                           "of the requester.\n"
  200.                           "E.g. at the top left of the screen, like this.\n"
  201.                           "This works for all requesters, not just rtEZRequest()!",
  202.                           "_Amazing", NULL, NULL,
  203.                           RT_ReqPos, REQPOS_TOPLEFTSCR,
  204.                           RT_Underscore, '_', TAG_END);
  205.  
  206.     rtEZRequestTags ("Alternatively, you can center the\n"
  207.                           "requester on the screen.\n"
  208.                           "Check out 'reqtools.doc' for all the possibilities.",
  209.                           "I'll do that", NULL, NULL,
  210.                           RT_ReqPos, REQPOS_CENTERSCR, TAG_END);
  211.  
  212.     rtEZRequestTags ("NUMBER 4:\nFile requester\n"
  213.                           "function: rtFileRequest()",
  214.                           "_Demonstrate", NULL, NULL, RT_Underscore, '_', TAG_END);
  215.  
  216.     if (filereq = rtAllocRequestA (RT_FILEREQ, NULL)) {
  217.  
  218.         filterhook.h_Entry = (ULONG (*)())file_filterfunc;
  219.  
  220.         filename[0] = 0;
  221.         if (rtFileRequest (filereq, filename, "Pick a file",
  222. #ifdef DOHOOKS
  223.                                  RTFI_FilterFunc, &filterhook,
  224. #endif
  225.                                  TAG_END))
  226.             rtEZRequest ("You picked the file:\n'%s'\nin directory:\n'%s'",
  227.                              "Right", NULL, NULL, filename, filereq->Dir);
  228.         else
  229.             rtEZRequest ("You didn't pick a file.", "No", NULL, NULL);
  230.  
  231.         rtFreeRequest (filereq);
  232.         }
  233.     else
  234.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  235.  
  236.  
  237.     rtEZRequestTags ("The file requester can be used\n"
  238.                           "as a directory requester as well.",
  239.                           "Let's _see that", NULL, NULL, RT_Underscore, '_', TAG_END);
  240.  
  241.     if (filereq = rtAllocRequestA (RT_FILEREQ, NULL)) {
  242.         if (rtFileRequest (filereq, filename, "Pick a directory",
  243.                                  RTFI_Flags, FREQF_NOFILES, TAG_END))
  244.             rtEZRequest ("You picked the directory:\n'%s'",
  245.                              "Right", NULL, NULL, filereq->Dir);
  246.         else
  247.             rtEZRequest ("You didn't pick a directory.", "No", NULL, NULL);
  248.  
  249.         rtFreeRequest (filereq);
  250.         }
  251.     else
  252.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  253.  
  254.     rtEZRequest ("NUMBER 5:\nFont requester\n"
  255.                      "function: rtFontRequest()",
  256.                      "Show", NULL, NULL);
  257.  
  258.     if (fontreq = rtAllocRequestA (RT_FONTREQ, NULL)) {
  259.  
  260.         fontreq->Flags = FREQF_STYLE|FREQF_COLORFONTS;
  261.         font_filterhook.h_Entry = (ULONG (*)())font_filterfunc;
  262.  
  263.         if (rtFontRequest (fontreq, "Pick a font",
  264. #ifdef DOHOOKS
  265.                                  RTFO_FilterFunc, &font_filterhook,
  266. #endif
  267.                                  TAG_END))
  268.             rtEZRequest ("You picked the font:\n'%s'\nwith size:\n'%ld'",
  269.                              "Right", NULL, NULL,
  270.                              fontreq->Attr.ta_Name, fontreq->Attr.ta_YSize);
  271.         else
  272.             rtEZRequestTags ("You canceled.\nWas there no font you liked ?",
  273.                                   "_Nope", NULL, NULL, RT_Underscore, '_', TAG_END);
  274.  
  275.         rtFreeRequest (fontreq);
  276.         }
  277.     else
  278.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  279.  
  280.     rtEZRequestTags ("NUMBER 6:\nPalette requester\n"
  281.                           "function: rtPaletteRequest()",
  282.                           "_Proceed", NULL, NULL, RT_Underscore, '_', TAG_END);
  283.  
  284.     color = rtPaletteRequest ("Change palette", NULL, TAG_END);
  285.     if (color == -1)
  286.         rtEZRequest ("You canceled.\nNo nice colors to be picked ?",
  287.                          "Nah", NULL, NULL);
  288.     else
  289.         rtEZRequest ("You picked color number %ld.", "Sure did",
  290.                          NULL, NULL, color);
  291.  
  292.     rtEZRequestTags ("NUMBER 7: (ReqTools 2.0)\n"
  293.                           "Volume requester\n"
  294.                           "function: rtFileRequest() with\n"
  295.                           "          RTFI_VolumeRequest tag.",
  296.                           "_Show me", NULL, NULL, RT_Underscore, '_', TAG_END);
  297.  
  298.     if (filereq = rtAllocRequestA (RT_FILEREQ, NULL)) {
  299.  
  300.         vol_filterhook.h_Entry = (ULONG (*)())vol_filterfunc;
  301.  
  302.         if (rtFileRequest (filereq, NULL, "Pick a volume",
  303. #ifdef DOHOOKS
  304.                                  RTFI_FilterFunc, &vol_filterhook,
  305. #endif
  306.                                  RTFI_VolumeRequest, 0, TAG_END))
  307.             rtEZRequest ("You picked the volume:\n'%s'",
  308.                              "Right", NULL, NULL, filereq->Dir);
  309.         else
  310.             rtEZRequest ("You didn't pick a volume.", "I did not", NULL, NULL);
  311.  
  312.         rtFreeRequest (filereq);
  313.         }
  314.     else
  315.         rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  316.  
  317.     rtEZRequestTags ("NUMBER 8: (ReqTools 2.0)\n"
  318.                           "Screen mode requester\n"
  319.                           "function: rtScreenModeRequest()\n"
  320.                           "Only available on Kickstart 2.0!",
  321.                           "_Proceed", NULL, NULL, RT_Underscore, '_', TAG_END);
  322.  
  323.     if (SysBase->LibNode.lib_Version < 37)
  324.         rtEZRequestTags ("Your Amiga doesn't seem to have\n"
  325.                               "Kickstart 2.0 in ROM so I am not\n"
  326.                               "able to show you the Screen mode\n"
  327.                               "requester.\n"
  328.                               "So upgrade to 2.0 *now* :-)",
  329.                               "_Allright", NULL, NULL, RT_Underscore, '_', TAG_END);
  330.     else {
  331.         if (scrmodereq = rtAllocRequestA (RT_SCREENMODEREQ, NULL)) {
  332.  
  333.             if (rtScreenModeRequest (scrmodereq, "Pick a screen mode:",
  334.                                              RTSC_Flags, SCREQF_DEPTHGAD|SCREQF_SIZEGADS|
  335.                                                  SCREQF_AUTOSCROLLGAD|SCREQF_OVERSCANGAD,
  336.                                               TAG_END))
  337.                 rtEZRequest ("You picked this mode:\n"
  338.                                  "ModeID  : 0x%lx\n"
  339.                                  "Size    : %ld x %ld\n"
  340.                                  "Depth   : %ld\n"
  341.                                  "Overscan: %ld\n"
  342.                                  "AutoScroll %s",
  343.                                  "Right", NULL, NULL,
  344.                                  scrmodereq->DisplayID,
  345.                                  scrmodereq->DisplayWidth,
  346.                                  scrmodereq->DisplayHeight,
  347.                                  scrmodereq->DisplayDepth,
  348.                                  scrmodereq->OverscanType,
  349.                                  scrmodereq->AutoScroll ? "On" : "Off");
  350.             else
  351.                 rtEZRequest ("You didn't pick a screen mode.", "Nope", NULL, NULL);
  352.  
  353.             rtFreeRequest (scrmodereq);
  354.             }
  355.         else
  356.             rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  357.         }
  358.  
  359.     rtEZRequestTags ("That's it!\n"
  360.                           "Hope you enjoyed the demo", "_Sure did", NULL, NULL,
  361.                           RT_Underscore, '_', TAG_END);
  362.  
  363.     /* free all resources */
  364.     CloseLibrary ((struct Library *)ReqToolsBase);
  365.  
  366.     exit (0);
  367. }
  368.  
  369. /********
  370. * HOOKS *
  371. ********/
  372.  
  373. BOOL __asm __saveds file_filterfunc (
  374.     REG __a0 struct Hook *hook,
  375.     REG __a2 struct rtFileRequester *filereq,
  376.     REG __a1 struct FileInfoBlock *fib
  377.     )
  378. {
  379.     myputs (fib->fib_FileName);
  380.     myputs ("\n");
  381.     return (TRUE);
  382. }
  383.  
  384. BOOL __asm __saveds font_filterfunc (
  385.     REG __a0 struct Hook *hook,
  386.     REG __a2 struct rtFontRequester *fontreq,
  387.     REG __a1 struct TextAttr *textattr
  388.     )
  389. {
  390.     myputs (textattr->ta_Name);
  391.     myputs ("\n");
  392.     return (TRUE);
  393. }
  394.  
  395. BOOL __asm __saveds vol_filterfunc (
  396.     REG __a0 struct Hook *hook,
  397.     REG __a2 struct rtFileRequester *filereq,
  398.     REG __a1 struct rtVolumeEntry *volentry
  399.     )
  400. {
  401.     myputs (volentry->Type == DLT_DEVICE ? "(Volume) " : "(Assign) ");
  402.     myputs (volentry->Name);
  403.     myputs ("\n");
  404.     return (TRUE);
  405. }
  406.