home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff242.lzh / CustReq / CustReq.c < prev    next >
C/C++ Source or Header  |  1989-08-30  |  4KB  |  125 lines

  1. #include <intuition/intuitionbase.h>
  2. #include <graphics/gfxbase.h>
  3.  
  4. #define OKAY 1
  5. #define CANCEL 0
  6.  
  7. static short SimpleRequestXYBorder[]={
  8.     0,0,101,0,101,12,0,12,0,0};
  9. static struct Border SimpleRequestBorder={
  10.     -1,-1,6,0,JAM1,5,SimpleRequestXYBorder,NULL};
  11. static struct IntuiText OkayText={
  12.     0,1,JAM1,5,2,NULL,NULL,NULL};
  13. static struct IntuiText CancelText={
  14.     0,1,JAM1,5,2,NULL,NULL,NULL};
  15. static struct Gadget OkayGadget={
  16.     NULL,8,30,100,11,GADGHCOMP,RELVERIFY,BOOLGADGET,
  17.     (APTR)&SimpleRequestBorder,NULL,&OkayText,NULL,NULL,OKAY,NULL};
  18. static struct Gadget CancelGadget={
  19.     &OkayGadget,120,30,100,11,GADGHCOMP,RELVERIFY,BOOLGADGET,
  20.     (APTR)&SimpleRequestBorder,NULL,&CancelText,NULL,NULL,CANCEL,NULL};
  21.  
  22. static struct IntuiText SimpleRequestText={
  23.     0,1,JAM1,8,17,NULL,NULL,NULL};
  24.  
  25. static struct NewWindow SimpleRequestWindow={
  26.     50,30,230,46,0,3,GADGETUP|VANILLAKEY|INTUITICKS,
  27.     ACTIVATE|RMBTRAP|WINDOWDRAG,NULL,
  28.     NULL,"Request",NULL,NULL,0,0,0,0,WBENCHSCREEN};
  29.  
  30. static struct Window *QWindow;
  31. static struct IntuiMessage *MyMsg;
  32. struct IntuitionBase *IntuitionBase;
  33. struct GfxBase *GfxBase;
  34.  
  35. request(hail,text,x,y,pos,neg,dfault,time)
  36. char *hail, *text;
  37. int x,y;
  38. char *pos, *neg;
  39. BOOL dfault;
  40. int time;
  41. {
  42.     int Class,Code,ticks=0;
  43.     char key;
  44.     struct Screen *Screen;
  45.     Screen=IntuitionBase->ActiveWindow->WScreen;
  46.     SimpleRequestWindow.Width=strlen(text)*8+16;
  47.     SimpleRequestText.LeftEdge=8;
  48.     if (SimpleRequestWindow.Width<230) {
  49.         SimpleRequestWindow.Width=230;
  50.         SimpleRequestText.LeftEdge=(214-(strlen(text)*8))/2+8;
  51.     }
  52.     if (SimpleRequestWindow.Width>Screen->Width)
  53.         SimpleRequestWindow.Width=Screen->Width;
  54.     CancelGadget.LeftEdge=(SimpleRequestWindow.Width)-108;
  55.     if (x==-1 || y==-1) {
  56.         x=Screen->MouseX;
  57.         y=Screen->MouseY;
  58.     }
  59.     if (x==-2 || y==-2) {
  60.         x=Screen->MouseX-20;
  61.         y=Screen->MouseY-35;
  62.     }
  63.     if (x==-3 || y==-3) {
  64.         x=Screen->MouseX-SimpleRequestWindow.Width+20;
  65.         y=Screen->MouseY-35;
  66.     }        
  67.     if (x<0) x=0; if (y<0) y=0;
  68.     if (x>Screen->Width-SimpleRequestWindow.Width)
  69.         x=Screen->Width-SimpleRequestWindow.Width;
  70.     if (y>Screen->Height-46)
  71.         y=Screen->Height-46;
  72.     SimpleRequestWindow.TopEdge=y; SimpleRequestWindow.LeftEdge=x;
  73.     CancelText.IText=neg; CancelText.LeftEdge=(100-(strlen(neg)*8))/2;
  74.     OkayText.IText=pos; OkayText.LeftEdge=(100-(strlen(pos)*8))/2;
  75.     if (hail) SimpleRequestWindow.Title=hail;
  76.     QWindow=(struct Window *) OpenWindow(&SimpleRequestWindow);
  77.     SetAPen(QWindow->RPort,1);
  78.     RectFill(QWindow->RPort,4,11,(SimpleRequestWindow.Width-5),43);
  79.     AddGList(QWindow,&CancelGadget,-1,2,NULL);
  80.     RefreshGList(&CancelGadget,QWindow,NULL,2);
  81.     SimpleRequestText.IText=text;
  82.     PrintIText(QWindow->RPort,&SimpleRequestText,0,0);
  83.     waitforinput:
  84.     Wait (1<<QWindow->UserPort->mp_SigBit);
  85.     MyMsg=GetMsg(QWindow->UserPort);
  86.     Class=MyMsg->Class; Code=MyMsg->Code; key=toupper((char ) Code);
  87.     ReplyMsg(MyMsg);
  88.     if (Class==INTUITICKS && time>0) {
  89.         ++ticks;
  90.         if ((ticks/10)<time) goto waitforinput;
  91.         Class=VANILLAKEY;
  92.         if (dfault) key='Y'; else key='N';
  93.     }
  94.     if (Class==VANILLAKEY && key!='Y' && key!='N') goto waitforinput;
  95.     CloseWindow(QWindow);
  96.     RemoveGList(QWindow,&CancelGadget,2);
  97.     if (((struct Gadget *) MyMsg->IAddress)->GadgetID==OKAY || key=='Y') return(TRUE);
  98.     return(FALSE);
  99. }
  100.  
  101. main(argc,argv)
  102. int argc;
  103. char *argv[];
  104. {
  105.     int dfault,timeout,ret;
  106.     printf("\x9b;33mCustReq v2\x9b;0;3m (c) 1989 Jonathan Potter\x9b;0m\n");
  107.     if (argc<5) {
  108.         printf("USAGE : CustReq \"hailstring\" \"string\" \"pos\" \"neg\" \
  109. [dfault] [timeout]\n");
  110.         exit(0);
  111.     }
  112.     IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
  113.     GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",0);
  114.     if (argc>5) dfault=atoi(argv[5]);
  115.     if (argc>6) timeout=atoi(argv[6]);
  116.     if (dfault)
  117.         ret=request(argv[1],argv[2],-2,-2,argv[3],argv[4],1,timeout);
  118.     else
  119.         ret=request(argv[1],argv[2],-3,-3,argv[3],argv[4],0,timeout);
  120.     CloseLibrary(IntuitionBase);
  121.     CloseLibrary(GfxBase);
  122.     if (ret) exit(5);
  123.     exit(0);
  124. }
  125.