1994-10-07 08:58:58 +00:00
|
|
|
|
|
|
|
/* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for *
|
|
|
|
* details. If they are missing then this copy is in violation of *
|
|
|
|
* the copyright conditions. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
** lib_scroll.c
|
|
|
|
**
|
|
|
|
** The routine wscrl(win, n).
|
|
|
|
** positive n scroll the window up (ie. move lines down)
|
|
|
|
** negative n scroll the window down (ie. move lines up)
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "curses.priv.h"
|
1994-12-02 06:40:24 +00:00
|
|
|
#include "terminfo.h"
|
1994-10-07 08:58:58 +00:00
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
void _nc_soft_scroll_window(WINDOW *win, int const n, short const top, short const bottom, chtype blank)
|
1994-10-07 08:58:58 +00:00
|
|
|
{
|
1994-12-02 06:40:24 +00:00
|
|
|
int line, i;
|
1994-10-07 08:58:58 +00:00
|
|
|
chtype *ptr, *temp;
|
1994-12-02 06:40:24 +00:00
|
|
|
chtype **saved;
|
1994-10-07 08:58:58 +00:00
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
saved = (chtype **)calloc(abs(n), sizeof(chtype *));
|
1994-12-02 06:40:24 +00:00
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
/* save overwritten lines */
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
for (i = 0; i < -n && bottom-i >= 0; i++)
|
|
|
|
saved[i] = win->_line[bottom-i];
|
1994-12-02 06:40:24 +00:00
|
|
|
|
|
|
|
/* shift n lines */
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
for (line = bottom; line >= top-n && line >= 0; line--)
|
1994-12-02 06:40:24 +00:00
|
|
|
win->_line[line] = win->_line[line+n];
|
|
|
|
|
|
|
|
/* restore saved lines and blank them */
|
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
for (i = 0, line = top; line < top-n && line <= win->_maxy; line++, i++) {
|
|
|
|
if (saved[i])
|
|
|
|
win->_line[line] = saved[i];
|
1994-12-02 06:40:24 +00:00
|
|
|
temp = win->_line[line];
|
|
|
|
for (ptr = temp; ptr - temp <= win->_maxx; ptr++)
|
|
|
|
*ptr = blank;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* save overwritten lines */
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
for (i = 0; i < n && top+i <= win->_maxy; i++)
|
|
|
|
saved[i] = win->_line[top+i];
|
1994-12-02 06:40:24 +00:00
|
|
|
|
|
|
|
/* shift n lines */
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
for (line = top; line <= bottom-n && line+n <= win->_maxy; line++)
|
1994-12-02 06:40:24 +00:00
|
|
|
win->_line[line] = win->_line[line+n];
|
|
|
|
|
|
|
|
/* restore saved lines and blank them */
|
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
for (i = 0, line = bottom; line > bottom - n && line >= 0; line--, i++) {
|
|
|
|
if (saved[i])
|
|
|
|
win->_line[line] = saved[i];
|
1994-12-02 06:40:24 +00:00
|
|
|
temp = win->_line[line];
|
|
|
|
for (ptr = temp; ptr - temp <= win->_maxx; ptr++)
|
|
|
|
*ptr = blank;
|
|
|
|
}
|
|
|
|
}
|
1998-01-02 04:36:51 +00:00
|
|
|
/* touchline(win, top, bottom-top+1); */ /* not yet */
|
1994-12-02 06:40:24 +00:00
|
|
|
free(saved);
|
|
|
|
}
|
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
void _nc_scroll_window(WINDOW *win, int n, short const top, short const bottom, chtype blank)
|
1994-12-02 06:40:24 +00:00
|
|
|
{
|
|
|
|
int physical = FALSE;
|
|
|
|
int i;
|
|
|
|
|
1998-01-02 04:36:51 +00:00
|
|
|
if (n > lines)
|
|
|
|
n = lines;
|
|
|
|
else if (-n > lines)
|
|
|
|
n = -lines;
|
1994-10-07 08:58:58 +00:00
|
|
|
|
1994-11-29 02:48:20 +00:00
|
|
|
/* as an optimization, if the scrolling region is the entire screen
|
|
|
|
scroll the physical screen */
|
1994-10-07 08:58:58 +00:00
|
|
|
|
1998-01-02 05:05:20 +00:00
|
|
|
if ( top != bottom
|
|
|
|
&& win->_begx == 0 && win->_maxx == columns - 1
|
1994-12-02 06:40:24 +00:00
|
|
|
&& !memory_above && !memory_below
|
1998-01-02 04:36:51 +00:00
|
|
|
&& ((((win->_begy+top == 0 && win->_begy+bottom == lines - 1)
|
1994-12-02 07:35:48 +00:00
|
|
|
|| change_scroll_region)
|
1994-12-02 06:40:24 +00:00
|
|
|
&& ( (n < 0 && (parm_rindex || scroll_reverse))
|
|
|
|
|| (n > 0 && (parm_index || scroll_forward))
|
|
|
|
)
|
|
|
|
) || (win->_idlok && (parm_insert_line || insert_line)
|
|
|
|
&& (parm_delete_line || delete_line)
|
|
|
|
)
|
|
|
|
)
|
1994-11-29 02:48:20 +00:00
|
|
|
)
|
1998-01-02 04:36:51 +00:00
|
|
|
physical = TRUE;
|
1994-12-02 06:40:24 +00:00
|
|
|
|
|
|
|
if (physical == TRUE) {
|
1994-11-29 02:48:20 +00:00
|
|
|
wrefresh(win);
|
1998-01-02 04:36:51 +00:00
|
|
|
_nc_soft_scroll_window(curscr, n, win->_begy+top, win->_begy+bottom, blank);
|
|
|
|
_nc_soft_scroll_window(newscr, n, win->_begy+top, win->_begy+bottom, blank);
|
1994-12-02 06:40:24 +00:00
|
|
|
}
|
1998-01-02 04:36:51 +00:00
|
|
|
_nc_soft_scroll_window(win, n, top, bottom, blank);
|
1994-12-02 06:40:24 +00:00
|
|
|
|
|
|
|
if (physical == TRUE) {
|
1994-11-29 02:48:20 +00:00
|
|
|
if (n < 0) {
|
1998-01-02 04:36:51 +00:00
|
|
|
if ( (( win->_begy+top == 0
|
|
|
|
&& win->_begy+bottom == lines - 1)
|
1994-12-02 07:35:48 +00:00
|
|
|
|| change_scroll_region)
|
1994-11-29 02:48:20 +00:00
|
|
|
&& (parm_rindex || scroll_reverse)
|
|
|
|
) {
|
1994-12-02 07:35:48 +00:00
|
|
|
if (change_scroll_region &&
|
1998-01-02 04:36:51 +00:00
|
|
|
(win->_begy+top != 0 || win->_begy+bottom != lines - 1)
|
1994-12-02 07:35:48 +00:00
|
|
|
)
|
1998-01-02 04:36:51 +00:00
|
|
|
putp(tparm(change_scroll_region, win->_begy+top, win->_begy+bottom));
|
1994-11-29 02:48:20 +00:00
|
|
|
i = abs(n);
|
1998-01-02 04:36:51 +00:00
|
|
|
mvcur(-1, -1, win->_begy+top, 0);
|
1994-11-29 02:48:20 +00:00
|
|
|
if (parm_rindex) {
|
|
|
|
putp(tparm(parm_rindex, i));
|
|
|
|
} else if (scroll_reverse) {
|
|
|
|
while (i--)
|
|
|
|
putp(scroll_reverse);
|
|
|
|
}
|
1994-12-02 07:35:48 +00:00
|
|
|
if (change_scroll_region &&
|
1998-01-02 04:36:51 +00:00
|
|
|
(win->_begy+top != 0 || win->_begy+bottom != lines - 1)
|
1994-12-02 07:35:48 +00:00
|
|
|
)
|
|
|
|
putp(tparm(change_scroll_region, 0, lines-1));
|
1994-11-29 02:48:20 +00:00
|
|
|
} else {
|
|
|
|
i = abs(n);
|
1998-01-02 04:36:51 +00:00
|
|
|
if (win->_begy+bottom < lines - 1) {
|
|
|
|
mvcur(-1, -1, win->_begy+bottom, 0);
|
1994-11-29 02:48:20 +00:00
|
|
|
if (parm_delete_line) {
|
|
|
|
putp(tparm(parm_delete_line, i));
|
|
|
|
} else if (delete_line) {
|
|
|
|
while (i--)
|
|
|
|
putp(delete_line);
|
|
|
|
i = abs(n);
|
|
|
|
}
|
|
|
|
}
|
1998-01-02 04:36:51 +00:00
|
|
|
mvcur(-1, -1, win->_begy+top, 0);
|
1994-11-29 02:48:20 +00:00
|
|
|
if (parm_insert_line) {
|
|
|
|
putp(tparm(parm_insert_line, i));
|
|
|
|
} else if (insert_line) {
|
|
|
|
while (i--)
|
|
|
|
putp(insert_line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
1998-01-02 04:36:51 +00:00
|
|
|
if ( (( win->_begy+top == 0
|
|
|
|
&& win->_begy+bottom == lines - 1)
|
1994-12-02 07:35:48 +00:00
|
|
|
|| change_scroll_region)
|
1994-11-29 02:48:20 +00:00
|
|
|
&& (parm_index || scroll_forward)
|
|
|
|
) {
|
1994-12-02 07:35:48 +00:00
|
|
|
if (change_scroll_region &&
|
1998-01-02 04:36:51 +00:00
|
|
|
(win->_begy+top != 0 || win->_begy+bottom != lines - 1)
|
1994-12-02 07:35:48 +00:00
|
|
|
)
|
1998-01-02 04:36:51 +00:00
|
|
|
putp(tparm(change_scroll_region, win->_begy+top, win->_begy+bottom));
|
|
|
|
mvcur(-1, -1, win->_begy+bottom, 0);
|
1994-11-29 02:48:20 +00:00
|
|
|
if (parm_index) {
|
|
|
|
putp(tparm(parm_index, n));
|
|
|
|
} else if (scroll_forward) {
|
|
|
|
i = n;
|
|
|
|
while (i--)
|
|
|
|
putp(scroll_forward);
|
|
|
|
}
|
1994-12-02 07:35:48 +00:00
|
|
|
if (change_scroll_region &&
|
1998-01-02 04:36:51 +00:00
|
|
|
(win->_begy+top != 0 || win->_begy+bottom != lines - 1)
|
1994-12-02 07:35:48 +00:00
|
|
|
)
|
|
|
|
putp(tparm(change_scroll_region, 0, lines-1));
|
1994-11-29 02:48:20 +00:00
|
|
|
} else {
|
1998-01-02 04:36:51 +00:00
|
|
|
mvcur(-1, -1, win->_begy+top, 0);
|
1994-11-29 02:48:20 +00:00
|
|
|
if (parm_delete_line) {
|
|
|
|
putp(tparm(parm_delete_line, n));
|
|
|
|
} else if (delete_line) {
|
|
|
|
i = n;
|
|
|
|
while (i--)
|
|
|
|
putp(delete_line);
|
|
|
|
}
|
1998-01-02 04:36:51 +00:00
|
|
|
if (win->_begy+bottom < lines - 1) {
|
|
|
|
mvcur(win->_begy+top, 0, win->_begy+bottom, 0);
|
1994-11-29 02:48:20 +00:00
|
|
|
if (parm_insert_line) {
|
|
|
|
putp(tparm(parm_insert_line, n));
|
|
|
|
} else if (insert_line) {
|
|
|
|
i = n;
|
|
|
|
while (i--)
|
|
|
|
putp(insert_line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-10-07 08:58:58 +00:00
|
|
|
}
|
|
|
|
|
1994-12-02 07:35:48 +00:00
|
|
|
mvcur(-1, -1, win->_begy+win->_cury, win->_begx+win->_curx);
|
1995-05-30 05:51:47 +00:00
|
|
|
} else
|
1998-01-02 04:36:51 +00:00
|
|
|
touchline(win, top, bottom - top + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
wscrl(WINDOW *win, int n)
|
|
|
|
{
|
|
|
|
T(("wscrl(%x,%d) called", win, n));
|
|
|
|
|
|
|
|
if (!win || !win->_scroll)
|
|
|
|
return ERR;
|
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
if ((n > (win->_regbottom - win->_regtop)) ||
|
|
|
|
(-n > (win->_regbottom - win->_regtop)))
|
|
|
|
return ERR;
|
|
|
|
|
|
|
|
_nc_scroll_window(win, n, win->_regtop, win->_regbottom, _nc_background(win));
|
1994-10-07 08:58:58 +00:00
|
|
|
|
1994-12-02 06:40:24 +00:00
|
|
|
return OK;
|
1994-10-07 08:58:58 +00:00
|
|
|
}
|