1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate * All rights reserved.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* LINTLIBRARY */
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate * wrefresh.c
31*7c478bd9Sstevel@tonic-gate *
32*7c478bd9Sstevel@tonic-gate * XCurses Library
33*7c478bd9Sstevel@tonic-gate *
34*7c478bd9Sstevel@tonic-gate * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
35*7c478bd9Sstevel@tonic-gate *
36*7c478bd9Sstevel@tonic-gate */
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate #ifdef M_RCSID
39*7c478bd9Sstevel@tonic-gate #ifndef lint
40*7c478bd9Sstevel@tonic-gate static char rcsID[] =
41*7c478bd9Sstevel@tonic-gate "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
42*7c478bd9Sstevel@tonic-gate "libxcurses/src/libc/xcurses/rcs/wrefresh.c 1.7 1998/06/04 17:52:06 "
43*7c478bd9Sstevel@tonic-gate "cbates Exp $";
44*7c478bd9Sstevel@tonic-gate #endif
45*7c478bd9Sstevel@tonic-gate #endif
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate #include <private.h>
48*7c478bd9Sstevel@tonic-gate #include <string.h>
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate * Update curscr with the given window then display to the terminal.
52*7c478bd9Sstevel@tonic-gate * Unless leaveok() has been enabled, the physical cursor of the
53*7c478bd9Sstevel@tonic-gate * terminal is left at the location of the cursor for that window.
54*7c478bd9Sstevel@tonic-gate */
55*7c478bd9Sstevel@tonic-gate int
wrefresh(WINDOW * w)56*7c478bd9Sstevel@tonic-gate wrefresh(WINDOW *w)
57*7c478bd9Sstevel@tonic-gate {
58*7c478bd9Sstevel@tonic-gate int value;
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate if (w == curscr)
61*7c478bd9Sstevel@tonic-gate value = clearok(__m_screen->_newscr, TRUE);
62*7c478bd9Sstevel@tonic-gate else
63*7c478bd9Sstevel@tonic-gate value = wnoutrefresh(w);
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gate if (value == OK)
66*7c478bd9Sstevel@tonic-gate value = doupdate();
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate return (value);
69*7c478bd9Sstevel@tonic-gate }
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate /*
72*7c478bd9Sstevel@tonic-gate * Update newscr with the given window. This allows newscr to be
73*7c478bd9Sstevel@tonic-gate * updated with several windows before doing a doupdate() (and so
74*7c478bd9Sstevel@tonic-gate * improve the efficiency of multiple updates in comparison to
75*7c478bd9Sstevel@tonic-gate * looping through wrefresh() for all windows).
76*7c478bd9Sstevel@tonic-gate */
77*7c478bd9Sstevel@tonic-gate int
wnoutrefresh(WINDOW * w)78*7c478bd9Sstevel@tonic-gate wnoutrefresh(WINDOW *w)
79*7c478bd9Sstevel@tonic-gate {
80*7c478bd9Sstevel@tonic-gate int wy, wx, ny, nx, dx, value;
81*7c478bd9Sstevel@tonic-gate WINDOW *ns = __m_screen->_newscr;
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate /* Kluge to make test suite happy ... */
84*7c478bd9Sstevel@tonic-gate if (w == stdscr)
85*7c478bd9Sstevel@tonic-gate (void) slk_noutrefresh();
86*7c478bd9Sstevel@tonic-gate
87*7c478bd9Sstevel@tonic-gate value = (w->_flags & W_IS_PAD) ? ERR : OK;
88*7c478bd9Sstevel@tonic-gate
89*7c478bd9Sstevel@tonic-gate if (value == OK) {
90*7c478bd9Sstevel@tonic-gate /*
91*7c478bd9Sstevel@tonic-gate * This loop is similar to what copywin() does, except that
92*7c478bd9Sstevel@tonic-gate * this loop only copies dirty lines, while copywin() copies
93*7c478bd9Sstevel@tonic-gate * every line.
94*7c478bd9Sstevel@tonic-gate */
95*7c478bd9Sstevel@tonic-gate for (wy = 0, ny = w->_begy; wy < w->_maxy; ++wy, ++ny) {
96*7c478bd9Sstevel@tonic-gate /* Has line been touched? */
97*7c478bd9Sstevel@tonic-gate if (w->_last[wy] <= w->_first[wy])
98*7c478bd9Sstevel@tonic-gate continue;
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate wx = w->_first[wy];
101*7c478bd9Sstevel@tonic-gate nx = w->_begx + wx;
102*7c478bd9Sstevel@tonic-gate dx = w->_last[wy] - wx;
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate /*
105*7c478bd9Sstevel@tonic-gate * Case 3 - Check target window for overlap of broad
106*7c478bd9Sstevel@tonic-gate * characters around the outer edge of the source
107*7c478bd9Sstevel@tonic-gate * window's location.
108*7c478bd9Sstevel@tonic-gate */
109*7c478bd9Sstevel@tonic-gate (void) memcpy(&ns->_line[ny][nx], &w->_line[wy][wx],
110*7c478bd9Sstevel@tonic-gate dx * sizeof (**w->_line));
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate /* Make destination dirtier */
113*7c478bd9Sstevel@tonic-gate if (ns->_first[ny] > nx)
114*7c478bd9Sstevel@tonic-gate ns->_first[ny] = (short) nx;
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate if (ns->_last[ny] < (nx + dx))
117*7c478bd9Sstevel@tonic-gate ns->_last[ny] = (short) (nx + dx);
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate if (!ns->_line[ny][nx]._f) {
120*7c478bd9Sstevel@tonic-gate /*
121*7c478bd9Sstevel@tonic-gate * Case 5 - Incomplete glyph copied from
122*7c478bd9Sstevel@tonic-gate * source at screen margins.
123*7c478bd9Sstevel@tonic-gate */
124*7c478bd9Sstevel@tonic-gate if (nx <= 0)
125*7c478bd9Sstevel@tonic-gate (void) __m_cc_erase(ns, ny, 0, ny, 0);
126*7c478bd9Sstevel@tonic-gate #ifdef M_CURSES_SENSIBLE_WINDOWS
127*7c478bd9Sstevel@tonic-gate /*
128*7c478bd9Sstevel@tonic-gate * Case 4 - Expand incomplete glyph from
129*7c478bd9Sstevel@tonic-gate * source into target window.
130*7c478bd9Sstevel@tonic-gate */
131*7c478bd9Sstevel@tonic-gate else if (0 < nx)
132*7c478bd9Sstevel@tonic-gate (void) __m_cc_expand(ns, ny, nx, -1);
133*7c478bd9Sstevel@tonic-gate #endif /* M_CURSES_SENSIBLE_WINDOWS */
134*7c478bd9Sstevel@tonic-gate }
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate if (!__m_cc_islast(ns, ny, nx+dx-1)) {
137*7c478bd9Sstevel@tonic-gate /*
138*7c478bd9Sstevel@tonic-gate * Case 5 - Incomplete glyph copied from
139*7c478bd9Sstevel@tonic-gate * source at screen margins.
140*7c478bd9Sstevel@tonic-gate */
141*7c478bd9Sstevel@tonic-gate if (ns->_maxx <= nx + dx)
142*7c478bd9Sstevel@tonic-gate (void) __m_cc_erase(ns, ny, nx + dx - 1,
143*7c478bd9Sstevel@tonic-gate ny, nx + dx - 1);
144*7c478bd9Sstevel@tonic-gate #ifdef M_CURSES_SENSIBLE_WINDOWS
145*7c478bd9Sstevel@tonic-gate /*
146*7c478bd9Sstevel@tonic-gate * Case 4 - Expand incomplete glyph from
147*7c478bd9Sstevel@tonic-gate * source into target window.
148*7c478bd9Sstevel@tonic-gate */
149*7c478bd9Sstevel@tonic-gate else if (nx + dx < ns->_maxx)
150*7c478bd9Sstevel@tonic-gate (void) __m_cc_expand(ns, ny,
151*7c478bd9Sstevel@tonic-gate nx + dx - 1, 1);
152*7c478bd9Sstevel@tonic-gate #endif /* M_CURSES_SENSIBLE_WINDOWS */
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate /* Untouch line. */
156*7c478bd9Sstevel@tonic-gate w->_first[wy] = w->_maxx;
157*7c478bd9Sstevel@tonic-gate w->_last[wy] = -1;
158*7c478bd9Sstevel@tonic-gate
159*7c478bd9Sstevel@tonic-gate /* Remember refresh region (inclusive). */
160*7c478bd9Sstevel@tonic-gate w->_refy = w->_begy;
161*7c478bd9Sstevel@tonic-gate w->_refx = w->_begx;
162*7c478bd9Sstevel@tonic-gate w->_sminy = w->_sminx = 0;
163*7c478bd9Sstevel@tonic-gate w->_smaxy = ns->_maxy - 1;
164*7c478bd9Sstevel@tonic-gate w->_smaxx = ns->_maxx - 1;
165*7c478bd9Sstevel@tonic-gate }
166*7c478bd9Sstevel@tonic-gate
167*7c478bd9Sstevel@tonic-gate ns->_scroll = w->_scroll;
168*7c478bd9Sstevel@tonic-gate w->_scroll = 0;
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate /* Last refreshed window controls W_LEAVE_CURSOR flag. */
171*7c478bd9Sstevel@tonic-gate ns->_flags &= ~W_LEAVE_CURSOR;
172*7c478bd9Sstevel@tonic-gate ns->_cury = w->_cury + w->_begy;
173*7c478bd9Sstevel@tonic-gate ns->_curx = w->_curx + w->_begx;
174*7c478bd9Sstevel@tonic-gate
175*7c478bd9Sstevel@tonic-gate ns->_flags |= w->_flags &
176*7c478bd9Sstevel@tonic-gate (W_CLEAR_WINDOW | W_REDRAW_WINDOW | W_LEAVE_CURSOR);
177*7c478bd9Sstevel@tonic-gate w->_flags &= ~(W_CLEAR_WINDOW | W_REDRAW_WINDOW);
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate return (value);
181*7c478bd9Sstevel@tonic-gate }
182*7c478bd9Sstevel@tonic-gate
183*7c478bd9Sstevel@tonic-gate /*
184*7c478bd9Sstevel@tonic-gate * Check overlaping region on a line.
185*7c478bd9Sstevel@tonic-gate *
186*7c478bd9Sstevel@tonic-gate * When copying a source window region over another target window
187*7c478bd9Sstevel@tonic-gate * region, we have a few cases which to concern ourselves with.
188*7c478bd9Sstevel@tonic-gate *
189*7c478bd9Sstevel@tonic-gate * Let {, [, ( and ), ], } denote the left and right halves of
190*7c478bd9Sstevel@tonic-gate * broad glyphes.
191*7c478bd9Sstevel@tonic-gate *
192*7c478bd9Sstevel@tonic-gate * Let alpha-numerics and periods (.) be narrow glyphes.
193*7c478bd9Sstevel@tonic-gate *
194*7c478bd9Sstevel@tonic-gate * Let hash (#) be a narrow background character.
195*7c478bd9Sstevel@tonic-gate *
196*7c478bd9Sstevel@tonic-gate * Let vertical bar, hyphen, and plus represent the borders
197*7c478bd9Sstevel@tonic-gate * of a window.
198*7c478bd9Sstevel@tonic-gate *
199*7c478bd9Sstevel@tonic-gate * 1. Copy narrow characters over narrow characters.
200*7c478bd9Sstevel@tonic-gate * copywin(s, t, 0, 1, 0, 1, 1, 3, 0)
201*7c478bd9Sstevel@tonic-gate * s t ==> t
202*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
203*7c478bd9Sstevel@tonic-gate * |abcdef| |......| |.bcd..|
204*7c478bd9Sstevel@tonic-gate * |ghijkl| |......| |.hij..|
205*7c478bd9Sstevel@tonic-gate * |mnopqr| |......| |......|
206*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
207*7c478bd9Sstevel@tonic-gate * Nothing special.
208*7c478bd9Sstevel@tonic-gate *
209*7c478bd9Sstevel@tonic-gate * 2. Copy whole broad characters over narrow characters.
210*7c478bd9Sstevel@tonic-gate * copywin(s, t, 0, 1, 0, 1, 1, 3, 0)
211*7c478bd9Sstevel@tonic-gate * s t ==> t
212*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
213*7c478bd9Sstevel@tonic-gate * |a[]def| |......| |.[]d..|
214*7c478bd9Sstevel@tonic-gate * |gh{}kl| |......| |.h{}..|
215*7c478bd9Sstevel@tonic-gate * |mnopqr| |......| |......|
216*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
217*7c478bd9Sstevel@tonic-gate * Nothing special.
218*7c478bd9Sstevel@tonic-gate *
219*7c478bd9Sstevel@tonic-gate * 3. Copy narrow from source overlaps broad in target.
220*7c478bd9Sstevel@tonic-gate * copywin(s, t, 0, 1, 0, 1, 1, 3, 0)
221*7c478bd9Sstevel@tonic-gate * s t ==> t
222*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
223*7c478bd9Sstevel@tonic-gate * |abcdef| |[]....| |#bcd..|
224*7c478bd9Sstevel@tonic-gate * |ghijkl| |...{}.| |.hij#.|
225*7c478bd9Sstevel@tonic-gate * |mnopqr| |......| |......|
226*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
227*7c478bd9Sstevel@tonic-gate * The # background characters have wiped out the remaining
228*7c478bd9Sstevel@tonic-gate * halves of broad characters. This may result also with
229*7c478bd9Sstevel@tonic-gate * a wnoutrefresh() of a window onto curscr.
230*7c478bd9Sstevel@tonic-gate *
231*7c478bd9Sstevel@tonic-gate * The following case appears to be disallowed in XPG4 V2
232*7c478bd9Sstevel@tonic-gate * and I think they're wrong, so I've conditionalised the code
233*7c478bd9Sstevel@tonic-gate * on M_CURSES_SENSIBLE_WINDOWS.
234*7c478bd9Sstevel@tonic-gate *
235*7c478bd9Sstevel@tonic-gate * 4. Copy incomplete broad from source to target.
236*7c478bd9Sstevel@tonic-gate * copywin(s, t, 0, 1, 0, 1, 1, 3, 0)
237*7c478bd9Sstevel@tonic-gate * s t ==> t
238*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
239*7c478bd9Sstevel@tonic-gate * |[]cdef| |123456| |[]cd56|
240*7c478bd9Sstevel@tonic-gate * |ghi{}l| |789012| |7hi{}2|
241*7c478bd9Sstevel@tonic-gate * |mnopqr| |......| |......|
242*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
243*7c478bd9Sstevel@tonic-gate * The ] and { halves of broad characters have been copied and
244*7c478bd9Sstevel@tonic-gate * expanded into the target outside of the specified target region.
245*7c478bd9Sstevel@tonic-gate * This may result also with a wnoutrefresh() of a window onto
246*7c478bd9Sstevel@tonic-gate * curscr.
247*7c478bd9Sstevel@tonic-gate *
248*7c478bd9Sstevel@tonic-gate * Consider a pop-up dialog that contains narrow characters and
249*7c478bd9Sstevel@tonic-gate * a base window that contains broad characters and we do the
250*7c478bd9Sstevel@tonic-gate * following:
251*7c478bd9Sstevel@tonic-gate *
252*7c478bd9Sstevel@tonic-gate * save = dupwin(dialog); // create backing store
253*7c478bd9Sstevel@tonic-gate * overwrite(curscr, save); // save region to be overlayed
254*7c478bd9Sstevel@tonic-gate * wrefresh(dialog); // display dialog
255*7c478bd9Sstevel@tonic-gate * ... // do dialog stuff
256*7c478bd9Sstevel@tonic-gate * wrefresh(save); // restore screen image
257*7c478bd9Sstevel@tonic-gate * delwin(save); // release backing store
258*7c478bd9Sstevel@tonic-gate *
259*7c478bd9Sstevel@tonic-gate * Code similar to this has been used to implement generic popup()
260*7c478bd9Sstevel@tonic-gate * and popdown() routines. In the simple case where the base window
261*7c478bd9Sstevel@tonic-gate * contains narrow characters only, it would be correctly restored.
262*7c478bd9Sstevel@tonic-gate *
263*7c478bd9Sstevel@tonic-gate * However with broad characters, the overwrite() could copy a
264*7c478bd9Sstevel@tonic-gate * region with incomplete broad characters. The wrefresh(dialog)
265*7c478bd9Sstevel@tonic-gate * results in case 3. In order to restore the window correctly with
266*7c478bd9Sstevel@tonic-gate * wrefresh(save), we require case 4.
267*7c478bd9Sstevel@tonic-gate *
268*7c478bd9Sstevel@tonic-gate * 5. Copy incomplete broad from source to target region next to margin.
269*7c478bd9Sstevel@tonic-gate *
270*7c478bd9Sstevel@tonic-gate * a)
271*7c478bd9Sstevel@tonic-gate * copywin(s, t, 0, 1, 0, 0, 1, 2, 0)
272*7c478bd9Sstevel@tonic-gate * s t ==> t
273*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
274*7c478bd9Sstevel@tonic-gate * |[]cdef| |123456| |#cd456|
275*7c478bd9Sstevel@tonic-gate * |ghijkl| |789012| |hij012|
276*7c478bd9Sstevel@tonic-gate * |mnopqr| |......| |......|
277*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
278*7c478bd9Sstevel@tonic-gate * The # background character has replaced the ] character that
279*7c478bd9Sstevel@tonic-gate * would have been copied from the source, because it is not possible
280*7c478bd9Sstevel@tonic-gate * to expand the broad character to its complete form (case 4).
281*7c478bd9Sstevel@tonic-gate *
282*7c478bd9Sstevel@tonic-gate * b)
283*7c478bd9Sstevel@tonic-gate * copywin(s, t, 0, 1, 0, 3, 1, 5, 0)
284*7c478bd9Sstevel@tonic-gate * s t ==> t
285*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
286*7c478bd9Sstevel@tonic-gate * |abcdef| |123456| |123bcd|
287*7c478bd9Sstevel@tonic-gate * |ghi{}l| |789012| |789hi#|
288*7c478bd9Sstevel@tonic-gate * |mnopqr| |......| |......|
289*7c478bd9Sstevel@tonic-gate * +------+ +------+ +------+
290*7c478bd9Sstevel@tonic-gate * Same a 5a. but with the right margin.
291*7c478bd9Sstevel@tonic-gate */
292