#include <intuition/intuitionbase.h>
#include <stdio.h>
#include <pragma/all.h>
#include <proto/all.h>
#include "PopInfo.i"

#define OKAY 1
#define CANCEL 0

static char dobuffer[255],undobuffer[255];

static struct StringInfo sinfo={
	dobuffer,undobuffer,0,80,0};
static short borderxy[]={
	-2,-1,283,-1,283,10,-2,10,-2,-1};
static struct Border gadborder={
	-1,-1,1,0,JAM1,5,borderxy,NULL};
static struct Gadget stringgadget={
	NULL,10,15,280,15,GADGHCOMP,TOGGLESELECT|RELVERIFY,STRGADGET,
	(APTR)&gadborder,NULL,NULL,NULL,(APTR)&sinfo,OKAY,NULL};
static struct IntuiText oktext={
	1,1,JAM1,5,2,NULL,"   OKAY!!",NULL};
static short borderxy1[]={
	0,0,101,0,101,12,0,12,0,0};
static struct Border gadborder1={
	-1,-1,1,0,JAM1,5,borderxy1,NULL};
static struct Gadget okgadget={
	&stringgadget,8,34,100,11,GADGHCOMP,RELVERIFY,BOOLGADGET,
	(APTR)&gadborder1,NULL,&oktext,NULL,NULL,OKAY,NULL};
static struct IntuiText notext={
	1,1,JAM1,5,2,NULL,"   CANCEL",NULL};
static short borderxy2[]={
	0,0,101,0,101,12,0,12,0,0};
static struct Border gadborder2={
	-1,-1,1,0,JAM1,5,borderxy2,NULL};
static struct Gadget nogadget={
	&okgadget,191,34,100,11,GADGHCOMP,RELVERIFY,BOOLGADGET,
	(APTR)&gadborder2,NULL,&notext,NULL,NULL,CANCEL,NULL};

static struct NewWindow fw={
	0,0,299,50,
	0,3,
	GADGETUP,
	WINDOWDRAG|ACTIVATE|RMBTRAP,
	&nogadget,
	NULL,
	"",
	NULL,NULL,
	0,0,0,0,CUSTOMSCREEN
};

static struct Window *MyWindow;
static struct IntuiMessage *MyMsg;
static struct IntuitionBase *IntuitionBase;

gf(title,x,y)
char *title;
int x,y;
{
	static struct Gadget *gad;
	int gadgetid;
	IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
	fw.Title=title;
	if (x+300>640) x=340;
	if (y+50>200) y=150;
	fw.TopEdge=y;
	fw.LeftEdge=x;
	fw.Screen=(struct Screen *) IntuitionBase->ActiveScreen;
	MyWindow=(struct Window *) OpenWindow(&fw);
	ActivateGadget(&stringgadget,MyWindow,NULL);
	for (;;) {
		Wait (1L<<MyWindow->UserPort->mp_SigBit);
		while (MyMsg=GetMsg(MyWindow->UserPort)) {
			ReplyMsg(MyMsg);
			if (MyMsg->Class==GADGETUP) {
				gad=(struct Gadget *) MyMsg->IAddress;
				gadgetid=gad->GadgetID;
				if (gadgetid!=OKAY && gadgetid!=CANCEL) break;
				CloseWindow(MyWindow);
				CloseLibrary(IntuitionBase);
				if (gadgetid==CANCEL) return(NULL);
				return(dobuffer);
			}
		}
	}
}

