iPXE
Data Structures | Enumerations | Functions | Variables
editbox.h File Reference

Editable text box widget. More...

#include <curses.h>
#include <ipxe/editstring.h>

Go to the source code of this file.

Data Structures

struct  edit_box
 An editable text box widget. More...

Enumerations

enum  edit_box_flags { EDITBOX_STARS = 0x0001 }
 Editable text box widget flags. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void init_editbox (struct edit_box *box, char *buf, size_t len, WINDOW *win, unsigned int row, unsigned int col, unsigned int width, unsigned int flags)
 Initialise text box widget.
void draw_editbox (struct edit_box *box) __nonnull
 Draw text box widget.
static int edit_editbox (struct edit_box *box, int key)
 Edit text box widget.

Variables

struct edit_box __attribute__

Detailed Description

Editable text box widget.

Definition in file editbox.h.


Enumeration Type Documentation

Editable text box widget flags.

Enumerator:
EDITBOX_STARS 

Show stars instead of contents (for password widgets)

Definition at line 34 of file editbox.h.

                    {
        /** Show stars instead of contents (for password widgets) */
        EDITBOX_STARS = 0x0001,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
void init_editbox ( struct edit_box box,
char *  buf,
size_t  len,
WINDOW win,
unsigned int  row,
unsigned int  col,
unsigned int  width,
unsigned int  flags 
)

Initialise text box widget.

Parameters:
boxEditable text box widget
bufText buffer
lenSize of text buffer
winContaining window
rowRow
colStarting column
widthWidth
flagsFlags

Definition at line 50 of file editbox.c.

References edit_box::col, edit_string::cursor, edit_box::flags, flags, init_editstring(), memset(), edit_box::row, stdscr, edit_box::string, strlen(), edit_box::width, and edit_box::win.

Referenced by login_ui(), and select_setting_row().

                                                             {
        memset ( box, 0, sizeof ( *box ) );
        init_editstring ( &box->string, buf, len );
        box->string.cursor = strlen ( buf );
        box->win = ( win ? win : stdscr );
        box->row = row;
        box->col = col;
        box->width = width;
        box->flags = flags;
}
void draw_editbox ( struct edit_box box)

Draw text box widget.

Parameters:
boxEditable text box widget

Definition at line 69 of file editbox.c.

References edit_string::buf, edit_box::col, edit_string::cursor, EDITBOX_MIN_CHARS, EDITBOX_STARS, edit_box::first, first, edit_box::flags, len, memcpy(), memset(), mvwprintw, edit_box::row, stdscr, edit_box::string, strlen(), edit_box::width, edit_box::win, and wmove().

Referenced by login_ui(), and main_loop().

                                           {
        size_t width = box->width;
        char buf[ width + 1 ];
        signed int cursor_offset, underflow, overflow, first;
        size_t len;

        /* Adjust starting offset so that cursor remains within box */
        cursor_offset = ( box->string.cursor - box->first );
        underflow = ( EDITBOX_MIN_CHARS - cursor_offset );
        overflow = ( cursor_offset - ( width - 1 ) );
        first = box->first;
        if ( underflow > 0 ) {
                first -= underflow;
                if ( first < 0 )
                        first = 0;
        } else if ( overflow > 0 ) {
                first += overflow;
        }
        box->first = first;
        cursor_offset = ( box->string.cursor - first );

        /* Construct underscore-padded string portion */
        memset ( buf, '_', width );
        buf[width] = '\0';
        len = ( strlen ( box->string.buf ) - first );
        if ( len > width )
                len = width;
        if ( box->flags & EDITBOX_STARS ) {
                memset ( buf, '*', len );
        } else {
                memcpy ( buf, ( box->string.buf + first ), len );
        }

        /* Print box content and move cursor */
        if ( ! box->win )
                box->win = stdscr;
        mvwprintw ( box->win, box->row, box->col, "%s", buf );
        wmove ( box->win, box->row, ( box->col + cursor_offset ) );
}
static int edit_editbox ( struct edit_box box,
int  key 
) [inline, static]

Edit text box widget.

Parameters:
boxEditable text box widget
keyKey pressed by user
Return values:
keyKey returned to application, or zero

You must call draw_editbox() to update the display after calling edit_editbox().

Definition at line 57 of file editbox.h.

References edit_string(), and edit_box::string.

Referenced by edit_setting(), and login_ui().

                                                                 {
        return edit_string ( &box->string, key );
}

Variable Documentation