/***************************************
*                                      *
*   Program: Custom Requester          *
****************************************
*                                      *
* Author:   Date:    Comments          *
* ------    ----     --------          *
* Wgb      12-26-88                    *
*                                      *
* Compile and link options             *
* ------------------------             *
* cc CustomRequest (-n for SourceDB)   *
* ln CustomRequest -lc +Cd (-g0        *
*                                      *
****************************************/

#include <exec/types.h>
#include <intuition/intuition.h>

struct IntuitionBase *IntuitionBase;
struct Screen        *FirstScreen;
struct Window        *FirstWindow;
struct IntuiMessage  *message;



unsigned char PathBuffer[512] = "df1:";
unsigned char FileBuffer[31]   = "";
unsigned char UndoBuffer  [512];

USHORT KnobGraphic[] =
   {
   0xCCCC,   0x6666,   0x3333,   0x9999,
   0xCCCC,   0x6666,   0x3333,   0x9999,
   0xCCCC,   0x6666,   0x3333,   0x9999,
   0xCCCC,   0x6666,   0x3333,   0x9999
   };

struct Image Knob =
   {
   0, 0, 16, 16, 1, &KnobGraphic[0], 1, 0, NULL
   };

struct PropInfo SliderProp =
{
   FREEVERT,
   0x8000,   0x8000,
   0x0800,   0x1000,
   0,        0,
   0,        0,
   0,        0
};

struct StringInfo PathInfo =
   {
   &PathBuffer[0], &UndoBuffer[0],
   5, 511, 0, 0, 0, 0, 0, 0, NULL, 0, NULL
   };

struct StringInfo FileInfo =
   {
   &FileBuffer[0], &UndoBuffer[0],
   0, 31, 0, 0, 0, 0, 0, 0, NULL, 0, NULL
   };

SHORT StringPairs[] =
   {
   0, 0, 248, 0
   };

SHORT SelectPairs[] =
   {
   0, 0, 61, 0, 61, 21, 0, 21, 0, 0,
   };

struct Border StringBorder =
   {
   0, 9, 1, 0, JAM1, 2, StringPairs, NULL,
   };

struct Border SelectBorder =
   {
   -1, -1, 1, 0, JAM1, 5, SelectPairs, NULL,
   };

struct IntuiText PathText =
   {
   1, 0, JAM2, -58, 1, NULL, (UBYTE *)"Path:" ,NULL,
   };

struct IntuiText FileText =
   {
   1, 0, JAM2, -58, 1, NULL, (UBYTE *)"File:" ,NULL,
   };

struct IntuiText OKText =
   {
   1, 0, JAM2, 22, 5, NULL, (UBYTE *)"OK" ,NULL,
   };

struct IntuiText CancelText =
   {
   1, 0, JAM2, 2, 5, NULL, (UBYTE *)"Cancel" ,NULL,
   };

struct IntuiText ReturnText =
   {
   1, 0, JAM2, 2, 5, NULL, (UBYTE *)"Return!" ,NULL,
   };

struct Gadget Files[15];
struct Gadget FileGadget =
   {
   NULL,
   80, 0, 240, 8,
   GADGHCOMP, RELVERIFY, BOOLGADGET | REQGADGET,
   NULL, NULL, NULL,
   NULL, NULL, 0, NULL
   };

struct Gadget Slider =
   {
   &Files[0],
   322, 30, 24, 120,
   GADGHNONE | GADGIMAGE, RELVERIFY, PROPGADGET | REQGADGET,
   (APTR)&Knob, NULL, NULL,
   NULL, (APTR)&SliderProp, 1, NULL
   };

struct Gadget Path =
   {
   &Slider,
   80, 150, 250, 8,
   GADGHCOMP, RELVERIFY, STRGADGET | REQGADGET,
   (APTR)&StringBorder, NULL, &PathText,
   NULL, (APTR)&PathInfo, 21, NULL
   }; /*165 pal*/

struct Gadget File =
   {
   &Path,
   80, 165, 250, 8,
   GADGHCOMP, RELVERIFY, STRGADGET | REQGADGET,
   (APTR)&StringBorder, NULL, &FileText,
   NULL, (APTR)&FileInfo, 22, NULL
   };  /*185pal*/

struct Gadget OK =
   {
   &File,
   10, 40, 60, 20,
   GADGHCOMP, RELVERIFY | ENDGADGET , BOOLGADGET | REQGADGET,
   (APTR)&SelectBorder, NULL, &OKText,
   NULL, NULL, 23, NULL
   };

struct Gadget Cancel =
   {
   &OK,
   10, 65, 60, 20,
   GADGHCOMP, RELVERIFY | ENDGADGET , BOOLGADGET | REQGADGET,
   (APTR)&SelectBorder, NULL, &CancelText,
   NULL, NULL, 24, NULL
   };

struct Gadget Return =
   {
   &Cancel,
   10, 90, 60, 20,
   GADGHCOMP, RELVERIFY, BOOLGADGET | REQGADGET,
   (APTR)&SelectBorder, NULL, &ReturnText,
   NULL, NULL, 25, NULL
   };

struct Requester FileSelectBox;

struct NewWindow FirstNewWindow =
   {
   160, 0,             /* LeftEdge, TopEdge   */
   370, 200,            /* Width, Height       */
   0, 1,                /* DetailPen, BlockPen */
   CLOSEWINDOW |        /* IDCMP Flags         */
   GADGETUP |
   REQCLEAR,
   WINDOWDEPTH |        /* Flags               */
   WINDOWSIZING |
   WINDOWDRAG |
   WINDOWCLOSE |
   SMART_REFRESH,
   NULL,                /* First Gadget        */
   NULL,                /* CheckMark           */
   (UBYTE *)"Requester Test",
   NULL,                /* Screen              */
   NULL,                /* BitMap              */
   100, 50,             /* Min Width, Height   */
   640, 200,            /* Max Width, Height   */
   WBENCHSCREEN,        /* Type                */
   };

#define SLIDER 1
#define PATH  21
#define FILE    22
#define RETURN 25

main()
   {
   ULONG MessageClass;
   USHORT code;

   struct Message *GetMsg();

   Open_All();

   Make_Files(Files);


   InitRequester(&FileSelectBox);

   FileSelectBox.LeftEdge = 2;
   FileSelectBox.TopEdge  = 10;
   FileSelectBox.Width    = 360;
   FileSelectBox.Height   = 200;
   FileSelectBox.ReqGadget= &Return;

   Request(&FileSelectBox, FirstWindow);
   FileSelectBox_Request();
   EndRequest(&FileSelectBox, FirstWindow);

/*  Close_All();
  exit(TRUE);
*/
   FOREVER
      {
      if (message = (struct IntuitMessage *)
         GetMsg(FirstWindow->UserPort))
         {
         MessageClass = message->Class;
         code = message->Code;
         ReplyMsg(message);
         switch (MessageClass)
            {
            case CLOSEWINDOW : Close_All();
                               exit(TRUE);
                               break;
            }
         }
      }
   }



/***************************************
 *                                     *
 * Function: Open library and window   *
 * =================================== *
 *                                     *
 * Author:  Date:      Comment:        *
 * ------  ----------  ----------      *
 * Wgb     10/16/1987                  *
 *                                     *
 *                                     *
 **************************************/

Open_All()

   {
   void          *OpenLibrary();
   struct Window *OpenWindow();
   
   if (!(IntuitionBase = (struct IntuitionBase *)
       OpenLibrary("intuition.library", 0L)))
      {
      printf("Intuition library not found!\n");
      Close_All();
      exit(FALSE);
      }
   
   if (!(FirstWindow = (struct Window *)
       OpenWindow(&FirstNewWindow)))
      {
      printf("Window will not open!\n");
      Close_All();
      exit(FALSE);
      }
   }

/***************************************
 *                                     *
 * Function: Close everything opened   *
 * =================================== *
 *                                     *
 * Author:  Date:      Comment:        *
 * ------  ----------  ----------      *
 * Wgb     10/16/1987  just Intuition  *
 *                     and window      *
 *                                     *
 **************************************/

Close_All()

   {
   if (FirstWindow)     CloseWindow(FirstWindow);
   if (IntuitionBase)   CloseLibrary(IntuitionBase);
   }




/****************************************
*                                       *
* Function:  Gadget duplication         *
*                                       *
*****************************************/

Make_Files(Struktur)

struct Gadget Struktur[];

   {
   int i;

      for (i=0; i<15; i++)
         {
         Struktur[i]             = FileGadget;
         Struktur[i].TopEdge     = 30 +i * 8;
         Struktur[i].GadgetID    = i + 1;
         Struktur[i].NextGadget  =&Struktur[i+1];
         }
      Struktur[14].NextGadget = NULL;
   }


/***************************************
 *                                     *
 * Funktion: Request Check             *
 * =================================== *
 *                                     *
 * Author: Date:       Comments:       *
 * ------  ----------  ----------      *
 * Wgb     12/28/1987                  *
 *                                     *
 *                                     *
 ***************************************/

FileSelectBox_Request()
   {
   BOOL Waiton = TRUE;
   ULONG MessageClass;
   
   struct IntuiMessage *message;
   struct Gadget       *GadgetPtr;
   USHORT GadgetID;
   
   while (Waiton)
      {
      if ((message = (struct IntuiMessage *)
          GetMsg(FirstWindow->UserPort)) == NULL)
         {
         Wait(1L << FirstWindow->UserPort->mp_SigBit);
         printf("SIGNAL!\n");
         continue;
         }

      MessageClass = message->Class;
      GadgetPtr = (struct Gadget *) message->IAddress;
      GadgetID  = GadgetPtr->GadgetID;
      ReplyMsg(message);
      
      if (MessageClass == REQCLEAR)
         {
         Waiton = FALSE;
         printf("End Requester\n");
         continue;
         }

      if (MessageClass == GADGETUP)
      switch (GadgetID)
         {
         case SLIDER   : printf("Slider\n");
                         break;
         
         case PATH     : printf("Path\n");
                         break;
         
         case FILE     : printf("File\n");
                         break;
         
         case RETURN   : printf("Return!\n");
                         break;

         }
      
      if (GadgetID <= 16 && 1 <= GadgetID)
         {
            /* Table output */
         printf("Gadget-Nr. %d\n", GadgetID);
         }

      }
   }

