8 * MuCurses windows instance functions
12 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
17 * @v *win pointer to window being deleted
18 * @ret rc return status code
20 int delwin ( WINDOW *win ) {
24 /* I think we should blank the region covered by the window -
25 ncurses doesn't do this, but they have a buffer, so they
26 may just be deleting from an offscreen context whereas we
27 are guaranteed to be deleting something onscreen */
29 chtype killch = (chtype)' ';
31 _wputch( win, killch, WRAP );
32 } while ( win->curs_x + win->curs_y );
36 wmove ( stdscr, 0, 0 );
42 * Create a new derived window
44 * @v parent parent window
45 * @v nlines window height
46 * @v ncols window width
47 * @v begin_y window y origin (relative to parent)
48 * @v begin_x window x origin (relative to parent)
49 * @ret ptr return pointer to child window
51 WINDOW *derwin ( WINDOW *parent, int nlines, int ncols,
52 int begin_y, int begin_x ) {
56 if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
58 if ( ( (unsigned)ncols > parent->width ) ||
59 ( (unsigned)nlines > parent->height ) )
61 child->ori_y = parent->ori_y + begin_y;
62 child->ori_x = parent->ori_x + begin_x;
63 child->height = nlines;
65 child->parent = parent;
66 child->scr = parent->scr;
71 * Create a duplicate of the specified window
73 * @v orig original window
74 * @ret ptr pointer to duplicate window
76 WINDOW *dupwin ( WINDOW *orig ) {
80 if ( ( copy = malloc( sizeof( WINDOW ) ) ) == NULL )
82 copy->scr = orig->scr;
83 copy->attrs = orig->attrs;
84 copy->ori_y = orig->ori_y;
85 copy->ori_x = orig->ori_x;
86 copy->curs_y = orig->curs_y;
87 copy->curs_x = orig->curs_x;
88 copy->height = orig->height;
89 copy->width = orig->width;
94 * Move window origin to specified coordinates
96 * @v *win window to move
99 * @ret rc return status code
101 int mvwin ( WINDOW *win, int y, int x ) {
104 if ( ( ( (unsigned)y + win->height ) > LINES ) ||
105 ( ( (unsigned)x + win->width ) > COLS ) )
117 * @v nlines number of lines
118 * @v ncols number of columns
119 * @v begin_y column origin
120 * @v begin_x line origin
121 * @ret *win return pointer to new window
123 WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
125 if ( ( win = malloc( sizeof(WINDOW) ) ) == NULL )
127 if ( ( (unsigned)( begin_y + nlines ) > stdscr->height ) &&
128 ( (unsigned)( begin_x + ncols ) > stdscr->width ) )
130 win->ori_y = begin_y;
131 win->ori_x = begin_x;
132 win->height = nlines;
134 win->scr = stdscr->scr;
135 win->parent = stdscr;
140 * Create a new sub-window
142 * @v orig parent window
143 * @v nlines window height
144 * @v ncols window width
145 * @v begin_y window y origin (absolute)
146 * @v begin_x window x origin (absolute)
147 * @ret ptr return pointer to child window
149 WINDOW *subwin ( WINDOW *parent, int nlines, int ncols,
150 int begin_y, int begin_x ) {
152 if ( parent == NULL )
154 if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
156 child = newwin( nlines, ncols, begin_y, begin_x );
157 child->parent = parent;
158 child->scr = parent->scr;