/**************************************
 *                                    *
 * Program : String-Gadget.c          *
 * ================================== *
 *                                    *
 * Author:  Date:      Comments:      *
 * ------  ----------  ----------     *
 * Wgb     10/16/1987  for testing    *
 *                     only           *
 *                                    *
 **************************************/


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


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


#define STRINGSIZE 80
unsigned char StringBuffer[STRINGSIZE] = "Hello Amiga";
unsigned char UndoBuffer  [STRINGSIZE];

struct StringInfo StringInfo =
   {
   StringBuffer,        /* Buffer              */
   UndoBuffer,          /* Undo Buffer         */
   0,                   /* Buffer Position     */
   STRINGSIZE,          /* MaxChars            */
   0,                   /* Display Positoin    */
   0,                   /* Undo Position       */
   0,                   /* NumChars            */
   0,                   /* Display Counter     */
   0, 0,                /* CLeft, CTop         */
   NULL,                /* LayerPtr            */
   0,                   /* LongInt             */
   NULL,                /* AltKeyMap           */
   };

SHORT GadgetPairs[] =
   {
   0, 0, 122, 0, 122, 12, 0, 12, 0, 0,
   };

struct Border GadgetBorder =
   {
   -2, -2, 1, 0, JAM1, 5, GadgetPairs, NULL,
   };

struct IntuiText GadgetText =
   {
   2, 0, JAM2, -40, 1, NULL, (UBYTE *)"Text" ,NULL,
   };

struct Gadget StringGadget =
   {
   NULL,                /* NextGadget          */
   50, 40,              /* LeftEdge, TopEdge   */
   120, 10,             /* Width, Height       */
   GADGHCOMP,           /* Flags               */
   RELVERIFY |          /* Activation          */
   STRINGCENTER,
   STRGADGET,           /* Gadget Type         */
   (APTR)&GadgetBorder, /* GadgetRender        */
   NULL,                /* Select Render       */
   &GadgetText,         /* GadgetText          */
   NULL,                /* MutualExclude       */
   (APTR)&StringInfo,   /* SpecialInfo         */
   1,                   /* GadgetID            */
   NULL,                /* UserData            */
   };

struct NewWindow FirstNewWindow =
   {
   160, 50,             /* LeftEdge, TopEdge   */
   320, 150,            /* Width, Height       */
   0, 1,                /* DetailPen, BlockPen */
   CLOSEWINDOW |        /* IDCMP Flags         */
   GADGETUP |
   GADGETDOWN,
   
   WINDOWDEPTH |        /* Flags               */
   WINDOWSIZING |
   WINDOWDRAG |
   WINDOWCLOSE |
   SMART_REFRESH,
   
   &StringGadget,       /* First Gadget        */
   NULL,                /* CheckMark           */
   
   (UBYTE *)"System programming test",
   
   NULL,                /* Screen              */
   NULL,                /* BitMap              */
   
   100, 50,             /* Min Width, Height   */
   640, 200,            /* Max Width, Height   */
   
   WBENCHSCREEN,        /* Type                */
   };


main()
   {
   ULONG MessageClass;
   USHORT code;

   struct Message *GetMsg();
   
   Open_All();
   
   RefreshGadgets(&StringGadget, FirstWindow, NULL);
   
   
   FOREVER
      {
      if ((message = (struct IntuiMessage *)
          GetMsg(FirstWindow->UserPort)) == NULL)
         {
         Wait(1L << FirstWindow->UserPort->mp_SigBit);
         continue;
         }
      MessageClass = message->Class;
      code = message->Code;
      ReplyMsg(message);
      switch (MessageClass)
         {
         case GADGETUP    : printf("The string is: %s\n",&StringBuffer[0]);
         
         case CLOSEWINDOW : Close_All();
                            exit(TRUE);
                            break;
         }
      }
   }


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);
      }
   }

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

