xref: /minix3/lib/libcurses/mvwin.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: mvwin.c,v 1.19 2014/02/20 09:42:42 blymn Exp $	*/
251ffecc1SBen Gras 
351ffecc1SBen Gras /*
451ffecc1SBen Gras  * Copyright (c) 1981, 1993, 1994
551ffecc1SBen Gras  *	The Regents of the University of California.  All rights reserved.
651ffecc1SBen Gras  *
751ffecc1SBen Gras  * Redistribution and use in source and binary forms, with or without
851ffecc1SBen Gras  * modification, are permitted provided that the following conditions
951ffecc1SBen Gras  * are met:
1051ffecc1SBen Gras  * 1. Redistributions of source code must retain the above copyright
1151ffecc1SBen Gras  *    notice, this list of conditions and the following disclaimer.
1251ffecc1SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
1351ffecc1SBen Gras  *    notice, this list of conditions and the following disclaimer in the
1451ffecc1SBen Gras  *    documentation and/or other materials provided with the distribution.
1551ffecc1SBen Gras  * 3. Neither the name of the University nor the names of its contributors
1651ffecc1SBen Gras  *    may be used to endorse or promote products derived from this software
1751ffecc1SBen Gras  *    without specific prior written permission.
1851ffecc1SBen Gras  *
1951ffecc1SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2051ffecc1SBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2151ffecc1SBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2251ffecc1SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2351ffecc1SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2451ffecc1SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2551ffecc1SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2651ffecc1SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2751ffecc1SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2851ffecc1SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2951ffecc1SBen Gras  * SUCH DAMAGE.
3051ffecc1SBen Gras  */
3151ffecc1SBen Gras 
3251ffecc1SBen Gras #include <sys/cdefs.h>
3351ffecc1SBen Gras #ifndef lint
3451ffecc1SBen Gras #if 0
3551ffecc1SBen Gras static char sccsid[] = "@(#)mvwin.c	8.2 (Berkeley) 5/4/94";
3651ffecc1SBen Gras #else
37*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: mvwin.c,v 1.19 2014/02/20 09:42:42 blymn Exp $");
3851ffecc1SBen Gras #endif
3951ffecc1SBen Gras #endif				/* not lint */
4051ffecc1SBen Gras 
4151ffecc1SBen Gras #include "curses.h"
4251ffecc1SBen Gras #include "curses_private.h"
4351ffecc1SBen Gras 
4451ffecc1SBen Gras /*
4551ffecc1SBen Gras  * mvderwin --
460c3ae37fSLionel Sambuc  *      Move a derived window.  This does not change the physical screen
470c3ae37fSLionel Sambuc  * coordinates of the subwin, rather maps the characters in the subwin
480c3ae37fSLionel Sambuc  * sized part of the parent window starting at dy, dx into the subwin.
4951ffecc1SBen Gras  *
5051ffecc1SBen Gras  */
5151ffecc1SBen Gras int
mvderwin(WINDOW * win,int dy,int dx)5251ffecc1SBen Gras mvderwin(WINDOW *win, int dy, int dx)
5351ffecc1SBen Gras {
5451ffecc1SBen Gras 	WINDOW *parent;
5584d9c625SLionel Sambuc 	int x, i;
56*0a6a1f1dSLionel Sambuc 	__LINE *plp;
5751ffecc1SBen Gras 
5851ffecc1SBen Gras 	if (win == NULL)
5951ffecc1SBen Gras 		return ERR;
6051ffecc1SBen Gras 
6151ffecc1SBen Gras 	parent = win->orig;
6251ffecc1SBen Gras 
6351ffecc1SBen Gras 	if (parent == NULL)
6451ffecc1SBen Gras 		return ERR;
6551ffecc1SBen Gras 
660c3ae37fSLionel Sambuc 	if (((win->maxx + dx) > parent->maxx) ||
670c3ae37fSLionel Sambuc 	    ((win->maxy + dy) > parent->maxy))
680c3ae37fSLionel Sambuc 		return ERR;
690c3ae37fSLionel Sambuc 
70*0a6a1f1dSLionel Sambuc 	win->flags |= __ISDERWIN;
71*0a6a1f1dSLionel Sambuc 	win->derx = dx;
72*0a6a1f1dSLionel Sambuc 	win->dery = dy;
73*0a6a1f1dSLionel Sambuc 
7451ffecc1SBen Gras 	x = parent->begx + dx;
750c3ae37fSLionel Sambuc 
76*0a6a1f1dSLionel Sambuc 	/*
77*0a6a1f1dSLionel Sambuc 	 * Mark the source area for the derwin as changed so it will be
78*0a6a1f1dSLionel Sambuc 	 * copied to the destination window on refresh.
79*0a6a1f1dSLionel Sambuc 	 */
80*0a6a1f1dSLionel Sambuc 	for (i = 0; i < win->maxy; i++) {
81*0a6a1f1dSLionel Sambuc 		plp = parent->alines[i + dy];
82*0a6a1f1dSLionel Sambuc 		plp->flags = __ISDIRTY;
83*0a6a1f1dSLionel Sambuc 		if (*plp->firstchp > x)
84*0a6a1f1dSLionel Sambuc 			*plp->firstchp = x;
85*0a6a1f1dSLionel Sambuc 		if (*plp->lastchp < x + win->maxx)
86*0a6a1f1dSLionel Sambuc 			*plp->lastchp = x + win->maxx;
870c3ae37fSLionel Sambuc #ifdef DEBUG
88*0a6a1f1dSLionel Sambuc 		__CTRACE(__CTRACE_REFRESH, "mvderwin: firstchp = %d, lastchp = %d\n", *plp->firstchp, *plp->lastchp);
890c3ae37fSLionel Sambuc #endif
900c3ae37fSLionel Sambuc 	}
910c3ae37fSLionel Sambuc 
920c3ae37fSLionel Sambuc 	return OK;
9351ffecc1SBen Gras }
9451ffecc1SBen Gras 
9551ffecc1SBen Gras /*
9651ffecc1SBen Gras  * mvwin --
9751ffecc1SBen Gras  *	Relocate the starting position of a window.
9851ffecc1SBen Gras  */
9951ffecc1SBen Gras int
mvwin(WINDOW * win,int by,int bx)10051ffecc1SBen Gras mvwin(WINDOW *win, int by, int bx)
10151ffecc1SBen Gras {
10251ffecc1SBen Gras 	WINDOW *orig;
10351ffecc1SBen Gras 	int     dy, dx;
10451ffecc1SBen Gras 
10551ffecc1SBen Gras 	if (by < 0 || by + win->maxy > LINES || bx < 0 || bx + win->maxx > COLS)
10651ffecc1SBen Gras 		return (ERR);
10751ffecc1SBen Gras 	dy = by - win->begy;
10851ffecc1SBen Gras 	dx = bx - win->begx;
10951ffecc1SBen Gras 	orig = win->orig;
11051ffecc1SBen Gras 	if (orig == NULL) {
11151ffecc1SBen Gras 		orig = win;
11251ffecc1SBen Gras 		do {
11351ffecc1SBen Gras 			win->begy += dy;
11451ffecc1SBen Gras 			win->begx += dx;
11551ffecc1SBen Gras 			__swflags(win);
11651ffecc1SBen Gras 			win = win->nextp;
11751ffecc1SBen Gras 		} while (win != orig);
11851ffecc1SBen Gras 	} else {
11951ffecc1SBen Gras 		if (by < orig->begy || win->maxy + dy > orig->maxy)
12051ffecc1SBen Gras 			return (ERR);
12151ffecc1SBen Gras 		if (bx < orig->begx || win->maxx + dx > orig->maxx)
12251ffecc1SBen Gras 			return (ERR);
12351ffecc1SBen Gras 		win->begy = by;
12451ffecc1SBen Gras 		win->begx = bx;
12551ffecc1SBen Gras 		__swflags(win);
12651ffecc1SBen Gras 		__set_subwin(orig, win);
12751ffecc1SBen Gras 	}
12851ffecc1SBen Gras 	__touchwin(win);
12951ffecc1SBen Gras 	return (OK);
13051ffecc1SBen Gras }
131