home *** CD-ROM | disk | FTP | other *** search
- /* dem_menu.c -- Demo of menu capabilities of Windows for C
-
- ********** Copyright 1985 by Vermont Creative Software **********
-
- USAGE
-
- To display a menu on a screen, allow menu selection, and then
- restore the original screen content.
-
- FUNCTION
-
- A pointer to a structure containing the menu information is passed
- as a calling parameter. Additional parameters specify the number
- of character spaces per item and the number of items in the menu.
-
- The menu window is made a pop-up window.
-
- The menu-window is placed on the screen and the menu text moved to
- the window.
-
- The first item is highlighted.
-
- Highlighting is accomplished by using a sub-window that is
- one-menu item in size. The sub-window is placed over the
- menu item, and v_natt() is called to change the text
- attribute within the window to LCHOICEA.
-
- Cursor pad keys are used to move the highlight area to other menu
- items.
-
- Pressing <Enter> "selects" the menu item highlighted, which causes
- the following sequence:
-
- The original screen is restored over the menu window.
-
- The code number of the menu item is returned on exit.
-
-
- COMMENT
-
- This program illustrates how the capabilities of Windows for C can
- be used to program a high-quality menu selection display.
-
- Pop-up windows are implemented just by designating the window to
- be a pop-up as opposed to an overwrite window.
-
- The capability to change the attribute of a section of a window is
- provided by v_natt().
-
- v_natt() is used in menu() to highlight the selected menu
- items.
-
- Highlighting is accomplished by placing a small window just
- the size of one menu-item space over the menu item and then
- using v_natt() to change the attribute of the window to
- REVERSE or LCHOICEA.
-
- When a menu item is de-selected, v_natt() is used to restore
- the original attribute.
-
- The status line that displays the number of the selected menu item
- provides another illustration of the ability of Windows for C to
- simplify screen management.
-
- */
-
- /* #define WN_DEBUG Commented out when debugging completed */
- #include <wfc.h>
- #include <wfc_glob.h>
-
- #define QITEMS 18 /*number of items in menu */
- #define ITEMLEN 10 /*length of each item in menu */
- #define ITEM_PER_ROW 7 /*number of items per row */
- #define DEF_ITEM 1 /*default item when menu is displayed */
-
- #define MAXCOL 80 /*maximum number of columns in file */
- #define WINDOW_Q 3 /*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 */
-
- /*----------------------------------------------------------------------------*/
- /* Declare structures externally to permit initialization */
- /*----------------------------------------------------------------------------*/
- KEYR keyrec = {0, 0, KEYMAX}; /*see wfc_stru.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 main_wn; /*main viewing window */
- WINDOW stat_wn; /*status window */
- WINDOW menu_wn; /*pop-up menu window */
- register int i;
- int key;
- int cur_file, next_file;
- int itemnumber; /* number or selected menu item */
-
-
- /*----------------------------------------------------------------------------*/
- /* Initialize the Windows for C System */
- /*----------------------------------------------------------------------------*/
- init_wfc();
-
- /*----------------------------------------------------------------------------*/
- /* Initialize MFILE structures */
- /*----------------------------------------------------------------------------*/
- mfp[0] = mf_def("menu.doc", 100, MAXCOL); /*documentation file */
- mfp[1] = mf_def("menu_hlp.doc", 75, MAXCOL); /*help file */
- mfp[2] = mf_def("menu.dem", 10, MAXCOL); /*menu item list */
-
- /*----------------------------------------------------------------------------*/
- /* Initialize the WINDOW structures */
- /*----------------------------------------------------------------------------*/
- def_wn(&main_wn, 0, 22, 0, 79, 1, 1, &bdr_dln); /*main viewing window */
- sw_mf(mfp[1], &main_wn);
- sw_name("Main Window", &main_wn);
-
- def_wn(&stat_wn, 23, 23, 0, 79, 2, 2, &bdr_0); /*status line window */
- sw_att(LREVERSE, &stat_wn);
-
- def_wn(&menu_wn, 19, 22, 0, 79, 0, 0, &bdr_dln); /*popup-menu window */
- sw_mf(mfp[2], &menu_wn);
-
-
- /*----------------------------------------------------------------------------*/
- /* Time to start the show */
- /*----------------------------------------------------------------------------*/
- cls(); /*clear screen */
-
- /*----------------------------------------------------------------------------*/
- /* Read in files for viewing */
- /*----------------------------------------------------------------------------*/
- for(i = 0; i < FILE_Q; i++)
- if(mf_rd(mfp[i]) == 0)
- errout("error in reading file ", mfp[i]->fn);
-
- /*----------------------------------------------------------------------------*/
- /* display message file (mfp[1]) in main window */
- /*----------------------------------------------------------------------------*/
- if(set_wn(&main_wn) == 0)
- errout("\ndefinitions inconsistent for window 1","");
- cur_file = 1;
- sw_mf(mfp[cur_file], &main_wn); /*set main window to display help file*/
- v_mf(&main_wn); /*display file */
-
- /*----------------------------------------------------------------------------*/
- /* establish status line and print menu number message */
- /*----------------------------------------------------------------------------*/
- if(set_wn(&stat_wn) == 0)
- errout("\ndefinitions inconsistent for status window","");
- v_plst(0, 9, "menu item number: ", &stat_wn);
-
- /*----------------------------------------------------------------------------*/
- /* Now that we have established the background text on the status line, we */
- /* will inhibit cursor advance so we can repeatedly update the item number */
- /* without having to worry about the cursor moving. */
- /*----------------------------------------------------------------------------*/
- sw_csadv(OFF, &stat_wn); /*set no cursor advance on status line*/
-
- /*----------------------------------------------------------------------------*/
- /* 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 F1 or F2. If so transfer file 1 or two to */
- /* the display window, main_wn. */
- /*----------------------------------------------------------------------------*/
- if(key == -K_F1 || key == -K_F2)
- {
- next_file = -key - K_F1;
- if(next_file != cur_file)
- {
- cur_file = next_file;
- sw_mf(mfp[cur_file], &main_wn);
- v_mf(&main_wn); /* display file */
- }
- }
- /*----------------------------------------------------------------------------*/
- /* Check if key code is F9. If so call menu() routine. Upon exit from */
- /* this routine, place screen cursor back in its original position */
- /*----------------------------------------------------------------------------*/
- else if(key == -K_F9)
- {
- itemnumber = menu2(&menu_wn, QITEMS, ITEMLEN, ITEM_PER_ROW,
- DEF_ITEM);
- v_printf(&stat_wn, "%d", itemnumber); /*print in stat_wn */
- }
- /*----------------------------------------------------------------------------*/
- /* 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, &main_wn) == 1) /*if window origin moved */
- v_mf(&main_wn); /*redraw window */
- }
-
- /*----------------------------------------------------------------------------*/
- /* The user has pressed the exit key. Time to clear the screen and say */
- /* goodbye. */
- /*----------------------------------------------------------------------------*/
- cls(); /*clear screen */
- unset_wn(&stat_wn); /*unset before changing border */
- mod_wn(9, 0, 7, 80, &stat_wn); /*change size and location of window */
- sw_att(LREVERSE, &stat_wn); /*change window attribute */
- sw_bdratt(LNORMAL, &stat_wn); /*change border attribute */
- sw_border(BDR_LNP, &stat_wn); /*change border */
- sw_csadv(ON, &stat_wn); /*turn on cursor advance */
- /*otherwise sign off message */
- /*gets garbled. */
- set_wn(&stat_wn); /*set window on screen */
- v_st(sign_off[0],&stat_wn); /*Windows for C */
- sw_att(LHIGHLITE, &stat_wn);
- v_st(sign_off[1],&stat_wn); /*For more information ... */
- mv_csr(v_rwq - 2, 0, &wn0); /*Place cursor at bottom of screen */
- exit_wfc();
- return(0);
- }