1 /* $NetBSD: copywin.c,v 1.14 2007/11/08 06:39:31 jdc Exp $ */
4 * Copyright (c) 1998-1999 Brett Lymn
5 * (blymn@baea.com.au, brett_lymn@yahoo.com.au)
8 * This code has been donated to The NetBSD Foundation by the Author.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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 without specific prior written permission
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.
32 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: copywin.c,v 1.14 2007/11/08 06:39:31 jdc Exp $");
40 #include "curses_private.h"
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.
47 * All these coordindinates are relative to the relevant window.
48 * If dooverlay is true then the copy is nondestructive otherwise the
49 * copy is destructive.
51 int copywin(const WINDOW
*srcwin
, WINDOW
*dstwin
,
52 int sminrow
, int smincol
,
53 int dminrow
, int dmincol
, int dmaxrow
, int dmaxcol
, int dooverlay
)
60 #endif /* HAVE_WCHAR */
62 /* overwrite() and overlay() can come here with -ve srcwin coords */
72 /* for symmetry allow dstwin coords to be -ve as well */
82 /* Bound dmaxcol for both windows (should be ok for dstwin) */
83 if (dmaxcol
>= dstwin
->maxx
)
84 dmaxcol
= dstwin
->maxx
- 1;
85 if (smincol
+ (dmaxcol
- dmincol
) >= srcwin
->maxx
)
86 dmaxcol
= srcwin
->maxx
+ dmincol
- smincol
- 1;
87 if (dmaxcol
< dmincol
)
88 /* nothing in the intersection */
91 /* Bound dmaxrow for both windows (should be ok for dstwin) */
92 if (dmaxrow
>= dstwin
->maxy
)
93 dmaxrow
= dstwin
->maxy
- 1;
94 if (sminrow
+ (dmaxrow
- dminrow
) >= srcwin
->maxy
)
95 dmaxrow
= srcwin
->maxy
+ dminrow
- sminrow
- 1;
98 __CTRACE(__CTRACE_WINDOW
,
99 "copywin %s mode: from (%d,%d) to (%d,%d-%d,%d)\n",
100 dooverlay
? "overlay" : "overwrite",
101 sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
);
104 for (; dminrow
<= dmaxrow
; sminrow
++, dminrow
++) {
105 sp
= &srcwin
->alines
[sminrow
]->line
[smincol
];
106 end
= sp
+ dmaxcol
- dmincol
;
107 for (dcol
= dmincol
; sp
<= end
; dcol
++, sp
++) {
108 /* XXX: Perhaps this should check for the
109 * background character
111 if ((dooverlay
&& !isspace(sp
->ch
)) || !dooverlay
) {
112 wmove(dstwin
, dminrow
, dcol
);
114 __waddch(dstwin
, sp
);
117 cc
.attributes
= sp
->attr
;
121 while (np
&& cc
.elements
<=
123 cc
.vals
[cc
.elements
++] = np
->ch
;
127 wadd_wch(dstwin
, &cc
);
128 #endif /* HAVE_WCHAR */