[hci] Draw all widgets on the standard screen
The curses concept of a window has been supported but never actively
used in iPXE since the mucurses library was first implemented in 2006.
Simplify the code by removing the ability to place a widget set in a
specified window, and instead use the standard screen for all drawing
operations.
This simplification allows the widget set parameter to be omitted for
the draw_widget() and edit_widget() operations, since the only reason
for its inclusion was to provide access to the specified window.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
diff --git a/src/hci/mucurses/widgets/editbox.c b/src/hci/mucurses/widgets/editbox.c
index 79e7cdd..c024688 100644
--- a/src/hci/mucurses/widgets/editbox.c
+++ b/src/hci/mucurses/widgets/editbox.c
@@ -39,10 +39,9 @@
/**
* Draw text box widget
*
- * @v widgets Text widget set
* @v widget Text widget
*/
-static void draw_editbox ( struct widgets *widgets, struct widget *widget ) {
+static void draw_editbox ( struct widget *widget ) {
struct edit_box *box = container_of ( widget, struct edit_box, widget );
const char *content = *(box->string.buf);
size_t width = widget->width;
@@ -79,21 +78,19 @@
/* Print box content and move cursor */
color_set ( CPAIR_EDIT, NULL );
- mvwprintw ( widgets->win, widget->row, widget->col, "%s", buf );
- wmove ( widgets->win, widget->row, ( widget->col + cursor_offset ) );
+ mvprintw ( widget->row, widget->col, "%s", buf );
+ move ( widget->row, ( widget->col + cursor_offset ) );
color_set ( CPAIR_NORMAL, NULL );
}
/**
* Edit text box widget
*
- * @v widgets Text widget set
* @v widget Text widget
* @v key Key pressed by user
* @ret key Key returned to application, or zero
*/
-static int edit_editbox ( struct widgets *widgets __unused,
- struct widget *widget, int key ) {
+static int edit_editbox ( struct widget *widget, int key ) {
struct edit_box *box = container_of ( widget, struct edit_box, widget );
return edit_string ( &box->string, key );
diff --git a/src/hci/mucurses/widgets/label.c b/src/hci/mucurses/widgets/label.c
index 29645a6..29057f0 100644
--- a/src/hci/mucurses/widgets/label.c
+++ b/src/hci/mucurses/widgets/label.c
@@ -36,10 +36,9 @@
/**
* Draw text label widget
*
- * @v widgets Text widget set
* @v widget Text widget
*/
-static void draw_label ( struct widgets *widgets, struct widget *widget ) {
+static void draw_label ( struct widget *widget ) {
struct label *label = container_of ( widget, struct label, widget );
unsigned int width = widget->width;
unsigned int col = widget->col;
@@ -51,20 +50,18 @@
/* Print label content */
attron ( A_BOLD );
- mvwprintw ( widgets->win, widget->row, col, "%s", text );
+ mvprintw ( widget->row, col, "%s", text );
attroff ( A_BOLD );
}
/**
* Edit text label widget
*
- * @v widgets Text widget set
* @v widget Text widget
* @v key Key pressed by user
* @ret key Key returned to application, or zero
*/
-static int edit_label ( struct widgets *widgets __unused,
- struct widget *widget __unused, int key ) {
+static int edit_label ( struct widget *widget __unused, int key ) {
/* Cannot be edited */
return key;
diff --git a/src/hci/tui/login_ui.c b/src/hci/tui/login_ui.c
index b76afb9..9c51488 100644
--- a/src/hci/tui/login_ui.c
+++ b/src/hci/tui/login_ui.c
@@ -67,7 +67,7 @@
/* Construct user interface */
memset ( &widgets, 0, sizeof ( widgets ) );
- init_widgets ( &widgets.widgets, NULL );
+ init_widgets ( &widgets.widgets );
init_label ( &widgets.username_label, USERNAME_LABEL_ROW, WIDGET_COL,
WIDGET_WIDTH, "Username" );
init_label ( &widgets.password_label, PASSWORD_LABEL_ROW, WIDGET_COL,
diff --git a/src/hci/tui/settings_ui.c b/src/hci/tui/settings_ui.c
index 53bf24d..045d978 100644
--- a/src/hci/tui/settings_ui.c
+++ b/src/hci/tui/settings_ui.c
@@ -253,7 +253,7 @@
static int edit_setting ( struct settings_ui *ui, int key ) {
assert ( ui->row.setting.name != NULL );
ui->row.editing = 1;
- return edit_widget ( &ui->widgets, &ui->row.editbox.widget, key );
+ return edit_widget ( &ui->row.editbox.widget, key );
}
/**
@@ -457,7 +457,7 @@
/* Print initial screen content */
color_set ( CPAIR_NORMAL, NULL );
memset ( &ui, 0, sizeof ( ui ) );
- init_widgets ( &ui.widgets, NULL );
+ init_widgets ( &ui.widgets );
select_settings ( &ui, settings );
while ( 1 ) {
@@ -481,7 +481,7 @@
assert ( ui.row.setting.name != NULL );
/* Redraw edit box */
- draw_widget ( &ui.widgets, &ui.row.editbox.widget );
+ draw_widget ( &ui.row.editbox.widget );
/* Process keypress */
key = edit_setting ( &ui, getkey ( 0 ) );
diff --git a/src/hci/tui/widget_ui.c b/src/hci/tui/widget_ui.c
index 5079eef..961545c 100644
--- a/src/hci/tui/widget_ui.c
+++ b/src/hci/tui/widget_ui.c
@@ -68,7 +68,7 @@
/* Draw all widgets */
list_for_each_entry ( widget, &widgets->list, list )
- draw_widget ( widgets, widget );
+ draw_widget ( widget );
/* Count editable widgets */
count = 0;
@@ -85,10 +85,10 @@
return -ENOENT;
/* Redraw current widget */
- draw_widget ( widgets, widget );
+ draw_widget ( widget );
/* Process keypress */
- key = edit_widget ( widgets, widget, getkey ( 0 ) );
+ key = edit_widget ( widget, getkey ( 0 ) );
switch ( key ) {
case KEY_UP:
if ( current > 0 )
diff --git a/src/include/ipxe/widget.h b/src/include/ipxe/widget.h
index fe93b9f..0d8af10 100644
--- a/src/include/ipxe/widget.h
+++ b/src/include/ipxe/widget.h
@@ -16,8 +16,6 @@
struct widgets {
/** List of widgets (in tab order) */
struct list_head list;
- /** Containing window */
- WINDOW *win;
};
/** A text widget */
@@ -50,14 +48,12 @@
/**
* Draw widget
*
- * @v widgets Text widget set
* @v widget Text widget
*/
- void ( * draw ) ( struct widgets *widgets, struct widget *widget );
+ void ( * draw ) ( struct widget *widget );
/**
* Edit widget
*
- * @v widgets Text widget set
* @v widget Text widget
* @v key Key pressed by user
* @ret key Key returned to application, or zero
@@ -66,21 +62,18 @@
* method to ensure that any changes to an editable widget are
* displayed to the user.
*/
- int ( * edit ) ( struct widgets *widgets, struct widget *widget,
- int key );
+ int ( * edit ) ( struct widget *widget, int key );
};
/**
* Initialise text widget set
*
* @v widgets Text widget set
- * @v win Containing window
*/
static inline __attribute__ (( always_inline )) void
-init_widgets ( struct widgets *widgets, WINDOW *win ) {
+init_widgets ( struct widgets *widgets ) {
INIT_LIST_HEAD ( &widgets->list );
- widgets->win = ( win ? win : stdscr );
}
/**
@@ -119,19 +112,17 @@
/**
* Draw text widget
*
- * @v widgets Text widget set
* @v widget Text widget
*/
static inline __attribute__ (( always_inline )) void
-draw_widget ( struct widgets *widgets, struct widget *widget ) {
+draw_widget ( struct widget *widget ) {
- widget->op->draw ( widgets, widget );
+ widget->op->draw ( widget );
}
/**
* Edit text widget
*
- * @v widgets Text widget set
* @v widget Text widget
* @v key Key pressed by user
* @ret key Key returned to application, or zero
@@ -141,9 +132,9 @@
* user.
*/
static inline __attribute__ (( always_inline )) int
-edit_widget ( struct widgets *widgets, struct widget *widget, int key ) {
+edit_widget ( struct widget *widget, int key ) {
- return widget->op->edit ( widgets, widget, key );
+ return widget->op->edit ( widget, key );
}
extern int widget_ui ( struct widgets *widgets );