/*********************************************/
/*                                           */
/*       Designer (C) Ian OConnor 1994       */
/*                                           */
/*      Designer Produced C include file     */
/*                                           */
/*********************************************/

#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dosextens.h>
#include <intuition/screens.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <diskfont/diskfont.h>
#include <utility/utility.h>
#include <graphics/gfxbase.h>
#include <workbench/workbench.h>
#include <graphics/scale.h>
#include <clib/exec_protos.h>
#include <clib/wb_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <string.h>
#include <clib/diskfont_protos.h>

#include "SuperPlay_Main.h"


struct IntuiText SP_WndTexts[] =
	{
	2, 0, JAM1, 39, 44, NULL, (UBYTE *)"Sample/Module Tool. Freeware.", NULL
	};

struct Window *SP_Wnd = NULL;
APTR SP_WndVisualInfo;
APTR SP_WndDrawInfo;
struct Gadget *SP_WndGList;
struct Gadget *SP_WndGadgets[9];
UBYTE SP_WndFirstRun = 0;

struct Node SPOGadListItems[] =
	{
	&SPOGadListItems[1], (struct Node *)&SPOGadList.mlh_Head, 0, 0, (char *)"8SVX",
	&SPOGadListItems[2], &SPOGadListItems[0], 0, 0, (char *)"VOC",
	&SPOGadListItems[3], &SPOGadListItems[1], 0, 0, (char *)"WAV",
	( struct Node *)&SPOGadList.mlh_Tail, &SPOGadListItems[2], 0, 0, (char *)"SPO"
	};

struct MinList SPOGadList =
	{
	( struct MinNode * )&SPOGadListItems[0], ( struct MinNode * )NULL , ( struct MinNode * )&SPOGadListItems[3]
	};

ULONG SP_WndGadgetTags[] =
	{
	(GT_Underscore), '_',
	(TAG_END),
	(GT_Underscore), '_',
	(TAG_END),
	(GT_Underscore), '_',
	(TAG_END),
	(GT_Underscore), '_',
	(TAG_END),
	(GT_Underscore), '_',
	(TAG_END),
	(GT_Underscore), '_',
	(TAG_END),
	(GT_Underscore), '_',
	(TAG_END),
	(GT_Underscore), '_',
	(TAG_END),
	(GTLV_ShowSelected), 0,
	(GTLV_Selected), 0,
	(LAYOUTA_Spacing), 1,
	(GTLV_Labels), (ULONG)&SPOGadList,
	(TAG_END),
	};

UWORD SP_WndGadgetTypes[] =
	{
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	LISTVIEW_KIND,
	};

struct NewGadget SP_WndNGad[] =
	{
	83, 29, 207, 12, (UBYTE *)"Load and _Convert to :", &topaz800, ConvertGad, 16, NULL,  (APTR)&SP_WndGadgetTags[0],
	3, 1, 113, 12, (UBYTE *)"Load and _Play", &topaz800, PlayGad, 16, NULL,  (APTR)&SP_WndGadgetTags[3],
	3, 13, 45, 12, (UBYTE *)"_Stop", &topaz800, StopGad, 16, NULL,  (APTR)&SP_WndGadgetTags[6],
	49, 13, 82, 12, (UBYTE *)"Con_tinue", &topaz800, ContGad, 16, NULL,  (APTR)&SP_WndGadgetTags[9],
	132, 13, 76, 12, (UBYTE *)"_Forward", &topaz800, ForGad, 16, NULL,  (APTR)&SP_WndGadgetTags[12],
	209, 13, 82, 12, (UBYTE *)"_Backward", &topaz800, BackGad, 16, NULL,  (APTR)&SP_WndGadgetTags[15],
	117, 1, 174, 12, (UBYTE *)"Get File _Information", &topaz800, InfoGad, 16, NULL,  (APTR)&SP_WndGadgetTags[18],
	3, 29, 79, 12, (UBYTE *)"_LED", &topaz800, LEDGad, 16, NULL,  (APTR)&SP_WndGadgetTags[21],
	291, 1, 209, 40, NULL, &topaz800, SPOGad, 1, NULL,  (APTR)&SP_WndGadgetTags[24],
	};

struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0, 0 };

void RendWindowSP_Wnd( struct Window *Win, void *vi )
{
int loop;
UWORD offx,offy;
offx = Win->BorderLeft;
offy = Win->BorderTop;
if (Win != NULL) 
	{
	for( loop=0; loop<1; loop++)
		if (SP_WndTexts[loop].ITextFont==NULL)
			SP_WndTexts[loop].ITextFont=Win->WScreen->Font;
	PrintIText( Win->RPort, SP_WndTexts, offx, offy);
	}
}

int OpenSP_WndWindow( void )
{
struct Screen *Scr;
UWORD offx, offy;
UWORD loop;
struct NewGadget newgad;
struct Gadget *Gad;
struct Gadget *Gad2;
APTR Cla;
if (SP_WndFirstRun == 0)
	{
	SP_WndFirstRun = 1;
	}
if (SP_Wnd == NULL)
	{
	Scr = LockPubScreen(NULL);
	if (NULL != Scr)
		{
		offx = Scr->WBorLeft;
		offy = Scr->WBorTop + Scr->Font->ta_YSize+1;
		if (NULL != ( SP_WndVisualInfo = GetVisualInfoA( Scr, NULL)))
			{
			if (NULL != ( SP_WndDrawInfo = GetScreenDrawInfo( Scr)))
				{
				SP_WndGList = NULL;
				Gad = CreateContext( &SP_WndGList);
				for ( loop=0 ; loop<9 ; loop++ )
					if (SP_WndGadgetTypes[loop] != 198)
						{
						CopyMem((char * )&SP_WndNGad[loop], ( char * )&newgad, (long)sizeof( struct NewGadget ));
						newgad.ng_VisualInfo = SP_WndVisualInfo;
						newgad.ng_LeftEdge += offx;
						newgad.ng_TopEdge += offy;
						SP_WndGadgets[ loop ] = NULL;
						SP_WndGadgets[ newgad.ng_GadgetID - SP_WndFirstID ] = Gad = CreateGadgetA( SP_WndGadgetTypes[loop], Gad, &newgad, (struct TagItem *) newgad.ng_UserData );
						}
				for ( loop=0 ; loop<9 ; loop++ )
					if (SP_WndGadgetTypes[loop] == 198)
						{
						SP_WndGadgets[ loop ] = NULL;
						Cla = NULL;
						if (Gad)
							SP_WndGadgets[ loop ] = Gad2 = (struct Gadget *) NewObjectA( (struct IClass *)Cla, SP_WndNGad[ loop ].ng_GadgetText, (struct TagItem *)SP_WndNGad[ loop ].ng_UserData );
						}
				if (Gad != NULL)
					{
					if (NULL != (SP_Wnd = OpenWindowTags( NULL, (WA_Left), 0,
									(WA_Top), 11,
									(WA_Width), 505+offx,
									(WA_Height), 56+offy,
									(WA_Title), "SuperPlay V5.4 - © 1994-97 by Andreas R. Kleinert",
									(WA_ScreenTitle), "SuperPlay",
									(WA_MinWidth), 67,
									(WA_MinHeight), 21,
									(WA_MaxWidth), 640,
									(WA_MaxHeight), 256,
									(WA_DragBar), TRUE,
									(WA_DepthGadget), TRUE,
									(WA_CloseGadget), TRUE,
									(WA_Activate), TRUE,
									(WA_Dummy+0x30), TRUE,
									(WA_SmartRefresh), TRUE,
									(WA_AutoAdjust), TRUE,
									(WA_Gadgets), SP_WndGList,
									(WA_IDCMP),4194936,
									(TAG_END))))
						{
						RendWindowSP_Wnd(SP_Wnd, SP_WndVisualInfo );
						GT_RefreshWindow( SP_Wnd, NULL);
						RefreshGList( SP_WndGList, SP_Wnd, NULL, ~0);
						UnlockPubScreen( NULL, Scr);
						return( 0L );
						}
					}
				FreeGadgets( SP_WndGList);
				FreeScreenDrawInfo( Scr, (struct DrawInfo *) SP_WndDrawInfo );
				}
			FreeVisualInfo( SP_WndVisualInfo );
			}
		UnlockPubScreen( NULL, Scr);
		}
	}
else
	{
	WindowToFront(SP_Wnd);
	ActivateWindow(SP_Wnd);
	return( 0L );
	}
return( 1L );
}

void CloseSP_WndWindow( void )
{
if (SP_Wnd != NULL)
	{
	FreeScreenDrawInfo( SP_Wnd->WScreen, (struct DrawInfo *) SP_WndDrawInfo );
	SP_WndDrawInfo = NULL;
	CloseWindow( SP_Wnd);
	SP_Wnd = NULL;
	FreeVisualInfo( SP_WndVisualInfo);
	FreeGadgets( SP_WndGList);
	}
}

