Back to index

tetex-bin  3.0
lib_refresh.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
00031  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
00032  ****************************************************************************/
00033 
00034 /*
00035  *     lib_refresh.c
00036  *
00037  *     The routines wrefresh() and wnoutrefresh().
00038  *
00039  */
00040 
00041 #include <curses.priv.h>
00042 
00043 MODULE_ID("$Id: lib_refresh.c,v 1.32 2002/05/26 00:17:04 tom Exp $")
00044 
00045 NCURSES_EXPORT(int)
00046 wrefresh(WINDOW *win)
00047 {
00048     int code;
00049 
00050     T((T_CALLED("wrefresh(%p)"), win));
00051 
00052     if (win == curscr) {
00053        curscr->_clear = TRUE;
00054        code = doupdate();
00055     } else if ((code = wnoutrefresh(win)) == OK) {
00056        if (win->_clear)
00057            newscr->_clear = TRUE;
00058        code = doupdate();
00059        /*
00060         * Reset the clearok() flag in case it was set for the special
00061         * case in hardscroll.c (if we don't reset it here, we'll get 2
00062         * refreshes because the flag is copied from stdscr to newscr).
00063         * Resetting the flag shouldn't do any harm, anyway.
00064         */
00065        win->_clear = FALSE;
00066     }
00067     returnCode(code);
00068 }
00069 
00070 NCURSES_EXPORT(int)
00071 wnoutrefresh(WINDOW *win)
00072 {
00073     NCURSES_SIZE_T limit_x;
00074     NCURSES_SIZE_T i, j;
00075     NCURSES_SIZE_T begx;
00076     NCURSES_SIZE_T begy;
00077     NCURSES_SIZE_T m, n;
00078 #if USE_SCROLL_HINTS
00079     bool wide;
00080 #endif
00081 
00082     T((T_CALLED("wnoutrefresh(%p)"), win));
00083 #ifdef TRACE
00084     if (_nc_tracing & TRACE_UPDATE)
00085        _tracedump("...win", win);
00086 #endif /* TRACE */
00087 
00088     /*
00089      * This function will break badly if we try to refresh a pad.
00090      */
00091     if ((win == 0)
00092        || (win->_flags & _ISPAD))
00093        returnCode(ERR);
00094 
00095     /* put them here so "win == 0" won't break our code */
00096     begx = win->_begx;
00097     begy = win->_begy;
00098 
00099     newscr->_nc_bkgd = win->_nc_bkgd;
00100     newscr->_attrs = win->_attrs;
00101 
00102     /* merge in change information from all subwindows of this window */
00103     wsyncdown(win);
00104 
00105 #if USE_SCROLL_HINTS
00106     /*
00107      * For pure efficiency, we'd want to transfer scrolling information
00108      * from the window to newscr whenever the window is wide enough that
00109      * its update will dominate the cost of the update for the horizontal
00110      * band of newscr that it occupies.  Unfortunately, this threshold
00111      * tends to be complex to estimate, and in any case scrolling the
00112      * whole band and rewriting the parts outside win's image would look
00113      * really ugly.  So.  What we do is consider the window "wide" if it
00114      * either (a) occupies the whole width of newscr, or (b) occupies
00115      * all but at most one column on either vertical edge of the screen
00116      * (this caters to fussy people who put boxes around full-screen
00117      * windows).  Note that changing this formula will not break any code,
00118      * merely change the costs of various update cases.
00119      */
00120     wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1));
00121 #endif
00122 
00123     win->_flags &= ~_HASMOVED;
00124 
00125     /*
00126      * Microtweaking alert!  This double loop is one of the genuine
00127      * hot spots in the code.  Even gcc doesn't seem to do enough
00128      * common-subexpression chunking to make it really tense,
00129      * so we'll force the issue.
00130      */
00131 
00132     /* limit(n) */
00133     limit_x = win->_maxx;
00134     /* limit(j) */
00135     if (limit_x > newscr->_maxx - begx)
00136        limit_x = newscr->_maxx - begx;
00137 
00138     for (i = 0, m = begy + win->_yoffset;
00139         i <= win->_maxy && m <= newscr->_maxy;
00140         i++, m++) {
00141        register struct ldat *nline = &newscr->_line[m];
00142        register struct ldat *oline = &win->_line[i];
00143 
00144        if (oline->firstchar != _NOCHANGE) {
00145            int last = oline->lastchar;
00146 
00147            if (last > limit_x)
00148               last = limit_x;
00149 
00150            for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) {
00151               if (!CharEq(oline->text[j], nline->text[n])) {
00152                   nline->text[n] = oline->text[j];
00153                   CHANGED_CELL(nline, n);
00154               }
00155            }
00156 
00157        }
00158 #if USE_SCROLL_HINTS
00159        if (wide) {
00160            int oind = oline->oldindex;
00161 
00162            nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind
00163               + win->_yoffset;
00164        }
00165 #endif /* USE_SCROLL_HINTS */
00166 
00167        oline->firstchar = oline->lastchar = _NOCHANGE;
00168        if_USE_SCROLL_HINTS(oline->oldindex = i);
00169     }
00170 
00171     if (win->_clear) {
00172        win->_clear = FALSE;
00173        newscr->_clear = TRUE;
00174     }
00175 
00176     if (!win->_leaveok) {
00177        newscr->_cury = win->_cury + win->_begy + win->_yoffset;
00178        newscr->_curx = win->_curx + win->_begx;
00179     }
00180     newscr->_leaveok = win->_leaveok;
00181 
00182 #ifdef TRACE
00183     if (_nc_tracing & TRACE_UPDATE)
00184        _tracedump("newscr", newscr);
00185 #endif /* TRACE */
00186     returnCode(OK);
00187 }