#include <intuition/intuisup.h>
#include <clib/macros.h>
#include <proto/all.h>

struct   GfxBase        *GfxBase;
struct   IntuitionBase  *IntuitionBase;

#ifdef ISUP_RUNTIME
struct   Library  *iSupBase;
#else
struct   Device   *ConsoleDevice;
struct   IOStdReq  ConsoleMsg;
#endif

VOID   Resize() {}

struct Window  *sr_window;

struct IntuiText  Body[3] =
   {
      { 0, 0, JAM1, 0,0, NULL, "This is requester One", &Body[1] },
      { 2, 0, JAM1, 0,0, NULL, "It has 3 text lines", &Body[2] },
      { 3, 0, JAM1, 0,0, NULL, "and 2 string gadgets", NULL }
   };

UBYTE Buffer1[40] = "Hi!";
UBYTE Buffer2[10] = "123456789";
UBYTE UBuffer1[40], UBuffer2[10];

struct StringInfoList Gad[2] =
   {
      { &Gad[1], { Buffer1, UBuffer1, 0, 40, 0, 0,0,0,0,0,NULL,0L,NULL } },
      { NULL,    { Buffer2, UBuffer2, 0, 10, 0, 0,0,0,0,0,NULL,0L,NULL } }
   };

struct SmartReq   sm =
   {
   Body,
   Gad,
   "Ok", "Cancel",
   NULL, NULL,
   Resize,
   NULL
   };

struct IntuiText  BBody[5] =
   {
      { 0, 0, JAM1, 0,0, NULL, "This is the second one", &BBody[1] },
      { 0, 0, JAM1, 0,0, NULL, "", &BBody[2] },
      { 0, 0, JAM1, 0,0, NULL, "The text attributes can", &BBody[3] },
      { 0, 0, JAM1, 0,0, NULL, "be controlled for each", &BBody[4] },
      { 2, 0, JAM1, 0,0, NULL, "individual line", NULL }
   };

UBYTE BBuffer0[40] = "This is Gadget 1";
UBYTE BBuffer1[40] = "This is Gadget 2";
UBYTE BBuffer2[40] = "This is Gadget 3";
UBYTE BBuffer3[40] = "This is Gadget 4";
UBYTE BBuffer4[40] = "This is Gadget 5";
UBYTE UUBuffer0[40];
UBYTE UUBuffer1[40];
UBYTE UUBuffer2[40];
UBYTE UUBuffer3[40];
UBYTE UUBuffer4[40];

struct StringInfoList GGad[10] =
   {
      { &GGad[1], { BBuffer0, UUBuffer0, 0, 40, 0, 0,0,0,0,0,NULL,0L,NULL } },
      { &GGad[2], { BBuffer1, UUBuffer1, 0, 40, 0, 0,0,0,0,0,NULL,0L,NULL } },
      { &GGad[3], { BBuffer2, UUBuffer2, 0, 40, 0, 0,0,0,0,0,NULL,0L,NULL } },
      { &GGad[4], { BBuffer3, UUBuffer3, 0, 40, 0, 0,0,0,0,0,NULL,0L,NULL } },
      { NULL,     { BBuffer4, UUBuffer4, 0, 40, 0, 0,0,0,0,0,NULL,0L,NULL } },
   };

struct SmartReq   ssm =
   {
   BBody,
   GGad,
   "Ok", NULL,
   NULL, NULL,
   Resize,
   NULL
   };


UBYTE buf1[20] = "";
UBYTE buf2[20] = "";
UBYTE buf3[20] = "";

static   USHORT   Pattern[7][8] =
   {
      { 0x7b9c, 0xda7b, 0x3327, 0xe5af, 0x5eac, 0xd96a, 0x6b6b, 0x1de7 },
      { 0xeeee, 0xdddd, 0xbbbb, 0x7777, 0xeeee, 0xdddd, 0xbbbb, 0x7777 },
      { 0x7777, 0xbbbb, 0xdddd, 0xeeee, 0x7777, 0xbbbb, 0xdddd, 0xeeee },
      { 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777 },
      { 0x6666, 0x9999, 0x6666, 0x9999, 0x6666, 0x9999, 0x6666, 0x9999 },
      { 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555 },
      { 0x7b9c, 0xda7b, 0x3327, 0xe5af, 0x5eac, 0xd96a, 0x6b6b, 0x1de7 },
   };


VOID
Cleanup(err)
BYTE  err;
{
#ifdef ISUP_RUNTIME
      if (iSupBase)      CloseLibrary(iSupBase);
#else
      if (ConsoleDevice) CloseDevice(&ConsoleMsg);
#endif
   if (GfxBase)         CloseLibrary(GfxBase);
   if (IntuitionBase)   CloseLibrary(IntuitionBase);

   exit(err);
}

VOID
main()
{
   extern struct Window *OpenStdWindow();

   if (  !(GfxBase       = (struct Library *)OpenLibrary("graphics.library", 0))
      || !(IntuitionBase = (struct Library *)OpenLibrary("intuition.library", 0))
      || !(DiskfontBase  = (struct Library *)OpenLibrary("diskfont.library", 0))
#ifdef ISUP_RUNTIME
      || !(iSupBase      = (struct Library *)OpenLibrary("isup.library", 0))
#else
      || !(!OpenDevice("console.device", -1, &ConsoleMsg, 0) && (ConsoleDevice=ConsoleMsg.io_Device))
#endif
      ) Cleanup(10);;

   if (!(sr_window = OpenStdWindow("WSmartReq example", 0x13, 15,15, 270,113, Pattern[0]))) Cleanup(15);
   WSmartReq(sr_window, &sm);
   CloseStdWindow(sr_window);

   if (!(sr_window = OpenStdWindow("WSmartReq example", 0x13, 15,15, 270,179, Pattern[1]))) Cleanup(15);
   WSmartReq(sr_window, &ssm);
   CloseStdWindow(sr_window);


   if (!(sr_window = OpenStdWindow("WSmartReq example", 0x13, 15,15, 270, 72, Pattern[2]))) Cleanup(15);
   AutoWSmartRequest(sr_window, 2, "Simple text only", "example", 0,
                        "Ok", NULL, Resize, NULL);
   CloseStdWindow(sr_window);

   if (!(sr_window = OpenStdWindow("WSmartReq example", 0x13, 15,15, 270, 79, Pattern[3]))) Cleanup(15);
   AutoWSmartRequest(sr_window, 1, "Enter a file name:", 1, buf1, 20, "Ok", NULL, Resize, NULL);
   CloseStdWindow(sr_window);

   if (!(sr_window = OpenStdWindow("WSmartReq example", 0x13, 15,15, 270, 63, Pattern[4]))) Cleanup(15);
   AutoWSmartRequest(sr_window, 1, "Software Failure?", 0, "Nope", NULL, Resize, NULL);
   CloseStdWindow(sr_window);

   if (!(sr_window = OpenStdWindow("WSmartReq example", 0x13, 15,15, 270,120, Pattern[5]))) Cleanup(15);
   AutoWSmartRequest(sr_window, 2, "Enter string to search,", "replacement, and wildcard",
                         3, buf1, 20, buf2, 20, buf3, 20,
                        "Replace", "Cancel", Resize, NULL);
   CloseStdWindow(sr_window);

   if (!(sr_window = OpenStdWindow("WSmartReq example", 0x13, 15,15, 270, 63, Pattern[6]))) Cleanup(15);
   AutoWSmartRequest(sr_window, 1, "Had enough?", 0, "YEAH!", NULL, Resize, NULL);
   CloseStdWindow(sr_window);

   Cleanup(0);
}

