home *** CD-ROM | disk | FTP | other *** search
- /*demo_wn.c -- demo of window viewing of files
-
- ********** Copyright 1985 by Vermont Creative Software **********
-
- COMMENT
-
- This program shows how the functions of Windows for C simplify
- display of multiple files within multiple windows.
-
- Three files are made available for viewing in five windows. A cursor
- pad interpreter permits the user to move through the files.
- Instructions for use are in the first file shown to the user.
-
-
- */
-
- #define WN_DEBUG
- #include <wfc.h>
- #include <wfc_glob.h>
-
- #define MAXCOL 80 /*Maximum number of col's in all files*/
- #define TABQ 8 /*Expand TABS to 8 spaces */
- #define WINDOW_Q 6 /*Number of windows */
- #define FILE_Q 3 /*Number of file records read */
-
- #define KEYMAX 5 /*max number of keystrokes to process */
- /*in one call to k_vcom */
-
- #define SCR_UPDATE v_tv
-
- /*----------------------------------------------------------------------------*/
- /* Declare structure externally to permit initialization */
- /*----------------------------------------------------------------------------*/
-
- KEYR keyrec = {0, 0, KEYMAX}; /*see bios.h for definition */
-
- /*----------------------------------------------------------------------------*/
- /* character string contains message put to window on exit */
- /*----------------------------------------------------------------------------*/
- char *sign_off[] = {
- "\n WINDOWS FOR C\n\n",
- " For more information contact Vermont Creative Software, (802) 848-7738."
- };
-
-
- main()
- {
- MFILEPTR mfp[3]; /*array of pointers to memory files */
- WINDOW wn[6]; /*window structures */
- register int i; /*loop variable */
- int key; /*keystroke value */
- int cur_wn; /*number for current window */
- int next_wn; /*number for next window */
-
- /*----------------------------------------------------------------------------*/
- /* Initialize the Windows for C System */
- /*----------------------------------------------------------------------------*/
- init_wfc();
-
- /*----------------------------------------------------------------------------*/
- /* Initialize MFILE structures */
- /*----------------------------------------------------------------------------*/
- mfp[0] = mf_def("demo_wn.c", 300, MAXCOL); /*this file */
- mfp[1] = mf_def("wfc_fly.doc", 300, MAXCOL); /*WFC information flyer*/
- mfp[2] = mf_def("wn_help.doc", 300, MAXCOL); /*help file for demo */
-
- /*----------------------------------------------------------------------------*/
- /* Initialize windows */
- /*----------------------------------------------------------------------------*/
- def_wn(&wn[0], 0, v_rwq - 6, 0, v_coq/2 + 10, 1, 1, BDR_DLNP);
- sw_name("Window 1", &wn[0]); /*window 1 */
- sw_namelocation(TOPLEFT, &wn[0]);
- sw_mf(mfp[0], &wn[0]); /*point to demo_wn.c */
-
- def_wn(&wn[1], 0, v_rwq - 6, v_coq/2 - 10, v_coq - 1, 1, 1, BDR_DLNP);
- sw_name("Window 2", &wn[1]); /*window 2 */
- sw_namelocation(TOPRIGHT, &wn[1]);
- sw_mf(mfp[1], &wn[1]); /*point to wfc_fly.doc */
- sw_att(LDOS, &wn[1]); /*set color to WHITE on BLACK */
- sw_bdratt(LDOS, &wn[1]);
-
- def_wn(&wn[2], 0, (v_rwq - 6)/2, 0, v_coq - 1, 1, 1, BDR_DLNP);
- sw_name("Window 3", &wn[2]); /*window 3 */
- sw_namelocation(BOTTOMLEFT, &wn[2]);
- sw_mf(mfp[0], &wn[2]); /*point to demo_wn.c */
- sw_att(LFIELDA, &wn[2]); /*set color to BLACK on CYAN */
- sw_bdratt(LFIELDA,&wn[2]);
-
- def_wn(&wn[3], (v_rwq - 6)/2 + 1, v_rwq - 6, 0, v_coq - 1, 1, 1, BDR_DLNP);
- sw_name("Window 4", &wn[3]); /*window 4 */
- sw_namelocation(BOTTOMLEFT, &wn[3]);
- sw_mf(mfp[1], &wn[3]); /*point to wfc_fly.doc */
- sw_att(LREVERSE, &wn[3]); /*set color to BLUE on WHITE */
- sw_bdratt(LREVERSE, &wn[3]);
-
- def_wn(&wn[4], v_rwq - 5, v_rwq - 1, 0, v_coq - 1, /*help window */
- 2, 2, BDR_0P);
- sw_mf(mfp[2], &wn[4]); /*point to wn_help.doc */
- wn[4].att = LREVERSE; /*set color to BLUE on WHITE */
-
- def_wn(&wn[5], 0, v_rwq - 6, 0, v_coq - 1, /*large window */
- 0, 0, BDR_LNP);
- sw_name("Big Window", &wn[5]);
- sw_mf(mfp[0], &wn[5]); /*point to demo_wn.c */
-
- /*----------------------------------------------------------------------------*/
- /* Now it's time to start the show */
- /*----------------------------------------------------------------------------*/
- cls(); /*clear screen */
- mv_csr(v_rwq - 1, 0, &wn0); /*move cursor to last row of screen */
- v_st("Please be patient while we read in some files ...", &wn0);
-
- /*----------------------------------------------------------------------------*/
- /* Read in files for viewing */
- /*----------------------------------------------------------------------------*/
- for(i = 0; i < FILE_Q; i++)
- if(mf_rd(mfp[i]) == 0)
- errout("Error reading file ", mfp[i]->fn);
- cls();
-
-
- /*----------------------------------------------------------------------------*/
- /* display message file (fr[2]) in window 4 */
- /*----------------------------------------------------------------------------*/
-
- cur_wn = 4; /*set current window */
- v_mf(&wn[cur_wn]); /*display help file */
-
- /*----------------------------------------------------------------------------*/
- /* Get keystrokes and implement commands: F1 - F2 change active files, */
- /* cursor pad keys move window over text. F10 ends program. */
- /* */
- /* ki_cum() captures multiple keystroke accumulated in the buffer so */
- /* that they can be processed by the scrolling subroutine as a single */
- /* unit. This speeds up scrolling and prevents accumulated keystrokes */
- /* that cause scrolling to continue after a depressed cursor is */
- /* released. */
- /* */
- /* The number of keystrokes collected is in keyrec.kq; this value can */
- /* be used in k_vcom, which can process multiple keystrokes at once. */
- /* */
- /* In this program we have chosen to call ki_cum() to collect keystrokes */
- /* but to use a value of only 1 keystroke in k_vcom always. This */
- /* slows down the scrolling slightly, but makes it evener and */
- /* pleasanter. You can experiment using keyrec.kq to see which you */
- /* prefer. */
- /*----------------------------------------------------------------------------*/
- while((key = ki_cum(&keyrec)) != -K_F10) /*loop until <F_10> is pressed */
- {
- /*----------------------------------------------------------------------------*/
- /* Check if key code is for a function key in the range of the number of */
- /* windows. If so, that numbered window is made "active" and cursor */
- /* commands will occur within that window. */
- /*----------------------------------------------------------------------------*/
- if(key <= -K_F1 && key >= -K_F1 - WINDOW_Q + 1)
- {
-
- /*----------------------------------------------------------------------------*/
- /* If function key for last window is pressed , current active file is tran- */
- /* sferred to that window. Last window is large window at */
- /* top of screen and F6 and extended code is -K_F1 - WINDOW_Q + 1. */
- /*----------------------------------------------------------------------------*/
- if((next_wn = -K_F1 - key) == WINDOW_Q - 1) /*if last window */
- {
- wn[next_wn].frp = wn[cur_wn].frp; /*set frp to current */
- /*active file */
- wn[next_wn].att = wn[cur_wn].att; /*copy attributes */
- wn[next_wn].bdratt = wn[cur_wn].bdratt;
- }
-
- /*----------------------------------------------------------------------------*/
- /* If next window is not equal to the current window then we want to set the */
- /* current window to the next window, set the new current window and display */
- /* the file in the new window. */
- /*----------------------------------------------------------------------------*/
- if(next_wn != cur_wn)
- {
- /*fool system into thinking this */
- dim_wn(FULL, &wn[cur_wn]); /*window is no longer on screen */
- cur_wn = next_wn;
- v_mf(&wn[cur_wn]); /*display file within current window */
- }
- }
-
- /*----------------------------------------------------------------------------*/
- /* If not function key, check for cursor pad key and implement commands. */
- /* If command moves window origin in file, redraw window contents. */
- /*----------------------------------------------------------------------------*/
- else
- if(k_vcom(-key, 1 , &wn[cur_wn]) == 1) /*if origin moved */
- v_mf(&wn[cur_wn]); /*redraw window */
- }
-
- /*----------------------------------------------------------------------------*/
- /* The user has pressed the exit key. Time to clear the screen and say */
- /* goodbye. */
- /*----------------------------------------------------------------------------*/
- cls(); /*clear screen */
- unset_wn(&wn[4]); /*unset before changing border */
- mod_wn(v_rwq/2 - 3, 0, 7, v_coq, &wn[4]);/*change window size and location*/
- sw_border(BDR_LNP, &wn[4]); /*change border */
- sw_csadv(ON, &wn[4]); /*turn on cursor advance */
- /*otherwise sign off message */
- /*gets garbled. */
- sw_att(LREVERSE, &wn[4]); /*window attribute is LREVERSE */
- sw_bdratt(LNORMAL, &wn[4]); /*border attribute is LNORMAL */
-
- tv_upd = OFF; /*turn off updating */
- set_wn(&wn[4]); /*set window on screen */
- v_st(sign_off[0],&wn[4]); /*Windows for C */
- sw_att(LHIGHLITE, &wn[4]);
- v_st(sign_off[1],&wn[4]); /*For more information ... */
- tv_upd = ON; /*turn updating back on */
- dim_wn(FULL, &wn[4]); /*update full window dimensions */
- SCR_UPDATE(0, row_qty(&wn[4]) - 1, /*force update of sign-off window */
- 0, col_qty(&wn[4]) - 1, &wn[4]);
- mv_csr(v_rwq - 2, 0, &wn0); /*Place cursor at bottom of screen */
- exit_wfc();
- return(0);
- }