home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name wnhoriz -- Horizontally scroll the current window.
- *
- * Synopsis presult = wnhoriz(num_cols,fore,back,dir);
- *
- * BWINDOW *presult Pointer to newly-scrolled BWINDOW
- * structure, or NIL if failure.
- * int num_cols Number of columns to scroll. A value
- * of 0 clears the window.
- * int fore,back Foreground and background attributes of
- * new blank columns. (-1 specifies
- * window's native attributes.)
- * int dir Scrolling direction (SCR_LEFT or
- * SCR_RIGHT).
- *
- * Description This function moves columns of characters (with their
- * attributes) to the left or right within the current
- * window. The vacant columns 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.
- * WN_NOT_SHOWN Internal error.
- * WN_BAD_DEV Internal error.
- * WN_ILL_DIM Internal error.
- * WN_NULL_PTR Internal error.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <bwindow.h>
-
- #if MSC300
- #include <memory.h>
- #else
- #include <stdlib.h>
- #endif
-
- BWINDOW *wnhoriz(num_cols,fore,back,dir)
- int num_cols,fore,back,dir;
- {
- char attr;
- int h,w,i,j;
- 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 = (char) utnybbyt(back,fore);
-
- h = b_pcurwin->img.dim.h; /* Height and width of data area*/
- w = b_pcurwin->img.dim.w;
-
- if (num_cols <= 0 || num_cols > w)
- num_cols = w;
-
- /* Update the memory image */
- if (num_cols < w)
- {
- if (dir == SCR_RIGHT)
- {
- pfrom = b_pcurwin->img.pdata;
- pto = b_pcurwin->img.pdata + num_cols;
- }
- else
- {
- pfrom = b_pcurwin->img.pdata + num_cols;
- pto = b_pcurwin->img.pdata;
- }
-
- for (i = 0; i < h; i++) /* Shift each row left or right */
- {
- memcpy((char *) pto,
- (char *) pfrom,
- (unsigned int) ((w - num_cols) * sizeof(CELL)));
- pto += w; /* Next row. */
- pfrom += w;
- }
- }
-
- if (dir == SCR_RIGHT)
- pto = b_pcurwin->img.pdata;
- else
- pto = b_pcurwin->img.pdata + (w - num_cols);
-
- for (i = 0; i < h; i++) /* Fill the blank columns. */
- {
- for (j = 0; j < num_cols; j++)
- {
- pto[j].ch = ' ';
- pto[j].attr = attr;
- }
- pto += w; /* Next row. */
- }
-
- b_pcurwin->internals.dirty = 1;
-
- /* Write whole window unless */
- /* delayed or not shown. */
- return ( b_pcurwin->options.delayed
- || b_pcurwin->where_shown.dev == ABSENT)
- ? b_pcurwin
- : wnupdate(b_pcurwin);
- }