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 /* LINTLIBRARY */ 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[] = 41 "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/" 42 "libxcurses/src/libc/xcurses/rcs/copywin.c 1.6 1998/06/01 17:29:15 " 43 "cbates Exp $"; 44 #endif 45 #endif 46 47 #include <private.h> 48 49 #undef min 50 #define min(a, b) ((a) < (b) ? (a) : (b)) 51 52 /* 53 * Version of copywin used internally by Curses to compute 54 * the intersection of the two windows before calling copywin(). 55 */ 56 int 57 __m_copywin(const WINDOW *s, WINDOW *t, int transparent) 58 { 59 int code, sminr, sminc, tminr, tminc, tmaxr, tmaxc; 60 61 tmaxc = min(s->_begx + s->_maxx, t->_begx + t->_maxx) - 1 - t->_begx; 62 tmaxr = min(s->_begy + s->_maxy, t->_begy + t->_maxy) - 1 - t->_begy; 63 64 if (s->_begy < t->_begy) { 65 sminr = t->_begy - s->_begy; 66 tminr = 0; 67 } else { 68 sminr = 0; 69 tminr = s->_begy - t->_begy; 70 } 71 if (s->_begx < t->_begx) { 72 sminc = t->_begx - s->_begx; 73 tminc = 0; 74 } else { 75 sminc = 0; 76 tminc = s->_begx- t->_begx; 77 } 78 code = copywin(s, t, sminr, sminc, 79 tminr, tminc, tmaxr, tmaxc, transparent); 80 81 return (code); 82 } 83 84 /* 85 * Overlay specified part of source window over destination window 86 * NOTE copying is destructive only if transparent is set to false. 87 */ 88 int 89 copywin(const WINDOW *s, WINDOW *t, 90 int sminr, int sminc, int tminr, int tminc, 91 int tmaxr, int tmaxc, int transparent) 92 { 93 int tc; 94 cchar_t *st, *tt; 95 cchar_t bg = s->_bg; 96 97 for (; tminr <= tmaxr; ++tminr, ++sminr) { 98 st = s->_line[sminr] + sminc; 99 tt = t->_line[tminr] + tminc; 100 101 /* Copy source region to target. */ 102 for (tc = tminc; tc <= tmaxc; ++tc, ++tt, ++st) { 103 if (transparent) { 104 if (__m_cc_compare(st, &bg, 1)) 105 continue; 106 } 107 *tt = *st; 108 __m_touch_locs(t, tminr, tc, tc + 1); 109 } 110 #ifdef M_CURSES_SENSIBLE_WINDOWS 111 /* 112 * Case 4 - 113 * Expand incomplete glyph from source into target window. 114 */ 115 if (0 < tminc && !t->_line[tminr][tminc]._f) 116 (void) __m_cc_expand(t, tminr, tminc, -1); 117 if (tmaxc + 1 < t->_maxx && !__m_cc_islast(t, tminr, tmaxc)) 118 (void) __m_cc_expand(t, tminr, tmaxc, 1); 119 #endif /* M_CURSES_SENSIBLE_WINDOWS */ 120 } 121 122 return (OK); 123 } 124