static char *
input_menu_edit(WINDOW *win, char **items, int choice)
{
    char *result;
    int offset = 0;
    int key = 0, fkey;
    int first = TRUE;
    /* see above */
    int y = ItemToRow(choice);

    result = malloc(dialog_vars.max_input);
    assert_ptr(result, "input_menu_edit");

    dialog_vars.max_input = dialog_vars.max_input;

    /* original item is used to initialize the input string. */
    result[0] = '\0';
    strcpy(result, ItemText(0));

    print_tag(win, items, choice, TRUE);

    /* taken out of inputbox.c - but somewhat modified */
    while (key != '\n' && key != '\r') {
	if (!first)
	    key = mouse_wgetch(win, &fkey);
	if (dlg_edit_string(result, &offset, key, fkey, first)) {
	    /* 
	     * menu_width - 2 ..... it's the actual number of maximal
	     *                      possible characters could be written
	     *                      to the screen.
	     *
	     * item_x - tag_x - 2 . same as "name_width"
	     *                      ( see in dialog_menu() )
	     */
	    dlg_show_string(win, result, offset, item_selected_attr,
			    y, item_x + 1, menu_width - item_x - 3,
			    FALSE, first);
	    first = FALSE;
	}
    }
    return result;
}
Example #2
0
/*
 * 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;
}