#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;
extern struct IntuitionBase *IntuitionBase;

gf(Window,title,x,y)
struct Window *Window;
char *title;
int x,y;
{
	static struct Gadget *gad;
	int gadgetid;
	fw.Title=title;
	if (x+300>Window->Width) x=340;
	if (y+50>Window->Height) y=150;
	fw.TopEdge=y;
	fw.LeftEdge=x;
	fw.Screen=Window->WScreen;
	MyWindow=(struct Window *) OpenWindow(&fw);
	ActivateGadget(&stringgadget,MyWindow,NULL);
	Wait (1L<<MyWindow->UserPort->mp_SigBit);
	MyMsg=GetMsg(MyWindow->UserPort);
	gad=(struct Gadget *) MyMsg->IAddress;
	gadgetid=gad->GadgetID;
	ReplyMsg(MyMsg);
	CloseWindow(MyWindow);
	if (gadgetid==CANCEL) return(NULL);
	return(dobuffer);
}
