home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c003 / 1.ddi / DEMOS / DEMO_WN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-01  |  10.4 KB  |  221 lines

  1. /*demo_wn.c -- demo of window viewing of files
  2.  
  3.     ********** Copyright 1985 by Vermont Creative Software **********
  4.  
  5. COMMENT
  6.  
  7.     This program shows how the functions of Windows for C simplify
  8.     display of multiple files within multiple windows.
  9.  
  10.     Three files are made available for viewing in five windows.  A cursor
  11.     pad interpreter permits the user to move through the files.
  12.     Instructions for use are in the first file shown to the user.
  13.  
  14.  
  15. */
  16.  
  17. #define WN_DEBUG
  18. #include <wfc.h>
  19. #include <wfc_glob.h>
  20.  
  21. #define MAXCOL 80            /*Maximum number of col's in all files*/
  22. #define TABQ  8             /*Expand TABS to 8 spaces          */
  23. #define WINDOW_Q 6            /*Number of windows              */
  24. #define FILE_Q 3            /*Number of file records read          */
  25.  
  26. #define KEYMAX 5            /*max number of keystrokes to process */
  27.                     /*in one call to k_vcom           */
  28.  
  29. #define SCR_UPDATE v_tv
  30.  
  31. /*----------------------------------------------------------------------------*/
  32. /*  Declare structure externally to permit initialization              */
  33. /*----------------------------------------------------------------------------*/
  34.  
  35. KEYR keyrec = {0, 0, KEYMAX};        /*see bios.h for definition          */
  36.  
  37. /*----------------------------------------------------------------------------*/
  38. /*   character string contains message put to window on exit              */
  39. /*----------------------------------------------------------------------------*/
  40. char *sign_off[] = {
  41.     "\n                          WINDOWS FOR C\n\n",
  42.     "  For more information contact Vermont Creative Software, (802) 848-7738."
  43.     };
  44.  
  45.  
  46. main()
  47. {
  48.     MFILEPTR mfp[3];            /*array of pointers to memory files   */
  49.     WINDOW wn[6];            /*window structures              */
  50.     register int i;            /*loop variable               */
  51.     int key;                /*keystroke value              */
  52.     int cur_wn;             /*number for current window          */
  53.     int next_wn;            /*number for next window          */
  54.  
  55. /*----------------------------------------------------------------------------*/
  56. /*  Initialize the Windows for C System                       */
  57. /*----------------------------------------------------------------------------*/
  58.     init_wfc();
  59.  
  60. /*----------------------------------------------------------------------------*/
  61. /*  Initialize MFILE structures                           */
  62. /*----------------------------------------------------------------------------*/
  63.     mfp[0] = mf_def("demo_wn.c", 300, MAXCOL);         /*this file            */
  64.     mfp[1] = mf_def("wfc_fly.doc", 300, MAXCOL);       /*WFC information flyer*/
  65.     mfp[2] = mf_def("wn_help.doc", 300, MAXCOL);       /*help file for demo   */
  66.  
  67. /*----------------------------------------------------------------------------*/
  68. /*  Initialize windows                                  */
  69. /*----------------------------------------------------------------------------*/
  70.     def_wn(&wn[0], 0, v_rwq - 6, 0, v_coq/2 + 10, 1, 1, BDR_DLNP);
  71.     sw_name("Window 1", &wn[0]);        /*window 1                            */
  72.     sw_namelocation(TOPLEFT, &wn[0]);
  73.     sw_mf(mfp[0], &wn[0]);        /*point to demo_wn.c              */
  74.  
  75.     def_wn(&wn[1], 0, v_rwq - 6, v_coq/2 - 10, v_coq - 1, 1, 1, BDR_DLNP);
  76.     sw_name("Window 2", &wn[1]);        /*window 2                            */
  77.     sw_namelocation(TOPRIGHT, &wn[1]);
  78.     sw_mf(mfp[1], &wn[1]);        /*point to wfc_fly.doc              */
  79.     sw_att(LDOS, &wn[1]);        /*set color to WHITE on BLACK          */
  80.     sw_bdratt(LDOS, &wn[1]);
  81.  
  82.     def_wn(&wn[2], 0, (v_rwq - 6)/2, 0, v_coq - 1, 1, 1, BDR_DLNP);
  83.     sw_name("Window 3", &wn[2]);        /*window 3                            */
  84.     sw_namelocation(BOTTOMLEFT, &wn[2]);
  85.     sw_mf(mfp[0], &wn[2]);        /*point to demo_wn.c              */
  86.     sw_att(LFIELDA, &wn[2]);        /*set color to BLACK on CYAN          */
  87.     sw_bdratt(LFIELDA,&wn[2]);
  88.  
  89.     def_wn(&wn[3], (v_rwq - 6)/2 + 1, v_rwq - 6, 0, v_coq - 1, 1, 1, BDR_DLNP);
  90.     sw_name("Window 4", &wn[3]);        /*window 4                            */
  91.     sw_namelocation(BOTTOMLEFT, &wn[3]);
  92.     sw_mf(mfp[1], &wn[3]);        /*point to wfc_fly.doc              */
  93.     sw_att(LREVERSE, &wn[3]);        /*set color to BLUE on WHITE          */
  94.     sw_bdratt(LREVERSE, &wn[3]);
  95.  
  96.     def_wn(&wn[4], v_rwq - 5, v_rwq - 1, 0, v_coq - 1,    /*help window          */
  97.         2, 2, BDR_0P);
  98.     sw_mf(mfp[2], &wn[4]);                   /*point to wn_help.doc */
  99.     wn[4].att = LREVERSE;        /*set color to BLUE on WHITE          */
  100.  
  101.     def_wn(&wn[5], 0, v_rwq - 6, 0, v_coq - 1,        /*large window          */
  102.         0, 0, BDR_LNP);
  103.     sw_name("Big Window", &wn[5]);
  104.     sw_mf(mfp[0], &wn[5]);                   /*point to demo_wn.c   */
  105.  
  106. /*----------------------------------------------------------------------------*/
  107. /*  Now it's time to start the show                                           */
  108. /*----------------------------------------------------------------------------*/
  109.     cls();                /*clear screen                  */
  110.     mv_csr(v_rwq - 1, 0, &wn0);     /*move cursor to last row of screen   */
  111.     v_st("Please be patient while we read in some files ...", &wn0);
  112.  
  113. /*----------------------------------------------------------------------------*/
  114. /* Read in files for viewing                              */
  115. /*----------------------------------------------------------------------------*/
  116.     for(i = 0; i < FILE_Q; i++)
  117.     if(mf_rd(mfp[i]) == 0)
  118.         errout("Error reading file ", mfp[i]->fn);
  119.     cls();
  120.  
  121.  
  122. /*----------------------------------------------------------------------------*/
  123. /*  display message file (fr[2]) in window 4                      */
  124. /*----------------------------------------------------------------------------*/
  125.  
  126.     cur_wn = 4;             /*set current window              */
  127.     v_mf(&wn[cur_wn]);            /*display help file              */
  128.  
  129. /*----------------------------------------------------------------------------*/
  130. /*    Get keystrokes and implement commands: F1 - F2 change active files,   */
  131. /*    cursor pad keys move window over text. F10 ends program.          */
  132. /*                                          */
  133. /*    ki_cum() captures multiple keystroke accumulated in the buffer so     */
  134. /*    that they can be processed by the scrolling subroutine as a single    */
  135. /*    unit.  This speeds up scrolling and prevents accumulated keystrokes   */
  136. /*    that cause scrolling to continue after a depressed cursor is          */
  137. /*    released.                                  */
  138. /*                                          */
  139. /*    The number of keystrokes collected is in keyrec.kq; this value can    */
  140. /*    be used in k_vcom, which can process multiple keystrokes at once.     */
  141. /*                                          */
  142. /*    In this program we have chosen to call ki_cum() to collect keystrokes */
  143. /*    but to use a value of only 1 keystroke in k_vcom always.  This          */
  144. /*    slows down the scrolling slightly, but makes it evener and          */
  145. /*    pleasanter.  You can experiment using keyrec.kq to see which you      */
  146. /*    prefer.                                   */
  147. /*----------------------------------------------------------------------------*/
  148.     while((key = ki_cum(&keyrec)) != -K_F10)   /*loop until <F_10> is pressed */
  149.     {
  150. /*----------------------------------------------------------------------------*/
  151. /*  Check if key code is for a function key in the range of the number of     */
  152. /*  windows.  If so, that numbered window is made "active" and cursor         */
  153. /*  commands will occur within that window.                      */
  154. /*----------------------------------------------------------------------------*/
  155.     if(key <= -K_F1 && key >= -K_F1 - WINDOW_Q + 1)
  156.     {
  157.  
  158. /*----------------------------------------------------------------------------*/
  159. /*  If function key for last window is pressed , current active file is tran- */
  160. /*  sferred to that window.  Last window is large window at              */
  161. /*  top of screen and F6 and extended code is -K_F1 - WINDOW_Q + 1.          */
  162. /*----------------------------------------------------------------------------*/
  163.         if((next_wn = -K_F1 - key) == WINDOW_Q - 1)      /*if last window */
  164.         {
  165.         wn[next_wn].frp = wn[cur_wn].frp;    /*set frp to current  */
  166.                             /*active file          */
  167.         wn[next_wn].att = wn[cur_wn].att;    /*copy attributes     */
  168.         wn[next_wn].bdratt = wn[cur_wn].bdratt;
  169.         }
  170.  
  171. /*----------------------------------------------------------------------------*/
  172. /*  If next window is not equal to the current window then we want to set the */
  173. /*  current window to the next window, set the new current window and display */
  174. /*  the file in the new window.                           */
  175. /*----------------------------------------------------------------------------*/
  176.         if(next_wn != cur_wn)
  177.         {
  178.                         /*fool system into thinking this  */
  179.         dim_wn(FULL, &wn[cur_wn]);  /*window is no longer on screen   */
  180.         cur_wn = next_wn;
  181.         v_mf(&wn[cur_wn]);    /*display file within current window  */
  182.         }
  183.     }
  184.  
  185. /*----------------------------------------------------------------------------*/
  186. /* If not function key, check for cursor pad key and implement commands.      */
  187. /* If command moves window origin in file, redraw window contents.          */
  188. /*----------------------------------------------------------------------------*/
  189.     else
  190.         if(k_vcom(-key, 1 , &wn[cur_wn]) == 1)     /*if origin moved      */
  191.         v_mf(&wn[cur_wn]);               /*redraw window          */
  192.     }
  193.  
  194. /*----------------------------------------------------------------------------*/
  195. /*  The user has pressed the exit key.    Time to clear the screen and say      */
  196. /*  goodbye.                                      */
  197. /*----------------------------------------------------------------------------*/
  198.     cls();                /*clear screen                  */
  199.     unset_wn(&wn[4]);            /*unset before changing border          */
  200.     mod_wn(v_rwq/2 - 3, 0, 7, v_coq, &wn[4]);/*change window size and location*/
  201.     sw_border(BDR_LNP, &wn[4]);     /*change border               */
  202.     sw_csadv(ON, &wn[4]);        /*turn on cursor advance          */
  203.                     /*otherwise sign off message          */
  204.                     /*gets garbled.               */
  205.     sw_att(LREVERSE, &wn[4]);        /*window attribute is LREVERSE          */
  206.     sw_bdratt(LNORMAL, &wn[4]);     /*border attribute is LNORMAL          */
  207.  
  208.     tv_upd = OFF;            /*turn off updating              */
  209.     set_wn(&wn[4]);            /*set window on screen              */
  210.     v_st(sign_off[0],&wn[4]);        /*Windows for C         */
  211.     sw_att(LHIGHLITE, &wn[4]);
  212.     v_st(sign_off[1],&wn[4]);        /*For more information ...  */
  213.     tv_upd = ON;            /*turn updating back on           */
  214.     dim_wn(FULL, &wn[4]);        /*update full window dimensions       */
  215.     SCR_UPDATE(0, row_qty(&wn[4]) - 1,    /*force update of sign-off window     */
  216.            0, col_qty(&wn[4]) - 1, &wn[4]);
  217.     mv_csr(v_rwq - 2, 0, &wn0);     /*Place cursor at bottom of screen    */
  218.     exit_wfc();
  219.     return(0);
  220. }
  221.