ui/ncurses: allow tab/backtab to skip through a widget's fields
[petitboot] / ui / ncurses / nc-widgets.c
index 2829040b46ba236a7ad01e9e1dd828d0199ac7d9..5592db9c7769a3c68fc03497776f469d208d0abc 100644 (file)
@@ -353,6 +353,11 @@ struct nc_widget_textbox *widget_new_textbox(struct nc_widgetset *set,
        return textbox;
 }
 
+void widget_textbox_set_fixed_size(struct nc_widget_textbox *textbox)
+{
+       field_opts_on(textbox->widget.field, O_STATIC);
+}
+
 void widget_textbox_set_validator_integer(struct nc_widget_textbox *textbox,
                long min, long max)
 {
@@ -684,19 +689,26 @@ static void widget_focus_change(struct nc_widget *widget, FIELD *field,
 bool widgetset_process_key(struct nc_widgetset *set, int key)
 {
        struct nc_widget *widget;
-       FIELD *field;
+       FIELD *field, *tmp;
        int req = 0;
+       bool tab;
 
        field = current_field(set->form);
        assert(field);
 
+       tab = false;
+
        /* handle field change events */
        switch (key) {
        case KEY_BTAB:
+               tab = true;
+               /* fall through */
        case KEY_UP:
                req = REQ_PREV_FIELD;
                break;
        case '\t':
+               tab = true;
+               /* fall through */
        case KEY_DOWN:
                req = REQ_NEXT_FIELD;
                break;
@@ -712,8 +724,18 @@ bool widgetset_process_key(struct nc_widgetset *set, int key)
        if (req) {
                widget_focus_change(widget, field, false);
                form_driver(set->form, req);
-               form_driver(set->form, REQ_END_FIELD);
+
+               /* if we're doing a tabbed-field-change, skip until we
+                * see the next widget */
+               tmp = field;
                field = current_field(set->form);
+
+               for (; tab && tmp != field && field_userptr(field) == widget;) {
+                       form_driver(set->form, req);
+                       field = current_field(set->form);
+               }
+
+               form_driver(set->form, REQ_END_FIELD);
                widget = field_userptr(field);
                widget_focus_change(widget, field, true);
                if (widget->field_focus)