From 5838be7eb13d726e871a886512ab30745f11e2dd Mon Sep 17 00:00:00 2001 From: Bill-Gray Date: Wed, 13 Mar 2024 13:32:06 -0400 Subject: [PATCH] Made a separate PDC_wscrl() function to scroll a window by 'n' lines between rows 'top' and 'bottom'. This can be used by wscrl(), wdeleteln(), winsertln(), and winsdelln(), avoiding some redundant code. See preceding commit for the test program and following commit for the use of this function elsewhere. --- pdcurses/scroll.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pdcurses/scroll.c b/pdcurses/scroll.c index 2c437914..8e1d2b33 100644 --- a/pdcurses/scroll.c +++ b/pdcurses/scroll.c @@ -40,7 +40,7 @@ scroll **man-end****************************************************************/ -int wscrl(WINDOW *win, int n) +int PDC_wscrl(WINDOW *win, const int top, const int bottom, int n) { int start, end, n_lines; chtype blank, *tptr, *endptr; @@ -48,12 +48,12 @@ int wscrl(WINDOW *win, int n) /* Check if window scrolls. Valid for window AND pad */ assert( win); - if (!win || !win->_scroll || !n) + if (!win || !n) return ERR; blank = win->_bkgd; - start = win->_tmarg; - end = win->_bmarg + 1; + start = top; + end = bottom + 1; n_lines = end - start; if (n > 0) /* scroll up */ @@ -71,7 +71,7 @@ int wscrl(WINDOW *win, int n) n = n_lines; memmove( win->_y[start + n], win->_y[start], (n_lines - n) * win->_maxx * sizeof( chtype)); - tptr = win->_y[win->_tmarg]; + tptr = win->_y[top]; } /* make blank lines */ @@ -81,11 +81,23 @@ int wscrl(WINDOW *win, int n) *tptr++ = blank; touchline(win, start, n_lines); - - PDC_sync(win); return OK; } +int wscrl(WINDOW *win, int n) +{ + int rval; + + assert( win); + if (!win || !win->_scroll || !n) + rval = ERR; + else + rval = PDC_wscrl( win, win->_tmarg, win->_bmarg, n); + if( OK == rval) + PDC_sync( win); + return( rval); +} + int scrl(int n) { PDC_LOG(("scrl() - called\n"));