iPXE
Functions
windows.c File Reference

MuCurses windows instance functions. More...

#include <curses.h>
#include <stddef.h>
#include <stdlib.h>
#include "mucurses.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int delwin (WINDOW *win)
 Delete a window.
WINDOWderwin (WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x)
 Create a new derived window.
WINDOWdupwin (WINDOW *orig)
 Create a duplicate of the specified window.
int mvwin (WINDOW *win, int y, int x)
 Move window origin to specified coordinates.
WINDOWnewwin (int nlines, int ncols, int begin_y, int begin_x)
 Create new WINDOW.
WINDOWsubwin (WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x)
 Create a new sub-window.

Detailed Description

MuCurses windows instance functions.

Definition in file windows.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int delwin ( WINDOW win)

Delete a window.

Parameters:
*winpointer to window being deleted
Return values:
rcreturn status code

Definition at line 20 of file windows.c.

References _wputch(), _curses_window::curs_x, _curses_window::curs_y, free, OK, stdscr, wmove(), and WRAP.

                           {
        /* I think we should blank the region covered by the window -
           ncurses doesn't do this, but they have a buffer, so they
           may just be deleting from an offscreen context whereas we
           are guaranteed to be deleting something onscreen */
        wmove( win, 0, 0 );
        chtype killch = (chtype)' ';
        do {
                _wputch( win, killch, WRAP );
        } while ( win->curs_x + win->curs_y );

        free( win );

        wmove ( stdscr, 0, 0 );

        return OK;
}
WINDOW* derwin ( WINDOW parent,
int  nlines,
int  ncols,
int  begin_y,
int  begin_x 
)

Create a new derived window.

Parameters:
parentparent window
nlineswindow height
ncolswindow width
begin_ywindow y origin (relative to parent)
begin_xwindow x origin (relative to parent)
Return values:
ptrreturn pointer to child window

Definition at line 48 of file windows.c.

References _curses_window::height, malloc(), NULL, _curses_window::ori_x, _curses_window::ori_y, _curses_window::parent, _curses_window::scr, and _curses_window::width.

                                                            {
        WINDOW *child;
        if ( ( (unsigned)ncols > parent->width ) || 
             ( (unsigned)nlines > parent->height ) )
                return NULL;
        if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
                return NULL;
        child->ori_y = parent->ori_y + begin_y;
        child->ori_x = parent->ori_x + begin_x;
        child->height = nlines;
        child->width = ncols;
        child->parent = parent;
        child->scr = parent->scr;
        return child;
}
WINDOW* dupwin ( WINDOW orig)

Create a duplicate of the specified window.

Parameters:
origoriginal window
Return values:
ptrpointer to duplicate window

Definition at line 71 of file windows.c.

References _curses_window::attrs, _curses_window::curs_x, _curses_window::curs_y, _curses_window::height, malloc(), NULL, _curses_window::ori_x, _curses_window::ori_y, _curses_window::scr, and _curses_window::width.

                                {
        WINDOW *copy;
        if ( ( copy = malloc( sizeof( WINDOW ) ) ) == NULL )
                return NULL;
        copy->scr = orig->scr;
        copy->attrs = orig->attrs;
        copy->ori_y = orig->ori_y;
        copy->ori_x = orig->ori_x;
        copy->curs_y = orig->curs_y;
        copy->curs_x = orig->curs_x;
        copy->height = orig->height;
        copy->width = orig->width;
        return copy;
}
int mvwin ( WINDOW win,
int  y,
int  x 
)

Move window origin to specified coordinates.

Parameters:
*winwindow to move
yY position
xX position
Return values:
rcreturn status code

Definition at line 94 of file windows.c.

References COLS, ERR, _curses_window::height, LINES, OK, _curses_window::ori_x, _curses_window::ori_y, and _curses_window::width.

                                        {
        if ( ( ( (unsigned)y + win->height ) > LINES ) ||
             ( ( (unsigned)x + win->width ) > COLS ) )
                return ERR;

        win->ori_y = y;
        win->ori_x = x;

        return OK;
}
WINDOW* newwin ( int  nlines,
int  ncols,
int  begin_y,
int  begin_x 
)

Create new WINDOW.

Parameters:
nlinesnumber of lines
ncolsnumber of columns
begin_ycolumn origin
begin_xline origin
Return values:
*winreturn pointer to new window

Definition at line 114 of file windows.c.

References _curses_window::height, malloc(), NULL, _curses_window::ori_x, _curses_window::ori_y, _curses_window::parent, _curses_window::scr, stdscr, and _curses_window::width.

Referenced by subwin().

                                                                   {
        WINDOW *win;
        if ( ( (unsigned)( begin_y + nlines ) > stdscr->height ) &&
             ( (unsigned)( begin_x + ncols ) > stdscr->width ) )
                return NULL;
        if ( ( win = malloc( sizeof(WINDOW) ) ) == NULL )
                return NULL;
        win->ori_y = begin_y;
        win->ori_x = begin_x;
        win->height = nlines;
        win->width = ncols;
        win->scr = stdscr->scr;
        win->parent = stdscr;
        return win;
}
WINDOW* subwin ( WINDOW parent,
int  nlines,
int  ncols,
int  begin_y,
int  begin_x 
)

Create a new sub-window.

Parameters:
origparent window
nlineswindow height
ncolswindow width
begin_ywindow y origin (absolute)
begin_xwindow x origin (absolute)
Return values:
ptrreturn pointer to child window

Definition at line 140 of file windows.c.

References newwin(), _curses_window::parent, and _curses_window::scr.

                                                            {
        WINDOW *child;
        child = newwin( nlines, ncols, begin_y, begin_x );
        child->parent = parent;
        child->scr = parent->scr;
        return child;
}