diff options
author | ache <ache@FreeBSD.org> | 1994-10-07 08:58:58 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1994-10-07 08:58:58 +0000 |
commit | a80c0624fbd8bd1c784b0b5b7a0fd20b09d317b9 (patch) | |
tree | 4a94ca97fb2fc2fdc1fcdd522a66e39c6e763138 /lib/libncurses/lib_newwin.c | |
download | FreeBSD-src-a80c0624fbd8bd1c784b0b5b7a0fd20b09d317b9.zip FreeBSD-src-a80c0624fbd8bd1c784b0b5b7a0fd20b09d317b9.tar.gz |
Moved from ports with several enhancements
Diffstat (limited to 'lib/libncurses/lib_newwin.c')
-rw-r--r-- | lib/libncurses/lib_newwin.c | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/lib/libncurses/lib_newwin.c b/lib/libncurses/lib_newwin.c new file mode 100644 index 0000000..f732a7c --- /dev/null +++ b/lib/libncurses/lib_newwin.c @@ -0,0 +1,177 @@ + +/* 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> +#include <nterm.h> +#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 + */ + if ( begy < 0 || begx < 0) + 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; + + 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)); + + return derwin(w, l, c, y - w->_begy, x - w->_begx); +} + +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) + return NULL; + + if ((win->_line = (chtype **) calloc(num_lines, sizeof (chtype *))) == NULL) { + free(win); + return NULL; + } + + if ((win->_firstchar = calloc(num_lines, sizeof(short))) == NULL) { + free(win); + free(win->_line); + return NULL; + } + + if ((win->_lastchar = calloc(num_lines, sizeof(short))) == NULL) { + free(win); + free(win->_line); + free(win->_firstchar); + return NULL; + } + + 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; + + 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; + win->_use_meta = FALSE; + win->_delay = -1; + 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); +} |