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

Generated on Tue Apr 6 20:01:06 2010 for gPXE by  doxygen 1.5.7.1