home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d049 / trees.lha / Trees / save.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-11  |  5.0 KB  |  157 lines

  1. /* save.c -- open a window to get filename,
  2. close it, and proceed as directed.... */
  3.  
  4. #define SWX 270      /* Save Window Size  */
  5. #define SWY 70
  6.  
  7. #define CANCEL_GAD 0
  8. #define OKAY_GAD 1
  9.  
  10. extern char name[31];
  11. extern char filename[31];
  12. extern struct TextAttr TestFont;
  13. /* define ok and cancel gadgets */
  14. struct IntuiText okay_text = {3,2,JAM2,0,2,NL,(UBYTE *) "  OK  ",NL};
  15. struct IntuiText cancel_text = {3,2,JAM2,0,2,NL,(UBYTE *) "Cancel",NL};
  16. struct Gadget cancel_gadget = {
  17.    NL, 155,50, 60,11, GADGHCOMP, RELVERIFY,
  18.    BOOLGADGET, NL, NL,
  19.    &cancel_text, NL,NL, CANCEL_GAD, NL };
  20.  
  21. struct Gadget okay_gadget = {
  22.    &cancel_gadget, 155,30, 60,11, GADGHCOMP, RELVERIFY,
  23.    BOOLGADGET, NL, NL,
  24.    &okay_text, NL,NL, OKAY_GAD, NL };
  25.  
  26. /* define filename gadget */
  27.  
  28. #define BUFFERSIZE 26
  29. USHORT FileNameVectors[] = {
  30.    -1,-1,
  31.    152,-1,
  32.    152, 12,
  33.    -1, 12,
  34.    -1, -1,
  35. };
  36.  
  37. struct Border FileNameBorder = {
  38.    -1, -1,           /* initial offsets, gadget relative */
  39.    1, 0, JAM1, /* pens (fore, back) and drawmode */
  40.    5,                /* number of vectors */
  41.    FileNameVectors,     /* pointer to the actual array of vectors */
  42.    NULL       /* no next Border, can point to another border */
  43. };
  44.  
  45. /* default text */
  46. UBYTE FileNameBuffer[BUFFERSIZE] = "temp";
  47. UBYTE UndoNameBuffer[BUFFERSIZE];
  48. struct StringInfo FileNameInfo = {
  49.    FileNameBuffer,    /* pointer to I/O buffer */
  50.    UndoNameBuffer,    /* pointer to undo buffer */
  51.    0,             /* buffer position */
  52.    BUFFERSIZE,   /* max number of chars, including NULL */
  53.    0, 0,          /* first char in display, undo positions */
  54.    5,          /* number of chars (currently) in the buffer */
  55.    0, 0, 0,    /* position variables calculated by Intuition */
  56.    NULL,          /* no pointer to RastPort */
  57.    0,            /* not a LongInt string gadget */
  58.    NULL           /* no pointer to alternate keymap */
  59. };
  60. struct IntuiText FileNameText = {
  61.    2, 2,    /* FrontPen, BackPen */
  62.    JAM1,          /* DrawMode */
  63.    -101, 0,        /* LeftEdge, TopEdge (relative to gadget) */
  64.    &TestFont,     /* pointer to TextFont */
  65.    (UBYTE *) "Filename:",    /* pointer to Text */
  66.    NL           /* no pointer to NextText */
  67. };
  68.  
  69. #define FILENAME_GAD 2
  70.  
  71. struct Gadget FileNameGadget = {
  72.    &okay_gadget,             /* pointer to Next Gadget */
  73.    110, 10, 150, 11,  /* (Left Top Width Height) Hit Box */
  74.    GADGHCOMP,        /* Flags */
  75.    RELVERIFY,        /* Activation flags */
  76.    STRGADGET,        /* Type */
  77.    (APTR)&FileNameBorder, /* pointer to Border Image */
  78.    NL,             /* no pointer to SelectRender */
  79.    &FileNameText,        /* pointer to GadgetText */
  80.    NL,                /* no MutualExclude */
  81.    (APTR)&FileNameInfo,  /* pointer to SpecialInfo */
  82.    FILENAME_GAD,                /*  ID */
  83.    NL              /* no pointer to special data */
  84. };
  85.  
  86. /* Used to open a Window   */
  87. struct NewWindow NewSwin = {
  88.    25,65, SWX,SWY, 2,BCOL, NL,    /* IDCMP set up AFTER CALL */
  89.    ACTIVATE | SMART_REFRESH,
  90.    &FileNameGadget,NL, NL,    /* FirstGadget, CheckMark, Title  */
  91.    NL,NL,              /* MUST SET SCREEN AFTER OPENSCREEN!!! */
  92.    SWX,SWY,SWX,SWY, CUSTOMSCREEN }; /* MinW, MinH, MaxW, MaxH */
  93.  
  94.  
  95. /********************************************************************
  96. * save(window)
  97. *    This is the meat. This routine opens the save window and
  98. * retains control until the user selects the OK or CANCEL gadget.
  99. *     The calling arguement is a window pointer.  That window
  100. * is expected to have opened an IDCMP port, which save uses.
  101. ********************************************************************/
  102. int save(calling_window)
  103. struct Window *calling_window;
  104. {
  105. struct Window *cW;      /* save window handle   */
  106.  
  107. FAST struct IntuiMessage *imsg;
  108. FAST struct Gadget *igad;
  109.  
  110. FAST int class;
  111. int confirmed;
  112. BOOL stayhere;
  113.  
  114.    /* Get screen from calling window   */
  115.    NewSwin.Screen = calling_window->WScreen;  /* NEED TO SET SCREEN!!! */
  116.    if ( ! (cW = (struct Window *)OpenWindow(&NewSwin)) ) {
  117.       return(FALSE); /* Oops...  */
  118.       }
  119.  
  120.    cW->UserPort = calling_window->UserPort;
  121.    ModifyIDCMP(cW, GADGETUP | GADGETDOWN);
  122.    stayhere=TRUE;
  123.    while (stayhere == TRUE) {
  124.       while (imsg=(struct IntuiMessage *)GetMsg(cW->UserPort)) {
  125.          class = imsg->Class;
  126.          ReplyMsg(imsg);
  127.          switch ( class ) {
  128.             case GADGETUP:
  129.             case GADGETDOWN:
  130.                igad =(struct Gadget *) imsg->IAddress;
  131.                switch ( igad->GadgetID ) {
  132.                   case CANCEL_GAD:
  133.                      confirmed=0;
  134.                      stayhere=FALSE;
  135.                      break;
  136.                   case OKAY_GAD:
  137.                      strcpy(name,FileNameBuffer);
  138.                      strcpy(filename,FileNameBuffer);
  139.                      confirmed=1;
  140.                      stayhere=FALSE;
  141.                      break;
  142.                   case FILENAME_GAD:
  143.                      strcpy(name,FileNameBuffer);
  144.                      strcpy(filename,FileNameBuffer);
  145.                      break;
  146.                }
  147.          }
  148.       }
  149.    }
  150.    cW->UserPort = NL;
  151.    CloseWindow(cW);
  152.    if (confirmed==1)
  153.       return(1);
  154.    else
  155.       return(0);
  156. }
  157.