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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
45 * This routine writes parts of Srcwin onto Dstwin,
46 * either non-destructively (over_lay = TRUE) or destructively
51 #include <sys/types.h>
52 #include "curses_inc.h"
55 copywin(WINDOW
*Srcwin
, WINDOW
*Dstwin
,
56 int minRowSrc
, int minColSrc
, int minRowDst
,
57 int minColDst
, int maxRowDst
, int maxColDst
,
60 int ySrc
, yDst
, which_copy
, t
;
61 int height
= (maxRowDst
- minRowDst
) + 1,
62 width
= (maxColDst
- minColDst
) + 1;
63 chtype
**_yDst
= Dstwin
->_y
, **_ySrc
= Srcwin
->_y
,
64 bkSrc
= Srcwin
->_bkgd
, atDst
= Dstwin
->_attrs
,
65 *spSrc
, *spDst
, *epSrc
, *epDst
, *savepS
,
66 *savepD
, width_bytes
, numcopied
;
70 fprintf(outf
, "copywin(%0.2o, %0.2o);\n", Srcwin
, Dstwin
);
74 * If we are going to be copying from curscr,
75 * first offset into curscr the offset the Dstwin knows about.
78 minRowSrc
+= Dstwin
->_yoffset
;
81 * There are three types of copy.
82 * 0 - Straight memcpy allowed
83 * 1 - We have to first check to see if the source character is a blank
84 * 2 - Dstwin has attributes or bkgd that must changed
85 * on a char-by-char basis.
87 if ((which_copy
= (over_lay
) ? 1 :
88 (2 * ((Dstwin
->_attrs
!= A_NORMAL
) ||
89 (Dstwin
->_bkgd
!= _BLNKCHAR
)))) == 0)
90 width_bytes
= width
* (int)sizeof (chtype
);
93 for (ySrc
= minRowSrc
, yDst
= minRowDst
; height
-- > 0; ySrc
++, yDst
++) {
95 spSrc
= &_ySrc
[ySrc
][minColSrc
];
96 spDst
= &_yDst
[yDst
][minColDst
];
99 epSrc
= savepS
= &_ySrc
[ySrc
][maxColDst
];
100 epDst
= savepD
= &_yDst
[yDst
][maxColDst
];
101 /* only copy into an area bounded by whole characters */
102 for (; spDst
<= epDst
; spSrc
++, spDst
++)
107 for (; epDst
>= spDst
; --epDst
, --epSrc
)
110 t
= _curs_scrwidth
[TYPE(RBYTE(*epDst
))] - 1;
111 if (epDst
+t
<= savepD
)
112 epDst
+= t
, epSrc
+= t
;
114 epDst
-= 1, epSrc
-= 1;
117 /* don't copy partial characters */
118 for (; spSrc
<= epSrc
; ++spSrc
, ++spDst
)
123 for (; epSrc
>= spSrc
; --epSrc
, --epDst
)
126 t
= _curs_scrwidth
[TYPE(RBYTE(*epSrc
))] - 1;
127 if (epSrc
+t
<= savepS
)
128 epSrc
+= t
, epDst
+= t
;
130 epSrc
-= 1, epDst
-= 1;
133 /* make sure that the copied-to place is clean */
135 (void) _mbclrch(Dstwin
, minRowDst
,
137 (intptr_t)(spDst
- *_yDst
[yDst
]));
139 (void) _mbclrch(Dstwin
, minRowDst
,
141 (intptr_t)(epDst
- *_yDst
[yDst
]));
143 numcopied
= (chtype
) (epDst
- spDst
+ 1);
145 if (which_copy
== 1) { /* overlay */
146 for (; numcopied
-- > 0; spSrc
++, spDst
++)
147 /* Check to see if the char is a "blank/bkgd". */
149 *spDst
= *spSrc
| atDst
;
151 for (; numcopied
-- > 0; spSrc
++, spDst
++)
152 *spDst
= *spSrc
| atDst
;
155 /* ... copy all chtypes */
156 (void) memcpy((char *)&_yDst
[yDst
][minColDst
],
157 (char *)&_ySrc
[ySrc
][minColSrc
], width_bytes
);
160 /* note that the line has changed */
161 if (minColDst
< Dstwin
->_firstch
[yDst
])
163 Dstwin
->_firstch
[yDst
] = (short)minColDst
;
164 if (maxColDst
> Dstwin
->_lastch
[yDst
])
166 Dstwin
->_lastch
[yDst
] = (short)maxColDst
;
169 #ifdef _VR3_COMPAT_CODE
171 (*_y16update
)(Dstwin
, (maxRowDst
- minRowDst
) + 1,
172 (maxColDst
- minColDst
) + 1, minRowDst
, minColDst
);
174 #endif /* _VR3_COMPAT_CODE */
176 /* note that something in Dstwin has changed */
177 Dstwin
->_flags
|= _WINCHANGED
;
182 return (Dstwin
->_immed
? wrefresh(Dstwin
) : OK
);