Back to index

tetex-bin  3.0
lib_scroll.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998,2001,2003 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: Thomas E. Dickey 1996-2003                                      *
00031  *     and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
00032  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
00033  ****************************************************************************/
00034 
00035 /*
00036 **     lib_scroll.c
00037 **
00038 **     The routine wscrl(win, n).
00039 **  positive n scroll the window up (ie. move lines down)
00040 **  negative n scroll the window down (ie. move lines up)
00041 **
00042 */
00043 
00044 #include <curses.priv.h>
00045 
00046 MODULE_ID("$Id: lib_scroll.c,v 1.24 2003/07/26 23:25:26 tom Exp $")
00047 
00048 NCURSES_EXPORT(void)
00049 _nc_scroll_window(WINDOW *win, int const n, NCURSES_SIZE_T const top,
00050                 NCURSES_SIZE_T const bottom, NCURSES_CH_T blank)
00051 {
00052     int limit;
00053     int line;
00054     int j;
00055     size_t to_copy = (size_t) (sizeof(NCURSES_CH_T) * (win->_maxx + 1));
00056 
00057     TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %d, %d)", win, n, top, bottom));
00058 
00059     if (top < 0
00060        || bottom < top
00061        || bottom > win->_maxy) {
00062        TR(TRACE_MOVE, ("nothing to scroll"));
00063        return;
00064     }
00065 
00066     /*
00067      * This used to do a line-text pointer-shuffle instead of text copies.
00068      * That (a) doesn't work when the window is derived and doesn't have
00069      * its own storage, (b) doesn't save you a lot on modern machines
00070      * anyway.  Your typical memcpy implementations are coded in
00071      * assembler using a tight BLT loop; for the size of copies we're
00072      * talking here, the total execution time is dominated by the one-time
00073      * setup cost.  So there is no point in trying to be excessively
00074      * clever -- esr.
00075      */
00076 
00077     /* shift n lines downwards */
00078     if (n < 0) {
00079        limit = top - n;
00080        for (line = bottom; line >= limit && line >= 0; line--) {
00081            TR(TRACE_MOVE, ("...copying %d to %d", line + n, line));
00082            memcpy(win->_line[line].text,
00083                  win->_line[line + n].text,
00084                  to_copy);
00085            if_USE_SCROLL_HINTS(win->_line[line].oldindex =
00086                             win->_line[line + n].oldindex);
00087        }
00088        for (line = top; line < limit && line <= win->_maxy; line++) {
00089            TR(TRACE_MOVE, ("...filling %d", line));
00090            for (j = 0; j <= win->_maxx; j++)
00091               win->_line[line].text[j] = blank;
00092            if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX);
00093        }
00094     }
00095 
00096     /* shift n lines upwards */
00097     if (n > 0) {
00098        limit = bottom - n;
00099        for (line = top; line <= limit && line <= win->_maxy; line++) {
00100            memcpy(win->_line[line].text,
00101                  win->_line[line + n].text,
00102                  to_copy);
00103            if_USE_SCROLL_HINTS(win->_line[line].oldindex =
00104                             win->_line[line + n].oldindex);
00105        }
00106        for (line = bottom; line > limit && line >= 0; line--) {
00107            for (j = 0; j <= win->_maxx; j++)
00108               win->_line[line].text[j] = blank;
00109            if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX);
00110        }
00111     }
00112     touchline(win, top, bottom - top + 1);
00113 }
00114 
00115 NCURSES_EXPORT(int)
00116 wscrl(WINDOW *win, int n)
00117 {
00118     T((T_CALLED("wscrl(%p,%d)"), win, n));
00119 
00120     if (!win || !win->_scroll) {
00121        TR(TRACE_MOVE, ("...scrollok is false"));
00122        returnCode(ERR);
00123     }
00124 
00125     if (n != 0) {
00126        _nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd);
00127        _nc_synchook(win);
00128     }
00129     returnCode(OK);
00130 }