5 /*man-start**************************************************************
12 int overlay(const WINDOW *src_w, WINDOW *dst_w)
13 int overwrite(const WINDOW *src_w, WINDOW *dst_w)
14 int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr,
15 int src_tc, int dst_tr, int dst_tc, int dst_br,
16 int dst_bc, int _overlay)
20 overlay() and overwrite() copy all the text from src_w into dst_w.
21 The windows need not be the same size. Those characters in the source
22 window that intersect with the destination window are copied, so that
23 the characters appear in the same physical position on the screen.
24 The difference between the two functions is that overlay() is non-
25 destructive (blanks are not copied) while overwrite() is destructive
28 copywin() is similar, but doesn't require that the two windows
29 overlap. The arguments src_tc and src_tr specify the top left corner
30 of the region to be copied. dst_tc, dst_tr, dst_br, and dst_bc
31 specify the region within the destination window to copy to. The
32 argument "overlay", if TRUE, indicates that the copy is done non-
33 destructively (as in overlay()); blanks in the source window are not
34 copied to the destination window. When overlay is FALSE, blanks are
39 All functions return OK on success and ERR on error.
47 **man-end****************************************************************/
49 /* Thanks to Andreas Otte <venn@@uni-paderborn.de> for the
50 corrected overlay()/overwrite() behavior. */
52 static int _copy_win(const WINDOW
*src_w
, WINDOW
*dst_w
, int src_tr
,
53 int src_tc
, int src_br
, int src_bc
, int dst_tr
,
54 int dst_tc
, bool _overlay
)
56 int col
, line
, y1
, fc
, *minchng
, *maxchng
;
57 chtype
*w1ptr
, *w2ptr
;
60 int xdiff
= src_bc
- src_tc
;
61 int ydiff
= src_br
- src_tr
;
66 minchng
= dst_w
->_firstch
;
67 maxchng
= dst_w
->_lastch
;
69 for (y1
= 0; y1
< dst_tr
; y1
++)
75 for (line
= 0; line
< ydiff
; line
++)
77 w1ptr
= src_w
->_y
[line
+ src_tr
] + src_tc
;
78 w2ptr
= dst_w
->_y
[line
+ dst_tr
] + dst_tc
;
82 for (col
= 0; col
< xdiff
; col
++)
84 if ((*w1ptr
) != (*w2ptr
) &&
85 !((*w1ptr
& A_CHARTEXT
) == ' ' && _overlay
))
99 if (*minchng
== _NO_CHANGE
)
104 else if (fc
!= _NO_CHANGE
)
119 int _copy_overlap(const WINDOW
*src_w
, WINDOW
*dst_w
, bool overlay
)
121 int first_line
, first_col
, last_line
, last_col
;
122 int src_start_x
, src_start_y
, dst_start_x
, dst_start_y
;
125 if (!src_w
|| !dst_w
)
128 first_col
= max(dst_w
->_begx
, src_w
->_begx
);
129 first_line
= max(dst_w
->_begy
, src_w
->_begy
);
131 last_col
= min(src_w
->_begx
+ src_w
->_maxx
, dst_w
->_begx
+ dst_w
->_maxx
);
132 last_line
= min(src_w
->_begy
+ src_w
->_maxy
, dst_w
->_begy
+ dst_w
->_maxy
);
134 /* determine the overlapping region of the two windows in real
137 /* if no overlapping region, do nothing */
139 if ((last_col
< first_col
) || (last_line
< first_line
))
142 /* size of overlapping region */
144 xdiff
= last_col
- first_col
;
145 ydiff
= last_line
- first_line
;
147 if (src_w
->_begx
<= dst_w
->_begx
)
149 src_start_x
= dst_w
->_begx
- src_w
->_begx
;
154 dst_start_x
= src_w
->_begx
- dst_w
->_begx
;
158 if (src_w
->_begy
<= dst_w
->_begy
)
160 src_start_y
= dst_w
->_begy
- src_w
->_begy
;
165 dst_start_y
= src_w
->_begy
- dst_w
->_begy
;
169 return _copy_win(src_w
, dst_w
, src_start_y
, src_start_x
,
170 src_start_y
+ ydiff
, src_start_x
+ xdiff
,
171 dst_start_y
, dst_start_x
, overlay
);
174 int overlay(const WINDOW
*src_w
, WINDOW
*dst_w
)
176 PDC_LOG(("overlay() - called\n"));
178 return _copy_overlap(src_w
, dst_w
, TRUE
);
181 int overwrite(const WINDOW
*src_w
, WINDOW
*dst_w
)
183 PDC_LOG(("overwrite() - called\n"));
185 return _copy_overlap(src_w
, dst_w
, FALSE
);
188 int copywin(const WINDOW
*src_w
, WINDOW
*dst_w
, int src_tr
, int src_tc
,
189 int dst_tr
, int dst_tc
, int dst_br
, int dst_bc
, int _overlay
)
191 int src_end_x
, src_end_y
;
192 int src_rows
, src_cols
, dst_rows
, dst_cols
;
193 int min_rows
, min_cols
;
195 PDC_LOG(("copywin() - called\n"));
197 if (!src_w
|| !dst_w
|| dst_w
== curscr
|| dst_br
>= dst_w
->_maxy
198 || dst_bc
>= dst_w
->_maxx
|| dst_tr
< 0 || dst_tc
< 0)
201 src_rows
= src_w
->_maxy
- src_tr
;
202 src_cols
= src_w
->_maxx
- src_tc
;
203 dst_rows
= dst_br
- dst_tr
+ 1;
204 dst_cols
= dst_bc
- dst_tc
+ 1;
206 min_rows
= min(src_rows
, dst_rows
);
207 min_cols
= min(src_cols
, dst_cols
);
209 src_end_y
= src_tr
+ min_rows
;
210 src_end_x
= src_tc
+ min_cols
;
212 return _copy_win(src_w
, dst_w
, src_tr
, src_tc
, src_end_y
, src_end_x
,
213 dst_tr
, dst_tc
, _overlay
);