2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2021-2023 Alfonso Sabato Siciliano
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include "bsddialog.h"
34 #include "bsddialog_theme.h"
46 const char *label; /* formitem.label */
47 unsigned int ylabel; /* formitem.ylabel */
48 unsigned int xlabel; /* formitem.xlabel */
49 unsigned int yfield; /* formitem.yfield */
50 unsigned int xfield; /* formitem.xfield */
51 bool secure; /* formitem.flags & BSDDIALOG_FIELDHIDDEN */
52 bool readonly; /* formitem.flags & BSDDIALOG_FIELDREADONLY */
53 bool fieldnocolor; /* formitem.flags & BSDDIALOG_FIELDNOCOLOR */
54 bool extendfield; /* formitem.flags & BSDDIALOG_FIELDEXTEND */
55 bool fieldonebyte; /* formitem.flags & BSDDIALOG_FIELDSINGLEBYTE */
56 bool cursorend; /* formitem.flags & BSDDIALOG_FIELDCURSOREND */
57 bool cursor; /* field cursor visibility */
58 const char *bottomdesc; /* formitem.bottomdesc */
60 wchar_t *privwbuf; /* formitem.value */
61 wchar_t *pubwbuf; /* string for drawitem() */
62 unsigned int maxletters; /* formitem.maxvaluelen, [priv|pub]wbuf size */
63 unsigned int nletters; /* letters in privwbuf and pubwbuf */
64 unsigned int pos; /* pos in privwbuf and pubwbuf */
65 unsigned int fieldcols; /* formitem.fieldlen */
66 unsigned int xcursor; /* position in fieldcols [0 - fieldcols-1] */
67 unsigned int xposdraw; /* first pubwbuf index to draw */
71 WINDOW *box; /* window to draw borders */
73 unsigned int h; /* only to create pad */
74 unsigned int w; /* only to create pad */
75 unsigned int wmin; /* to refresh, w can change for FIELDEXTEND */
76 unsigned int ys; /* to refresh */
77 unsigned int ye; /* to refresh */
78 unsigned int xs; /* to refresh */
79 unsigned int xe; /* to refresh */
80 unsigned int y; /* changes moving focus around items */
81 unsigned int formheight; /* API formheight */
82 unsigned int viewrows; /* visible rows, real formheight */
83 unsigned int minviewrows; /* min viewrows, ylabel != yfield */
84 wchar_t securewch; /* wide char of conf.form.secure[mb]ch */
85 unsigned int nitems; /* like API nkitems */
86 struct privateitem *pritems;
87 int sel; /* selected item in pritem, can be -1 */
88 bool hasbottomdesc; /* some item has bottomdesc */
92 build_privateform(struct bsddialog_conf*conf, unsigned int nitems,
93 struct bsddialog_formitem *items, struct privateform *f)
97 unsigned int i, j, itemybeg, itemxbeg, tmp;
99 struct privateitem *item;
102 CHECK_ARRAY(nitems, items);
103 for (i = 0; i < nitems; i++) {
104 if (items[i].maxvaluelen == 0)
105 RETURN_FMTERROR("item %u [0-%u] maxvaluelen = 0",
107 if (items[i].fieldlen == 0)
108 RETURN_FMTERROR("item %u [0-%u] fieldlen = 0",
114 insecurecursor = false;
115 if (conf->form.securembch != NULL) {
116 mbchsize = mblen(conf->form.securembch, MB_LEN_MAX);
117 if(mbtowc(&f->securewch, conf->form.securembch, mbchsize) < 0)
118 RETURN_ERROR("Cannot convert securembch to wchar_t");
119 insecurecursor = true;
120 } else if (conf->form.securech != '\0') {
121 f->securewch = btowc(conf->form.securech);
122 insecurecursor = true;
127 /* alloc and set private items */
128 f->pritems = malloc(f->nitems * sizeof(struct privateitem));
129 if (f->pritems == NULL)
130 RETURN_ERROR("Cannot allocate internal form.pritems");
131 f->hasbottomdesc = false;
132 f->h = f->w = f->minviewrows = 0;
133 for (i = 0; i < f->nitems; i++) {
134 item = &f->pritems[i];
135 item->label = CHECK_STR(items[i].label);
136 item->ylabel = items[i].ylabel;
137 item->xlabel = items[i].xlabel;
138 item->yfield = items[i].yfield;
139 item->xfield = items[i].xfield;
140 item->secure = items[i].flags & BSDDIALOG_FIELDHIDDEN;
141 item->readonly = items[i].flags & BSDDIALOG_FIELDREADONLY;
142 item->fieldnocolor = items[i].flags & BSDDIALOG_FIELDNOCOLOR;
143 item->extendfield = items[i].flags & BSDDIALOG_FIELDEXTEND;
144 item->fieldonebyte = items[i].flags &
145 BSDDIALOG_FIELDSINGLEBYTE;
146 item->cursorend = items[i].flags & BSDDIALOG_FIELDCURSOREND;
147 item->bottomdesc = CHECK_STR(items[i].bottomdesc);
148 if (items[i].bottomdesc != NULL)
149 f->hasbottomdesc = true;
150 if (item->readonly || (item->secure && !insecurecursor))
151 item->cursor = false;
155 item->maxletters = items[i].maxvaluelen;
156 item->privwbuf = calloc(item->maxletters + 1, sizeof(wchar_t));
157 if (item->privwbuf == NULL)
158 RETURN_ERROR("Cannot allocate item private buffer");
159 memset(item->privwbuf, 0, item->maxletters + 1);
160 item->pubwbuf = calloc(item->maxletters + 1, sizeof(wchar_t));
161 if (item->pubwbuf == NULL)
162 RETURN_ERROR("Cannot allocate item private buffer");
163 memset(item->pubwbuf, 0, item->maxletters + 1);
165 if ((winit = alloc_mbstows(CHECK_STR(items[i].init))) == NULL)
166 RETURN_ERROR("Cannot allocate item.init in wchar_t*");
167 wcsncpy(item->privwbuf, winit, item->maxletters);
168 wcsncpy(item->pubwbuf, winit, item->maxletters);
170 item->nletters = wcslen(item->pubwbuf);
172 for (j = 0; j < item->nletters; j++)
173 item->pubwbuf[j] = f->securewch;
176 item->fieldcols = items[i].fieldlen;
181 /* size and position */
182 f->h = MAX(f->h, item->ylabel);
183 f->h = MAX(f->h, item->yfield);
184 f->w = MAX(f->w, item->xlabel + strcols(item->label));
185 f->w = MAX(f->w, item->xfield + item->fieldcols);
187 itemybeg = MIN(item->ylabel, item->yfield);
188 itemxbeg = MIN(item->xlabel, item->xfield);
190 tmp = MIN(item->ylabel, item->yfield);
191 itemybeg = MIN(itemybeg, tmp);
192 tmp = MIN(item->xlabel, item->xfield);
193 itemxbeg = MIN(itemxbeg, tmp);
195 tmp = abs((int)item->ylabel - (int)item->yfield);
196 f->minviewrows = MAX(f->minviewrows, tmp);
199 f->h = f->h + 1 - itemybeg;
204 for (i = 0; i < f->nitems; i++) {
205 f->pritems[i].ylabel -= itemybeg;
206 f->pritems[i].yfield -= itemybeg;
207 f->pritems[i].xlabel -= itemxbeg;
208 f->pritems[i].xfield -= itemxbeg;
214 static bool fieldctl(struct privateitem *item, enum field_action act)
217 int width, oldwidth, nextwidth, cols;
222 case MOVE_CURSOR_BEGIN:
223 if (item->pos == 0 && item->xcursor == 0)
225 /* here the cursor is changed */
231 case MOVE_CURSOR_END:
232 while (fieldctl(item, MOVE_CURSOR_RIGHT))
235 case MOVE_CURSOR_LEFT:
238 /* check redundant by item->pos == 0 because of 'while' below */
239 if (item->xcursor == 0 && item->xposdraw == 0)
241 /* here some letter to left */
244 width = wcwidth(item->pubwbuf[item->pos]);
245 if (((int)item->xcursor) - width < 0) {
249 item->xcursor -= width;
252 if (item->xposdraw == 0)
254 if (item->xcursor >= item->fieldcols / 2)
256 if (wcwidth(item->pubwbuf[item->xposdraw - 1]) +
257 item->xcursor + width > item->fieldcols)
262 wcwidth(item->pubwbuf[item->xposdraw]);
266 if (item->nletters == 0)
268 if (item->pos == item->nletters)
270 /* here a letter under the cursor */
272 for (i = item->pos; i < item->nletters; i++) {
273 item->privwbuf[i] = item->privwbuf[i+1];
274 item->pubwbuf[i] = item->pubwbuf[i+1];
277 item->privwbuf[i] = L'\0';
278 item->pubwbuf[i] = L'\0';
280 case MOVE_CURSOR_RIGHT: /* used also by "insert", see handler loop */
281 if (item->pos + 1 == item->maxletters)
283 if (item->pos == item->nletters)
285 /* here a change to right */
287 oldwidth = wcwidth(item->pubwbuf[item->pos]);
289 if (item->pos == item->nletters) { /* empty column */
291 } else { /* a letter to right */
292 nextwidth = wcwidth(item->pubwbuf[item->pos]);
294 if (item->xcursor + oldwidth + nextwidth - 1 >= item->fieldcols) {
296 item->xposdraw = item->pos;
297 while (item->xposdraw != 0) {
298 cols += wcwidth(item->pubwbuf[item->xposdraw - 1]);
299 if (cols > (int)item->fieldcols)
304 for (i = item->xposdraw; i < item->pos ; i++)
305 item->xcursor += wcwidth(item->pubwbuf[i]);
308 item->xcursor += oldwidth;
317 static bool insertch(struct privateitem *item, wchar_t wch, wchar_t securewch)
321 if (item->nletters >= item->maxletters)
324 for (i = (int)item->nletters - 1; i >= (int)item->pos; i--) {
325 item->privwbuf[i+1] = item->privwbuf[i];
326 item->pubwbuf[i+1] = item->pubwbuf[i];
329 item->privwbuf[item->pos] = wch;
330 item->pubwbuf[item->pos] = item->secure ? securewch : wch;
332 item->privwbuf[item->nletters] = L'\0';
333 item->pubwbuf[item->nletters] = L'\0';
338 static char* alloc_wstomb(wchar_t *wstr)
341 char mbch[MB_LEN_MAX], *mbstr;
343 nbytes = MB_LEN_MAX; /* to ensure a null terminated string */
345 for (i = 0; i < len; i++) {
346 wctomb(mbch, wstr[i]);
347 nbytes += mblen(mbch, MB_LEN_MAX);
349 if((mbstr = malloc(nbytes)) == NULL)
352 wcstombs(mbstr, wstr, nbytes);
358 return_values(struct bsddialog_conf *conf, struct privateform *f,
359 struct bsddialog_formitem *items)
363 for (i = 0; i < f->nitems; i++) {
364 if (conf->form.value_wchar)
365 items[i].value = (char*)wcsdup(f->pritems[i].privwbuf);
367 items[i].value = alloc_wstomb(f->pritems[i].privwbuf);
369 if (items[i].value == NULL)
371 "Cannot allocate memory for item[%d].value", i);
377 static void set_first_with_default(struct privateform *f, int *focusitem)
382 if(focusitem != NULL && *focusitem >=0 && *focusitem < (int)f->nitems)
383 if (f->pritems[*focusitem].readonly == false) {
387 for (i = 0 ; i < f->nitems; i++)
388 if (f->pritems[i].readonly == false) {
394 static unsigned int firstitem(unsigned int nitems, struct privateitem *items)
398 for (i = 0; i < (int)nitems; i++)
399 if (items[i].readonly == false)
405 static unsigned int lastitem(unsigned int nitems, struct privateitem *items)
409 for (i = nitems - 1; i >= 0 ; i--)
410 if (items[i].readonly == false)
417 previtem(unsigned int nitems, struct privateitem *items, int curritem)
421 for (i = curritem - 1; i >= 0; i--)
422 if (items[i].readonly == false)
425 for (i = nitems - 1; i > curritem - 1; i--)
426 if (items[i].readonly == false)
433 nextitem(unsigned int nitems, struct privateitem *items, int curritem)
437 for (i = curritem + 1; i < (int)nitems; i++)
438 if (items[i].readonly == false)
441 for (i = 0; i < curritem; i++)
442 if (items[i].readonly == false)
448 static void redrawbuttons(struct dialog *d, bool focus, bool shortcut)
452 selected = d->bs.curr;
455 d->bs.shortcut = shortcut;
457 d->bs.curr = selected;
461 drawitem(struct privateform *f, int idx, bool focus)
464 unsigned int n, cols;
465 struct privateitem *item;
467 item = &f->pritems[idx];
470 wattron(f->pad, t.dialog.color);
471 mvwaddstr(f->pad, item->ylabel, item->xlabel, item->label);
472 wattroff(f->pad, t.dialog.color);
476 color = t.form.readonlycolor;
477 else if (item->fieldnocolor)
478 color = t.dialog.color;
480 color = focus ? t.form.f_fieldcolor : t.form.fieldcolor;
481 wattron(f->pad, color);
482 mvwhline(f->pad, item->yfield, item->xfield, ' ', item->fieldcols);
484 cols = wcwidth(item->pubwbuf[item->xposdraw]);
485 while (cols <= item->fieldcols &&
486 item->xposdraw + n < wcslen(item->pubwbuf)) {
488 cols += wcwidth(item->pubwbuf[item->xposdraw + n]);
491 mvwaddnwstr(f->pad, item->yfield, item->xfield,
492 &item->pubwbuf[item->xposdraw], n);
493 wattroff(f->pad, color);
496 if (f->hasbottomdesc) {
497 move(SCREENLINES - 1, 2);
499 if (item->bottomdesc != NULL && focus) {
500 attron(t.form.bottomdesccolor);
501 addstr(item->bottomdesc);
502 attroff(t.form.bottomdesccolor);
508 curs_set((focus && item->cursor) ? 1 : 0);
509 wmove(f->pad, item->yfield, item->xfield + item->xcursor);
513 * Trick: draw 2 times an item switching focus.
514 * Problem: curses tries to optimize the rendering but sometimes it misses some
515 * updates or draws old stuff. libformw has a similar problem fixed by the
517 * Case 1: KEY_DC and KEY_BACKSPACE, deleted multicolumn letters are drawn
518 * again. It seems fixed by new items pad and prefresh(), previously WINDOW.
519 * Case2: some terminal, tmux and ssh does not show the cursor.
521 #define DRAWITEM_TRICK(f, idx, focus) do { \
522 drawitem(f, idx, !focus); \
523 prefresh((f)->pad, (f)->y, 0, (f)->ys, (f)->xs, (f)->ye, (f)->xe); \
524 drawitem(f, idx, focus); \
525 prefresh((f)->pad, (f)->y, 0, (f)->ys, (f)->xs, (f)->ye, (f)->xe); \
528 static void update_formbox(struct bsddialog_conf *conf, struct privateform *f)
532 getmaxyx(f->box, h, w);
533 draw_borders(conf, f->box, LOWERED);
535 if (f->viewrows < f->h) {
536 wattron(f->box, t.dialog.arrowcolor);
538 mvwhline(f->box, 0, (w / 2) - 2,
539 conf->ascii_lines ? '^' : ACS_UARROW, 5);
541 if (f->y + f->viewrows < f->h)
542 mvwhline(f->box, h-1, (w / 2) - 2,
543 conf->ascii_lines ? 'v' : ACS_DARROW, 5);
544 wattroff(f->box, t.dialog.arrowcolor);
548 static void curriteminview(struct privateform *f, struct privateitem *item)
550 unsigned int yup, ydown;
552 yup = MIN(item->ylabel, item->yfield);
553 ydown = MAX(item->ylabel, item->yfield);
555 /* selected item in view */
556 if (f->y > yup && f->y > 0)
558 if ((int)(f->y + f->viewrows) - 1 < (int)ydown)
559 f->y = ydown - f->viewrows + 1;
560 /* lower pad after a terminal expansion */
561 if (f->y > 0 && (f->h - f->y) < f->viewrows)
562 f->y = f->h - f->viewrows;
565 static int form_size_position(struct dialog *d, struct privateform *f)
569 if (set_widget_size(d->conf, d->rows, d->cols, &d->h, &d->w) != 0)
570 return (BSDDIALOG_ERROR);
573 hform = (int) f->viewrows;
574 if (f->viewrows == BSDDIALOG_AUTOSIZE)
575 hform = MAX(f->h, f->minviewrows);
576 hform += 2; /* formborders */
578 if (set_widget_autosize(d->conf, d->rows, d->cols, &d->h, &d->w,
579 d->text, &htext, &d->bs, hform, f->w + 4) != 0)
580 return (BSDDIALOG_ERROR);
581 /* formheight: avoid overflow, "at most" and at least minviewrows */
582 if (d->h - BORDERS - htext - HBUTTONS < 2 + (int)f->minviewrows) {
583 f->viewrows = f->minviewrows; /* for widget_checksize() */
584 } else if (f->viewrows == BSDDIALOG_AUTOSIZE) {
585 f->viewrows = MIN(d->h - BORDERS - htext - HBUTTONS, hform) - 2;
586 f->viewrows = MAX(f->viewrows, f->minviewrows);
588 f->viewrows = MIN(d->h - BORDERS - htext - HBUTTONS, hform) - 2;
592 if (f->viewrows < f->minviewrows)
593 RETURN_FMTERROR("formheight, current: %u needed at least %u",
594 f->viewrows, f->minviewrows);
595 if (widget_checksize(d->h, d->w, &d->bs,
596 2 /* borders */ + f->minviewrows, f->w + 4) != 0)
597 return (BSDDIALOG_ERROR);
599 if (set_widget_position(d->conf, &d->y, &d->x, d->h, d->w) != 0)
600 return (BSDDIALOG_ERROR);
606 form_redraw(struct dialog *d, struct privateform *f, bool focusinform)
612 refresh(); /* Important for decreasing screen */
614 f->viewrows = f->formheight;
616 if (form_size_position(d, f) != 0)
617 return (BSDDIALOG_ERROR);
618 if (draw_dialog(d) != 0)
619 return (BSDDIALOG_ERROR);
621 refresh(); /* Important to fix grey lines expanding screen */
622 TEXTPAD(d, 2 /* box borders */ + f->viewrows + HBUTTONS);
624 update_box(d->conf, f->box, d->y + d->h - 5 - f->viewrows, d->x + 2,
625 f->viewrows + 2, d->w - 4, LOWERED);
627 for (i = 0; i < f->nitems; i++) {
628 fieldctl(&f->pritems[i], MOVE_CURSOR_BEGIN);
629 if (f->pritems[i].extendfield) {
631 f->pritems[i].fieldcols = f->w - f->pritems[i].xfield;
633 if (f->pritems[i].cursorend)
634 fieldctl(&f->pritems[i], MOVE_CURSOR_END);
637 wresize(f->pad, f->h, f->w);
638 for (i = 0; i < f->nitems; i++)
639 drawitem(f, i, false);
641 f->ys = d->y + d->h - 5 - f->viewrows + 1;
642 f->ye = d->y + d->h - 5 ;
643 if ((int)f->w >= d->w - 6) { /* left */
645 f->xe = f->xs + d->w - 7;
646 } else { /* center */
647 f->xs = d->x + 3 + (d->w - 6)/2 - f->w/2;
648 f->xe = f->xs + d->w - 5;
651 if (f->sel != -1) { /* at least 1 writable item */
653 d->conf->button.always_active || !focusinform,
655 wnoutrefresh(d->widget);
656 curriteminview(f, &f->pritems[f->sel]);
657 update_formbox(d->conf, f);
658 wnoutrefresh(f->box);
659 DRAWITEM_TRICK(f, f->sel, focusinform);
660 } else if (f->sel == -1 && f->nitems > 0) { /* all read only */
661 redrawbuttons(d, true, true);
662 wnoutrefresh(d->widget);
663 update_formbox(d->conf, f);
664 wnoutrefresh(f->box);
665 DRAWITEM_TRICK(f, 0, false); /* to refresh pad*/
666 } else { /* no item */
667 wnoutrefresh(f->box);
675 bsddialog_form(struct bsddialog_conf *conf, const char *text, int rows,
676 int cols, unsigned int formheight, unsigned int nitems,
677 struct bsddialog_formitem *items, int *focusitem)
679 bool switchfocus, changeitem, focusinform, loop;
680 int next, retval, wchtype;
683 struct privateitem *item;
684 struct privateform form;
687 if (prepare_dialog(conf, text, rows, cols, &d) != 0)
688 return (BSDDIALOG_ERROR);
689 set_buttons(&d, true, OK_LABEL, CANCEL_LABEL);
691 if (build_privateform(conf, nitems, items, &form) != 0)
692 return (BSDDIALOG_ERROR);
694 if ((form.box = newwin(1, 1, 1, 1)) == NULL)
695 RETURN_ERROR("Cannot build WINDOW form box");
696 wbkgd(form.box, t.dialog.color);
697 if ((form.pad = newpad(1, 1)) == NULL)
698 RETURN_ERROR("Cannot build WINDOW form pad");
699 wbkgd(form.pad, t.dialog.color);
701 set_first_with_default(&form, focusitem);
702 if (form.sel != -1) {
705 item = &form.pritems[form.sel];
711 form.formheight = formheight;
712 if (form_redraw(&d, &form, focusinform) != 0)
713 return (BSDDIALOG_ERROR);
715 changeitem = switchfocus = false;
719 if ((wchtype = get_wch(&input)) == ERR)
724 if (focusinform && conf->button.always_active == false)
726 retval = BUTTONVALUE(d.bs);
730 if (conf->key.enable_esc) {
731 retval = BSDDIALOG_ESC;
739 if (d.bs.curr + 1 < (int)d.bs.nbuttons) {
743 if (form.sel != -1) {
747 redrawbuttons(&d, true, true);
748 wnoutrefresh(d.widget);
753 if(fieldctl(item, MOVE_CURSOR_LEFT))
754 DRAWITEM_TRICK(&form, form.sel, true);
755 } else if (d.bs.curr > 0) {
757 redrawbuttons(&d, true, true);
758 wnoutrefresh(d.widget);
759 } else if (form.sel != -1) {
765 if(fieldctl(item, MOVE_CURSOR_RIGHT))
766 DRAWITEM_TRICK(&form, form.sel, true);
767 } else if (d.bs.curr < (int) d.bs.nbuttons - 1) {
769 redrawbuttons(&d, true, true);
770 wnoutrefresh(d.widget);
771 } else if (form.sel != -1) {
777 next = previtem(form.nitems, form.pritems,
779 changeitem = form.sel != next;
780 } else if (form.sel != -1) {
785 if (focusinform == false)
787 if (form.nitems == 1) {
790 next = nextitem(form.nitems, form.pritems,
792 changeitem = form.sel != next;
797 next = firstitem(form.nitems, form.pritems);
798 changeitem = form.sel != next;
803 next = lastitem(form.nitems, form.pritems);
804 changeitem = form.sel != next;
808 case 127: /* Backspace */
809 if (focusinform == false)
811 if(fieldctl(item, MOVE_CURSOR_LEFT))
812 if(fieldctl(item, DEL_LETTER))
813 DRAWITEM_TRICK(&form, form.sel, true);
816 if (focusinform == false)
818 if(fieldctl(item, DEL_LETTER))
819 DRAWITEM_TRICK(&form, form.sel, true);
822 if (focusinform == false)
824 if(fieldctl(item, MOVE_CURSOR_BEGIN))
825 DRAWITEM_TRICK(&form, form.sel, true);
828 if (focusinform == false)
830 if (fieldctl(item, MOVE_CURSOR_END))
831 DRAWITEM_TRICK(&form, form.sel, true);
834 if (conf->key.f1_file == NULL &&
835 conf->key.f1_message == NULL)
838 if (f1help_dialog(conf) != 0) {
839 retval = BSDDIALOG_ERROR;
842 if (form_redraw(&d, &form, focusinform) != 0)
843 return (BSDDIALOG_ERROR);
846 if (form_redraw(&d, &form, focusinform) != 0)
847 return (BSDDIALOG_ERROR);
850 if (wchtype == KEY_CODE_YES)
853 if (item->fieldonebyte && wctob(input) == EOF)
856 * MOVE_CURSOR_RIGHT manages new positions
857 * because the cursor remains on the new letter,
858 * "if" and "while" update the positions.
860 if(insertch(item, input, form.securewch)) {
861 fieldctl(item, MOVE_CURSOR_RIGHT);
863 * no if(fieldctl), update always
864 * because it fails with maxletters.
866 DRAWITEM_TRICK(&form, form.sel, true);
869 if (shortcut_buttons(input, &d.bs)) {
872 retval = BUTTONVALUE(d.bs);
877 } /* end switch get_wch() */
880 focusinform = !focusinform;
883 conf->button.always_active || !focusinform,
885 wnoutrefresh(d.widget);
886 DRAWITEM_TRICK(&form, form.sel, focusinform);
891 DRAWITEM_TRICK(&form, form.sel, false);
893 item = &form.pritems[form.sel];
894 curriteminview(&form, item);
895 update_formbox(conf, &form);
896 wnoutrefresh(form.box);
897 DRAWITEM_TRICK(&form, form.sel, true);
900 } /* end while(loop) */
904 if (return_values(conf, &form, items) == BSDDIALOG_ERROR)
905 return (BSDDIALOG_ERROR);
907 if (focusitem != NULL)
908 *focusitem = form.sel;
910 if (form.hasbottomdesc && conf->clear) {
911 move(SCREENLINES - 1, 2);
914 for (i = 0; i < form.nitems; i++) {
915 free(form.pritems[i].privwbuf);
916 free(form.pritems[i].pubwbuf);