	/* Label2.c  a sticky label printer by Gary Walker */
/* This program will print address labels in 1-across or 3-across format */
/* It is set up for the typical 25 character @pica 10cpi wide labels	*/
/* It's not the most efficient or smallest it could be, but it works!	*/
/* Thanx to PowerWindows for the structs, and Willy Langeveld for the	*/
/* mutual exclude routine. This is Version 2, my first attempt at	*/
/* 		******		GADGETS		******			*/

#include "stdio.h"
#include "intuition/intuition.h"
#include "intuition/intuitionbase.h"
#include "graphics/gfxbase.h"


UBYTE UNDOBUFFER[26];

SHORT BorderVectors1[] = {
	0,0,
	19,0,
	19,10,
	0,10,
	0,0
};
struct Border Border1 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors1,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct IntuiText IText1 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	5,1,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"3",	/* pointer to text */
	NULL	/* next IntuiText structure */
};

struct Gadget ThreeWide = {
	NULL,	/* next gadget */
	184,90,	/* origin XY of hit box relative to window TopLeft */
	18,9,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	GADGIMMEDIATE,	/* activation flags */
	BOOLGADGET,	/* gadget type flags */
	(APTR)&Border1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&IText1,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	10,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

SHORT BorderVectors2[] = {
	0,0,
	19,0,
	19,10,
	0,10,
	0,0
};
struct Border Border2 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors2,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct IntuiText IText2 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	5,1,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"1",	/* pointer to text */
	NULL	/* next IntuiText structure */
};

struct Gadget OneWide = {
	&ThreeWide,	/* next gadget */
	134,90,	/* origin XY of hit box relative to window TopLeft */
	18,9,	/* hit box width and height */
	GADGHCOMP+SELECTED,	/* gadget flags */
	GADGIMMEDIATE,	/* activation flags */
	BOOLGADGET,	/* gadget type flags */
	(APTR)&Border2,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&IText2,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	9,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

UBYTE PagesSIBuff[3];
struct StringInfo PagesSInfo = {
	PagesSIBuff,	/* buffer where text will be edited */
	UNDOBUFFER,	/* optional undo buffer */
	0,	/* character position in buffer */
	3,	/* maximum number of characters to allow */
	0,	/* first displayed character buffer position */
	0,0,0,0,0,	/* Intuition initialized and maintained variables */
	0,	/* Rastport of gadget */
	0,	/* initial value for integer gadgets */
	NULL	/* alternate keymap (fill in if you set the flag) */
};

SHORT BorderVectors3[] = {
	0,0,
	29,0,
	29,9,
	0,9,
	0,0
};
struct Border Border3 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors3,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct Gadget Pages = {
	&OneWide,	/* next gadget */
	31,90,	/* origin XY of hit box relative to window TopLeft */
	28,8,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY+STRINGCENTER+LONGINT,	/* activation flags */
	STRGADGET,	/* gadget type flags */
	(APTR)&Border3,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	NULL,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	(APTR)&PagesSInfo,	/* SpecialInfo structure */
	8,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

SHORT BorderVectors4[] = {
	0,0,
	67,0,
	67,19,
	0,19,
	0,0
};
struct Border Border4 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors4,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct IntuiText IText3 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	25,5,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Go",	/* pointer to text */
	NULL	/* next IntuiText structure */
};

struct Gadget Go = {
	&Pages,	/* next gadget */
	133,104,	/* origin XY of hit box relative to window TopLeft */
	66,18,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	BOOLGADGET,	/* gadget type flags */
	(APTR)&Border4,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&IText3,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	7,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

SHORT BorderVectors5[] = {
	0,0,
	67,0,
	67,19,
	0,19,
	0,0
};
struct Border Border5 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors5,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct IntuiText IText4 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	9,5,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Cancel",	/* pointer to text */
	NULL	/* next IntuiText structure */
};

struct Gadget Cancel = {
	&Go,	/* next gadget */
	230,104,	/* origin XY of hit box relative to window TopLeft */
	66,18,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	BOOLGADGET,	/* gadget type flags */
	(APTR)&Border5,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&IText4,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	6,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

UBYTE Line5SIBuff[26];
struct StringInfo Line5SInfo = {
	Line5SIBuff,	/* buffer where text will be edited */
	UNDOBUFFER,	/* optional undo buffer */
	0,	/* character position in buffer */
	26,	/* maximum number of characters to allow */
	0,	/* first displayed character buffer position */
	0,0,0,0,0,	/* Intuition initialized and maintained variables */
	0,	/* Rastport of gadget */
	0,	/* initial value for integer gadgets */
	NULL	/* alternate keymap (fill in if you set the flag) */
};

SHORT BorderVectors6[] = {
	0,0,
	211,0,
	211,9,
	0,9,
	0,0
};
struct Border Border6 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors6,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct Gadget Line5 = {
	&Cancel,	/* next gadget */
	31,75,	/* origin XY of hit box relative to window TopLeft */
	210,8,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	STRGADGET,	/* gadget type flags */
	(APTR)&Border6,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	NULL,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	(APTR)&Line5SInfo,	/* SpecialInfo structure */
	5,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

UBYTE Line4SIBuff[26];
struct StringInfo Line4SInfo = {
	Line4SIBuff,	/* buffer where text will be edited */
	UNDOBUFFER,	/* optional undo buffer */
	0,	/* character position in buffer */
	26,	/* maximum number of characters to allow */
	0,	/* first displayed character buffer position */
	0,0,0,0,0,	/* Intuition initialized and maintained variables */
	0,	/* Rastport of gadget */
	0,	/* initial value for integer gadgets */
	NULL	/* alternate keymap (fill in if you set the flag) */
};

SHORT BorderVectors7[] = {
	0,0,
	211,0,
	211,9,
	0,9,
	0,0
};
struct Border Border7 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors7,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct Gadget Line4 = {
	&Line5,	/* next gadget */
	31,60,	/* origin XY of hit box relative to window TopLeft */
	210,8,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	STRGADGET,	/* gadget type flags */
	(APTR)&Border7,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	NULL,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	(APTR)&Line4SInfo,	/* SpecialInfo structure */
	4,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

UBYTE Line3SIBuff[26];
struct StringInfo Line3SInfo = {
	Line3SIBuff,	/* buffer where text will be edited */
	UNDOBUFFER,	/* optional undo buffer */
	0,	/* character position in buffer */
	26,	/* maximum number of characters to allow */
	0,	/* first displayed character buffer position */
	0,0,0,0,0,	/* Intuition initialized and maintained variables */
	0,	/* Rastport of gadget */
	0,	/* initial value for integer gadgets */
	NULL	/* alternate keymap (fill in if you set the flag) */
};

SHORT BorderVectors8[] = {
	0,0,
	211,0,
	211,9,
	0,9,
	0,0
};
struct Border Border8 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors8,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct Gadget Line3 = {
	&Line4,	/* next gadget */
	31,45,	/* origin XY of hit box relative to window TopLeft */
	210,8,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	STRGADGET,	/* gadget type flags */
	(APTR)&Border8,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	NULL,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	(APTR)&Line3SInfo,	/* SpecialInfo structure */
	3,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

UBYTE Line2SIBuff[26];
struct StringInfo Line2SInfo = {
	Line2SIBuff,	/* buffer where text will be edited */
	UNDOBUFFER,	/* optional undo buffer */
	0,	/* character position in buffer */
	26,	/* maximum number of characters to allow */
	0,	/* first displayed character buffer position */
	0,0,0,0,0,	/* Intuition initialized and maintained variables */
	0,	/* Rastport of gadget */
	0,	/* initial value for integer gadgets */
	NULL	/* alternate keymap (fill in if you set the flag) */
};

SHORT BorderVectors9[] = {
	0,0,
	211,0,
	211,9,
	0,9,
	0,0
};
struct Border Border9 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors9,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct Gadget Line2 = {
	&Line3,	/* next gadget */
	31,30,	/* origin XY of hit box relative to window TopLeft */
	210,8,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	STRGADGET,	/* gadget type flags */
	(APTR)&Border9,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	NULL,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	(APTR)&Line2SInfo,	/* SpecialInfo structure */
	2,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

UBYTE Line1SIBuff[26];
struct StringInfo Line1SInfo = {
	Line1SIBuff,	/* buffer where text will be edited */
	UNDOBUFFER,	/* optional undo buffer */
	0,	/* character position in buffer */
	26,	/* maximum number of characters to allow */
	0,	/* first displayed character buffer position */
	0,0,0,0,0,	/* Intuition initialized and maintained variables */
	0,	/* Rastport of gadget */
	0,	/* initial value for integer gadgets */
	NULL	/* alternate keymap (fill in if you set the flag) */
};

SHORT BorderVectors10[] = {
	0,0,
	211,0,
	211,9,
	0,9,
	0,0
};
struct Border Border10 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors10,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct Gadget Line1 = {
	&Line2,	/* next gadget */
	31,15,	/* origin XY of hit box relative to window TopLeft */
	210,8,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	STRGADGET,	/* gadget type flags */
	(APTR)&Border10,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	NULL,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	(APTR)&Line1SInfo,	/* SpecialInfo structure */
	1,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

SHORT BorderVectors11[] = {
	0,0,
	67,0,
	67,19,
	0,19,
	0,0
};
struct Border Border11 = {
	-1,-1,	/* XY origin relative to container TopLeft */
	3,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BorderVectors11,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct IntuiText IText5 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	15,5,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Test",	/* pointer to text */
	NULL	/* next IntuiText structure */
};

struct Gadget Test = {
	&Line1,	/* next gadget */
	31,104,	/* origin XY of hit box relative to window TopLeft */
	66,18,	/* hit box width and height */
	NULL,	/* gadget flags */
	RELVERIFY,	/* activation flags */
	BOOLGADGET,	/* gadget type flags */
	(APTR)&Border11,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&IText5,	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	0,	/* user-definable data */
	NULL	/* pointer to user-definable data */
};

#define GadgetList1 Test

struct IntuiText IText13 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	160,90,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"or",	/* pointer to text */
	NULL	/* next IntuiText structure */
};

struct IntuiText IText12 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	208,90,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Labels wide",	/* pointer to text */
	&IText13	/* next IntuiText structure */
};

struct IntuiText IText11 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	69,90,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Pages",	/* pointer to text */
	&IText12	/* next IntuiText structure */
};

struct IntuiText IText10 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	247,75,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Line 5",	/* pointer to text */
	&IText11	/* next IntuiText structure */
};

struct IntuiText IText9 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	247,60,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Line 4",	/* pointer to text */
	&IText10	/* next IntuiText structure */
};

struct IntuiText IText8 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	247,45,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Line 3",	/* pointer to text */
	&IText9	/* next IntuiText structure */
};

struct IntuiText IText7 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	247,30,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Line 2",	/* pointer to text */
	&IText8	/* next IntuiText structure */
};

struct IntuiText IText6 = {
	3,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	247,15,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	"Line 1",	/* pointer to text */
	&IText7	/* next IntuiText structure */
};

#define IntuiTextList1 IText6

struct NewWindow NewWindowStructure1 = {
	51,19,	/* window XY origin relative to TopLeft of screen */
	325,127,	/* window width and height */
	0,1,	/* detail and block pens */
	GADGETUP+GADGETDOWN+CLOSEWINDOW,	/* IDCMP flags */
	WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH,	/* other window flags */
	&Test,	/* first gadget in gadget list */
	NULL,	/* custom CHECKMARK imagery */
	"Label Printer by Gary Walker",	/* window title */
	NULL,	/* custom screen pointer */
	NULL,	/* custom bitmap */
	5,5,	/* minimum width and height */
	-1,-1,	/* maximum width and height */
	WBENCHSCREEN	/* destination screen type */
};

extern struct ExecBase 	*SysBase;
struct IntuitionBase	*IntuitionBase;
struct GfxBase		*GfxBase;
struct Window		*MagicWindow,*OutputWindow;
struct IntuiMessage	*MagicMsg;

#define NO_INTUI	"Intuition won't open!\n"
#define NO_GFX		"Graphics won't open!\n"
#define NO_WINDOW	"Can't open window!\n"
void GadMXSel(),MxGad();

char pline1[26];
char pline2[26];
char pline3[26];
char pline4[26];
char pline5[26];
int numpag,numrows,numtests,width = 1;
FILE *pfp;


printonewide(pfp,x)
FILE *pfp;
int x;
{
	int i;

	for (i=0;i<x;i++)	{
	fprintf(pfp,"%-25.25s\n",pline1);
	fprintf(pfp,"%-25.25s\n",pline2);
	fprintf(pfp,"%-25.25s\n",pline3);
	fprintf(pfp,"%-25.25s\n",pline4);
	fprintf(pfp,"%-25.25s\n",pline5);
	fprintf(pfp,"\n");
				}
	return(0);
}		

printthreewide(pfp,x)
FILE *pfp;
int x;
{
	int i;

	for (i=0;i<x;i++)	{
	fprintf(pfp,"%-25.25s %-25.25s %-25.25s",pline1,pline1,pline1);
	fprintf(pfp,"\n");
	fprintf(pfp,"%-25.25s %-25.25s %-25.25s",pline2,pline2,pline2);
	fprintf(pfp,"\n");
	fprintf(pfp,"%-25.25s %-25.25s %-25.25s",pline3,pline3,pline3);
	fprintf(pfp,"\n");
	fprintf(pfp,"%-25.25s %-25.25s %-25.25s",pline4,pline4,pline4);
	fprintf(pfp,"\n");
	fprintf(pfp,"%-25.25s %-25.25s %-25.25s",pline5,pline5,pline5);
	fprintf(pfp,"\n");
	fprintf(pfp,"\n");
				}
	return(0);
}

VOID OpenStuff() 
{
 if(!(IntuitionBase=(struct Intuitionbase *)
   OpenLibrary("intuition.library",0)))
   {
    Write(Output(),NO_INTUI,strlen(NO_INTUI));
    exit(0);
   } 

 if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)))
   {
    Write(Output(),NO_GFX,strlen(NO_GFX));
    CloseLibrary(IntuitionBase);
    exit(0);
   } 

   OutputWindow=IntuitionBase->FirstScreen->FirstWindow;

	MagicWindow = (struct Window *)OpenWindow(&NewWindowStructure1);
	if (MagicWindow == NULL)
   {
    Write(Output(),NO_WINDOW,strlen(NO_WINDOW));
    CloseLibrary(IntuitionBase);
    CloseLibrary(GfxBase);
    exit(0);
   } 
   PrintIText(MagicWindow->RPort,&IntuiTextList1,0,0);
}

VOID GetLines()
{
	int i,buflen = 25;

	for (i=0;i<buflen;i++) {
		pline1[i] = Line1SIBuff[i];
		pline2[i] = Line2SIBuff[i];
		pline3[i] = Line3SIBuff[i];
		pline4[i] = Line4SIBuff[i];
		pline5[i] = Line5SIBuff[i];
			       }
}

VOID GetPages()
{
	stcd_i(PagesSIBuff,&numpag);
	numrows = numpag*12;
}

VOID TestIt()
{

	GetLines();
	numtests++;
	numrows = 1;
	Printit(numrows);
}

VOID DoIt()
{
	GetLines();
	GetPages();
	numrows = (numrows - numtests);
	Printit(numrows);
}

Printit(numrows)
int numrows;
{

	pfp = fopen("PRT:","w");
	if (pfp == NULL) {
		exit(1);
			 }

	if (width == 1)  printonewide(pfp,numrows);
	if (width == 3)  printthreewide(pfp,numrows);
	fclose(pfp);
	return(0);
}

VOID CloseStuff() 
{
 CloseWindow(MagicWindow);		
 CloseLibrary(IntuitionBase);
 CloseLibrary(GfxBase);		/* Lets get outa here */
}

VOID _main()
{
	int end = FALSE,gadg;
	long Code,Class;

	OpenStuff();

 while(!end)
      {
       Wait(1<<MagicWindow->UserPort->mp_SigBit);
	      
       while(MagicMsg=(struct IntuiMessage *)GetMsg(MagicWindow->UserPort))
	    {
	     Code=MagicMsg->Code;
	     Class=MagicMsg->Class;	     
	     gadg=((struct Gadget *)(MagicMsg->IAddress))->GadgetID;
	     ReplyMsg(MagicMsg);
		if (Class == CLOSEWINDOW) {
				CloseStuff();
				exit(0);
					  }
		if ((Class == GADGETUP) || (Class == GADGETDOWN)) {
		  switch(gadg)
		      {
		       case 0:  TestIt(); break;
		       case 1:  break;
		       case 2:  break;
		       case 3:  break;
		       case 4:  break;
		       case 5:  break;
		       case 6:  CloseStuff();exit(0);break;
		       case 7:  DoIt();numtests=0; break;
		       case 8:  break;
                       case 9:  width = 1;
				GadMXSel(&OneWide,&ThreeWide);
				break;
		       case 10: width = 3;
				GadMXSel(&ThreeWide,&OneWide); 
				break;
		      }	
               }
            }
      }

}	/* End of Main */
VOID GadMXSel(gad1,gad2)
struct Gadget *gad1,*gad2;
{
	static struct Gadget *gadprev;

	gadprev = NULL;
	if (gad1 != NULL)
		if (gad1->Flags & SELECTED) return;
	if (gad2 != NULL)
		if (gad2->Flags & SELECTED) gadprev = gad2;

	MxGad(gad1,gadprev);

	return;
}

VOID MxGad(gad1,gad2)
struct Gadget *gad1,*gad2;
{

	if (gad2 != NULL) {
	RemoveGadget(MagicWindow,gad2);
	gad2->Flags |= SELECTED;
	AddGadget(MagicWindow,gad2,-1);
			  }
	if (gad2 != NULL) RefreshGadgets(gad2,MagicWindow,NULL);

	if (gad1 != NULL) {
	RemoveGadget(MagicWindow,gad1);
	gad1->Flags |= SELECTED;
	AddGadget(MagicWindow,gad1,-1);
			  }
	if (gad2 != NULL) {
	RemoveGadget(MagicWindow,gad2);
	gad2->Flags &= ~SELECTED;
	AddGadget(MagicWindow,gad2,-1);
			  }
	if (gad1 != NULL) RefreshGadgets(gad1,MagicWindow,NULL);
	return;
}
