/* save.c -- open a window to get filename, close it, and proceed as directed.... */ #define SWX 270 /* Save Window Size */ #define SWY 70 #define CANCEL_GAD 0 #define OKAY_GAD 1 extern char name[31]; extern char filename[31]; extern struct TextAttr TestFont; /* define ok and cancel gadgets */ struct IntuiText okay_text = {3,2,JAM2,0,2,NL,(UBYTE *) " OK ",NL}; struct IntuiText cancel_text = {3,2,JAM2,0,2,NL,(UBYTE *) "Cancel",NL}; struct Gadget cancel_gadget = { NL, 155,50, 60,11, GADGHCOMP, RELVERIFY, BOOLGADGET, NL, NL, &cancel_text, NL,NL, CANCEL_GAD, NL }; struct Gadget okay_gadget = { &cancel_gadget, 155,30, 60,11, GADGHCOMP, RELVERIFY, BOOLGADGET, NL, NL, &okay_text, NL,NL, OKAY_GAD, NL }; /* define filename gadget */ #define BUFFERSIZE 26 USHORT FileNameVectors[] = { -1,-1, 152,-1, 152, 12, -1, 12, -1, -1, }; struct Border FileNameBorder = { -1, -1, /* initial offsets, gadget relative */ 1, 0, JAM1, /* pens (fore, back) and drawmode */ 5, /* number of vectors */ FileNameVectors, /* pointer to the actual array of vectors */ NULL /* no next Border, can point to another border */ }; /* default text */ UBYTE FileNameBuffer[BUFFERSIZE] = "temp"; UBYTE UndoNameBuffer[BUFFERSIZE]; struct StringInfo FileNameInfo = { FileNameBuffer, /* pointer to I/O buffer */ UndoNameBuffer, /* pointer to undo buffer */ 0, /* buffer position */ BUFFERSIZE, /* max number of chars, including NULL */ 0, 0, /* first char in display, undo positions */ 5, /* number of chars (currently) in the buffer */ 0, 0, 0, /* position variables calculated by Intuition */ NULL, /* no pointer to RastPort */ 0, /* not a LongInt string gadget */ NULL /* no pointer to alternate keymap */ }; struct IntuiText FileNameText = { 2, 2, /* FrontPen, BackPen */ JAM1, /* DrawMode */ -101, 0, /* LeftEdge, TopEdge (relative to gadget) */ &TestFont, /* pointer to TextFont */ (UBYTE *) "Filename:", /* pointer to Text */ NL /* no pointer to NextText */ }; #define FILENAME_GAD 2 struct Gadget FileNameGadget = { &okay_gadget, /* pointer to Next Gadget */ 110, 10, 150, 11, /* (Left Top Width Height) Hit Box */ GADGHCOMP, /* Flags */ RELVERIFY, /* Activation flags */ STRGADGET, /* Type */ (APTR)&FileNameBorder, /* pointer to Border Image */ NL, /* no pointer to SelectRender */ &FileNameText, /* pointer to GadgetText */ NL, /* no MutualExclude */ (APTR)&FileNameInfo, /* pointer to SpecialInfo */ FILENAME_GAD, /* ID */ NL /* no pointer to special data */ }; /* Used to open a Window */ struct NewWindow NewSwin = { 25,65, SWX,SWY, 2,BCOL, NL, /* IDCMP set up AFTER CALL */ ACTIVATE | SMART_REFRESH, &FileNameGadget,NL, NL, /* FirstGadget, CheckMark, Title */ NL,NL, /* MUST SET SCREEN AFTER OPENSCREEN!!! */ SWX,SWY,SWX,SWY, CUSTOMSCREEN }; /* MinW, MinH, MaxW, MaxH */ /******************************************************************** * save(window) * This is the meat. This routine opens the save window and * retains control until the user selects the OK or CANCEL gadget. * The calling arguement is a window pointer. That window * is expected to have opened an IDCMP port, which save uses. ********************************************************************/ int save(calling_window) struct Window *calling_window; { struct Window *cW; /* save window handle */ FAST struct IntuiMessage *imsg; FAST struct Gadget *igad; FAST int class; int confirmed; BOOL stayhere; /* Get screen from calling window */ NewSwin.Screen = calling_window->WScreen; /* NEED TO SET SCREEN!!! */ if ( ! (cW = (struct Window *)OpenWindow(&NewSwin)) ) { return(FALSE); /* Oops... */ } cW->UserPort = calling_window->UserPort; ModifyIDCMP(cW, GADGETUP | GADGETDOWN); stayhere=TRUE; while (stayhere == TRUE) { while (imsg=(struct IntuiMessage *)GetMsg(cW->UserPort)) { class = imsg->Class; ReplyMsg(imsg); switch ( class ) { case GADGETUP: case GADGETDOWN: igad =(struct Gadget *) imsg->IAddress; switch ( igad->GadgetID ) { case CANCEL_GAD: confirmed=0; stayhere=FALSE; break; case OKAY_GAD: strcpy(name,FileNameBuffer); strcpy(filename,FileNameBuffer); confirmed=1; stayhere=FALSE; break; case FILENAME_GAD: strcpy(name,FileNameBuffer); strcpy(filename,FileNameBuffer); break; } } } } cW->UserPort = NL; CloseWindow(cW); if (confirmed==1) return(1); else return(0); }