#include <intuition/intuitionbase.h>
#include <stdio.h>

#define OKAY 1
#define CANCEL 0

char dobuffer[255],undobuffer[255];

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

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

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

gf(title,x,y)
char *title;
int x,y;
{
	struct Gadget *gad;
	int a,gadgetid,mx,my;
	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);
			}
		}
	}
}

