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

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

int delwin ( WINDOW win  ) 

Delete a window.

Parameters:
*win pointer to window being deleted
Return values:
rc return status code

Definition at line 18 of file windows.c.

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

00018                            {
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 }

WINDOW* derwin ( WINDOW parent,
int  nlines,
int  ncols,
int  begin_y,
int  begin_x 
)

Create a new derived window.

Parameters:
parent parent window
nlines window height
ncols window width
begin_y window y origin (relative to parent)
begin_x window x origin (relative to parent)
Return values:
ptr return pointer to child window

Definition at line 49 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.

00050                                                             {
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 }

WINDOW* dupwin ( WINDOW orig  ) 

Create a duplicate of the specified window.

Parameters:
orig original window
Return values:
ptr pointer to duplicate window

Definition at line 74 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.

00074                                 {
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 }

int mvwin ( WINDOW win,
int  y,
int  x 
)

Move window origin to specified coordinates.

Parameters:
*win window to move
y Y position
x X position
Return values:
rc return status code

Definition at line 99 of file windows.c.

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

00099                                         {
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 }

WINDOW* newwin ( int  nlines,
int  ncols,
int  begin_y,
int  begin_x 
)

Create new WINDOW.

Parameters:
nlines number of lines
ncols number of columns
begin_y column origin
begin_x line origin
Return values:
*win return pointer to new window

Definition at line 121 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().

00121                                                                    {
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 }

WINDOW* subwin ( WINDOW parent,
int  nlines,
int  ncols,
int  begin_y,
int  begin_x 
)

Create a new sub-window.

Parameters:
orig parent window
nlines window height
ncols window width
begin_y window y origin (absolute)
begin_x window x origin (absolute)
Return values:
ptr return pointer to child window

Definition at line 147 of file windows.c.

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

00148                                                             {
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:47 2010 for gPXE by  doxygen 1.5.7.1