home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / dbase / vviews.zip / SPACE.C < prev    next >
Text File  |  1990-09-28  |  16KB  |  408 lines

  1. /*
  2.     ************* Copyright 1988 by Vermont Creative Software **************
  3.  
  4. space.c
  5. A demo program designed and written using Vermont Views and the Vermont Views
  6. Designer.
  7.  
  8. Description
  9.  
  10. This program demonstrates how to use data-entry and menu forms created with
  11. the Vermont Views Designer.
  12.  
  13. */
  14.  
  15. #include <string.h>
  16.  
  17. #include <vv_help.h>            /* Enables to use help system          */
  18. #include <vv_clist.h>
  19. #include <vv_extch.h>
  20. #include <vv_str.h>            /* Enables use of string fields       */
  21. #include <vv_sr.h>
  22. #include <vv_memo.h>
  23. #include <vv_menu.h>            /* Enables use of menus           */
  24. #include <vv_des.h>            /* Enables use of Designer forms      */
  25. #include <space.h>            /* Data structures of space form      */
  26. #include <spacepro.h>            /* Prototypes of space functions      */
  27. #include <spacefun.h>            /* Function list              */
  28. #include <vv_main.h>
  29.  
  30.  
  31. #define MAXTRANSP   6            /* Number of fields in the transport  */
  32.                     /* menu                   */
  33. #define MAXDEST     9            /* Number of fields in the destination*/
  34.                     /* menu                   */
  35.  
  36. TRANSPORT_FORM transport;        /* Data storage for transport_form    */
  37. OTHER_DEST_FORM destination;        /* Data storage for other_dest_form   */
  38. CREW_FORM crew;             /* Data storage for crew_form          */
  39. SUPPLY_FORM supplies;            /* Data storage for supply_form       */
  40. SUMMARY_FORM summary;            /* Data storage for summary_form      */
  41.  
  42. DFORMPTR fmptransport;            /* Pointer to transport_form          */
  43. DFORMPTR fmpdest;            /* Pointer to other_dest_form          */
  44.  
  45. #ifdef LINT_ARGS
  46. int CDECL main(void);
  47. #endif
  48.  
  49. /*----------------------------------------------------------------------------*/
  50. /* Main program                                   */
  51. /*----------------------------------------------------------------------------*/
  52.  
  53. int CDECL main()
  54. {
  55.     DFORMPTR fmpopening;        /* Pointer to opening form          */
  56.     DFORMPTR fmpmessage;        /* Pointer to message form          */
  57.     MFORMPTR main_menu;         /* Pointer to top menu form          */
  58.     DLIBPTR libp;            /* Pointer to library              */
  59.     MFILEPTR mfp;            /* Pointer to memory file          */
  60.     WINDOWPTR wnp;            /* Pointer to a window structure      */
  61.     int i;
  62.  
  63.    /*-------------------------------------------------------------------------*/
  64.    /*  Defines data form information array                      */
  65.    /*-------------------------------------------------------------------------*/
  66.     static DFMINFO fmlistp[] =
  67.     {
  68.     {"crew_form", &crew, space, NULLP},
  69.     {"supply_form", &supplies, space, NULLP},
  70.     {"summary_form", &summary, space, NULLP},
  71.     {NULLP, NULLP, NULLP, NULLP}
  72.     };
  73.  
  74.  
  75.     init_vv();                /* Initializes Vermont Views          */
  76.     vs_clr();                /* Clears the video screen          */
  77.  
  78.                     /* Changes the colors used for shadows*/
  79.     latt_rpl(LSHADOW, NORMAL, BLACK, BLUE, LATT_SYS);
  80.     latt_rpl(LSYS, NORMAL | HIGH_INT, WHITE | HIGH_INT, BLACK, LATT_SYS);
  81.  
  82.    /*-------------------------------------------------------------------------*/
  83.    /*    Sets us up to use shadows and exploding windows on all forms and      */
  84.    /*    menus and choice lists                              */
  85.    /*-------------------------------------------------------------------------*/
  86.  
  87.     sw_shad(CH_MEDSHADE, LSHADOW, BOTTOMLEFT, MN_WNP);
  88.     sw_updnfp(wn_expset, wn_expunset, MN_WNP);
  89.     sw_exporg(EXPTOPLFT, MN_WNP);
  90.  
  91.     sw_updnfp(wn_expset, wn_expunset, FM_WNP);
  92.     sw_exporg(EXPTOPLFT, FM_WNP);
  93.  
  94.     sw_shad(TRANSPARENT, LSYS, BOTTOMLEFT, CLIST_WNP);
  95.     sw_updnfp(wn_rollset, wn_rollunset, CLIST_WNP);
  96.     sw_exporg(EXPTOP, CLIST_WNP);
  97.  
  98.    /*-------------------------------------------------------------------------*/
  99.    /*  Defines memory file, reads in a choice list text to memory file, reads */
  100.    /*  in a help text file to memory file.                      */
  101.    /*-------------------------------------------------------------------------*/
  102.  
  103.     mfp = mf_def(200, 80);
  104.     mf_rd("space.chc", mfp);
  105.     for (i = 0; i < 3; i++)
  106.     fmlistp[i].clist_mfp = mfp;
  107.  
  108.     help_mf("help.txt", 200);
  109.  
  110.    /*-------------------------------------------------------------------------*/
  111.    /*  Get forms from library.                              */
  112.    /*-------------------------------------------------------------------------*/
  113.  
  114.     libp = dl_open("space.vvd");        /* Opens library                      */
  115.  
  116.     fmpopening = dl_fmget("opening", NULLP, NULLP, NULLP, libp);
  117.     fmpmessage = dl_fmget("message", NULLP, NULLP, NULLP, libp);
  118.     main_menu = dl_mnget("main_menu", SUBMENUS, space, fmlistp, libp);
  119.     fmptransport = dl_fmget("transport_form", &transport, NULLP, NULLP, libp);
  120.     fmpdest = dl_fmget("other_dest_form", &destination, NULLP, mfp, libp);
  121.     sw_shad(CH_MEDSHADE, LSHADOW, BOTTOMLEFT, fmpdest->wnp);
  122.  
  123.     dl_close(libp);            /* Closes library              */
  124.  
  125.    /*-------------------------------------------------------------------------*/
  126.    /*  Assigns the underlying data variables for fields on the summary_form   */
  127.    /*-------------------------------------------------------------------------*/
  128.  
  129.     sf_datap("scofficer", crew.scofficer, fm_namptr("summary_form"));
  130.     sf_datap("comofficer", crew.comofficer,  fm_namptr("summary_form"));
  131.     sf_datap("navigator", crew.navigator, fm_namptr("summary_form"));
  132.     sf_datap("pilot", crew.pilot, fm_namptr("summary_form"));
  133.     sf_datap("warlord", crew.warlord, fm_namptr("summary_form"));
  134.  
  135.     ssr_datap("general_staff", crew.general_staff, fm_namptr("summary_form"));
  136.     ssr_datap("supplies", supplies.supplies, fm_namptr("summary_form"));
  137.  
  138.  
  139.    /*-------------------------------------------------------------------------*/
  140.    /*  Process menu system.                              */
  141.    /*-------------------------------------------------------------------------*/
  142.  
  143.     fm_up(fmpopening);            /* Displays opening form on screen    */
  144.     ki();                /* Waits for a key              */
  145.     fm_dn(fmpopening);            /* Removes opening form from screen   */
  146.  
  147.  
  148.     fm_up(fmpmessage);            /* Displays message form on screen    */
  149.     ki();                /* Waits for a key              */
  150.     fm_dn(fmpmessage);            /* Removes message form from screen   */
  151.  
  152.     vs_clratt(LFLDACT);         /* Changes the color used to clear    */
  153.                     /* the video screen              */
  154.     vs_clr();                /* Clears the video screen          */
  155.  
  156.     mn_proc(0, main_menu);        /* Process menu system              */
  157.     mn_free(main_menu);         /* Frees menu forms              */
  158.  
  159.                     /* Allocate and initialize window     */
  160.     wnp = wn_def(5, 9, 14, 65, LHIGHLITE, BDR_DLNP);
  161.                     /*Special effects - shadows, exploding*/
  162.                     /*window, title               */
  163.     sw_shad(CH_MEDSHADE, LSHADOW, BOTTOMRIGHT, wnp);
  164.     sw_updnfp(wn_expset, wn_expunset, wnp);
  165.     sw_title("Press any key to continue.", LNORMAL, BOTTOMCENTER, wnp);
  166.     wn_up(wnp);             /* Sets the window on screen          */
  167.                     /* Writes to the window           */
  168.     v_stpl(2, 2, "Captain ", wnp);
  169.     if (! st_isblank(summary.missioncom))
  170.     v_st(summary.missioncom, wnp);
  171.     else
  172.     wnp->c--;
  173.     v_st(",", wnp);
  174.  
  175.     v_stpl(4, 2, "News of your completed mission to ", wnp);
  176.     v_st(destination.destination, wnp);
  177.     v_stpl(5, 2, "has reached Star Fleet Command.  Your field promotion", wnp);
  178.     v_stpl(6, 2, "awaits your return.  Congratulations!", wnp);
  179.     v_stpl(9, 28, "Fleet Admiral James T. Kirk", wnp);
  180.  
  181.     ki();                /* Waits for a key              */
  182.     wn_dn(wnp);             /* Removes the window from screen     */
  183.  
  184.     wn_mod(6, 5, 13, 69, wnp);        /*Modifies window size and location   */
  185.     for (i = 0; i < 3; i++)        /*Makes window seem to "pulse" onto   */
  186.     {                    /*the screen.                  */
  187.     wn_up(wnp);
  188.     wn_dn(wnp);
  189.     }
  190.  
  191.     wn_up(wnp);             /*Puts window up for the last time    */
  192.                     /*Writes to window buffer          */
  193.     v_stpl(2, CENTER_TEXT, "Congratulations on a successful mission!", wnp);
  194.     v_stpl(5, CENTER_TEXT, "You may now plot a new course to", wnp);
  195.     v_stpl(6, CENTER_TEXT, "faster user interface development with", wnp);
  196.     v_stpl(8, CENTER_TEXT, "Vermont Views(TM)!", wnp);
  197.  
  198.     ki();                /*Waits for keystroke              */
  199.     wn_dn(wnp);             /*Takes window down              */
  200.  
  201.     wn_free(wnp);            /* Frees memory allocated for window  */
  202.  
  203.                     /* Set the clear attribute to normal  */
  204.     latt_rpl(LSYS, NORMAL, WHITE, BLACK, LATT_SYS);
  205.     vs_clratt(LSYS);            /* Changes the color used to clear    */
  206.                     /* the video screen              */
  207.     vs_clr();                /* Clears the video screen          */
  208.  
  209.     csr_mv(vs_rowq() - 1, 0);        /* Moves the cursor to the last row   */
  210.     exit_vv();                /* Exit Vermont Views              */
  211.     return(0);
  212. }
  213.  
  214.  
  215.  
  216.  
  217. /*----------------------------------------------------------------------------*/
  218. /*  This function will exit the main menu.                      */
  219. /*----------------------------------------------------------------------------*/
  220.  
  221. int exit_function(mfmp)
  222. MFORMPTR mfmp;
  223. {
  224.     return(EXITMENU);
  225. }
  226.  
  227.  
  228. /*----------------------------------------------------------------------------*/
  229. /*  End destination menu form function.                       */
  230. /*  This function writes the destination (which may be indicated by a          */
  231. /*  checkmark on the destination menu) out to the global destination variable.*/
  232. /*----------------------------------------------------------------------------*/
  233.  
  234. int efmdestination(mfmp)
  235. MFORMPTR mfmp;
  236. {
  237.     int i;                /* Loop counter               */
  238.     int lastfldnum = 0;         /* Number of last field on form       */
  239.     MFIELDPTR mfldp;            /* Pointer to menu field on form      */
  240.  
  241.                     /* Fills in destination if user didn't*/
  242.                     /* enter it                  */
  243.     if (st_isblank(destination.destination))
  244.     strcpy(destination.destination, "(unspecified destination)");
  245.     lastfldnum = i_maxnum(mfmp);    /* Gets number of last field          */
  246.                     /* Loops through fields, looking for  */
  247.                     /* the checkmarked field          */
  248.     for (i = 0; i < lastfldnum - 1; i++)
  249.     {
  250.     mfldp = i_numptr(i, mfmp);    /* Gets a pointer to the field          */
  251.     if (mnf_ischecked(mfldp))    /* Checks whether user checked field  */
  252.     {                /* Copies item into destination string*/
  253.         strcpy(destination.destination, mfldp->datap);
  254.                     /* Only one field can be checked, so  */
  255.         break;            /*break after finding it          */
  256.     }
  257.     }
  258.     return(1);
  259. }
  260.  
  261. /*----------------------------------------------------------------------------*/
  262. /*  End transport menu form function.                          */
  263. /*  This function will remove transport_form from the video screen          */
  264. /*----------------------------------------------------------------------------*/
  265.  
  266. int efmtransport(mfmp)
  267. MFORMPTR mfmp;
  268. {
  269.     fm_dn(fmptransport);
  270.     return(1);
  271. }
  272.  
  273.  
  274. /*----------------------------------------------------------------------------*/
  275. /*  Begin transport menu form function.                       */
  276. /*  This function will display transport_form on the screen.              */
  277. /*----------------------------------------------------------------------------*/
  278.  
  279. int bfmtransport(mfmp)
  280. MFORMPTR mfmp;
  281. {
  282.     fm_up(fmptransport);
  283.     return(1);
  284. }
  285.  
  286.  
  287.  
  288. /*----------------------------------------------------------------------------*/
  289. /*  Action function for each field of the destination menu form.          */
  290. /*                                          */
  291. /*  This function will update checkmark in the destination checkmark menu,    */
  292. /*  so only one item can be selected at a time, for the last item (Other      */
  293. /*  Destination) will read the dest_other_form, and will update the          */
  294. /*  destination field in the summary_form.                      */
  295. /*----------------------------------------------------------------------------*/
  296.  
  297. int dest_check_mark(mfmp)
  298. MFORMPTR mfmp;
  299. {
  300.    int i;
  301.  
  302.    /*-------------------------------------------------------------------------*/
  303.    /* If checkmark for the current item is ON, updates it to OFF and clears   */
  304.    /* destination fields on the dest_other_form and summary_form.          */
  305.    /*-------------------------------------------------------------------------*/
  306.  
  307.    if (mnf_ischecked(curmfldp(mfmp)))
  308.    {
  309.       smnf_checkstatus(OFF, curmfldp(mfmp));
  310.       *summary.destination = '\0';
  311.       *destination.destination = '\0';
  312.    }
  313.  
  314.    /*-------------------------------------------------------------------------*/
  315.    /* If the checkmark for the current item is OFF, clears checkmark for all  */
  316.    /* items of the destination menu, sets checkmark for the current item to   */
  317.    /* ON.  If current item is the last item (Other Destination) it displays   */
  318.    /* and processes the other_dest_form and then updates the summary_form,    */
  319.    /* otherwise updates the summary_form and clears the destination field     */
  320.    /* on the other_dest_form.                              */
  321.    /*-------------------------------------------------------------------------*/
  322.    else
  323.    {
  324.       for (i = 0; i <= MAXDEST; i++)
  325.         smnf_checkstatus(OFF, (MFIELDPTR) i_numptr(i, mfmp));
  326.  
  327.       smnf_checkstatus(ON, curmfldp(mfmp));
  328.  
  329.       if (curitemnum(mfmp) == MAXDEST)
  330.       {
  331.      fm_up(fmpdest);
  332.      fm_rd(0, fmpdest);
  333.      strcpy(summary.destination, destination.destination);
  334.       }
  335.       else
  336.       {
  337.      strcpy(summary.destination, i_numnam(curitemnum(mfmp), mfmp));
  338.      *destination.destination = '\0';
  339.       }
  340.    }
  341.  
  342.    if (fm_isup(fmpdest))        /* if destination form is up,          */
  343.       fm_dn(fmpdest);            /* removes it from the screen          */
  344.  
  345.    smn_altered(mfmp);            /* sets the altered flag for the menu */
  346.    return(SAMELEVEL);
  347. }
  348.  
  349.  
  350.  
  351. /*----------------------------------------------------------------------------*/
  352. /*  Action function for each field of the transport menu form.              */
  353. /*                                          */
  354. /*  This function will update checkmark in the transport checkmark menu,      */
  355. /*  so only one item can be selected at a time, for the last item (Other)     */
  356. /*  will read the transport_form, and will update the transport field in the  */
  357. /*  summary_form.                                  */
  358. /*----------------------------------------------------------------------------*/
  359.  
  360.  
  361. int tran_check_mark(mfmp)
  362. MFORMPTR mfmp;
  363. {
  364.    int i;
  365.  
  366.    /*-------------------------------------------------------------------------*/
  367.    /* If checkmark for the current item is ON, updates it to OFF and clears   */
  368.    /* transport field on the transport_form and summary_form.              */
  369.    /*-------------------------------------------------------------------------*/
  370.  
  371.    if (mnf_ischecked(curmfldp(mfmp)))
  372.    {
  373.       smnf_checkstatus(OFF, curmfldp(mfmp));
  374.       *summary.transport = '\0';
  375.       *transport.transport = '\0';
  376.    }
  377.  
  378.    /*-------------------------------------------------------------------------*/
  379.    /* If the checkmark for the current item is OFF, clears checkmark for all  */
  380.    /* items of the transport menu, sets checkmark for the current item to ON. */
  381.    /* If the current item is the last item (Other) it processes the transport_*/
  382.    /* form and then  updates the summary_form, otherwise updates the summary_ */
  383.    /* form and clears the transport field on the transport_form.          */
  384.    /*-------------------------------------------------------------------------*/
  385.  
  386.    else
  387.    {
  388.       for (i = 0; i <= MAXTRANSP; i++)
  389.       smnf_checkstatus(OFF, (MFIELDPTR) i_numptr(i, mfmp));
  390.  
  391.       smnf_checkstatus(ON, curmfldp(mfmp));
  392.       if (curitemnum(mfmp) == MAXTRANSP)
  393.       {
  394.      fm_rd(0, fmptransport);
  395.      strcpy(summary.transport, transport.transport);
  396.       }
  397.       else
  398.       {
  399.      strcpy(summary.transport, i_numnam(curitemnum(mfmp), mfmp));
  400.      *transport.transport = '\0';
  401.       }
  402.    }
  403.  
  404.    fm_upd(fmptransport);        /* updates the transport_form          */
  405.    smn_altered(mfmp);            /* sets the altered flag for the menu */
  406.    return(SAMELEVEL);
  407. }
  408.