iPXE
windows.c
Go to the documentation of this file.
00001 #include <curses.h>
00002 #include <stddef.h>
00003 #include <stdlib.h>
00004 #include "mucurses.h"
00005 
00006 /** @file
00007  *
00008  * MuCurses windows instance functions
00009  *
00010  */
00011 
00012 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00013 
00014 /**
00015  * Delete a window
00016  *
00017  * @v *win      pointer to window being deleted
00018  * @ret rc      return status code
00019  */
00020 int delwin ( WINDOW *win ) {
00021         /* I think we should blank the region covered by the window -
00022            ncurses doesn't do this, but they have a buffer, so they
00023            may just be deleting from an offscreen context whereas we
00024            are guaranteed to be deleting something onscreen */
00025         wmove( win, 0, 0 );
00026         chtype killch = (chtype)' ';
00027         do {
00028                 _wputch( win, killch, WRAP );
00029         } while ( win->curs_x + win->curs_y );
00030 
00031         free( win );
00032 
00033         wmove ( stdscr, 0, 0 );
00034 
00035         return OK;
00036 }
00037 
00038 /**
00039  * Create a new derived window
00040  *
00041  * @v parent    parent window
00042  * @v nlines    window height
00043  * @v ncols     window width
00044  * @v begin_y   window y origin (relative to parent)
00045  * @v begin_x   window x origin (relative to parent)
00046  * @ret ptr     return pointer to child window
00047  */
00048 WINDOW *derwin ( WINDOW *parent, int nlines, int ncols,
00049                                  int begin_y, int begin_x ) {
00050         WINDOW *child;
00051         if ( ( (unsigned)ncols > parent->width ) || 
00052              ( (unsigned)nlines > parent->height ) )
00053                 return NULL;
00054         if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
00055                 return NULL;
00056         child->ori_y = parent->ori_y + begin_y;
00057         child->ori_x = parent->ori_x + begin_x;
00058         child->height = nlines;
00059         child->width = ncols;
00060         child->parent = parent;
00061         child->scr = parent->scr;
00062         return child;
00063 }
00064 
00065 /**
00066  * Create a duplicate of the specified window
00067  *
00068  * @v orig      original window
00069  * @ret ptr     pointer to duplicate window
00070  */
00071 WINDOW *dupwin ( WINDOW *orig ) {
00072         WINDOW *copy;
00073         if ( ( copy = malloc( sizeof( WINDOW ) ) ) == NULL )
00074                 return NULL;
00075         copy->scr = orig->scr;
00076         copy->attrs = orig->attrs;
00077         copy->ori_y = orig->ori_y;
00078         copy->ori_x = orig->ori_x;
00079         copy->curs_y = orig->curs_y;
00080         copy->curs_x = orig->curs_x;
00081         copy->height = orig->height;
00082         copy->width = orig->width;
00083         return copy;
00084 }
00085 
00086 /**
00087  * Move window origin to specified coordinates
00088  *
00089  * @v *win      window to move
00090  * @v y         Y position
00091  * @v x         X position
00092  * @ret rc      return status code
00093  */
00094 int mvwin ( WINDOW *win, int y, int x ) {
00095         if ( ( ( (unsigned)y + win->height ) > LINES ) ||
00096              ( ( (unsigned)x + win->width ) > COLS ) )
00097                 return ERR;
00098 
00099         win->ori_y = y;
00100         win->ori_x = x;
00101 
00102         return OK;
00103 }
00104 
00105 /**
00106  * Create new WINDOW
00107  *
00108  * @v nlines    number of lines
00109  * @v ncols     number of columns
00110  * @v begin_y   column origin
00111  * @v begin_x   line origin
00112  * @ret *win    return pointer to new window
00113  */
00114 WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
00115         WINDOW *win;
00116         if ( ( (unsigned)( begin_y + nlines ) > stdscr->height ) &&
00117              ( (unsigned)( begin_x + ncols ) > stdscr->width ) )
00118                 return NULL;
00119         if ( ( win = malloc( sizeof(WINDOW) ) ) == NULL )
00120                 return NULL;
00121         win->ori_y = begin_y;
00122         win->ori_x = begin_x;
00123         win->height = nlines;
00124         win->width = ncols;
00125         win->scr = stdscr->scr;
00126         win->parent = stdscr;
00127         return win;
00128 }
00129 
00130 /**
00131  * Create a new sub-window
00132  *
00133  * @v orig      parent window
00134  * @v nlines    window height
00135  * @v ncols     window width
00136  * @v begin_y   window y origin (absolute)
00137  * @v begin_x   window x origin (absolute)
00138  * @ret ptr     return pointer to child window
00139  */
00140 WINDOW *subwin ( WINDOW *parent, int nlines, int ncols,
00141                                  int begin_y, int begin_x ) {
00142         WINDOW *child;
00143         child = newwin( nlines, ncols, begin_y, begin_x );
00144         child->parent = parent;
00145         child->scr = parent->scr;
00146         return child;
00147 }