📄 formbox.c
字号:
int first = TRUE; int chr_offset = 0; int state = dialog_vars.defaultno ? dlg_defaultno_button() : sTEXT; const int password = 0; int i, x, y, cur_x, cur_y, box_x, box_y; int code; int key = 0; int fkey; int choice = dlg_default_item(items, FORMBOX_TAGS); int new_choice, new_scroll; int scrollamt = 0; int result = DLG_EXIT_UNKNOWN; int min_width = 0, min_height = 0; bool was_autosize = (height == 0 || width == 0); bool show_buttons = FALSE; bool scroll_changed = FALSE; bool field_changed = FALSE; WINDOW *dialog, *form; char *prompt = dlg_strclone(cprompt); const char **buttons = dlg_ok_labels(); FORM_ELT *elt, *current; elt = init_fe(items, item_no, &min_height, &min_width); dlg_tab_correct_str(prompt); dlg_auto_size(title, prompt, &height, &width, 1 + 3 * MARGIN, MAX(26, 2 + min_width)); if (form_height == 0) form_height = min_height; if (was_autosize) { form_height = MIN(SLINES - height, form_height); height += form_height; } else { int thigh = 0; int twide = 0; dlg_auto_size(title, prompt, &thigh, &twide, 0, width); thigh = SLINES - (height - (thigh + 1 + 3 * MARGIN)); form_height = MIN(thigh, form_height); } dlg_print_size(height, width); dlg_ctl_size(height, width); x = dlg_box_x_ordinate(width); y = dlg_box_y_ordinate(height); dialog = dlg_new_window(height, width, y, x); dlg_mouse_setbase(x, y); dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); dlg_draw_bottom_box(dialog); dlg_draw_title(dialog, title); wattrset(dialog, dialog_attr); dlg_print_autowrap(dialog, prompt, height, width); form_width = width - 6; getyx(dialog, cur_y, cur_x); box_y = cur_y + 1; box_x = (width - form_width) / 2 - 1; /* create new window for the form */ form = dlg_sub_window(dialog, form_height, form_width, y + box_y + 1, x + box_x + 1); /* draw a box around the form items */ dlg_draw_box(dialog, box_y, box_x, form_height + 2, form_width + 2, menubox_border_attr, menubox_attr); /* register the new window, along with its borders */ dlg_mouse_mkbigregion(getbegy(form) - getbegy(dialog), getbegx(form) - getbegx(dialog), getmaxy(form), getmaxx(form), KEY_MAX, 1, 1, 3 /* by cells */ ); show_buttons = TRUE; scroll_changed = TRUE; field_changed = TRUE; choice = set_choice(elt, choice, item_no); current = &elt[choice]; wtimeout(dialog, WTIMEOUT_VAL); while (result == DLG_EXIT_UNKNOWN) { int edit = FALSE; if (scroll_changed) { print_form(form, elt, item_no, scrollamt, choice); dlg_draw_arrows(dialog, scrollamt, scrollamt + form_height < item_no, box_x + 1, box_y, box_y + form_height + 1); scroll_changed = FALSE; } if (show_buttons) { dlg_item_help(""); dlg_draw_buttons(dialog, height - 2, 0, buttons, ((state < 0) ? 1000 /* no such button, not highlighted */ : state), FALSE, width); show_buttons = FALSE; } if (field_changed || state == sTEXT) { if (field_changed) chr_offset = 0; current = &elt[choice]; dialog_vars.max_input = current->text_ilen; dlg_item_help(current->help); dlg_show_string(form, current->text, chr_offset, form_active_text_attr, current->text_y - scrollamt, current->text_x, current->text_flen, password, first); field_changed = FALSE; } key = dlg_mouse_wgetch(dialog, &fkey); /* handle non-functionkeys */ if (!fkey) { if (state != sTEXT) { code = dlg_char_to_button(key, buttons); if (code >= 0) { dlg_del_window(dialog); result = code; continue; } } fkey = TRUE; switch (key) { case ESC: result = DLG_EXIT_ESC; continue; case CHR_NEXT: key = KEY_NEXT; break; case CHR_PREVIOUS: key = KEY_PREVIOUS; break; case ' ': if (state == sTEXT) { fkey = FALSE; break; } /* FALLTHRU */ case '\n': case '\r': key = KEY_ENTER; break; case TAB: state = dlg_next_ok_buttonindex(state, sTEXT); show_buttons = TRUE; continue; default: fkey = FALSE; break; } } /* handle functionkeys */ if (fkey) { bool do_scroll = FALSE; bool do_tab = FALSE; int move_by = 0; switch (key) { case M_EVENT + KEY_PPAGE: case KEY_PPAGE: do_scroll = TRUE; move_by = -form_height; break; case M_EVENT + KEY_NPAGE: case KEY_NPAGE: do_scroll = TRUE; move_by = form_height; break; case KEY_ENTER: dlg_del_window(dialog); result = (state >= 0) ? dlg_ok_buttoncode(state) : DLG_EXIT_OK; continue; case KEY_LEFT: if (state == sTEXT) break; /* FALLTHRU */ case KEY_UP: case KEY_PREVIOUS: if (state == sTEXT) { do_tab = TRUE; move_by = -1; break; } else { state = dlg_prev_ok_buttonindex(state, 0); show_buttons = TRUE; continue; } case KEY_BTAB: state = dlg_prev_ok_buttonindex(state, sTEXT); show_buttons = TRUE; continue; case KEY_RIGHT: if (state == sTEXT) break; /* FALLTHRU */ case KEY_DOWN: case KEY_NEXT: if (state == sTEXT) { do_tab = TRUE; move_by = 1; break; } else { state = dlg_next_ok_buttonindex(state, 0); show_buttons = TRUE; continue; } default:#if USE_MOUSE if (key >= M_EVENT) { if (key >= M_EVENT + KEY_MAX) { int cell = key - (M_EVENT + KEY_MAX); int row = (cell / getmaxx(form)) + scrollamt; int col = (cell % getmaxx(form)); int n; for (n = 0; n < item_no; ++n) { if (elt[n].name_y == row && elt[n].name_x <= col && (elt[n].name_x + elt[n].name_len > col || (elt[n].name_y == elt[n].text_y && elt[n].text_x > col))) { field_changed = TRUE; break; } if (elt[n].text_y == row && elt[n].text_x <= col && elt[n].text_x + elt[n].text_ilen > col) { field_changed = TRUE; break; } } if (field_changed) { print_item(form, elt + choice, scrollamt, FALSE); choice = n; continue; } beep(); } else if ((code = dlg_ok_buttoncode(key - M_EVENT)) >= 0) { result = code; } continue; }#endif break; } new_scroll = scrollamt; new_choice = choice; if (do_scroll) { if (scroll_next(form, elt, move_by, &new_choice, &new_scroll)) { if (choice != new_choice) { choice = new_choice; field_changed = TRUE; } if (scrollamt != new_scroll) { scrollamt = new_scroll; scroll_changed = TRUE; } } continue; } if (do_tab) { if (tab_next(form, elt, item_no, move_by, &new_choice, &new_scroll)) { if (choice != new_choice) { choice = new_choice; field_changed = TRUE; } if (scrollamt != new_scroll) { scrollamt = new_scroll; scroll_changed = TRUE; } } continue; } } if (state == sTEXT) { /* Input box selected */ edit = dlg_edit_string(current->text, &chr_offset, key, fkey, first); if (edit) { dlg_show_string(form, current->text, chr_offset, form_active_text_attr, current->text_y - scrollamt, current->text_x, current->text_flen, password, first); continue; } } } for (i = 0; i < item_no; i++) { if (elt[i].text_flen != 0) { dlg_add_result(elt[i].text); dlg_add_result("\n"); free(elt[i].text); } } free(elt); dlg_mouse_free_regions(); dlg_del_window(dialog); free(prompt); return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -