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, by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 /* 30 * copywin.c 31 * 32 * XCurses Library 33 * 34 * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved. 35 * 36 */ 37 38 #ifdef M_RCSID 39 #ifndef lint 40 static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/copywin.c 1.2 1995/09/19 19:15:33 ant Exp $"; 41 #endif 42 #endif 43 44 #include <private.h> 45 #include <wctype.h> 46 47 #undef min 48 #define min(a,b) ((a) < (b) ? (a) : (b)) 49 50 /*f 51 * Version of copywin used internally by Curses to compute 52 * the intersection of the two windows before calling copywin(). 53 */ 54 int 55 __m_copywin(s, t, transparent) 56 const WINDOW *s; 57 WINDOW *t; 58 int transparent; 59 { 60 int code, sminr, sminc, tminr, tminc, tmaxr, tmaxc; 61 62 #ifdef M_CURSES_TRACE 63 __m_trace("__m_copywin(%p, %p, %d)", s, t, transparent); 64 #endif 65 66 tmaxc = min(s->_begx + s->_maxx, t->_begx + t->_maxx) - 1 - t->_begx; 67 tmaxr = min(s->_begy + s->_maxy, t->_begy + t->_maxy) - 1 - t->_begy; 68 69 if (s->_begy < t->_begy) { 70 sminr = t->_begy - s->_begy; 71 tminr = 0; 72 } else { 73 sminr = 0; 74 tminr = s->_begy - t->_begy; 75 } 76 if (s->_begx < t->_begx) { 77 sminc = t->_begx - s->_begx; 78 tminc = 0; 79 } else { 80 sminc = 0; 81 tminc = s->_begx- t->_begx; 82 } 83 code = copywin( 84 s, t, sminr, sminc, tminr, tminc, tmaxr, tmaxc, transparent 85 ); 86 87 return __m_return_code("__m_copywin", code); 88 } 89 90 /*f 91 * Overlay specified part of source window over destination window 92 * NOTE copying is destructive only if transparent is set to false. 93 */ 94 int 95 copywin(s, t, sminr, sminc, tminr, tminc, tmaxr, tmaxc, transparent) 96 const WINDOW *s; 97 WINDOW *t; 98 int sminr, sminc, tminr, tminc, tmaxr, tmaxc, transparent; 99 { 100 int i, tc; 101 cchar_t *st, *tt; 102 103 #ifdef M_CURSES_TRACE 104 __m_trace( 105 "copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)", 106 s, t, sminr, sminc, tminr, tminc, tmaxr, tmaxc, transparent 107 ); 108 #endif 109 110 for (; tminr <= tmaxr; ++tminr, ++sminr) { 111 st = s->_line[sminr] + sminc; 112 tt = t->_line[tminr] + tminc; 113 114 /* Check target window for overlap of broad 115 * characters around the outer edge of the 116 * source window's location. 117 */ 118 __m_cc_erase(t, tminr, tminc, tminr, tminc); 119 __m_cc_erase(t, tminr, tmaxc, tminr, tmaxc); 120 121 /* Copy source region to target. */ 122 for (tc = tminc; tc <= tmaxc; ++tc, ++tt, ++st) { 123 if (transparent) 124 if (iswspace(st->_wc[0])) 125 continue; 126 *tt = *st; 127 } 128 129 #ifdef M_CURSES_SENSIBLE_WINDOWS 130 /* Case 4 - 131 * Expand incomplete glyph from source into target window. 132 */ 133 if (0 < tminc && !t->_line[tminr][tminc]._f) 134 (void) __m_cc_expand(t, tminr, tminc, -1); 135 if (tmaxc + 1 < t->_maxx && !__m_cc_islast(t, tminr, tmaxc)) 136 (void) __m_cc_expand(t, tminr, tmaxc, 1); 137 #endif /* M_CURSES_SENSIBLE_WINDOWS */ 138 } 139 140 return __m_return_code("copywin", OK); 141 } 142