/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1991 by Torsten Jürgeleit
 *
 *	Name .....: gadgets_test.c
 *	Created ..: Thursday 19-Dec-91 20:52:59
 *	Revision .: 2
 *
 *	Date        Author                 Comment
 *	=========   ====================   ====================
 *	06-Aug-92   Torsten Jürgeleit      list view gadget with flag
 *					   GADGET_DATA_FLAG_LISTVIEW_ENTRY_COLOR
 *	11-Jul-92   Torsten Jürgeleit      now get pointer to console device
 *	19-Dec-91   Torsten Jürgeleit      Created this file!
 *
 * $Revision Header ********************************************************/

	/* Includes */

#include <exec/types.h>
#include <exec/memory.h>
#include <graphics/gfxbase.h>
#include <graphics/text.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 "gadgets.h"

	/* Defines */

#define WINDOW_WIDTH		600
#define WINDOW_HEIGHT		180
#define WINDOW_IDCMP		(CLOSEWINDOW | GADGET_IDCMP_FLAGS_ALL)
#define WINDOW_FLAGS		(WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | NOCAREREFRESH | RMBTRAP | ACTIVATE)
#define WINDOW_TITLE		(UBYTE *)" Gadgets 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

#define MESSAGE_LEFT_EDGE	0
#define MESSAGE_TOP_EDGE	(WINDOW_HEIGHT - MESSAGE_HEIGHT - 10)
#define MESSAGE_WIDTH		WINDOW_WIDTH
#define MESSAGE_HEIGHT		8
#define MESSAGE_TEXT1		"Gadget %d text %s"
#define MESSAGE_TEXT2		"Gadget %d value %ld"
#define MESSAGE_TEXT_ATTR	&topaz80_attr

	/* 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 TEST_GADGET_BUTTON		0
#define TEST_GADGET_BUTTON_IMAGE	1
#define TEST_GADGET_CHECK		2
#define TEST_GADGET_MX			3
#define TEST_GADGET_STRING		4
#define TEST_GADGET_INTEGER		5
#define TEST_GADGET_SLIDER_HORIZ	6
#define TEST_GADGET_SLIDER_VERT		7
#define TEST_GADGET_SCROLLER_HORIZ	8
#define TEST_GADGET_SCROLLER_VERT	9
#define TEST_GADGET_CYCLE		10
#define TEST_GADGET_COUNT		11
#define TEST_GADGET_LISTVIEW		12
#define TEST_GADGET_PALETTE		13

#define TEST_GADGET1_TYPE		GADGET_DATA_TYPE_BUTTON
#define TEST_GADGET1_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_COLOR2)
#define TEST_GADGET1_LEFT_EDGE		20
#define TEST_GADGET1_TOP_EDGE		10
#define TEST_GADGET1_WIDTH		((6 + 2) * 10)
#define TEST_GADGET1_HEIGHT		19
#define TEST_GADGET1_TEXT		"_Button"
#define TEST_GADGET1_TEXT_ATTR		&topaz60_attr

#define TEST_GADGET2_TYPE		GADGET_DATA_TYPE_BUTTON
#define TEST_GADGET2_FLAGS		(GADGET_DATA_FLAG_BUTTON_TOGGLE | GADGET_DATA_FLAG_BUTTON_IMAGE | GADGET_DATA_FLAG_NO_BORDER | GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_RIGHT | GADGET_DATA_FLAG_TEXT_COLOR2)
#define TEST_GADGET2_LEFT_EDGE		120
#define TEST_GADGET2_TOP_EDGE		15
#define TEST_GADGET2_WIDTH		16
#define TEST_GADGET2_HEIGHT		8
#define TEST_GADGET2_TEXT		"_Image"
#define TEST_GADGET2_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET2_NORMAL_RENDER	NULL	/* (LONG)&image1 */
#define TEST_GADGET2_SELECT_RENDER	(BYTE *)&image2

#define TEST_GADGET3_TYPE		GADGET_DATA_TYPE_CHECK
#define TEST_GADGET3_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_RIGHT)
#define TEST_GADGET3_LEFT_EDGE		20
#define TEST_GADGET3_TOP_EDGE		33
#define TEST_GADGET3_WIDTH		0
#define TEST_GADGET3_HEIGHT		0
#define TEST_GADGET3_TEXT		"_Check gadget"
#define TEST_GADGET3_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET3_CHECK_STATE	1

#define TEST_GADGET4_TYPE		GADGET_DATA_TYPE_MX
#define TEST_GADGET4_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_LEFT | GADGET_DATA_FLAG_TEXT_COLOR2)
#define TEST_GADGET4_LEFT_EDGE		20
#define TEST_GADGET4_TOP_EDGE		60
#define TEST_GADGET4_WIDTH		0
#define TEST_GADGET4_HEIGHT		0
#define TEST_GADGET4_TEXT		"Mutual e_xclude gadget"
#define TEST_GADGET4_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET4_SPACING		2
#define TEST_GADGET4_ACTIVE		1
#define TEST_GADGET4_TEXT_ARRAY		&mx_array[0]

#define TEST_GADGET5_TYPE		GADGET_DATA_TYPE_STRING
#define TEST_GADGET5_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_INPUT_AUTO_ACTIVATE | GADGET_DATA_FLAG_TEXT_RIGHT)
#define TEST_GADGET5_LEFT_EDGE		20
#define TEST_GADGET5_TOP_EDGE		103
#define TEST_GADGET5_WIDTH		68
#define TEST_GADGET5_HEIGHT		0
#define TEST_GADGET5_TEXT		"_String gadget"
#define TEST_GADGET5_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET5_INPUT_LEN		10
#define TEST_GADGET5_AUTO_ACTIVATE	((LONG)TEST_GADGET_INTEGER << 16 | TEST_GADGET_INTEGER)
#define TEST_GADGET5_INPUT_DEFAULT	"Test"

#define TEST_GADGET6_TYPE		GADGET_DATA_TYPE_INTEGER
#define TEST_GADGET6_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_INPUT_AUTO_ACTIVATE | GADGET_DATA_FLAG_TEXT_LEFT | GADGET_DATA_FLAG_TEXT_COLOR2)
#define TEST_GADGET6_LEFT_EDGE		(20 + 14 * 10 + 8)
#define TEST_GADGET6_TOP_EDGE		118
#define TEST_GADGET6_WIDTH		68
#define TEST_GADGET6_HEIGHT		0
#define TEST_GADGET6_TEXT		"I_nteger gadget"
#define TEST_GADGET6_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET6_INPUT_LEN		10
#define TEST_GADGET6_AUTO_ACTIVATE	((LONG)TEST_GADGET_STRING << 16 | TEST_GADGET_STRING)
#define TEST_GADGET6_INPUT_DEFAULT	(BYTE *)123

#define TEST_GADGET7_TYPE		GADGET_DATA_TYPE_SLIDER
#define TEST_GADGET7_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_RIGHT)
#define TEST_GADGET7_LEFT_EDGE		20
#define TEST_GADGET7_TOP_EDGE		135
#define TEST_GADGET7_WIDTH		100
#define TEST_GADGET7_HEIGHT		9
#define TEST_GADGET7_TEXT		"S_lider gadget"
#define TEST_GADGET7_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET7_MIN		-10
#define TEST_GADGET7_MAX		10
#define TEST_GADGET7_LEVEL		0

#define TEST_GADGET8_TYPE		GADGET_DATA_TYPE_SLIDER
#define TEST_GADGET8_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_ORIENTATION_VERT | GADGET_DATA_FLAG_TEXT_BELOW)
#define TEST_GADGET8_LEFT_EDGE		390
#define TEST_GADGET8_TOP_EDGE		10
#define TEST_GADGET8_WIDTH		18
#define TEST_GADGET8_HEIGHT		50
#define TEST_GADGET8_TEXT		"Sli_der gadget"
#define TEST_GADGET8_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET8_MIN		-10
#define TEST_GADGET8_MAX		10
#define TEST_GADGET8_LEVEL		(BYTE *)0

#define TEST_GADGET9_TYPE		GADGET_DATA_TYPE_SCROLLER
#define TEST_GADGET9_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_LEFT | GADGET_DATA_FLAG_TEXT_COLOR2)
#define TEST_GADGET9_LEFT_EDGE		(20 + 15 * 10 + 8)
#define TEST_GADGET9_TOP_EDGE		148
#define TEST_GADGET9_WIDTH		100
#define TEST_GADGET9_HEIGHT		0
#define TEST_GADGET9_TEXT		"Scr_oller gadget"
#define TEST_GADGET9_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET9_VISIBLE		4
#define TEST_GADGET9_TOTAL		20
#define TEST_GADGET9_TOP		(BYTE *)10

#define TEST_GADGET10_TYPE		GADGET_DATA_TYPE_SCROLLER
#define TEST_GADGET10_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_ORIENTATION_VERT | GADGET_DATA_FLAG_TEXT_ABOVE)
#define TEST_GADGET10_LEFT_EDGE		490
#define TEST_GADGET10_TOP_EDGE		24
#define TEST_GADGET10_WIDTH		0
#define TEST_GADGET10_HEIGHT		50
#define TEST_GADGET10_TEXT		"Sc_roller gadget"
#define TEST_GADGET10_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET10_VISIBLE		4
#define TEST_GADGET10_TOTAL		20
#define TEST_GADGET10_TOP		(BYTE *)10

#define TEST_GADGET11_TYPE		GADGET_DATA_TYPE_CYCLE
#define TEST_GADGET11_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_RIGHT | GADGET_DATA_FLAG_TEXT_COLOR2)
#define TEST_GADGET11_LEFT_EDGE		265
#define TEST_GADGET11_TOP_EDGE		78
#define TEST_GADGET11_WIDTH		160
#define TEST_GADGET11_HEIGHT		15
#define TEST_GADGET11_TEXT		"C_ycle gadget"
#define TEST_GADGET11_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET11_SPACING		1
#define TEST_GADGET11_ACTIVE		2
#define TEST_GADGET11_TEXT_ARRAY	&cycle_array[0]

#define TEST_GADGET12_TYPE		GADGET_DATA_TYPE_COUNT
#define TEST_GADGET12_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_RIGHT)
#define TEST_GADGET12_LEFT_EDGE		325
#define TEST_GADGET12_TOP_EDGE		96
#define TEST_GADGET12_WIDTH		80
#define TEST_GADGET12_HEIGHT		12
#define TEST_GADGET12_TEXT		"Co_unt gadget"
#define TEST_GADGET12_TEXT_ATTR		&topaz80_attr
#define TEST_GADGET12_MIN		100
#define TEST_GADGET12_MAX		1000
#define TEST_GADGET12_VALUE		(BYTE *)600

#define TEST_GADGET13_TYPE		GADGET_DATA_TYPE_LISTVIEW
#define TEST_GADGET13_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_COLOR2 | GADGET_DATA_FLAG_LISTVIEW_SHOW_SELECTED | GADGET_DATA_FLAG_LISTVIEW_ENTRY_COLOR)
#define TEST_GADGET13_LEFT_EDGE		370
#define TEST_GADGET13_TOP_EDGE		126
#define TEST_GADGET13_WIDTH		104
#define TEST_GADGET13_HEIGHT		35
#define TEST_GADGET13_TEXT		"List _view gadget"
#define TEST_GADGET13_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET13_SPACING		0
#define TEST_GADGET13_TOP		0
#define TEST_GADGET13_LIST		(BYTE *)&test_list

#define TEST_GADGET14_TYPE		GADGET_DATA_TYPE_PALETTE
#define TEST_GADGET14_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_TEXT_COLOR2)
#define TEST_GADGET14_LEFT_EDGE		220
#define TEST_GADGET14_TOP_EDGE		23
#define TEST_GADGET14_WIDTH		150
#define TEST_GADGET14_HEIGHT		20
#define TEST_GADGET14_TEXT		"_Palette gadget"
#define TEST_GADGET14_TEXT_ATTR		&topaz60_attr
#define TEST_GADGET14_DEPTH		2
#define TEST_GADGET14_COLOR_OFFSET	0
#define TEST_GADGET14_ACTIVE_COLOR	(BYTE *)0

	/* Statics for test gadgets */

STATIC UWORD image1_data[] = {
	0xffff, 0x8000, 0xbff0, 0xa00c, 0xa00c, 0xbff0, 0x8000, 0x8000,
	0x0000, 0x0001, 0x0005, 0x1ff1, 0x1ff1, 0x0005, 0x0001, 0x7fff
};
STATIC struct Image  image1 = { 0, 0, 16, 8, 2, &image1_data[0], 3, 0, NULL };
STATIC UWORD image2_data[] = {
	0x0000, 0x000f, 0x3fff, 0x23fd, 0x3fcd, 0x7ff1, 0x7001, 0x7fff,
	0xffff, 0x800e, 0x807e, 0x9ff8, 0x9ff0, 0xfe04, 0xf000, 0x8000
};
STATIC struct Image  image2 = { 0, 0, 16, 8, 2, &image2_data[0], 3, 0, NULL };
STATIC BYTE *mx_array[] = {
	"Fast File System", "Old File System", "Custom File System", NULL
};
STATIC BYTE *cycle_array[] = {
	"Amiga", "Workbench", "AmigaDOS", "Multitasking", "CLI", "ARexx",
	"TeX", "Unix", NULL
};
STATIC BYTE *list_array[] = {
	"\001Amiga", "Workbench", "\001AmigaDOS", "Multitasking", "\001CLI",
	"ARexx", "\001TeX", "Unix", NULL
};
STATIC struct List  test_list;
STATIC struct GadgetData  test_gadget_data[] = {
   {
	TEST_GADGET1_TYPE,		/* gd_Type */
	TEST_GADGET1_FLAGS,		/* gd_Flags */
	TEST_GADGET1_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET1_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET1_WIDTH,		/* gd_Width */
	TEST_GADGET1_HEIGHT,		/* gd_Height */
	TEST_GADGET1_TEXT,		/* *gd_Text */
	TEST_GADGET1_TEXT_ATTR,		/* *gd_TextAttr */
	{ 0, 0, 0 }
   }, {
	TEST_GADGET2_TYPE,		/* gd_Type */
	TEST_GADGET2_FLAGS,		/* gd_Flags */
	TEST_GADGET2_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET2_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET2_WIDTH,		/* gd_Width */
	TEST_GADGET2_HEIGHT,		/* gd_Height */
	TEST_GADGET2_TEXT,		/* *gd_Text */
	TEST_GADGET2_TEXT_ATTR,		/* *gd_TextAttr */
	{ 0,
	TEST_GADGET2_NORMAL_RENDER,	/* gd_ButtonNormalRender */
	TEST_GADGET2_SELECT_RENDER	/* gd_ButtonSelectRender */
	}
   }, {
	TEST_GADGET3_TYPE,		/* gd_Type */
	TEST_GADGET3_FLAGS,		/* gd_Flags */
	TEST_GADGET3_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET3_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET3_WIDTH,		/* gd_Width */
	TEST_GADGET3_HEIGHT,		/* gd_Height */
	TEST_GADGET3_TEXT,		/* *gd_Text */
	TEST_GADGET3_TEXT_ATTR,		/* *gd_TextAttr */
	{
	TEST_GADGET3_CHECK_STATE,	/* gd_CheckState */
	0, 0 }
   }, {
	TEST_GADGET4_TYPE,		/* gd_Type */
	TEST_GADGET4_FLAGS,		/* gd_Flags */
	TEST_GADGET4_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET4_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET4_WIDTH,		/* gd_Width */
	TEST_GADGET4_HEIGHT,		/* gd_Height */
	TEST_GADGET4_TEXT,		/* *gd_Text */
	TEST_GADGET4_TEXT_ATTR,		/* *gd_TextAttr */
	{
	TEST_GADGET4_SPACING,		/* gd_MXSpacing */
	TEST_GADGET4_ACTIVE,		/* gd_MXActiveEntry */
	TEST_GADGET4_TEXT_ARRAY		/* gd_MXTextArray */
	}
   }, {
	TEST_GADGET5_TYPE,		/* gd_Type */
	TEST_GADGET5_FLAGS,		/* gd_Flags */
	TEST_GADGET5_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET5_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET5_WIDTH,		/* gd_Width */
	TEST_GADGET5_HEIGHT,		/* gd_Height */
	TEST_GADGET5_TEXT,		/* *gd_Text */
	TEST_GADGET5_TEXT_ATTR,		/* *gd_TextAttr */
	{
	TEST_GADGET5_INPUT_LEN,		/* gd_InputLen */
	TEST_GADGET5_AUTO_ACTIVATE,	/* gd_InputActivatePrev/Next */
	TEST_GADGET5_INPUT_DEFAULT	/* gd_InputDefault */
	}
   }, {
	TEST_GADGET6_TYPE,		/* gd_Type */
	TEST_GADGET6_FLAGS,		/* gd_Flags */
	TEST_GADGET6_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET6_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET6_WIDTH,		/* gd_Width */
	TEST_GADGET6_HEIGHT,		/* gd_Height */
	TEST_GADGET6_TEXT,		/* *gd_Text */
	TEST_GADGET6_TEXT_ATTR,		/* *gd_TextAttr */
	{
	TEST_GADGET6_INPUT_LEN,		/* gd_InputLen */
	TEST_GADGET6_AUTO_ACTIVATE,	/* gd_InputActivatePrev/Next */
	TEST_GADGET6_INPUT_DEFAULT	/* gd_InputDefault */
	}
   }, {
	TEST_GADGET7_TYPE,		/* gd_Type */
	TEST_GADGET7_FLAGS,		/* gd_Flags */
	TEST_GADGET7_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET7_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET7_WIDTH,		/* gd_Width */
	TEST_GADGET7_HEIGHT,		/* gd_Height */
	TEST_GADGET7_TEXT,		/* *gd_Text */
	TEST_GADGET7_TEXT_ATTR,		/* *gd_TextAttr */
	{
	TEST_GADGET7_MIN,		/* gd_SliderMin */
	TEST_GADGET7_MAX,		/* gd_SliderMax */
	TEST_GADGET7_LEVEL		/* gd_SliderLevel */
	}
   }, {
	TEST_GADGET8_TYPE,		/* gd_Type */
	TEST_GADGET8_FLAGS,		/* gd_Flags */
	TEST_GADGET8_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET8_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET8_WIDTH,		/* gd_Width */
	TEST_GADGET8_HEIGHT,		/* gd_Height */
	TEST_GADGET8_TEXT,		/* *gd_Text */
	TEST_GADGET8_TEXT_ATTR,		/* *gd_TextAttr */
	{
	TEST_GADGET8_MIN,		/* gd_SliderMin */
	TEST_GADGET8_MAX,		/* gd_SliderMax */
	TEST_GADGET8_LEVEL		/* gd_SliderLevel */
	}
   }, {
	TEST_GADGET9_TYPE,		/* gd_Type */
	TEST_GADGET9_FLAGS,		/* gd_Flags */
	TEST_GADGET9_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET9_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET9_WIDTH,		/* gd_Width */
	TEST_GADGET9_HEIGHT,		/* gd_Height */
	TEST_GADGET9_TEXT,		/* *gd_Text */
	TEST_GADGET9_TEXT_ATTR,		/* *gd_TextAttr */
	{
	TEST_GADGET9_VISIBLE,		/* gd_ScrollerVisible */
	TEST_GADGET9_TOTAL,		/* gd_ScrollerTotal */
	TEST_GADGET9_TOP		/* gd_ScrollerTop */
	}
   }, {
	TEST_GADGET10_TYPE,		/* gd_Type */
	TEST_GADGET10_FLAGS,		/* gd_Flags */
	TEST_GADGET10_LEFT_EDGE,	/* gd_LeftEdge */
	TEST_GADGET10_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET10_WIDTH,		/* gd_Width */
	TEST_GADGET10_HEIGHT,		/* gd_Height */
	TEST_GADGET10_TEXT,		/* *gd_Text */
	TEST_GADGET10_TEXT_ATTR,	/* *gd_TextAttr */
	{
	TEST_GADGET10_VISIBLE,		/* gd_ScrollerVisible */
	TEST_GADGET10_TOTAL,		/* gd_ScrollerTotal */
	TEST_GADGET10_TOP		/* gd_ScrollerTop */
	}
   }, {
	TEST_GADGET11_TYPE,		/* gd_Type */
	TEST_GADGET11_FLAGS,		/* gd_Flags */
	TEST_GADGET11_LEFT_EDGE,	/* gd_LeftEdge */
	TEST_GADGET11_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET11_WIDTH,		/* gd_Width */
	TEST_GADGET11_HEIGHT,		/* gd_Height */
	TEST_GADGET11_TEXT,		/* *gd_Text */
	TEST_GADGET11_TEXT_ATTR,	/* *gd_TextAttr */
	{
	TEST_GADGET11_SPACING,		/* gd_CycleSpacing */
	TEST_GADGET11_ACTIVE,		/* gd_CycleActive */
	TEST_GADGET11_TEXT_ARRAY	/* gd_CycleTextArray */
	}
   }, {
	TEST_GADGET12_TYPE,		/* gd_Type */
	TEST_GADGET12_FLAGS,		/* gd_Flags */
	TEST_GADGET12_LEFT_EDGE,	/* gd_LeftEdge */
	TEST_GADGET12_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET12_WIDTH,		/* gd_Width */
	TEST_GADGET12_HEIGHT,		/* gd_Height */
	TEST_GADGET12_TEXT,		/* *gd_Text */
	TEST_GADGET12_TEXT_ATTR,	/* *gd_TextAttr */
	{
	TEST_GADGET12_MIN,		/* gd_CountMin */
	TEST_GADGET12_MAX,		/* gd_CountMax */
	TEST_GADGET12_VALUE		/* gd_CountValue */
	}
   }, {
	TEST_GADGET13_TYPE,		/* gd_Type */
	TEST_GADGET13_FLAGS,		/* gd_Flags */
	TEST_GADGET13_LEFT_EDGE,	/* gd_LeftEdge */
	TEST_GADGET13_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET13_WIDTH,		/* gd_Width */
	TEST_GADGET13_HEIGHT,		/* gd_Height */
	TEST_GADGET13_TEXT,		/* *gd_Text */
	TEST_GADGET13_TEXT_ATTR,	/* *gd_TextAttr */
	{
	TEST_GADGET13_SPACING,		/* gd_ListViewSpacing */
	TEST_GADGET13_TOP,		/* gd_ListViewTop */
	TEST_GADGET13_LIST		/* gd_ListViewList */
	}
   }, {
	TEST_GADGET14_TYPE,		/* gd_Type */
	TEST_GADGET14_FLAGS,		/* gd_Flags */
	TEST_GADGET14_LEFT_EDGE,	/* gd_LeftEdge */
	TEST_GADGET14_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET14_WIDTH,		/* gd_Width */
	TEST_GADGET14_HEIGHT,		/* gd_Height */
	TEST_GADGET14_TEXT,		/* *gd_Text */
	TEST_GADGET14_TEXT_ATTR,	/* *gd_TextAttr */
	{
	TEST_GADGET14_DEPTH,		/* gd_PaletteDepth */
	TEST_GADGET14_COLOR_OFFSET,	/* gd_PaletteColorOffset */
	TEST_GADGET14_ACTIVE_COLOR	/* gd_PaletteActiveColor */
	}
   }, {
	INTUISUP_DATA_END		/* end of gadget data array */
   }
};
	/* Prototypes */

VOID test_action(struct RenderInfo  *ri, struct Window  *win,
						    struct GadgetList  *gl);
BOOL build_test_list(VOID);
VOID free_test_list(VOID);

	/* Gadgets 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 (build_test_list() == TRUE) {
		     if (ri = get_render_info(NULL, RENDER_INFO_FLAGS)) {
		        if (win = open_window(ri, &test_new_window,
						       OPEN_WINDOW_FLAGS)) {
			   test_gadget_data[TEST_GADGET_BUTTON_IMAGE].gd_SpecialData.gd_ButtonData.gd_ButtonNormalRender = &image1;
			   if (gl = create_gadgets(ri, &test_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);
		     }
		     free_test_list();
		  }
		  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 input = TRUE, keepon = TRUE;

   /* Waiting for close window event */
   do {
      struct IntuiMessage  *msg;

      WaitPort(up);
      while (msg = get_msg(up)) {
	 BYTE *format, buffer[80];

	 switch (msg->Class) {
	    case CLOSEWINDOW :
	       keepon = FALSE;
	       break;

	    case ISUP_ID :
	       clear_window(ri, win, MESSAGE_LEFT_EDGE, MESSAGE_TOP_EDGE,
				      MESSAGE_LEFT_EDGE + MESSAGE_WIDTH - 1,
				  MESSAGE_TOP_EDGE + MESSAGE_HEIGHT - 1, 0);
	       if (msg->Code == TEST_GADGET_STRING) {
		  format = MESSAGE_TEXT1;
	       } else {
		  format = MESSAGE_TEXT2;
	       }
	       sprintf(&buffer[0], format, msg->Code, msg->IAddress);
	       print_text(ri, win, &buffer[0], 0, MESSAGE_TOP_EDGE,
				TEXT_DATA_TYPE_TEXT, TEXT_DATA_FLAG_CENTER |
				  TEXT_DATA_FLAG_COLOR2, MESSAGE_TEXT_ATTR);
	       /* Change gadgets */
	       switch (msg->Code) {
		  case TEST_GADGET_CHECK :
		     if (msg->IAddress) {
			set_gadget_attributes(gl, TEST_GADGET_LISTVIEW,
					      GADGET_DATA_FLAG_DISABLED, 0L,
				USE_CURRENT_VALUE, (ULONG)TEST_GADGET13_TOP,
						(VOID *)TEST_GADGET13_LIST);
		     } else {
			set_gadget_attributes(gl, TEST_GADGET_LISTVIEW,
						  GADGET_DATA_FLAG_DISABLED,
			       GADGET_DATA_FLAG_DISABLED, USE_CURRENT_VALUE,
					   USE_CURRENT_VALUE, (VOID *)NULL);
		     }
		     break;

		  case TEST_GADGET_BUTTON :
		     if (input == FALSE) {
			set_gadget_attributes(gl, TEST_GADGET_INTEGER,
			   GADGET_DATA_FLAG_DISABLED, 0L, USE_CURRENT_VALUE,
			      USE_CURRENT_VALUE, (VOID *)USE_CURRENT_VALUE);
			input = TRUE;
		     } else {
			set_gadget_attributes(gl, TEST_GADGET_INTEGER,
						  GADGET_DATA_FLAG_DISABLED,
			       GADGET_DATA_FLAG_DISABLED, USE_CURRENT_VALUE,
			      USE_CURRENT_VALUE, (VOID *)USE_CURRENT_VALUE);
			input = FALSE;
		     }
		     break;
	       }
	       break;
	 }
	 reply_msg(msg);
      }
   } while (keepon == TRUE);
}
	/* Build test list */

   BOOL
build_test_list(VOID)
{
   struct List  *list = &test_list;
   BYTE **text = &list_array[0];
   BOOL success = TRUE;

   NewList(list);
   while (*text) {
      struct Node  *node;

      if (node = AllocMem((LONG)sizeof(struct Node), (LONG)MEMF_PUBLIC |
							      MEMF_CLEAR)) {
	 node->ln_Name = *text++;
	 AddTail(list, node);
      } else {
	 free_test_list();
	 success = FALSE;
	 break;
      }
   }
   return(success);
}
	/* Free test list */

   VOID
free_test_list(VOID)
{
   struct List  *list = &test_list;
   struct Node  *node;

   while (node = RemHead(list)) {
      FreeMem(node, (LONG)sizeof(struct Node));
   }
}
