Annotation of src/lib/libcurses/copywin.c, Revision 1.12
1.12 ! jdc 1: /* $NetBSD: copywin.c,v 1.11 2004/08/02 18:47:52 dsl Exp $ */
1.1 blymn 2:
3: /*-
4: * Copyright (c) 1998-1999 Brett Lymn
5: * (blymn@baea.com.au, brett_lymn@yahoo.com.au)
6: * All rights reserved.
7: *
8: * This code has been donated to The NetBSD Foundation by the Author.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. The name of the author may not be used to endorse or promote products
1.7 wiz 16: * derived from this software without specific prior written permission
1.1 blymn 17: *
18: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28: *
29: *
30: */
1.5 blymn 31:
32: #include <sys/cdefs.h>
33: #ifndef lint
1.12 ! jdc 34: __RCSID("$NetBSD: copywin.c,v 1.11 2004/08/02 18:47:52 dsl Exp $");
1.5 blymn 35: #endif /* not lint */
1.1 blymn 36:
37: #include <ctype.h>
1.2 jdc 38: #include <string.h>
1.1 blymn 39: #include "curses.h"
40: #include "curses_private.h"
41:
42: /*
43: * copywin --
44: * Copy the box starting at (sminrow, smincol) with a size that
45: * matches the destination box (dminrow, dmincol) by (dmaxrow, dmaxcol)
46: * from the source window srcwin to the destination window dstwin.
1.10 dsl 47: * All these coordindinates are relative to the relevant window.
1.8 lukem 48: * If dooverlay is true then the copy is nondestructive otherwise the
1.1 blymn 49: * copy is destructive.
50: */
1.10 dsl 51: int copywin(const WINDOW *srcwin, WINDOW *dstwin,
52: int sminrow, int smincol,
53: int dminrow, int dmincol, int dmaxrow, int dmaxcol, int dooverlay)
1.1 blymn 54: {
1.10 dsl 55: int dcol;
1.1 blymn 56: __LDATA *sp, *end;
1.9 blymn 57:
1.10 dsl 58: /* overwrite() and overlay() can come here with -ve srcwin coords */
59: if (sminrow < 0) {
60: dminrow -= sminrow;
61: sminrow = 0;
62: }
63: if (smincol < 0) {
64: dmincol -= smincol;
65: smincol = 0;
66: }
1.9 blymn 67:
1.10 dsl 68: /* for symmetry allow dstwin coords to be -ve as well */
69: if (dminrow < 0) {
70: sminrow -= dminrow;
71: dminrow = 0;
72: }
73: if (dmincol < 0) {
74: smincol -= dmincol;
75: dmincol = 0;
1.4 blymn 76: }
1.9 blymn 77:
1.10 dsl 78: /* Bound dmaxcol for both windows (should be ok for dstwin) */
79: if (dmaxcol >= dstwin->maxx)
80: dmaxcol = dstwin->maxx - 1;
81: if (smincol + (dmaxcol - dmincol) >= srcwin->maxx)
1.11 dsl 82: dmaxcol = srcwin->maxx + dmincol - smincol - 1;
1.10 dsl 83: if (dmaxcol < dmincol)
84: /* nothing in the intersection */
85: return OK;
86:
87: /* Bound dmaxrow for both windows (should be ok for dstwin) */
1.11 dsl 88: if (dmaxrow >= dstwin->maxy)
1.10 dsl 89: dmaxrow = dstwin->maxy - 1;
90: if (sminrow + (dmaxrow - dminrow) >= srcwin->maxy)
1.11 dsl 91: dmaxrow = srcwin->maxy + dminrow - sminrow - 1;
1.10 dsl 92:
93: #ifdef DEBUG
1.12 ! jdc 94: __CTRACE(__CTRACE_WINDOW,
! 95: "copywin %s mode: from (%d,%d) to (%d,%d-%d,%d)\n",
! 96: dooverlay ? "overlay" : "overwrite",
! 97: sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol);
1.1 blymn 98: #endif
1.10 dsl 99:
100: for (; dminrow <= dmaxrow; sminrow++, dminrow++) {
101: sp = &srcwin->lines[sminrow]->line[smincol];
102: end = sp + dmaxcol - dmincol;
103: if (dooverlay) {
104: for (dcol = dmincol; sp <= end; dcol++, sp++) {
105: /* XXX: Perhaps this should check for the
106: * background character
107: */
108: if (!isspace(sp->ch)) {
109: wmove(dstwin, dminrow, dcol);
110: __waddch(dstwin, sp);
111: }
112: }
113: } else {
114: wmove(dstwin, dminrow, dmincol);
115: for (; sp <= end; sp++) {
1.4 blymn 116: __waddch(dstwin, sp);
117: }
1.1 blymn 118: }
119: }
1.10 dsl 120: return OK;
1.1 blymn 121: }
122:
CVSweb <webmaster@jp.NetBSD.org>