home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name wnscroll -- Vertically scroll the current window.
- *
- * Synopsis presult = wnscroll(num_rows,fore,back,dir);
- *
- * BWINDOW *presult Pointer to newly-scrolled BWINDOW
- * structure, or NIL if failure.
- * int num_rows Number of lines to scroll. A value of 0
- * specifies that all lines within the
- * window should be scrolled (thus clearing
- * the window).
- * int fore Foreground attribute of new blank lines.
- * (-1 specifies window's native foreground
- * color).
- * int back Background attribute of new blank lines.
- * (-1 specifies window's native background
- * color).
- * int dir Scrolling direction (SCR_UP or SCR_DOWN).
- *
- * Description This function moves rows of characters (with their
- * attributes) up or down within the current window. The
- * vacant rows are filled with blanks and a specified
- * attribute.
- *
- * An error occurs if no window is current.
- *
- * Returns presult Pointer to newly-scrolled BWINDOW
- * structure, or NIL if failure.
- * b_wnerr Possible values:
- * (No change) Success.
- * WN_BAD_WIN b_pcurwin is invalid.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- * Version 3.02 March 23, 1987
- * Forced WNUPDATE before performing screen I/O.
- *
- **/
-
- #include <bgenvid.h> /* This routine doesn't care */
- /* whether direct or BIOS */
- /* version of BGENVID.H is used.*/
- #include <bwindow.h>
-
- #if MSC300
- #include <memory.h>
- #else
- #include <stdlib.h>
- #endif
-
- BWINDOW *wnscroll(num_rows,fore,back,dir)
- int num_rows,fore,back,dir;
- {
- int attr,h,w,i,limit;
- CELL *pto,*pfrom;
-
- if (wnvalwin(b_pcurwin) == NIL)
- {
- wnerror(WN_BAD_WIN);
- return NIL;
- }
-
- if (fore == -1)
- fore = utlonyb(b_pcurwin->attr);
- if (back == -1)
- back = uthinyb(b_pcurwin->attr);
- attr = utnybbyt(back,fore);
-
- h = b_pcurwin->img.dim.h; /* Height and width of data area*/
- w = b_pcurwin->img.dim.w;
-
- if (num_rows <= 0 || num_rows > h)
- num_rows = h;
-
- /* Update the physical screen if possible. */
-
- if ( b_pcurwin->where_shown.dev != MONO
- && b_pcurwin->where_shown.dev != COLOR)
- { /* Not shown anywhere. */
- b_pcurwin->internals.dirty = 1;
- }
- else if (b_pcurwin->options.hidden)
- {
- /* Do nothing if hidden. */
- }
- else if ( b_pcurwin->options.delayed
- || b_pcurwin->internals.frozen)
- { /* Displayed, but can't be */
- b_pcurwin->internals.dirty = 1; /* written to. */
- }
- else
- { /* Actually do the write. */
-
- wnupdate(b_pcurwin); /* Flush pending output. */
-
- /* Update the window. */
- gvscroll(num_rows,
- attr,
- b_pcurwin->where_shown.corner.row,
- b_pcurwin->where_shown.corner.col,
- b_pcurwin->where_shown.corner.row + h - 1,
- b_pcurwin->where_shown.corner.col + w - 1,
- dir);
- }
-
- /* Update the memory copy of the window's data area. */
-
- if (num_rows < h)
- { /* Copy rows of the window */
- /* upward or downward. */
- if (dir == SCR_UP)
- {
- pfrom = b_pcurwin->img.pdata + (w * num_rows);
- pto = b_pcurwin->img.pdata;
- }
- else
- {
- pfrom = b_pcurwin->img.pdata;
- pto = b_pcurwin->img.pdata + (w * num_rows);
- }
-
- memcpy((char *) pto,
- (char *) pfrom,
- (unsigned int) (w * (h - num_rows) * sizeof(CELL)));
- }
-
- /* Finally fill the new lines with blanks. */
-
- if (dir == SCR_UP)
- { /* Fill bottom of window. */
- pto = b_pcurwin->img.pdata + (w * (h - num_rows));
- }
- else
- { /* Fill top of window. */
- pto = b_pcurwin->img.pdata;
- }
-
- limit = num_rows * w;
- for (i = 0; i < limit; i++)
- {
- pto[i].ch = ' ';
- pto[i].attr = (char) attr;
- }
-
- return b_pcurwin; /* Success. */
- }