X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fnc-widgets.c;h=93c882b0849af43a00cbe417584e7edd375eb46b;hp=50909ab6c4af459261cb681995ff4bfe35f1ee35;hb=18a47a31b46d916c58a31e8784a7c3a3abcae446;hpb=96f9b8cd29dae248838d4221f3cb1c38e3aa1396 diff --git a/ui/ncurses/nc-widgets.c b/ui/ncurses/nc-widgets.c index 50909ab..93c882b 100644 --- a/ui/ncurses/nc-widgets.c +++ b/ui/ncurses/nc-widgets.c @@ -53,6 +53,7 @@ #include #include #include +#include #include "nc-cui.h" #include "nc-widgets.h" @@ -83,6 +84,7 @@ struct nc_widgetset { /* custom validators */ FIELDTYPE *ipv4_multi_type; + FIELDTYPE *url_type; }; struct nc_widget { @@ -337,6 +339,14 @@ static bool textbox_process_key( case KEY_DC: form_driver(form, REQ_DEL_CHAR); break; + case '\t': + case KEY_BTAB: + case KEY_UP: + case KEY_DOWN: + case KEY_PPAGE: + case KEY_NPAGE: + /* Don't catch navigational keys */ + return false; default: form_driver(form, key); break; @@ -391,6 +401,20 @@ void widget_textbox_set_validator_integer(struct nc_widget_textbox *textbox, set_field_type(textbox->widget.field, TYPE_INTEGER, 1, min, max); } +static bool check_url_field(FIELD *field, + const void *arg __attribute__((unused))) +{ + return is_url(field_buffer(field, 0)); +} + +void widget_textbox_set_validator_url(struct nc_widget_textbox *textbox) +{ + if (!textbox->set->url_type) + textbox->set->url_type = new_fieldtype(check_url_field, NULL); + + set_field_type(textbox->widget.field, textbox->set->url_type); +} + void widget_textbox_set_validator_ipv4(struct nc_widget_textbox *textbox) { set_field_type(textbox->widget.field, TYPE_IPV4); @@ -466,6 +490,7 @@ static void subset_delete_active(struct nc_widget_subset *subset, int idx) struct nc_widget *widget; size_t rem; int i, val; + uint32_t opts; /* Shift field focus to nearest active option or next visible field */ if (subset->n_active > 1) { @@ -477,8 +502,11 @@ static void subset_delete_active(struct nc_widget_subset *subset, int idx) } else { for (i = 0; i < set->n_fields; i++) if (field_visible(set->fields[i])) { - set->cur_field = set->fields[i]; - break; + opts = field_opts(set->fields[i]); + if ((opts & O_ACTIVE) == O_ACTIVE) { + set->cur_field = set->fields[i]; + break; + } } } @@ -1106,6 +1134,12 @@ bool widgetset_process_key(struct nc_widgetset *set, int key) field = current_field(set->form); assert(field); + widget = field_userptr(field); + + if (widget->process_key) + if (widget->process_key(widget, set->form, key)) + return true; + tab = false; /* handle field change events */ @@ -1114,14 +1148,12 @@ bool widgetset_process_key(struct nc_widgetset *set, int key) tab = true; /* fall through */ case KEY_UP: - case KEY_LEFT: req = REQ_SPREV_FIELD; break; case '\t': tab = true; /* fall through */ case KEY_DOWN: - case KEY_RIGHT: req = REQ_SNEXT_FIELD; break; case KEY_PPAGE: @@ -1130,9 +1162,14 @@ bool widgetset_process_key(struct nc_widgetset *set, int key) case KEY_NPAGE: req = REQ_SLAST_FIELD; break; + case KEY_LEFT: + req = REQ_LEFT_FIELD; + break; + case KEY_RIGHT: + req = REQ_RIGHT_FIELD; + break; } - widget = field_userptr(field); if (req) { widget_focus_change(widget, field, false); form_driver(set->form, req); @@ -1157,10 +1194,7 @@ bool widgetset_process_key(struct nc_widgetset *set, int key) return true; } - if (!widget->process_key) - return false; - - return widget->process_key(widget, set->form, key); + return false; } static int widgetset_destructor(void *ptr)