-int sx, sy, dx, dy;
-bool touched;
-chtype bk = AttrOf(dst->_bkgd);
-chtype mask = ~(chtype)((bk&A_COLOR) ? A_COLOR : 0);
-
- T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
- src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
-
- if (!src || !dst)
- returnCode(ERR);
-
- /* make sure rectangle exists in source */
- if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) ||
- (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) {
- returnCode(ERR);
+ int sx, sy, dx, dy;
+ bool touched;
+ attr_t bk;
+ attr_t mask;
+
+ T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
+ src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
+
+ if (!src || !dst)
+ returnCode(ERR);
+
+ bk = AttrOf(dst->_nc_bkgd);
+ mask = ~(attr_t) ((bk & A_COLOR) ? A_COLOR : 0);
+
+ /* make sure rectangle exists in source */
+ if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) ||
+ (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) {
+ returnCode(ERR);
+ }
+
+ T(("rectangle exists in source"));
+
+ /* make sure rectangle fits in destination */
+ if (dmaxrow > dst->_maxy || dmaxcol > dst->_maxx) {
+ returnCode(ERR);
+ }
+
+ T(("rectangle fits in destination"));
+
+ for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) {
+ touched = FALSE;
+ for (dx = dmincol, sx = smincol; dx <= dmaxcol; sx++, dx++) {
+ if (over) {
+ if ((CharOf(src->_line[sy].text[sx]) != L(' ')) &&
+ (!CharEq(dst->_line[dy].text[dx], src->_line[sy].text[sx]))) {
+ dst->_line[dy].text[dx] = src->_line[sy].text[sx];
+ SetAttr(dst->_line[dy].text[dx],
+ (AttrOf(src->_line[sy].text[sx]) & mask) | bk);
+ touched = TRUE;
+ }
+ } else {
+ if (!CharEq(dst->_line[dy].text[dx], src->_line[sy].text[sx])) {
+ dst->_line[dy].text[dx] = src->_line[sy].text[sx];
+ touched = TRUE;
+ }
+ }