void position_cursor( HELP_WINDOW *hw, int len, int *un, int *cc, int *ch ) { int col, row, y, yy; col = hw->ulft_col + hw->dply_col; row = hw->ulft_row + hw->dply_row + hw->v_row; y = hw->ulft_row + hw->dply_row; yy = hw->ulft_row + hw->dply_row + hw->avail_lines - 1; *un = FALSE; switch (*ch) { case UP : if (hw->v_row > 0 && hw->select > 0) { hlight_line( col, row, len, NORMAL ); --hw->v_row; --hw->select; *cc = TRUE; } else if (hw->v_row == 0 && hw->select > 0) { hlight_line( col, row, len, NORMAL ); --hw->select; scroll_window( -1, y, col, yy+1, col+hw->line_length, NORMAL ); *un = TRUE; *cc = TRUE; } break; case DOWN : if (hw->v_row < hw->avail_lines-1 && hw->select < hw->num_entries-1) { hlight_line( col, row, len, NORMAL ); ++hw->v_row; ++hw->select; *cc = TRUE; } else if (hw->v_row == hw->avail_lines-1 && hw->select < hw->num_entries-1) { hlight_line( col, row, len, NORMAL ); ++hw->select; scroll_window( 1, y, col, yy, col+hw->line_length, NORMAL ); *un = TRUE; *cc = TRUE; } else if (hw->select == hw->num_entries - 1 && hw->v_row > 0) { --hw->v_row; scroll_window(1, y, col, yy, col+hw->line_length, NORMAL ); } break; } }
/* * Name: select_file * Purpose: To let user select a file from dir list * Date: February 13, 1992 * Passed: flist: pointer to list of files * stem: base directory * dir: directory display stuff * Notes: let user move thru the file names with the cursor keys */ int select_file( FTYPE *flist, char *stem, DIRECTORY *dir ) { int ch; /* input character from user */ int func; /* function of character input by user */ int fno; /* index into flist of the file under cursor */ int goodkey; /* is key a recognized function key? */ int r; /* current row of cursor */ int c; /* current column of cursor */ int offset; /* offset into file list */ int stop; /* stop indicator */ int stem_len; /* stem length */ int color; /* color of help screen */ int file_color; /* color of current file */ int change; /* boolean, hilite another file? */ int oldr; /* old row */ int oldc; /* old column */ char asize[20]; /* ascii file size */ char blank[20]; /* blank out file names */ /* * initial everything. */ memset( blank, ' ', 12 ); blank[12] = '\0'; c = r = 1; ch = fno = offset = 0; color = g_display.help_color; file_color = g_display.hilited_file; goodkey = TRUE; stop = FALSE; stem_len = strlen( stem ); s_output( stem, dir->row+1, dir->col+19, color ); s_output( flist[fno].fname, dir->row+1, dir->col+19+stem_len, color ); ltoa( flist[fno].fsize, asize, 10 ); s_output( blank, dir->row+2, dir->col+19, color ); s_output( asize, dir->row+2, dir->col+19, color ); itoa( dir->cnt, asize, 10 ); s_output( blank, dir->row+2, dir->col+57, color ); s_output( asize, dir->row+2, dir->col+57, color ); xygoto( (c-1)*14+dir->col+2, r+dir->row+3 ); hlight_line( (c-1)*14+dir->col+2, r+dir->row+3, 12, file_color ); change = FALSE; while (stop == FALSE) { oldr = r; oldc = c; ch = getkey( ); func = getfunc( ch ); /* * User may have redefined the Enter and ESC keys. Make the Enter key * perform a Rturn in this function. Make the ESC key do an AbortCommand. */ if (ch == RTURN) func = Rturn; else if (ch == ESC) func = AbortCommand; switch (func) { case Rturn : case NextLine : case BegNextLine : stop = TRUE; break; case AbortCommand : stop = TRUE; break; case LineUp : if (r > 1) { change = TRUE; --r; } else { r = dir->lines; change = TRUE; if (offset == 0 || c > 1) { if (c > 1) --c; } else if (dir->vcols > 0 && offset > 0 && c == 1) { /* * recalculate the dir display stuff. */ offset -= dir->lines; recalculate_dir( dir, flist, offset ); } } goodkey = TRUE; break; case LineDown : if (r < dir->prow) { change = TRUE; ++r; } else if (r < dir->lines && c != dir->cols) { change = TRUE; ++r; } else { change = TRUE; r = 1; if (offset == dir->vcols * dir->lines || c < dir->cols) { if (c < dir->cols) ++c; } else if (dir->vcols > 0 && offset < dir->vcols * dir->lines && c == dir->cols) { offset += dir->lines; recalculate_dir( dir, flist, offset ); } } goodkey = TRUE; break; case CharLeft : if (offset == 0 || c > 1) { if (c > 1) { change = TRUE; --c; } } else if (dir->vcols > 0 && offset > 0 && c == 1) { change = TRUE; /* * recalculate the dir display stuff. */ offset -= dir->lines; recalculate_dir( dir, flist, offset ); } goodkey = TRUE; break; case CharRight : if (offset == dir->vcols * dir->lines || c < dir->cols) { if (c < dir->cols) { change = TRUE; ++c; if (c == dir->cols) { if ( r > dir->prow) r = dir->prow; } } } else if (dir->vcols > 0 && offset < dir->vcols * dir->lines && c == dir->cols) { change = TRUE; offset += dir->lines; recalculate_dir( dir, flist, offset ); if (r > dir->prow) r = dir->prow; } goodkey = TRUE; break; case BegOfLine : change = TRUE; c = r = 1; goodkey = TRUE; break; case EndOfLine : change = TRUE; r = dir->prow; c = dir->cols; goodkey = TRUE; break; case ScreenDown : change = TRUE; r = (c == dir->cols) ? r = dir->prow : dir->lines; goodkey = TRUE; break; case ScreenUp : change = TRUE; r = 1; goodkey = TRUE; break; default : break; } if (goodkey) { s_output( blank, dir->row+1, dir->col+19+stem_len, color ); fno = offset + (c-1)*dir->lines + (r-1); s_output( flist[fno].fname, dir->row+1, dir->col+19+stem_len, color ); ltoa( flist[fno].fsize, asize, 10 ); s_output( blank, dir->row+2, dir->col+19, color ); s_output( asize, dir->row+2, dir->col+19, color ); xygoto( (c-1)*14+dir->col+2, r+dir->row+3 ); goodkey = FALSE; if (change) { hlight_line( (oldc-1)*14+dir->col+2, oldr+dir->row+3, 12, color ); hlight_line( (c-1)*14+dir->col+2, r+dir->row+3, 12, file_color ); change = FALSE; } } } dir->select = fno; return( func == AbortCommand ? ERROR : OK ); }
void new_assignment_help( HELP_WINDOW *hw, char *help[], struct screen *help_heading, int *ch ) { int col, row, i; int update_name, change_color, draw_page; save_and_draw( hw, help_heading, &w_ptr ); show_func_list( hw, help ); col = hw->ulft_col + hw->dply_col; row = hw->ulft_row + hw->dply_row + hw->v_row; change_color = TRUE; *ch = 0; while (*ch!=RTURN && *ch!=ESC) { draw_page = FALSE; position_cursor( hw, hw->line_length, &update_name, &change_color, ch ); switch (*ch) { case PGUP : if (hw->select > hw->avail_lines-1) { hw->select = hw->select - hw->avail_lines; if (hw->v_row > hw->select) hw->select = hw->v_row; draw_page = TRUE; } else if (hw->select - hw->v_row > 0) { hw->select = hw->v_row; draw_page = TRUE; } break; case PGDN : if (hw->select + hw->avail_lines < hw->num_entries) { hw->select = hw->select + hw->avail_lines; draw_page = TRUE; } else if (hw->select + hw->avail_lines - hw->v_row < hw->num_entries) { hw->select = hw->num_entries - 1; draw_page = TRUE; } if ((hw->num_entries - 1) - hw->select < hw->avail_lines && draw_page) { i = row - hw->v_row; scroll_window( 0, i, col, i+hw->avail_lines-1, col+hw->line_length, NORMAL ); } break; } if (draw_page == TRUE) { show_func_list( hw, help ); update_name = TRUE; change_color = TRUE; } row = hw->ulft_row + hw->dply_row + hw->v_row; if (update_name) s_output( help[hw->select], row, col, NORMAL ); if (change_color) hlight_line( col, row, hw->line_length, cfg.attr ); *ch = getkey( ); change_color = FALSE; } window_control( &w_ptr, RESTORE, hw->ulft_col, hw->ulft_row, hw->total_col, hw->total_row ); if (*ch != RTURN) *ch = 0; }
void master_help( HELP_WINDOW *hw, KEY_DEFS *help, struct screen *help_heading, char *t, int *ch ) { FILE *fp; int col, row, i, j; int update_name, change_color, draw_page; char str[80]; char *blank = " "; char temp[20]; HELP_WINDOW hw_k; xygoto( -1, -1 ); save_and_draw( hw, help_heading, &w_ptr ); show_key_def_list( hw, help ); col = hw->ulft_col + hw->dply_col; row = hw->ulft_row + hw->dply_row + hw->v_row; change_color = TRUE; *ch = 0; while (*ch!=F3 && *ch != F10 && *ch!=ESC) { draw_page = FALSE; position_cursor( hw, hw->line_length, &update_name, &change_color, ch ); switch (*ch) { case PGUP : if (hw->select > hw->avail_lines-1) { hw->select = hw->select - hw->avail_lines; if (hw->v_row > hw->select) hw->select = hw->v_row; draw_page = TRUE; } else if (hw->select - hw->v_row > 0) { hw->select = hw->v_row; draw_page = TRUE; } break; case PGDN : if (hw->select + hw->avail_lines < hw->num_entries) { hw->select = hw->select + hw->avail_lines; draw_page = TRUE; } else if (hw->select + hw->avail_lines - hw->v_row < hw->num_entries) { hw->select = hw->num_entries - 1; draw_page = TRUE; } if ((hw->num_entries - 1) - hw->select < hw->avail_lines && draw_page) { i = row - hw->v_row; scroll_window( 0, i, col, i+hw->avail_lines-1, col+hw->line_length, NORMAL ); } break; case F5 : hw_k.dply_col = 2; hw_k.dply_row = 3; hw_k.line_length = 33; hw_k.avail_lines = 6; hw_k.v_row = 0; hw_k.select = 0; hw_k.num_entries = NUM_FUNC; hw_k.ulft_col = 20; hw_k.ulft_row = row + 1; if (hw_k.ulft_row > 12) hw_k.ulft_row = row - 12; hw_k.total_col = 37; hw_k.total_row = 12; new_assignment_help( &hw_k, avail_func, func_head, ch ); if (*ch == RTURN) { help[hw->select].key[0] = '*'; help[hw->select].func_index = (unsigned char)hw_k.select; s_output( help[hw->select].key, row, col, cfg.attr ); s_output( " ", row, col+31, cfg.attr ); s_output( avail_func[help[hw->select].func_index], row, col+31, cfg.attr ); *ch = 0; } break; case F7 : hw_k.ulft_col = 14; hw_k.ulft_row = 10; hw_k.total_col = 52; hw_k.total_row = 5; save_and_draw( &hw_k, file_head, &w_ptr ); xygoto( hw_k.ulft_col+28, hw_k.ulft_row+2 ); gets( str ); j = TRUE; if ((i = access( str, EXIST )) == 0) { s_output( blank, hw_k.ulft_row+2, hw_k.ulft_col+1, NORMAL ); s_output( "OK to overwrite exiting file (y/n)?", hw_k.ulft_row+2, hw_k.ulft_col+1, NORMAL ); xygoto( hw_k.ulft_col+38, hw_k.ulft_row+2 ); i = getkey( ); while (i != 'Y' && i != 'y' && i != 'N' && i != 'n') i = getkey( ); if (i == 'n' || i == 'N') j = FALSE; } xygoto( -1, -1 ); if (j == TRUE && (fp = fopen( str, "w" )) != NULL) { for (i=0; i<hw->num_entries && j; i++) { fprintf( fp, " %22s = ", help[i].key+3 ); fprintf( fp, " %s\n", avail_func[help[i].func_index] ); } fclose( fp ); } else { s_output( blank, hw_k.ulft_row+2, hw_k.ulft_col+1, NORMAL ); s_output( "Cannot open file. Press any key to contine.", hw_k.ulft_row+2, hw_k.ulft_col+1, NORMAL ); j = getkey( ); } window_control( &w_ptr, RESTORE, hw_k.ulft_col, hw_k.ulft_row, hw_k.total_col, hw_k.total_row ); break; case F8 : if ((fp = fopen( "PRN", "a" )) != NULL) { hw_k.ulft_col = 20; hw_k.ulft_row = 10; hw_k.total_col = 42; hw_k.total_row = 5; save_and_draw( &hw_k, print_head, &w_ptr ); j = TRUE; for (i=0; i<hw->num_entries && j; i++) { itoa( i+1, temp, 10 ); s_output( temp, hw_k.ulft_row+2, hw_k.ulft_col+16, NORMAL ); fprintf( fp, " %22s = ", help[i].key+3 ); fprintf( fp, " %s\n", avail_func[help[i].func_index] ); if (kbhit()) { j = getkey( ); if (j == ESC) j = FALSE; else j = TRUE; } } fprintf( fp, "\f" ); fclose( fp ); window_control( &w_ptr, RESTORE, hw_k.ulft_col, hw_k.ulft_row, hw_k.total_col, hw_k.total_row ); } break; } if (draw_page == TRUE) { show_key_def_list( hw, help ); update_name = TRUE; change_color = TRUE; } row = hw->ulft_row + hw->dply_row + hw->v_row; if (update_name) { s_output( help[hw->select].key, row, col, NORMAL ); s_output( avail_func[help[hw->select].func_index], row, col+31, NORMAL ); } if (change_color) hlight_line( col, row, hw->line_length, cfg.attr ); *ch = getkey( ); change_color = FALSE; } window_control( &w_ptr, RESTORE, hw->ulft_col, hw->ulft_row, hw->total_col, hw->total_row ); }