xref: /titanic_51/usr/src/lib/libxcurses2/src/libc/xcurses/copywin.c (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /* LINTLIBRARY */
30 
31 /*
32  * copywin.c
33  *
34  * XCurses Library
35  *
36  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
37  *
38  */
39 
40 #ifdef M_RCSID
41 #ifndef lint
42 static char rcsID[] =
43 "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
44 "libxcurses/src/libc/xcurses/rcs/copywin.c 1.6 1998/06/01 17:29:15 "
45 "cbates Exp $";
46 #endif
47 #endif
48 
49 #include <private.h>
50 
51 #undef min
52 #define	min(a, b)		((a) < (b) ? (a) : (b))
53 
54 /*
55  * Version of copywin used internally by Curses to compute
56  * the intersection of the two windows before calling copywin().
57  */
58 int
59 __m_copywin(const WINDOW *s, WINDOW *t, int transparent)
60 {
61 	int code, sminr, sminc, tminr, tminc, tmaxr, tmaxc;
62 
63 	tmaxc = min(s->_begx + s->_maxx, t->_begx + t->_maxx) - 1 - t->_begx;
64 	tmaxr = min(s->_begy + s->_maxy, t->_begy + t->_maxy) - 1 - t->_begy;
65 
66 	if (s->_begy < t->_begy) {
67 		sminr = t->_begy - s->_begy;
68 		tminr = 0;
69 	} else {
70 		sminr = 0;
71 		tminr = s->_begy - t->_begy;
72 	}
73 	if (s->_begx < t->_begx) {
74 		sminc = t->_begx - s->_begx;
75 		tminc = 0;
76 	} else {
77 		sminc = 0;
78 		tminc = s->_begx- t->_begx;
79 	}
80 	code = copywin(s, t, sminr, sminc,
81 		tminr, tminc, tmaxr, tmaxc, transparent);
82 
83 	return (code);
84 }
85 
86 /*
87  * Overlay specified part of source window over destination window
88  * NOTE copying is destructive only if transparent is set to false.
89  */
90 int
91 copywin(const WINDOW *s, WINDOW *t,
92 	int sminr, int sminc, int tminr, int tminc,
93 	int tmaxr, int tmaxc, int transparent)
94 {
95 	int	tc;
96 	cchar_t	*st, *tt;
97 	cchar_t	bg = s->_bg;
98 
99 	for (; tminr <= tmaxr; ++tminr, ++sminr) {
100 		st = s->_line[sminr] + sminc;
101 		tt = t->_line[tminr] + tminc;
102 
103 		/* Copy source region to target. */
104 		for (tc = tminc; tc <= tmaxc; ++tc, ++tt, ++st) {
105 			if (transparent) {
106 				if (__m_cc_compare(st, &bg, 1))
107 					continue;
108 			}
109 			*tt = *st;
110 			__m_touch_locs(t, tminr, tc, tc + 1);
111 		}
112 #ifdef M_CURSES_SENSIBLE_WINDOWS
113 		/*
114 		 * Case 4 -
115 		 * Expand incomplete glyph from source into target window.
116 		 */
117 		if (0 < tminc && !t->_line[tminr][tminc]._f)
118 			(void) __m_cc_expand(t, tminr, tminc, -1);
119 		if (tmaxc + 1 < t->_maxx && !__m_cc_islast(t, tminr, tmaxc))
120 			(void) __m_cc_expand(t, tminr, tmaxc, 1);
121 #endif /* M_CURSES_SENSIBLE_WINDOWS */
122 	}
123 
124 	return (OK);
125 }
126