]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-widgets.c
configure: Use AC_GNU_SOURCE
[petitboot] / ui / ncurses / nc-widgets.c
index 688722cd69cc7826aba7d8b60dc5f54286bd856f..60f91007ce94f280be21d01f59503cdfb3868d09 100644 (file)
@@ -15,9 +15,9 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define _GNU_SOURCE
-
+#if defined(HAVE_CONFIG_H)
 #include "config.h"
+#endif
 
 #include <linux/input.h> /* This must be included before ncurses.h */
 #if defined HAVE_NCURSESW_CURSES_H
@@ -52,7 +52,6 @@
 #include <log/log.h>
 #include <util/util.h>
 
-#include "config.h"
 #include "nc-cui.h"
 #include "nc-widgets.h"
 
@@ -132,6 +131,11 @@ struct nc_widget_button {
 static void widgetset_add_field(struct nc_widgetset *set, FIELD *field);
 static void widgetset_remove_field(struct nc_widgetset *set, FIELD *field);
 
+static bool key_is_select(int key)
+{
+       return key == ' ' || key == '\r' || key == '\n' || key == KEY_ENTER;
+}
+
 static bool process_key_nop(struct nc_widget *widget __attribute__((unused)),
                FORM *form __attribute((unused)),
                int key __attribute__((unused)))
@@ -206,7 +210,7 @@ static bool checkbox_process_key(struct nc_widget *widget,
 {
        struct nc_widget_checkbox *checkbox = to_checkbox(widget);
 
-       if (key != ' ')
+       if (!key_is_select(key))
                return false;
 
        checkbox->checked = !checkbox->checked;
@@ -361,13 +365,8 @@ static bool select_process_key(struct nc_widget *w, FORM *form, int key)
        int i, new_idx;
        FIELD *field;
 
-       switch (key) {
-       case ' ':
-       case KEY_ENTER:
-               break;
-       default:
+       if (!key_is_select(key))
                return false;
-       }
 
        field = current_field(form);
        new_opt = NULL;
@@ -556,15 +555,11 @@ static bool button_process_key(struct nc_widget *widget,
        if (!button->click)
                return false;
 
-       switch (key) {
-       case ' ':
-       case '\r':
-       case '\n':
-               button->click(button->arg);
-               return true;
-       }
+       if (!key_is_select(key))
+               return false;
 
-       return false;
+       button->click(button->arg);
+       return true;
 }
 
 static int button_destructor(void *ptr)
@@ -694,6 +689,13 @@ struct nc_widgetset *widgetset_create(void *ctx, WINDOW *main, WINDOW *sub)
        return set;
 }
 
+void widgetset_set_windows(struct nc_widgetset *set,
+               WINDOW *main, WINDOW *sub)
+{
+       set->mainwin = main;
+       set->subwin = sub;
+}
+
 void widgetset_set_widget_focus(struct nc_widgetset *set,
                widget_focus_cb cb, void *arg)
 {