copywin.c revision 1.1 1 /* $NetBSD: copywin.c,v 1.1 2000/04/18 12:23:01 blymn Exp $ */
2
3 /*-
4 * Copyright (c) 1998-1999 Brett Lymn
5 * (blymn (at) baea.com.au, brett_lymn (at) 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
16 * derived from this software withough specific prior written permission
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 */
31
32 #include <ctype.h>
33 #include "curses.h"
34 #include "curses_private.h"
35
36 /*
37 * copywin --
38 * Copy the box starting at (sminrow, smincol) with a size that
39 * matches the destination box (dminrow, dmincol) by (dmaxrow, dmaxcol)
40 * from the source window srcwin to the destination window dstwin.
41 * If overlay is true then the copy is nondestructive otherwise the
42 * copy is destructive.
43 */
44 int copywin(const WINDOW *srcwin, WINDOW *dstwin, int sminrow,
45 int smincol, int dminrow, int dmincol, int dmaxrow,
46 int dmaxcol, int overlay)
47 {
48 int starty, startx, endy, endx, x, y, y1, y2, smaxrow, smaxcol;
49 __LDATA *sp, *end;
50
51 smaxrow = sminrow + dmaxrow - dminrow;
52 smaxcol = smincol + dmaxcol - dmincol;
53 starty = max(sminrow, dminrow);
54 startx = max(smincol, dmincol);
55 endy = min(sminrow + smaxrow, dminrow + dmaxrow);
56 endx = min(smincol + smaxcol, dmincol + dmaxcol);
57 if (starty >= endy || startx >= endx)
58 return (OK);
59
60 if (overlay == TRUE) {
61 /* non destructive copy */
62 #ifdef DEBUG
63 __CTRACE("copywin overlay mode: from (%d,%d) to (%d,%d)\n",
64 starty, startx, endy, endx);
65 #endif
66 y1 = starty - sminrow;
67 y2 = starty - dminrow;
68 for (y = starty; y < endy; y++, y1++, y2++) {
69 end = &srcwin->lines[y1]->line[endx - srcwin->begx];
70 x = startx - dstwin->begx;
71 for (sp = &srcwin->lines[y1]->line[startx - srcwin->begx];
72 sp < end; sp++) {
73 if (!isspace(sp->ch)) {
74 wmove(dstwin, y2, x);
75 __waddch(dstwin, sp);
76 }
77 x++;
78 }
79 }
80 return (OK);
81 } else {
82 /* destructive copy */
83 #ifdef DEBUG
84 __CTRACE("copywin overwrite mode: from (%d,%d) to (%d,%d)\n",
85 starty, startx, endy, endx);
86 #endif
87 x = endx - startx;
88 for (y = starty; y < endy; y++) {
89 (void) memcpy(
90 &dstwin->lines[y - dstwin->begy]->line[startx - dstwin->begx],
91 &srcwin->lines[y - srcwin->begy]->line[startx - srcwin->begx],
92 (size_t) x * __LDATASIZE);
93 __touchline(dstwin, y, (int) (startx - dstwin->begx),
94 (int) (endx - dstwin->begx), 0);
95 }
96 return (OK);
97 }
98 }
99
100