1 /****************************************************************************
2 * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-on *
33 * and: Juergen Pfeifer *
34 ****************************************************************************/
39 * The routines wrefresh() and wnoutrefresh().
43 #include <curses.priv.h>
45 MODULE_ID("$Id: lib_refresh.c,v 1.45 2011/06/25 19:02:22 Vassili.Courzakis Exp $")
52 SCREEN *SP_PARM = _nc_screen_of(win);
55 T((T_CALLED("wrefresh(%p)"), (void *) win));
59 } else if (win == CurScreen(SP_PARM)) {
60 CurScreen(SP_PARM)->_clear = TRUE;
61 code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
62 } else if ((code = wnoutrefresh(win)) == OK) {
64 NewScreen(SP_PARM)->_clear = TRUE;
65 code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
67 * Reset the clearok() flag in case it was set for the special
68 * case in hardscroll.c (if we don't reset it here, we'll get 2
69 * refreshes because the flag is copied from stdscr to newscr).
70 * Resetting the flag shouldn't do any harm, anyway.
78 wnoutrefresh(WINDOW *win)
89 SCREEN *SP_PARM = _nc_screen_of(win);
92 T((T_CALLED("wnoutrefresh(%p)"), (void *) win));
95 * This function will break badly if we try to refresh a pad.
98 || (win->_flags & _ISPAD))
102 if (USE_TRACEF(TRACE_UPDATE)) {
103 _tracedump("...win", win);
104 _nc_unlock_global(tracef);
108 /* put them here so "win == 0" won't break our code */
112 NewScreen(SP_PARM)->_nc_bkgd = win->_nc_bkgd;
113 WINDOW_ATTRS(NewScreen(SP_PARM)) = WINDOW_ATTRS(win);
115 /* merge in change information from all subwindows of this window */
120 * For pure efficiency, we'd want to transfer scrolling information
121 * from the window to newscr whenever the window is wide enough that
122 * its update will dominate the cost of the update for the horizontal
123 * band of newscr that it occupies. Unfortunately, this threshold
124 * tends to be complex to estimate, and in any case scrolling the
125 * whole band and rewriting the parts outside win's image would look
126 * really ugly. So. What we do is consider the window "wide" if it
127 * either (a) occupies the whole width of newscr, or (b) occupies
128 * all but at most one column on either vertical edge of the screen
129 * (this caters to fussy people who put boxes around full-screen
130 * windows). Note that changing this formula will not break any code,
131 * merely change the costs of various update cases.
133 wide = (begx <= 1 && win->_maxx >= (NewScreen(SP_PARM)->_maxx - 1));
136 win->_flags &= ~_HASMOVED;
139 * Microtweaking alert! This double loop is one of the genuine
140 * hot spots in the code. Even gcc doesn't seem to do enough
141 * common-subexpression chunking to make it really tense,
142 * so we'll force the issue.
146 limit_x = win->_maxx;
148 if (limit_x > NewScreen(SP_PARM)->_maxx - begx)
149 limit_x = NewScreen(SP_PARM)->_maxx - begx;
151 for (src_row = 0, dst_row = begy + win->_yoffset;
152 src_row <= win->_maxy && dst_row <= NewScreen(SP_PARM)->_maxy;
153 src_row++, dst_row++) {
154 struct ldat *nline = &(NewScreen(SP_PARM)->_line[dst_row]);
155 struct ldat *oline = &win->_line[src_row];
157 if (oline->firstchar != _NOCHANGE) {
158 int last_src = oline->lastchar;
160 if (last_src > limit_x)
163 src_col = oline->firstchar;
164 dst_col = src_col + begx;
170 * Ensure that we will copy complete multi-column characters
171 * on the left-boundary.
173 if (isWidecExt(oline->text[src_col])) {
174 j = 1 + dst_col - WidecExt(oline->text[src_col]);
178 src_col -= (dst_col - j);
184 * Ensure that we will copy complete multi-column characters
185 * on the right-boundary.
188 if (WidecExt(oline->text[j])) {
190 while (j <= limit_x) {
191 if (isWidecBase(oline->text[j])) {
202 static cchar_t blank = BLANK;
203 int last_dst = begx + ((last_src < win->_maxx)
206 int fix_left = dst_col;
207 int fix_right = last_dst;
211 * Check for boundary cases where we may overwrite part of a
212 * multi-column character. For those, wipe the remainder of
213 * the character to blanks.
216 if (isWidecExt(nline->text[j])) {
218 * On the left, we only care about multi-column characters
219 * that extend into the changed region.
221 fix_left = 1 + j - WidecExt(nline->text[j]);
223 fix_left = 0; /* only if cell is corrupt */
227 if (WidecExt(nline->text[j]) != 0) {
229 * On the right, any multi-column character is a problem,
230 * unless it happens to be contained in the change, and
231 * ending at the right boundary of the change. The
232 * computation for 'fix_left' accounts for the left-side of
233 * this character. Find the end of the character.
236 while (j <= NewScreen(SP_PARM)->_maxx &&
237 isWidecExt(nline->text[j])) {
243 * The analysis is simpler if we do the clearing afterwards.
246 if (fix_left < dst_col || fix_right > last_dst) {
247 for (j = fix_left; j <= fix_right; ++j) {
248 nline->text[j] = blank;
249 CHANGED_CELL(nline, j);
255 * Copy the changed text.
257 for (; src_col <= last_src; src_col++, dst_col++) {
258 if (!CharEq(oline->text[src_col], nline->text[dst_col])) {
259 nline->text[dst_col] = oline->text[src_col];
260 CHANGED_CELL(nline, dst_col);
267 int oind = oline->oldindex;
269 nline->oldindex = ((oind == _NEWINDEX)
271 : (begy + oind + win->_yoffset));
273 #endif /* USE_SCROLL_HINTS */
275 oline->firstchar = oline->lastchar = _NOCHANGE;
276 if_USE_SCROLL_HINTS(oline->oldindex = src_row);
281 NewScreen(SP_PARM)->_clear = TRUE;
284 if (!win->_leaveok) {
285 NewScreen(SP_PARM)->_cury = (NCURSES_SIZE_T) (win->_cury +
286 win->_begy + win->_yoffset);
287 NewScreen(SP_PARM)->_curx = (NCURSES_SIZE_T) (win->_curx + win->_begx);
289 NewScreen(SP_PARM)->_leaveok = win->_leaveok;
292 if (USE_TRACEF(TRACE_UPDATE)) {
293 _tracedump("newscr", NewScreen(SP_PARM));
294 _nc_unlock_global(tracef);