/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1991 by Torsten Jürgeleit
 *
 *	Name .....: requester_test.c
 *	Created ..: Thursday 19-Dec-91 18:55:29
 *	Revision .: 2
 *
 *	Date        Author                 Comment
 *	=========   ====================   ====================
 *	11-Jul-92   Torsten Jürgeleit      now get pointer to console device
 *	30-Apr-92   Torsten Jürgeleit      now requester support rasters
 *	19-Dec-91   Torsten Jürgeleit      Created this file!
 *
 ****************************************************************************
 *
 *	Test of requester support functions
 *
 * $Revision Header ********************************************************/

	/* Includes */

#include <exec/types.h>
#include <graphics/gfxbase.h>
#include <graphics/text.h>
#include <intuition/intuitionbase.h>
#include <intuition/intuition.h>
#ifdef AZTEC_C
#include <functions.h>   /* needed for Aztec C - prototypes and pragmas for all Amiga system functions */
#endif
#include <libraries/memwatch.h>   /* header file for memory debug link library (Fish 240) - AFTER functions.h */
#include "/render/render.h"
#include "/texts/texts.h"
#include "/borders/borders.h"
#include "/gadgets/gadgets.h"
#include "requester.h"

	/* Defines */

#define WINDOW_WIDTH		600
#define WINDOW_HEIGHT		180
#define WINDOW_IDCMP		(CLOSEWINDOW | GADGET_IDCMP_FLAGS_BUTTON)
#define WINDOW_FLAGS		(WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | NOCAREREFRESH | RMBTRAP | ACTIVATE)
#define WINDOW_TITLE		(UBYTE *)" Requester test "

#define RENDER_INFO_FLAGS	(USHORT)(RENDER_INFO_FLAG_INNER_WINDOW | RENDER_INFO_FLAG_BACK_FILL)
#define OPEN_WINDOW_FLAGS	OPEN_WINDOW_FLAG_CENTER_SCREEN

	/* Globals */

struct IntuitionBase  *IntuitionBase;
struct GfxBase        *GfxBase;
struct Library        *DiskfontBase;
struct Library        *LayersBase;
struct Device         *ConsoleDevice;

	/* Statics */

STATIC struct NewWindow  test_new_window = {
   0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 1, WINDOW_IDCMP, WINDOW_FLAGS,
   NULL, NULL, WINDOW_TITLE, NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN
};
STATIC struct TextAttr  topaz60_attr = { (STRPTR)"topaz.font", TOPAZ_SIXTY,
						   FS_NORMAL, FPF_ROMFONT },
			topaz80_attr = { (STRPTR)"topaz.font", TOPAZ_EIGHTY,
						   FS_NORMAL, FPF_ROMFONT };
	/* Defines for test gadgets */

#define TEST1_GADGET_AUTO_REQUEST	0
#define TEST1_GADGET_REQUESTER		1

#define TEST1_GADGET1_TYPE		GADGET_DATA_TYPE_BUTTON
#define TEST1_GADGET1_FLAGS		GADGET_DATA_FLAG_HOTKEY
#define TEST1_GADGET1_LEFT_EDGE		((WINDOW_WIDTH / 2 - TEST1_GADGET1_WIDTH) / 2)
#define TEST1_GADGET1_TOP_EDGE		((WINDOW_HEIGHT - TEST1_GADGET1_HEIGHT) / 2)
#define TEST1_GADGET1_WIDTH		((12 + 2) * 10)
#define TEST1_GADGET1_HEIGHT		19
#define TEST1_GADGET1_TEXT		"_Auto Request"
#define TEST1_GADGET1_TEXT_ATTR		&topaz60_attr

#define TEST1_GADGET2_TYPE		GADGET_DATA_TYPE_BUTTON
#define TEST1_GADGET2_FLAGS		GADGET_DATA_FLAG_HOTKEY
#define TEST1_GADGET2_LEFT_EDGE		(WINDOW_WIDTH - (TEST1_GADGET2_WIDTH + TEST1_GADGET1_LEFT_EDGE))
#define TEST1_GADGET2_TOP_EDGE		TEST1_GADGET1_TOP_EDGE
#define TEST1_GADGET2_WIDTH		TEST1_GADGET1_WIDTH
#define TEST1_GADGET2_HEIGHT		TEST1_GADGET1_HEIGHT
#define TEST1_GADGET2_TEXT		"_Requester"
#define TEST1_GADGET2_TEXT_ATTR		TEST1_GADGET1_TEXT_ATTR

STATIC struct GadgetData  test1_gadget_data[] = {
   {
	TEST1_GADGET1_TYPE,		/* gd_Type */
	TEST1_GADGET1_FLAGS,		/* gd_Flags */
	TEST1_GADGET1_LEFT_EDGE,	/* gd_LeftEdge */
	TEST1_GADGET1_TOP_EDGE,		/* gd_TopEdge */
	TEST1_GADGET1_WIDTH,		/* gd_Width */
	TEST1_GADGET1_HEIGHT,		/* gd_Height */
	TEST1_GADGET1_TEXT,		/* *gd_Text */
	TEST1_GADGET1_TEXT_ATTR,	/* *gd_TextAttr */
	{ 0, 0, 0 }
   }, {
	TEST1_GADGET2_TYPE,		/* gd_Type */
	TEST1_GADGET2_FLAGS,		/* gd_Flags */
	TEST1_GADGET2_LEFT_EDGE,	/* gd_LeftEdge */
	TEST1_GADGET2_TOP_EDGE,		/* gd_TopEdge */
	TEST1_GADGET2_WIDTH,		/* gd_Width */
	TEST1_GADGET2_HEIGHT,		/* gd_Height */
	TEST1_GADGET2_TEXT,		/* *gd_Text */
	TEST1_GADGET2_TEXT_ATTR,	/* *gd_TextAttr */
	{ 0, 0, 0 }
   }, {
	INTUISUP_DATA_END		/* mark end of border data array */
   }
};
	/* Defines for auto request */

#define TEST1_AUTO_REQ_TITLE		" Auto Request "
#define TEST1_AUTO_REQ_BODY_TEXT	"Test line 1\\n\\nTest line 2\\nTest line 3\\n\\nTest line 4"
#define TEST1_AUTO_REQ_POS_TEXT		"_Positive"
#define TEST1_AUTO_REQ_NEG_TEXT		"_Negative"
#define TEST1_AUTO_REQ_FLAGS		(AUTO_REQ_FLAG_BACK_FILL | AUTO_REQ_FLAG_TEXT_CENTER | AUTO_REQ_FLAG_TEXT_COLOR2 | AUTO_REQ_FLAG_HOTKEY | AUTO_REQ_FLAG_CENTER_MOUSE | AUTO_REQ_FLAG_DRAW_RASTER)

	/* Defines for requester */

#define TEST2_REQ_WIDTH		200
#define TEST2_REQ_HEIGHT	100
#define TEST2_REQ_FLAGS		(REQ_DATA_FLAG_BACK_FILL | REQ_DATA_FLAG_CENTER_WINDOW | REQ_DATA_FLAG_INNER_WINDOW)
#define TEST2_REQ_TITLE		" Requester "

#define TEST2_TEXT1_TYPE	TEXT_DATA_TYPE_TEXT
#define TEST2_TEXT1_FLAGS	(TEXT_DATA_FLAG_CENTER | TEXT_DATA_FLAG_BOLD)
#define TEST2_TEXT1_LEFT_EDGE	0
#define TEST2_TEXT1_TOP_EDGE	20
#define TEST2_TEXT1_TEXT	"Text Line 1"
#define TEST2_TEXT1_TEXT_ATTR	&topaz60_attr

#define TEST2_TEXT2_TYPE	TEXT_DATA_TYPE_TEXT
#define TEST2_TEXT2_FLAGS	(TEXT_DATA_FLAG_CENTER | TEXT_DATA_FLAG_ITALIC | TEXT_DATA_FLAG_COLOR2)
#define TEST2_TEXT2_LEFT_EDGE	0
#define TEST2_TEXT2_TOP_EDGE	(TEST2_TEXT1_TOP_EDGE + 10)
#define TEST2_TEXT2_TEXT	"Text Line 2"
#define TEST2_TEXT2_TEXT_ATTR	&topaz80_attr

#define TEST2_TEXT3_TYPE	TEXT_DATA_TYPE_TEXT
#define TEST2_TEXT3_FLAGS	(TEXT_DATA_FLAG_CENTER | TEXT_DATA_FLAG_UNDERLINED)
#define TEST2_TEXT3_LEFT_EDGE	0
#define TEST2_TEXT3_TOP_EDGE	(TEST2_TEXT2_TOP_EDGE + 10)
#define TEST2_TEXT3_TEXT	"Text Line 3"
#define TEST2_TEXT3_TEXT_ATTR	&topaz80_attr

#define TEST2_BORDER1_TYPE		BORDER_DATA_TYPE_BOX2_OUT
#define TEST2_BORDER1_LEFT_EDGE		20
#define TEST2_BORDER1_TOP_EDGE		10
#define TEST2_BORDER1_WIDTH		(TEST2_REQ_WIDTH - 2 * TEST2_BORDER1_LEFT_EDGE)
#define TEST2_BORDER1_HEIGHT		(TEST2_REQ_HEIGHT - (3 * TEST2_BORDER1_TOP_EDGE + TEST2_GADGET1_HEIGHT))

#define TEST2_GADGET_CONTINUE		0

#define TEST2_GADGET1_TYPE		GADGET_DATA_TYPE_BUTTON
#define TEST2_GADGET1_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_MOVE_POINTER)
#define TEST2_GADGET1_LEFT_EDGE		((TEST2_REQ_WIDTH - TEST2_GADGET1_WIDTH) / 2)
#define TEST2_GADGET1_TOP_EDGE		(TEST2_REQ_HEIGHT - (TEST2_GADGET1_HEIGHT + 10))
#define TEST2_GADGET1_WIDTH		((8 + 2) * 10)
#define TEST2_GADGET1_HEIGHT		19
#define TEST2_GADGET1_TEXT		"_Continue"
#define TEST2_GADGET1_TEXT_ATTR		&topaz60_attr

	/* Statics for test borders */

STATIC struct TextData  test2_text_data[] = {
   {
	TEST2_TEXT1_TYPE,	/* td_Type */
	TEST2_TEXT1_FLAGS,	/* td_Flags */
	TEST2_TEXT1_LEFT_EDGE,	/* td_LeftEdge */
	TEST2_TEXT1_TOP_EDGE,	/* td_TopEdge */
	TEST2_TEXT1_TEXT,	/* *td_Text */
	TEST2_TEXT1_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST2_TEXT2_TYPE,	/* td_Type */
	TEST2_TEXT2_FLAGS,	/* td_Flags */
	TEST2_TEXT2_LEFT_EDGE,	/* td_LeftEdge */
	TEST2_TEXT2_TOP_EDGE,	/* td_TopEdge */
	TEST2_TEXT2_TEXT,	/* *td_Text */
	TEST2_TEXT2_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST2_TEXT3_TYPE,	/* td_Type */
	TEST2_TEXT3_FLAGS,	/* td_Flags */
	TEST2_TEXT3_LEFT_EDGE,	/* td_LeftEdge */
	TEST2_TEXT3_TOP_EDGE,	/* td_TopEdge */
	TEST2_TEXT3_TEXT,	/* *td_Text */
	TEST2_TEXT3_TEXT_ATTR	/* *td_TextAttr */
   }, {
	INTUISUP_DATA_END		/* mark end of border data array */
   }
};
STATIC struct BorderData  test2_border_data[] = {
   {
	TEST2_BORDER1_TYPE,		/* bd_Type */
	TEST2_BORDER1_LEFT_EDGE,	/* bd_LeftEdge */
	TEST2_BORDER1_TOP_EDGE,		/* bd_TopEdge */
	TEST2_BORDER1_WIDTH,		/* bd_Width */
	TEST2_BORDER1_HEIGHT		/* bd_Height */
   }, {
	INTUISUP_DATA_END		/* mark end of border data array */
   }
};
STATIC struct GadgetData  test2_gadget_data[] = {
   {
	TEST2_GADGET1_TYPE,		/* gd_Type */
	TEST2_GADGET1_FLAGS,		/* gd_Flags */
	TEST2_GADGET1_LEFT_EDGE,	/* gd_LeftEdge */
	TEST2_GADGET1_TOP_EDGE,		/* gd_TopEdge */
	TEST2_GADGET1_WIDTH,		/* gd_Width */
	TEST2_GADGET1_HEIGHT,		/* gd_Height */
	TEST2_GADGET1_TEXT,		/* *gd_Text */
	TEST2_GADGET1_TEXT_ATTR,	/* *gd_TextAttr */
	{ 0, 0, 0 }
   }, {
	INTUISUP_DATA_END		/* mark end of border data array */
   }
};
STATIC struct RequesterData  test2_requester_data = {
	0,			/* rd_LeftEdge */
	0,			/* rd_TopEdge */
	TEST2_REQ_WIDTH,	/* rd_Width */
	TEST2_REQ_HEIGHT,	/* rd_Height */
	TEST2_REQ_FLAGS,	/* rd_Flags */
	TEST2_REQ_TITLE,	/* *rd_Title */
	&test2_text_data[0],	/* *rd_Texts */
	&test2_border_data[0],	/* *rd_Borders */
	&test2_gadget_data[0]	/* *rd_Gadgets */
};
	/* Prototypes */

VOID test_action(struct RenderInfo  *ri, struct Window  *win,
						    struct GadgetList  *gl);
	/* Pragmas */

#pragma regcall(test_action(a0,a1,a2))

	/* Requester test */

   LONG
main(VOID)
{
   struct IOStdReq    io;
   struct RenderInfo  *ri;
   struct Window      *win;
   struct GadgetList  *gl;

   MWInit((BPTR)NULL, 0L);
   if (IntuitionBase = OpenLibrary("intuition.library", 0L)) {
      if (GfxBase = OpenLibrary("graphics.library", 0L)) {
	 if (DiskfontBase = OpenLibrary("diskfont.library", 0L)) {
	    if (LayersBase = OpenLibrary("layers.library", 0L)) {
	       if (!OpenDevice("console.device", -1L,
					     (struct IORequest *)&io, 0L)) {
		  ConsoleDevice = io.io_Device;
		  if (ri = get_render_info(NULL, RENDER_INFO_FLAGS)) {
		     if (win = open_window(ri, &test_new_window,
						       OPEN_WINDOW_FLAGS)) {
			if (gl = create_gadgets(ri, &test1_gadget_data[0],
							      0, 0, NULL)) {
			   display_gadgets(win, gl);
			   test_action(ri, win, gl);
			   remove_gadgets(gl);
			   free_gadgets(gl);
			}
			close_window(win, FALSE);
		     }
		     free_render_info(ri);
		  }
		  CloseDevice((struct IORequest *)&io);
	       }
	       CloseLibrary(LayersBase);
	    }
	    CloseLibrary(DiskfontBase);
	 }
	 CloseLibrary(GfxBase);
      }
      CloseLibrary(IntuitionBase);
   }
   MWTerm();
   return(0L);
}
	/* Perform IDCMP action */

   VOID
test_action(struct RenderInfo  *ri, struct Window  *win,
						     struct GadgetList  *gl)
{
   struct MsgPort  *up = win->UserPort;
   BOOL keepon2 = TRUE;

   do {
      struct IntuiMessage   *msg2;
      struct RequesterList  *rl;

      WaitPort(up);
      while (msg2 = get_msg(up)) {
	 switch (msg2->Class) {
	    case CLOSEWINDOW :
	       keepon2 = FALSE;
	       break;

	    case ISUP_ID :
	       if (msg2->Code == TEST1_GADGET_AUTO_REQUEST) {
		  auto_request(win, TEST1_AUTO_REQ_TITLE,
			  TEST1_AUTO_REQ_BODY_TEXT, TEST1_AUTO_REQ_POS_TEXT,
					    TEST1_AUTO_REQ_NEG_TEXT, 0L, 0L,
						TEST1_AUTO_REQ_FLAGS, NULL);
	       } else {
		  if (rl = display_requester(win, &test2_requester_data,
								    NULL)) {
		     BOOL keepon1 = TRUE;

		     do {
		        struct IntuiMessage  *msg1;

			WaitPort(up);
			while (msg1 = get_msg(up)) {
			   if (msg1->Class == ISUP_ID) {
			      keepon1 = FALSE;
			   }
			   reply_msg(msg1);
			}
		     } while (keepon1 == TRUE);
		     remove_requester(rl);
		  }
	       }
	       break;
	 }
	 reply_msg(msg2);
      }
   } while (keepon2 == TRUE);
}
