static int mouse_wgetch(WINDOW *win, int *fkey, bool ignore_errs) { int mouse_err = FALSE; int key; do { key = dlg_getc(win, fkey); #if USE_MOUSE mouse_err = FALSE; if (fkey && (key == KEY_MOUSE)) { MEVENT event; mseRegion *p; if (getmouse(&event) != ERR) { if ((p = dlg_mouse_region(event.y, event.x)) != 0) { key = DLGK_MOUSE(p->code); } else if ((p = dlg_mouse_bigregion(event.y, event.x)) != 0) { int x = event.x - p->x; int y = event.y - p->y; int row = (p->X - p->x) / p->step_x; key = -(p->code); switch (p->mode) { case 1: /* index by lines */ key += y; break; case 2: /* index by columns */ key += (x / p->step_x); break; default: case 3: /* index by cells */ key += (x / p->step_x) + (y * row); break; } } else { (void) beep(); mouse_err = TRUE; } } else { (void) beep(); mouse_err = TRUE; } } #endif } while (ignore_errs && mouse_err); return key; }
/* * Display a gauge, or progress meter. Starts at percent% and reads stdin. If * stdin is not XXX, then it is interpreted as a percentage, and the display is * updated accordingly. Otherwise the next line is the percentage, and * subsequent lines up to another XXX are used for the new prompt. Note that * the size of the window never changes, so the prompt can not get any larger * than the height and width specified. */ int dialog_gauge(const char *title, const char *cprompt, int height, int width, int percent) { int fkey; int ch, result; void *objptr = dlg_allocate_gauge(title, cprompt, height, width, percent); MY_OBJ *obj = (MY_OBJ *) objptr; dlg_add_callback_ref((DIALOG_CALLBACK **) & obj, my_cleanup); dlg_update_gauge(obj, percent); dlg_trace_win(obj->obj.win); do { ch = dlg_getc(obj->obj.win, &fkey); #ifdef KEY_RESIZE if (fkey && ch == KEY_RESIZE) { MY_OBJ *oldobj = obj; dlg_mouse_free_regions(); obj = dlg_allocate_gauge(title, cprompt, height, width, oldobj->percent); /* avoid breaking new window in dlg_remove_callback */ oldobj->obj.caller = 0; oldobj->obj.input = 0; oldobj->obj.keep_win = FALSE; /* remove the old version of the gauge */ dlg_clear(); dlg_remove_callback(&(oldobj->obj)); refresh(); dlg_add_callback_ref((DIALOG_CALLBACK **) & obj, my_cleanup); dlg_update_gauge(obj, obj->percent); } #endif } while (valid(obj) && handle_my_getc(&(obj->obj), ch, fkey, &result)); dlg_free_gauge(obj); return (DLG_EXIT_OK); }
/* * Display text from a file in a dialog box, like in a "tail -f". */ int dialog_tailbox(const char *title, const char *file, int height, int width, int bg_task) { /* *INDENT-OFF* */ static DLG_KEYS_BINDING binding[] = { HELPKEY_BINDINGS, ENTERKEY_BINDINGS, DLG_KEYS_DATA( DLGK_BEGIN, '0' ), DLG_KEYS_DATA( DLGK_BEGIN, KEY_BEG ), DLG_KEYS_DATA( DLGK_GRID_LEFT, 'H' ), DLG_KEYS_DATA( DLGK_GRID_LEFT, 'h' ), DLG_KEYS_DATA( DLGK_GRID_LEFT, KEY_LEFT ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'L' ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'l' ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_RIGHT ), END_KEYS_BINDING }; /* *INDENT-ON* */ #ifdef KEY_RESIZE int old_height = height; int old_width = width; #endif int fkey; int x, y, result, thigh; WINDOW *dialog, *text; const char **buttons = 0; MY_OBJ *obj; FILE *fd; int min_width = 12; /* Open input file for reading */ if ((fd = fopen(file, "rb")) == NULL) dlg_exiterr("Can't open input file in dialog_tailbox()."); #ifdef KEY_RESIZE retry: #endif dlg_auto_sizefile(title, file, &height, &width, 2, min_width); dlg_print_size(height, width); dlg_ctl_size(height, width); x = dlg_box_x_ordinate(width); y = dlg_box_y_ordinate(height); thigh = height - ((2 * MARGIN) + (bg_task ? 0 : 2)); dialog = dlg_new_window(height, width, y, x); dlg_mouse_setbase(x, y); /* Create window for text region, used for scrolling text */ text = dlg_sub_window(dialog, thigh, width - (2 * MARGIN), y + MARGIN, x + MARGIN); dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); dlg_draw_bottom_box(dialog); dlg_draw_title(dialog, title); dlg_draw_helpline(dialog, FALSE); if (!bg_task) { buttons = dlg_exit_label(); dlg_button_layout(buttons, &min_width); dlg_draw_buttons(dialog, height - (2 * MARGIN), 0, buttons, FALSE, FALSE, width); } (void) wmove(dialog, thigh, (MARGIN + 1)); (void) wnoutrefresh(dialog); obj = dlg_calloc(MY_OBJ, 1); assert_ptr(obj, "dialog_tailbox"); obj->obj.input = fd; obj->obj.win = dialog; obj->obj.handle_getc = handle_my_getc; obj->obj.handle_input = bg_task ? handle_input : 0; obj->obj.keep_bg = bg_task && dialog_vars.cant_kill; obj->obj.bg_task = bg_task; obj->text = text; obj->buttons = buttons; dlg_add_callback(&(obj->obj)); dlg_register_window(dialog, "tailbox", binding); dlg_register_buttons(dialog, "tailbox", buttons); /* Print last page of text */ dlg_attr_clear(text, thigh, getmaxx(text), dialog_attr); repaint_text(obj); if (bg_task) { result = DLG_EXIT_OK; } else { int ch; do { ch = dlg_getc(dialog, &fkey); #ifdef KEY_RESIZE if (fkey && ch == KEY_RESIZE) { /* reset data */ height = old_height; width = old_width; /* repaint */ dlg_clear(); dlg_del_window(dialog); refresh(); dlg_mouse_free_regions(); dlg_button_layout(buttons, &min_width); goto retry; } #endif } while (handle_my_getc(&(obj->obj), ch, fkey, &result)); } dlg_mouse_free_regions(); return result; }
/* * Display a dialog box and get the search term from user. */ static int get_search_term(WINDOW *dialog, char *input, int height, int width) { /* *INDENT-OFF* */ static DLG_KEYS_BINDING binding[] = { INPUTSTR_BINDINGS, HELPKEY_BINDINGS, ENTERKEY_BINDINGS, END_KEYS_BINDING }; /* *INDENT-ON* */ int old_x, old_y; int box_x, box_y; int box_height, box_width; int offset = 0; int key = 0; int fkey = 0; bool first = TRUE; int result = DLG_EXIT_UNKNOWN; const char *caption = _("Search"); int len_caption = dlg_count_columns(caption); const int *indx; int limit; WINDOW *widget; getbegyx(dialog, old_y, old_x); box_height = 1 + (2 * MARGIN); box_width = len_caption + (2 * (MARGIN + 2)); box_width = MAX(box_width, 30); box_width = MIN(box_width, getmaxx(dialog) - 2 * MARGIN); len_caption = MIN(len_caption, box_width - (2 * (MARGIN + 1))); box_x = (width - box_width) / 2; box_y = (height - box_height) / 2; widget = dlg_new_modal_window(dialog, box_height, box_width, old_y + box_y, old_x + box_x); keypad(widget, TRUE); dlg_register_window(widget, "searchbox", binding); dlg_draw_box2(widget, 0, 0, box_height, box_width, searchbox_attr, searchbox_border_attr, searchbox_border2_attr); (void) wattrset(widget, searchbox_title_attr); (void) wmove(widget, 0, (box_width - len_caption) / 2); indx = dlg_index_wchars(caption); limit = dlg_limit_columns(caption, len_caption, 0); (void) waddnstr(widget, caption + indx[0], indx[limit] - indx[0]); box_width -= 2; offset = dlg_count_columns(input); while (result == DLG_EXIT_UNKNOWN) { if (!first) { key = dlg_getc(widget, &fkey); if (fkey) { switch (fkey) { #ifdef KEY_RESIZE case KEY_RESIZE: result = DLG_EXIT_CANCEL; continue; #endif case DLGK_ENTER: result = DLG_EXIT_OK; continue; } } else if (key == ESC) { result = DLG_EXIT_ESC; continue; } else if (key == ERR) { napms(50); continue; } } if (dlg_edit_string(input, &offset, key, fkey, first)) { dlg_show_string(widget, input, offset, searchbox_attr, 1, 1, box_width, FALSE, first); first = FALSE; } } dlg_del_window(widget); return result; }
int mouse_wgetch(WINDOW *win) { int key; #if defined(NCURSES_MOUSE_VERSION) /* before calling this you have to put (only the first time) a "wtimeout(dialog, WTIMEOUT_VAL);" */ do { key = dlg_getc(win); if (key == KEY_MOUSE) { MEVENT event; mseRegion *p; if (getmouse(&event) != ERR && (p = mouse_region(event.y, event.x)) != 0) { key = M_EVENT + p->code; } else { (void) beep(); key = ERR; } } } while (key == ERR); #elif defined(HAVE_LIBGPM) fd_set selSet; int flag, result; int fd = STDIN_FILENO; static Gpm_Event ev; key = 0; if (!gpm_flag || gpm_fd <= -1) return dlg_getc(win); if (gpm_morekeys) return (*gpm_handler) (&ev, gpm_data); gpm_hflag = 0; while (1) { if (gpm_visiblepointer) GPM_DRAWPOINTER(&ev); do { FD_ZERO(&selSet); FD_SET(fd, &selSet); FD_SET(gpm_fd, &selSet); gpm_timeout.tv_usec = WTIMEOUT_VAL * 10000; gpm_timeout.tv_sec = 0; flag = select(5, &selSet, (fd_set *) 0, (fd_set *) 0, &gpm_timeout); /* fprintf(stderr, "X"); */ } while (!flag); if (FD_ISSET(fd, &selSet)) return dlg_getc(win); if (flag == -1) continue; if (Gpm_GetEvent(&ev) && gpm_handler && (result = (*gpm_handler) (&ev, gpm_data))) { gpm_hflag = 1; return result; } } #else /* before calling this you have to put (only the first time) a "wtimeout(dialog, WTIMEOUT_VAL);" */ do { key = dlg_getc(win); } while (key == ERR); #endif return key; }