2000-04-20 17:12:14 +04:00
|
|
|
/* $NetBSD: newwin.c,v 1.22 2000/04/20 13:12:14 blymn Exp $ */
|
1997-07-22 11:36:20 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-08-18 01:51:41 +04:00
|
|
|
* Copyright (c) 1981, 1993, 1994
|
1993-11-09 06:34:01 +03:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-22 11:36:20 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1997-07-22 11:36:20 +04:00
|
|
|
#if 0
|
1994-08-18 01:51:41 +04:00
|
|
|
static char sccsid[] = "@(#)newwin.c 8.3 (Berkeley) 7/27/94";
|
1997-07-22 11:36:20 +04:00
|
|
|
#else
|
2000-04-20 17:12:14 +04:00
|
|
|
__RCSID("$NetBSD: newwin.c,v 1.22 2000/04/20 13:12:14 blymn Exp $");
|
1997-07-22 11:36:20 +04:00
|
|
|
#endif
|
1999-04-13 18:08:17 +04:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-08-07 09:48:37 +04:00
|
|
|
#include <stdlib.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-08-18 01:51:41 +04:00
|
|
|
#include "curses.h"
|
2000-04-11 17:57:08 +04:00
|
|
|
#include "curses_private.h"
|
1994-08-18 01:51:41 +04:00
|
|
|
|
2000-04-14 21:35:14 +04:00
|
|
|
extern struct __winlist *winlistp;
|
|
|
|
|
2000-04-17 16:25:45 +04:00
|
|
|
static WINDOW *__makenew(int nlines, int ncols, int by, int bx, int sub);
|
1993-11-09 06:34:01 +03:00
|
|
|
|
2000-04-17 16:25:45 +04:00
|
|
|
void __set_subwin(WINDOW *orig, WINDOW *win);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-04-18 16:23:01 +04:00
|
|
|
/*
|
|
|
|
* derwin --
|
|
|
|
* Create a new window in the same manner as subwin but (by, bx)
|
|
|
|
* are relative to the origin of window orig instead of absolute.
|
|
|
|
*/
|
|
|
|
WINDOW *
|
|
|
|
derwin(WINDOW *orig, int nlines, int ncols, int by, int bx)
|
|
|
|
{
|
|
|
|
if (orig == NULL)
|
|
|
|
return ERR;
|
|
|
|
|
|
|
|
return subwin(orig, nlines, ncols, orig->begy + by, orig->begx + bx);
|
|
|
|
}
|
|
|
|
|
2000-04-20 17:12:14 +04:00
|
|
|
/*
|
|
|
|
* dupwin --
|
|
|
|
* Create a copy of the given window.
|
|
|
|
*/
|
|
|
|
WINDOW *
|
|
|
|
dupwin(WINDOW *win)
|
|
|
|
{
|
|
|
|
WINDOW *new_one;
|
|
|
|
|
|
|
|
if ((new_one =
|
|
|
|
newwin(win->maxy, win->maxx, win->begy, win->begx)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
overwrite(win, new_one);
|
|
|
|
return new_one;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1993-08-07 09:48:37 +04:00
|
|
|
/*
|
|
|
|
* newwin --
|
|
|
|
* Allocate space for and set up defaults for a new window.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
WINDOW *
|
2000-04-17 16:25:45 +04:00
|
|
|
newwin(int nlines, int ncols, int by, int bx)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-03 22:12:13 +03:00
|
|
|
WINDOW *win;
|
|
|
|
__LINE *lp;
|
1999-04-13 18:08:17 +04:00
|
|
|
int i, j;
|
1998-02-03 22:12:13 +03:00
|
|
|
__LDATA *sp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-04-17 16:25:45 +04:00
|
|
|
if (nlines == 0)
|
|
|
|
nlines = LINES - by;
|
|
|
|
if (ncols == 0)
|
|
|
|
ncols = COLS - bx;
|
1993-11-09 06:34:01 +03:00
|
|
|
|
2000-04-17 16:25:45 +04:00
|
|
|
if ((win = __makenew(nlines, ncols, by, bx, 0)) == NULL)
|
1993-08-07 09:48:37 +04:00
|
|
|
return (NULL);
|
1993-11-09 06:34:01 +03:00
|
|
|
|
|
|
|
win->nextp = win;
|
|
|
|
win->ch_off = 0;
|
|
|
|
win->orig = NULL;
|
|
|
|
|
1993-08-07 09:48:37 +04:00
|
|
|
#ifdef DEBUG
|
1993-11-09 06:34:01 +03:00
|
|
|
__CTRACE("newwin: win->ch_off = %d\n", win->ch_off);
|
1993-08-07 09:48:37 +04:00
|
|
|
#endif
|
1993-11-09 06:34:01 +03:00
|
|
|
|
2000-04-17 16:25:45 +04:00
|
|
|
for (i = 0; i < nlines; i++) {
|
1993-11-09 06:34:01 +03:00
|
|
|
lp = win->lines[i];
|
|
|
|
lp->flags = 0;
|
2000-04-17 16:25:45 +04:00
|
|
|
for (sp = lp->line, j = 0; j < ncols; j++, sp++) {
|
1993-11-09 06:34:01 +03:00
|
|
|
sp->ch = ' ';
|
2000-04-19 02:45:23 +04:00
|
|
|
sp->bch = ' ';
|
1993-11-09 06:34:01 +03:00
|
|
|
sp->attr = 0;
|
2000-04-19 02:45:23 +04:00
|
|
|
sp->battr = 0;
|
1993-11-09 06:34:01 +03:00
|
|
|
}
|
1999-06-23 07:26:02 +04:00
|
|
|
lp->hash = __hash((char *)(void *)lp->line,
|
2000-04-17 16:25:45 +04:00
|
|
|
(int) (ncols * __LDATASIZE));
|
1993-11-09 06:34:01 +03:00
|
|
|
}
|
1993-08-07 09:48:37 +04:00
|
|
|
return (win);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WINDOW *
|
2000-04-17 16:25:45 +04:00
|
|
|
subwin(WINDOW *orig, int nlines, int ncols, int by, int bx)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1999-04-13 18:08:17 +04:00
|
|
|
int i;
|
1993-11-09 06:34:01 +03:00
|
|
|
__LINE *lp;
|
1998-02-03 22:12:13 +03:00
|
|
|
WINDOW *win;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-08-07 09:48:37 +04:00
|
|
|
/* Make sure window fits inside the original one. */
|
|
|
|
#ifdef DEBUG
|
2000-04-17 16:25:45 +04:00
|
|
|
__CTRACE("subwin: (%0.2o, %d, %d, %d, %d)\n", orig, nlines, ncols, by, bx);
|
1993-08-07 09:48:37 +04:00
|
|
|
#endif
|
1993-11-09 06:34:01 +03:00
|
|
|
if (by < orig->begy || bx < orig->begx
|
2000-04-17 16:25:45 +04:00
|
|
|
|| by + nlines > orig->maxy + orig->begy
|
|
|
|
|| bx + ncols > orig->maxx + orig->begx)
|
1993-08-07 09:48:37 +04:00
|
|
|
return (NULL);
|
2000-04-17 16:25:45 +04:00
|
|
|
if (nlines == 0)
|
|
|
|
nlines = orig->maxy + orig->begy - by;
|
|
|
|
if (ncols == 0)
|
|
|
|
ncols = orig->maxx + orig->begx - bx;
|
|
|
|
if ((win = __makenew(nlines, ncols, by, bx, 1)) == NULL)
|
1993-08-07 09:48:37 +04:00
|
|
|
return (NULL);
|
1993-11-09 06:34:01 +03:00
|
|
|
win->nextp = orig->nextp;
|
|
|
|
orig->nextp = win;
|
|
|
|
win->orig = orig;
|
|
|
|
|
|
|
|
/* Initialize flags here so that refresh can also use __set_subwin. */
|
|
|
|
for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++)
|
|
|
|
lp->flags = 0;
|
1993-08-07 09:48:37 +04:00
|
|
|
__set_subwin(orig, win);
|
|
|
|
return (win);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/*
|
1993-08-07 09:48:37 +04:00
|
|
|
* This code is shared with mvwin().
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1993-08-07 09:48:37 +04:00
|
|
|
void
|
2000-04-15 17:17:02 +04:00
|
|
|
__set_subwin(WINDOW *orig, WINDOW *win)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1999-04-13 18:08:17 +04:00
|
|
|
int i;
|
1993-11-09 06:34:01 +03:00
|
|
|
__LINE *lp, *olp;
|
|
|
|
|
|
|
|
win->ch_off = win->begx - orig->begx;
|
1999-04-13 18:08:17 +04:00
|
|
|
/* Point line pointers to line space. */
|
1993-11-09 06:34:01 +03:00
|
|
|
for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) {
|
|
|
|
win->lines[i] = lp;
|
1999-04-23 02:39:09 +04:00
|
|
|
olp = orig->lines[i + win->begy - orig->begy];
|
2000-04-16 09:48:25 +04:00
|
|
|
lp->line = &olp->line[win->ch_off];
|
1993-11-09 06:34:01 +03:00
|
|
|
lp->firstchp = &olp->firstch;
|
|
|
|
lp->lastchp = &olp->lastch;
|
1999-06-23 07:26:02 +04:00
|
|
|
lp->hash = __hash((char *)(void *)lp->line,
|
|
|
|
(int) (win->maxx * __LDATASIZE));
|
1993-11-09 06:34:01 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-08-07 09:48:37 +04:00
|
|
|
#ifdef DEBUG
|
1993-11-09 06:34:01 +03:00
|
|
|
__CTRACE("__set_subwin: win->ch_off = %d\n", win->ch_off);
|
1993-08-07 09:48:37 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/*
|
1993-11-09 06:34:01 +03:00
|
|
|
* __makenew --
|
1993-08-07 09:48:37 +04:00
|
|
|
* Set up a window buffer and returns a pointer to it.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
static WINDOW *
|
2000-04-17 16:25:45 +04:00
|
|
|
__makenew(int nlines, int ncols, int by, int bx, int sub)
|
1993-08-07 09:48:37 +04:00
|
|
|
{
|
2000-04-14 21:35:14 +04:00
|
|
|
WINDOW *win;
|
|
|
|
__LINE *lp;
|
|
|
|
struct __winlist *wlp, *wlp2;
|
|
|
|
int i;
|
1999-04-13 18:08:17 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-08-07 09:48:37 +04:00
|
|
|
#ifdef DEBUG
|
2000-04-17 16:25:45 +04:00
|
|
|
__CTRACE("makenew: (%d, %d, %d, %d)\n", nlines, ncols, by, bx);
|
1993-08-07 09:48:37 +04:00
|
|
|
#endif
|
|
|
|
if ((win = malloc(sizeof(*win))) == NULL)
|
|
|
|
return (NULL);
|
|
|
|
#ifdef DEBUG
|
2000-04-17 16:25:45 +04:00
|
|
|
__CTRACE("makenew: nlines = %d\n", nlines);
|
1993-08-07 09:48:37 +04:00
|
|
|
#endif
|
1993-11-09 06:34:01 +03:00
|
|
|
|
1999-04-13 18:08:17 +04:00
|
|
|
/* Set up line pointer array and line space. */
|
2000-04-17 16:25:45 +04:00
|
|
|
if ((win->lines = malloc(nlines * sizeof(__LINE *))) == NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
free(win);
|
1993-11-09 06:34:01 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-04-17 16:25:45 +04:00
|
|
|
if ((win->lspace = malloc(nlines * sizeof(__LINE))) == NULL) {
|
1999-04-13 18:08:17 +04:00
|
|
|
free(win);
|
|
|
|
free(win->lines);
|
1993-11-09 06:34:01 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* Don't allocate window and line space if it's a subwindow */
|
|
|
|
if (!sub) {
|
|
|
|
/*
|
|
|
|
* Allocate window space in one chunk.
|
|
|
|
*/
|
1999-04-13 18:08:17 +04:00
|
|
|
if ((win->wspace =
|
2000-04-17 16:25:45 +04:00
|
|
|
malloc(ncols * nlines * sizeof(__LDATA))) == NULL) {
|
1993-11-09 06:34:01 +03:00
|
|
|
free(win->lines);
|
|
|
|
free(win->lspace);
|
|
|
|
free(win);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-04-14 21:35:14 +04:00
|
|
|
/*
|
|
|
|
* Append window to window list.
|
|
|
|
*/
|
|
|
|
if ((wlp = malloc(sizeof(struct __winlist))) == NULL) {
|
|
|
|
free(win->wspace);
|
|
|
|
free(win->lines);
|
|
|
|
free(win->lspace);
|
|
|
|
free(win);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wlp->winp = win;
|
|
|
|
wlp->nextp = NULL;
|
|
|
|
if (__winlistp == NULL)
|
|
|
|
__winlistp = wlp;
|
|
|
|
else {
|
|
|
|
wlp2 = __winlistp;
|
|
|
|
while (wlp2->nextp != NULL)
|
|
|
|
wlp2 = wlp2->nextp;
|
|
|
|
wlp2->nextp = wlp;
|
|
|
|
}
|
1993-11-09 06:34:01 +03:00
|
|
|
/*
|
|
|
|
* Point line pointers to line space, and lines themselves into
|
|
|
|
* window space.
|
|
|
|
*/
|
2000-04-17 16:25:45 +04:00
|
|
|
for (lp = win->lspace, i = 0; i < nlines; i++, lp++) {
|
1993-11-09 06:34:01 +03:00
|
|
|
win->lines[i] = lp;
|
2000-04-17 16:25:45 +04:00
|
|
|
lp->line = &win->wspace[i * ncols];
|
1993-11-09 06:34:01 +03:00
|
|
|
lp->firstchp = &lp->firstch;
|
|
|
|
lp->lastchp = &lp->lastch;
|
|
|
|
lp->firstch = 0;
|
|
|
|
lp->lastch = 0;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-08-07 09:48:37 +04:00
|
|
|
#ifdef DEBUG
|
2000-04-17 16:25:45 +04:00
|
|
|
__CTRACE("makenew: ncols = %d\n", ncols);
|
1993-08-07 09:48:37 +04:00
|
|
|
#endif
|
1993-11-09 06:34:01 +03:00
|
|
|
win->cury = win->curx = 0;
|
2000-04-17 16:25:45 +04:00
|
|
|
win->maxy = nlines;
|
|
|
|
win->maxx = ncols;
|
1993-11-09 06:34:01 +03:00
|
|
|
|
|
|
|
win->begy = by;
|
|
|
|
win->begx = bx;
|
|
|
|
win->flags = 0;
|
2000-04-16 02:53:46 +04:00
|
|
|
win->delay = -1;
|
2000-04-11 17:57:08 +04:00
|
|
|
win->wattr = 0;
|
2000-04-19 02:45:23 +04:00
|
|
|
win->bch = ' ';
|
2000-04-13 01:48:46 +04:00
|
|
|
win->battr = 0;
|
1993-08-07 09:48:37 +04:00
|
|
|
__swflags(win);
|
|
|
|
#ifdef DEBUG
|
2000-04-11 17:57:08 +04:00
|
|
|
__CTRACE("makenew: win->wattr = %0.2o\n", win->wattr);
|
1993-11-09 06:34:01 +03:00
|
|
|
__CTRACE("makenew: win->flags = %0.2o\n", win->flags);
|
|
|
|
__CTRACE("makenew: win->maxy = %d\n", win->maxy);
|
|
|
|
__CTRACE("makenew: win->maxx = %d\n", win->maxx);
|
|
|
|
__CTRACE("makenew: win->begy = %d\n", win->begy);
|
|
|
|
__CTRACE("makenew: win->begx = %d\n", win->begx);
|
1993-08-07 09:48:37 +04:00
|
|
|
#endif
|
|
|
|
return (win);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1993-08-07 09:48:37 +04:00
|
|
|
void
|
2000-04-15 17:17:02 +04:00
|
|
|
__swflags(WINDOW *win)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-08-18 01:51:41 +04:00
|
|
|
win->flags &= ~(__ENDLINE | __FULLWIN | __SCROLLWIN | __LEAVEOK);
|
1993-11-09 06:34:01 +03:00
|
|
|
if (win->begx + win->maxx == COLS) {
|
|
|
|
win->flags |= __ENDLINE;
|
1994-08-18 01:51:41 +04:00
|
|
|
if (win->begx == 0 && win->maxy == LINES && win->begy == 0)
|
|
|
|
win->flags |= __FULLWIN;
|
1993-11-09 06:34:01 +03:00
|
|
|
if (win->begy + win->maxy == LINES)
|
|
|
|
win->flags |= __SCROLLWIN;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|