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