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