1994-10-07 08:58:58 +00:00
|
|
|
|
|
|
|
/* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for *
|
|
|
|
* details. If they are missing then this copy is in violation of *
|
|
|
|
* the copyright conditions. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
** lib_newwin.c
|
|
|
|
**
|
|
|
|
** The routines newwin(), subwin() and their dependent
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
1994-12-02 06:40:24 +00:00
|
|
|
#include "terminfo.h"
|
1994-10-07 08:58:58 +00:00
|
|
|
#include "curses.priv.h"
|
|
|
|
|
|
|
|
WINDOW * newwin(int num_lines, int num_columns, int begy, int begx)
|
|
|
|
{
|
|
|
|
WINDOW *win;
|
|
|
|
chtype *ptr;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
T(("newwin(%d,%d,%d,%d) called", num_lines, num_columns, begy, begx));
|
|
|
|
|
|
|
|
if (num_lines == 0)
|
|
|
|
num_lines = lines - begy;
|
|
|
|
|
|
|
|
if (num_columns == 0)
|
|
|
|
num_columns = columns - begx;
|
|
|
|
|
|
|
|
if (num_columns + begx > columns || num_lines + begy > lines)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((win = makenew(num_lines, num_columns, begy, begx)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < num_lines; i++) {
|
|
|
|
if ((win->_line[i] = (chtype *) calloc(num_columns, sizeof(chtype))) == NULL) {
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
free(win->_line[j]);
|
|
|
|
|
|
|
|
free(win->_firstchar);
|
|
|
|
free(win->_lastchar);
|
|
|
|
free(win->_line);
|
|
|
|
free(win);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (ptr = win->_line[i]; ptr < win->_line[i] + num_columns; )
|
|
|
|
*ptr++ = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
T(("newwin: returned window is %x", win));
|
|
|
|
|
|
|
|
return(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
WINDOW * derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
|
|
|
|
{
|
|
|
|
WINDOW *win;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
T(("derwin(%x, %d,%d,%d,%d) called", orig, num_lines, num_columns, begy, begx));
|
|
|
|
|
|
|
|
/*
|
|
|
|
** make sure window fits inside the original one
|
|
|
|
*/
|
1995-05-30 05:51:47 +00:00
|
|
|
if ( begy < 0 || begx < 0)
|
1994-10-07 08:58:58 +00:00
|
|
|
return NULL;
|
|
|
|
if ( begy + num_lines > orig->_maxy + 1
|
|
|
|
|| begx + num_columns > orig->_maxx + 1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (num_lines == 0)
|
|
|
|
num_lines = orig->_maxy - orig->_begy - begy;
|
|
|
|
|
|
|
|
if (num_columns == 0)
|
|
|
|
num_columns = orig->_maxx - orig->_begx - begx;
|
|
|
|
|
|
|
|
if ((win = makenew(num_lines, num_columns, orig->_begy + begy, orig->_begx + begx)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
win->_pary = begy;
|
|
|
|
win->_parx = begx;
|
1994-12-02 06:40:24 +00:00
|
|
|
win->_attrs = orig->_attrs;
|
|
|
|
win->_bkgd = orig->_bkgd;
|
1994-10-07 08:58:58 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num_lines; i++)
|
|
|
|
win->_line[i] = &orig->_line[begy++][begx];
|
|
|
|
|
|
|
|
win->_flags = _SUBWIN;
|
|
|
|
win->_parent = orig;
|
|
|
|
|
|
|
|
T(("derwin: returned window is %x", win));
|
|
|
|
|
|
|
|
return(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WINDOW *subwin(WINDOW *w, int l, int c, int y, int x)
|
|
|
|
{
|
|
|
|
T(("subwin(%x, %d, %d, %d, %d) called", w, l, c, y, x));
|
|
|
|
T(("parent has begy = %d, begx = %d", w->_begy, w->_begx));
|
|
|
|
|
1995-05-30 05:51:47 +00:00
|
|
|
return derwin(w, l, c, y - w->_begy, x - w->_begx);
|
1994-10-07 08:58:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WINDOW *
|
|
|
|
makenew(int num_lines, int num_columns, int begy, int begx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
WINDOW *win;
|
|
|
|
|
|
|
|
T(("makenew(%d,%d,%d,%d)", num_lines, num_columns, begy, begx));
|
|
|
|
|
|
|
|
if ((win = (WINDOW *) malloc(sizeof(WINDOW))) == NULL)
|
1995-05-30 05:51:47 +00:00
|
|
|
return NULL;
|
1994-10-07 08:58:58 +00:00
|
|
|
|
|
|
|
if ((win->_line = (chtype **) calloc(num_lines, sizeof (chtype *))) == NULL) {
|
|
|
|
free(win);
|
1995-05-30 05:51:47 +00:00
|
|
|
return NULL;
|
1994-10-07 08:58:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((win->_firstchar = calloc(num_lines, sizeof(short))) == NULL) {
|
|
|
|
free(win);
|
|
|
|
free(win->_line);
|
1995-05-30 05:51:47 +00:00
|
|
|
return NULL;
|
1994-10-07 08:58:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((win->_lastchar = calloc(num_lines, sizeof(short))) == NULL) {
|
|
|
|
free(win);
|
|
|
|
free(win->_line);
|
|
|
|
free(win->_firstchar);
|
1995-05-30 05:51:47 +00:00
|
|
|
return NULL;
|
1994-10-07 08:58:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
win->_curx = 0;
|
|
|
|
win->_cury = 0;
|
|
|
|
win->_maxy = num_lines - 1;
|
|
|
|
win->_maxx = num_columns - 1;
|
|
|
|
win->_begy = begy;
|
|
|
|
win->_begx = begx;
|
|
|
|
|
|
|
|
win->_flags = 0;
|
|
|
|
win->_attrs = A_NORMAL;
|
1997-07-30 17:21:39 +00:00
|
|
|
win->_bkgd = BLANK;
|
1994-10-07 08:58:58 +00:00
|
|
|
|
|
|
|
win->_clear = (num_lines == lines && num_columns == columns);
|
|
|
|
win->_idlok = FALSE;
|
|
|
|
win->_use_idc = TRUE;
|
|
|
|
win->_scroll = FALSE;
|
|
|
|
win->_leave = FALSE;
|
|
|
|
win->_use_keypad = FALSE;
|
1994-10-11 16:36:53 +00:00
|
|
|
#ifdef TERMIOS
|
|
|
|
win->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 &&
|
|
|
|
!(cur_term->Ottyb.c_iflag & ISTRIP));
|
|
|
|
#else
|
1994-10-07 08:58:58 +00:00
|
|
|
win->_use_meta = FALSE;
|
1994-10-11 16:36:53 +00:00
|
|
|
#endif
|
1995-05-30 05:51:47 +00:00
|
|
|
win->_delay = -1;
|
1994-10-07 08:58:58 +00:00
|
|
|
win->_immed = FALSE;
|
|
|
|
win->_sync = 0;
|
|
|
|
win->_parx = 0;
|
|
|
|
win->_pary = 0;
|
|
|
|
win->_parent = (WINDOW *)NULL;
|
|
|
|
|
|
|
|
win->_regtop = 0;
|
|
|
|
win->_regbottom = num_lines - 1;
|
|
|
|
|
|
|
|
for (i = 0; i < num_lines; i++)
|
|
|
|
win->_firstchar[i] = win->_lastchar[i] = _NOCHANGE;
|
|
|
|
|
|
|
|
if (begx + num_columns == columns) {
|
|
|
|
win->_flags |= _ENDLINE;
|
|
|
|
|
|
|
|
if (begx == 0 && num_lines == lines && begy == 0)
|
|
|
|
win->_flags |= _FULLWIN;
|
|
|
|
|
|
|
|
if (begy + num_lines == lines)
|
|
|
|
win->_flags |= _SCROLLWIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(win);
|
|
|
|
}
|