home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / utility / misc / pmod23a.lzh / pmod23a / Request.c < prev   
Encoding:
C/C++ Source or Header  |  1992-10-19  |  11.2 KB  |  345 lines

  1. /* Request.c - Support file of Intuition for pmod23 */
  2.  
  3. #include <stdio.h>
  4. #include "pmod23.h"
  5.  
  6. USHORT __chip UP_ImageData[] = {
  7.     0xFFFF,0xFFFF,0xFFFF,0x8000,0xC000,0x0000,0x0000,0x0000,
  8.     0xC000,0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,
  9.     0xC000,0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,
  10.     0xC000,0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,
  11.     0xC000,0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,
  12.     0xC000,0x0000,0x0000,0x0000,0x8000,0x0000,0x0000,0x0000,
  13.     0x0000,0x0000,0x0000,0x4000,0x0000,0x0000,0x0000,0xC000,
  14.     0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,0xC000,
  15.     0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,0xC000,
  16.     0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,0xC000,
  17.     0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,0xC000,
  18.     0x0000,0x0000,0x0000,0xC000,0x7FFF,0xFFFF,0xFFFF,0xC000
  19. };
  20.  
  21. USHORT __chip DOWN_ImageData[] = {
  22.     0x0000,0x0000,0x0000,0x4000,0x0000,0x0000,0x0000,0xC000,
  23.     0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,0xC000,
  24.     0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,0xC000,
  25.     0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,0xC000,
  26.     0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,0xC000,
  27.     0x0000,0x0000,0x0000,0xC000,0x7FFF,0xFFFF,0xFFFF,0xC000,
  28.     0xFFFF,0xFFFF,0xFFFF,0x8000,0xC000,0x0000,0x0000,0x0000,
  29.     0xC000,0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,
  30.     0xC000,0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,
  31.     0xC000,0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,
  32.     0xC000,0x0000,0x0000,0x0000,0xC000,0x0000,0x0000,0x0000,
  33.     0xC000,0x0000,0x0000,0x0000,0x8000,0x0000,0x0000,0x0000
  34. };
  35.  
  36. struct Image Abort_UP_Image = {
  37.     0,0,    /* XY origin relative to container TopLeft */
  38.     50,12,    /* Image width and height in pixels */
  39.     2,    /* number of bitplanes in Image */
  40.     UP_ImageData,    /* pointer to ImageData */
  41.     0x0003,0x0000,    /* PlanePick and PlaneOnOff */
  42.     NULL    /* next Image structure */
  43. };
  44.  
  45. struct Image Abort_DOWN_Image = {
  46.     0,0,    /* XY origin relative to container TopLeft */
  47.     50,12,    /* Image width and height in pixels */
  48.     2,    /* number of bitplanes in Image */
  49.     DOWN_ImageData,    /* pointer to ImageData */
  50.     0x0003,0x0000,    /* PlanePick and PlaneOnOff */
  51.     NULL    /* next Image structure */
  52. };
  53.  
  54. struct IntuiText Abort_IText = {
  55.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  56.     6,2,    /* XY origin relative to container TopLeft */
  57.     NULL,    /* font pointer or NULL for default */
  58.     "Abort",    /* pointer to text */
  59.     NULL    /* next IntuiText structure */
  60. };
  61.  
  62. GAD Abort_Gad = {
  63.     NULL,    /* next gadget */
  64.     250,44,    /* origin XY of hit box relative to window TopLeft */
  65.     50,12,    /* hit box width and height */
  66.     GADGHIMAGE | GADGIMAGE,    /* gadget flags */
  67.     RELVERIFY | GADGIMMEDIATE,    /* activation flags */
  68.     BOOLGADGET,    /* gadget type flags */
  69.     (APTR)&Abort_UP_Image,    /* gadget border or image to be rendered */
  70.     (APTR)&Abort_DOWN_Image,    /* alternate imagery for selection */
  71.     &Abort_IText,    /* first IntuiText structure */
  72.     NULL,    /* gadget mutual-exclude long word */
  73.     NULL,    /* SpecialInfo structure */
  74.     3,    /* gadget ID */
  75.     NULL    /* pointer to user-definable data */
  76. };
  77.  
  78. struct Image Retry_UP_Image = {
  79.     0,0,    /* XY origin relative to container TopLeft */
  80.     50,12,    /* Image width and height in pixels */
  81.     2,    /* number of bitplanes in Image */
  82.     UP_ImageData,    /* pointer to ImageData */
  83.     0x0003,0x0000,    /* PlanePick and PlaneOnOff */
  84.     NULL    /* next Image structure */
  85. };
  86.  
  87. struct Image Retry_DOWN_Image = {
  88.     0,0,    /* XY origin relative to container TopLeft */
  89.     50,12,    /* Image width and height in pixels */
  90.     2,    /* number of bitplanes in Image */
  91.     DOWN_ImageData,    /* pointer to ImageData */
  92.     0x0003,0x0000,    /* PlanePick and PlaneOnOff */
  93.     NULL    /* next Image structure */
  94. };
  95.  
  96. struct IntuiText Retry_IText = {
  97.     1,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  98.     5,2,    /* XY origin relative to container TopLeft */
  99.     NULL,    /* font pointer or NULL for default */
  100.     "Retry",    /* pointer to text */
  101.     NULL    /* next IntuiText structure */
  102. };
  103.  
  104. GAD Retry_Gad = {
  105.     &Abort_Gad,    /* next gadget */
  106.     133,44,    /* origin XY of hit box relative to window TopLeft */
  107.     50,12,    /* hit box width and height */
  108.     GADGHIMAGE | GADGIMAGE,    /* gadget flags */
  109.     RELVERIFY | GADGIMMEDIATE,    /* activation flags */
  110.     BOOLGADGET,    /* gadget type flags */
  111.     (APTR)&Retry_UP_Image,    /* gadget border or image to be rendered */
  112.     (APTR)&Retry_DOWN_Image,    /* alternate imagery for selection */
  113.     &Retry_IText,    /* first IntuiText structure */
  114.     NULL,    /* gadget mutual-exclude long word */
  115.     NULL,    /* SpecialInfo structure */
  116.     2,    /* gadget ID */
  117.     NULL    /* pointer to user-definable data */
  118. };
  119.  
  120. struct Image Skip_UP_Image = {
  121.     0,0,    /* XY origin relative to container TopLeft */
  122.     50,12,    /* Image width and height in pixels */
  123.     2,    /* number of bitplanes in Image */
  124.     UP_ImageData,    /* pointer to ImageData */
  125.     0x0003,0x0000,    /* PlanePick and PlaneOnOff */
  126.     NULL    /* next Image structure */
  127. };
  128.  
  129. struct Image Skip_DOWN_Image = {
  130.     0,0,    /* XY origin relative to container TopLeft */
  131.     50,12,    /* Image width and height in pixels */
  132.     2,    /* number of bitplanes in Image */
  133.     DOWN_ImageData,    /* pointer to ImageData */
  134.     0x0003,0x0000,    /* PlanePick and PlaneOnOff */
  135.     NULL    /* next Image structure */
  136. };
  137.  
  138. struct IntuiText Skip_IText = {
  139.     1,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  140.     9,2,    /* XY origin relative to container TopLeft */
  141.     NULL,    /* font pointer or NULL for default */
  142.     "Skip",    /* pointer to text */
  143.     NULL    /* next IntuiText structure */
  144. };
  145.  
  146. GAD Skip_Gad = {
  147.     &Retry_Gad,    /* next gadget */
  148.     13,44,    /* origin XY of hit box relative to window TopLeft */
  149.     50,12,    /* hit box width and height */
  150.     GADGHIMAGE | GADGIMAGE,    /* gadget flags */
  151.     RELVERIFY | GADGIMMEDIATE,    /* activation flags */
  152.     BOOLGADGET,    /* gadget type flags */
  153.     (APTR)&Skip_UP_Image,    /* gadget border or image to be rendered */
  154.     (APTR)&Skip_DOWN_Image,    /* alternate imagery for selection */
  155.     &Skip_IText,    /* first IntuiText structure */
  156.     NULL,    /* gadget mutual-exclude long word */
  157.     NULL,    /* SpecialInfo structure */
  158.     1,    /* gadget ID */
  159.     NULL    /* pointer to user-definable data */
  160. };
  161.  
  162. UBYTE UNDOBUFFER[81], String_GadSIBuff[81];
  163.  
  164. struct StringInfo String_GadSInfo = {
  165.     String_GadSIBuff,    /* buffer where text will be edited */
  166.     UNDOBUFFER,    /* optional undo buffer */
  167.     0,    /* character position in buffer */
  168.     81,    /* maximum number of characters to allow */
  169.     0,    /* first displayed character buffer position */
  170.     0,0,0,0,0,    /* Intuition initialized and maintained variables */
  171.     0,    /* Rastport of gadget */
  172.     0,    /* initial value for integer gadgets */
  173.     NULL    /* alternate keymap (fill in if you set the flag) */
  174. };
  175.  
  176. SHORT File_BorderVectors[] = {
  177.     0,0,
  178.     286,0,
  179.     286,13,
  180.     0,13,
  181.     0,1
  182. };
  183. struct Border File_Border = {
  184.     -4,-3,    /* XY origin relative to container TopLeft */
  185.     3,0,JAM2,    /* front pen, back pen and drawmode */
  186.     5,    /* number of XY vectors */
  187.     File_BorderVectors,    /* pointer to XY vectors */
  188.     NULL    /* next border in list */
  189. };
  190.  
  191. char String_Text[25];
  192.  
  193. struct IntuiText String_IText = {
  194.     1,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  195.     -4,-13,    /* XY origin relative to container TopLeft */
  196.     NULL,    /* font pointer or NULL for default */
  197.     String_Text,    /* pointer to text */
  198.     NULL    /* next IntuiText structure */
  199. };
  200.  
  201. GAD String_Gad = {
  202.     &Skip_Gad,    /* next gadget */
  203.     17,28,    /* origin XY of hit box relative to window TopLeft */
  204.     280,10,    /* hit box width and height */
  205.     NULL,    /* gadget flags */
  206.     RELVERIFY | GADGIMMEDIATE,    /* activation flags */
  207.     STRGADGET,    /* gadget type flags */
  208.     (APTR)&File_Border,    /* gadget border or image to be rendered */
  209.     NULL,    /* alternate imagery for selection */
  210.     &String_IText,    /* first IntuiText structure */
  211.     NULL,    /* gadget mutual-exclude long word */
  212.     (APTR)&String_GadSInfo,    /* SpecialInfo structure */
  213.     0,    /* gadget ID */
  214.     NULL    /* pointer to user-definable data */
  215. };
  216.  
  217. struct NewWindow ReqWindow = {
  218.     174,88,    /* window XY origin relative to TopLeft of screen */
  219.     312,61,    /* window width and height */
  220.     0,1,    /* detail and block pens */
  221.     GADGETDOWN | GADGETUP,    /* IDCMP flags */
  222.     SMART_REFRESH | WINDOWDRAG | WINDOWDEPTH | ACTIVATE,    /* other window flags */
  223.     &String_Gad,    /* first gadget in gadget list */
  224.     NULL,    /* custom CHECKMARK imagery */
  225.     NAME,    /* window title */
  226.     NULL,    /* custom screen pointer */
  227.     NULL,    /* custom bitmap */
  228.     5,5,    /* minimum width and height */
  229.     -1,-1,    /* maximum width and height */
  230.     WBENCHSCREEN    /* destination screen type */
  231. };
  232.  
  233. struct IntuitionBase *IntuitionBase;
  234. struct GfxBase *GfxBase;
  235.  
  236.  
  237. /* Sets up the intuition environment for the user. */
  238. char Open_All(void) {
  239.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", INTUITION_REV);
  240.     if(IntuitionBase == NULL) return(0);
  241.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", GRAPHICS_REV);
  242.     if(GfxBase == NULL) {
  243.         CloseLibrary(IntuitionBase);
  244.         return(0);
  245.     } /* if */
  246.     return(1);
  247. } /* Open_All() */
  248.  
  249.  
  250. /* Closes the intuition and graphics libs. */
  251. void CloseLibs(void) {
  252.     CloseLibrary(GfxBase);
  253.     CloseLibrary(IntuitionBase);
  254. } /* CloseLibs() */
  255.  
  256.  
  257. /*
  258. ** Brings up the spiffy error requestor
  259. */
  260. void Do_Request(char *string, GRESPTR result, char req_type) {
  261.     struct Window *Wind;
  262.     USHORT gadID;
  263.     char option[81] = "-";
  264.  
  265.     /* check the argument type and place the appropriate text in the window */
  266.     if(req_type == FILE_REQ)
  267.         strcpy(String_Text, "Could not find file:");
  268.     else if(req_type == OPTION_REQ)
  269.         sprintf(String_Text, "Unknown option \"%c\":", *string);
  270.     strcpy(String_GadSIBuff, string);
  271.     strcpy(UNDOBUFFER, string);
  272.     if(Open_All() == 0) {
  273.         printf("%s: Couldn't open Intuition\n", NAME);
  274.         result->ID = NOTHING;
  275.         return;
  276.     } /* if */
  277.     if((Wind = (struct Window *)OpenWindow(&ReqWindow)) == NULL) {
  278.         printf("%s: Could not open window\n", NAME);
  279.         CloseLibs();
  280.         result->ID = NOTHING;
  281.         return;
  282.     } /* if */
  283.     /* Whee! Give a beep! */
  284.     DisplayBeep(Wind->WScreen);
  285.     /* poll the message port for one of the buttons */
  286.     while((gadID = pop_gadget(Wind)) == NOTHING);
  287.     result->ID = gadID;
  288.     switch(gadID) {
  289.         case RETRY_UP:
  290.             if(req_type == OPTION_REQ) {
  291.                 /* ugh.  Make sure this arg has a dash in front of it. */
  292.                 strcat(option, String_GadSIBuff);
  293.                 strcpy(String_GadSIBuff, option);
  294.             } /* if */
  295.             result->string = String_GadSIBuff;
  296.         case SKIP_UP:
  297.         case ABORT_UP:
  298.             break;
  299.         default:
  300.             printf("%s: Unknown gadget ID: %u\n", NAME, gadID);
  301.             result->ID = NOTHING;
  302.     } /* switch */
  303.     CloseWindow(Wind);
  304.     CloseLibs();
  305. } /* Do_Request() */
  306.  
  307.  
  308. /* checks the requester's message port for buttons and returns it's ID */
  309. USHORT pop_gadget(struct Window *Wind) {
  310.     ULONG class;
  311.     USHORT gadget;
  312.     APTR address;
  313.     struct IntuiMessage *my_message;
  314.  
  315.     /* Check if we have recieved a message: */
  316.     Wait(1 << Wind->UserPort->mp_SigBit);
  317.  
  318.     /* Collect the message: */
  319.     my_message = (struct IntuiMessage *)GetMsg(Wind->UserPort);
  320.  
  321.     /* Have we collected the message sucessfully? */
  322.     if(my_message) {
  323.         /* After we have collected the message we can read it, and save any */
  324.         /* important values which we maybe want to check later: */
  325.  
  326.         class = my_message->Class;      /* Save the IDCMP flag. */
  327.         address = my_message->IAddress; /* Save the address. */
  328.  
  329.         /* After we have read it we reply as fast as possible: */
  330.         /* REMEMBER! Do never try to read a message after you have replied! */
  331.         /* Some other process has maybe changed it. */
  332.  
  333.         ReplyMsg(my_message);
  334.  
  335.         /* Check which IDCMP flag was sent: */
  336.         if(class == GADGETUP) {
  337.             /* check which gadget was struck */
  338.             gadget = ((GADPTR)address)->GadgetID;
  339.             if(gadget >= SKIP_UP && gadget <= ABORT_UP)
  340.                 return(gadget);
  341.         } /* if */
  342.     } /* if */
  343.     return(NOTHING);
  344. } /* pop_gadget() */
  345.