home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / WNSCROLL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-13  |  3.9 KB  |  148 lines

  1. /**
  2. *
  3. * Name        wnscroll -- Vertically scroll the current window.
  4. *
  5. * Synopsis    presult = wnscroll(num_rows,fore,back,dir);
  6. *
  7. *        BWINDOW *presult  Pointer to newly-scrolled BWINDOW
  8. *                  structure, or NIL if failure.
  9. *        int num_rows      Number of lines to scroll.  A value of 0
  10. *                  specifies that all lines within the
  11. *                  window should be scrolled (thus clearing
  12. *                  the window).
  13. *        int fore      Foreground attribute of new blank lines.
  14. *                  (-1 specifies window's native foreground
  15. *                  color).
  16. *        int back      Background attribute of new blank lines.
  17. *                  (-1 specifies window's native background
  18. *                  color).
  19. *        int dir       Scrolling direction (SCR_UP or SCR_DOWN).
  20. *
  21. * Description    This function moves rows of characters (with their
  22. *        attributes) up or down within the current window.  The
  23. *        vacant rows are filled with blanks and a specified
  24. *        attribute.
  25. *
  26. *        An error occurs if no window is current.
  27. *
  28. * Returns    presult       Pointer to newly-scrolled BWINDOW
  29. *                  structure, or NIL if failure.
  30. *        b_wnerr       Possible values:
  31. *                  (No change)       Success.
  32. *                  WN_BAD_WIN       b_pcurwin is invalid.
  33. *
  34. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  35. *
  36. * Version    3.02 March 23, 1987
  37. *        Forced WNUPDATE before performing screen I/O.
  38. *
  39. **/
  40.  
  41. #include <bgenvid.h>              /* This routine doesn't care    */
  42.                       /* whether direct or BIOS       */
  43.                       /* version of BGENVID.H is used.*/
  44. #include <bwindow.h>
  45.  
  46. #if MSC300
  47. #include <memory.h>
  48. #else
  49. #include <stdlib.h>
  50. #endif
  51.  
  52. BWINDOW *wnscroll(num_rows,fore,back,dir)
  53. int num_rows,fore,back,dir;
  54. {
  55.     int  attr,h,w,i,limit;
  56.     CELL *pto,*pfrom;
  57.  
  58.     if (wnvalwin(b_pcurwin) == NIL)
  59.     {
  60.     wnerror(WN_BAD_WIN);
  61.     return NIL;
  62.     }
  63.  
  64.     if (fore == -1)
  65.     fore = utlonyb(b_pcurwin->attr);
  66.     if (back == -1)
  67.     back = uthinyb(b_pcurwin->attr);
  68.     attr = utnybbyt(back,fore);
  69.  
  70.     h = b_pcurwin->img.dim.h;          /* Height and width of data area*/
  71.     w = b_pcurwin->img.dim.w;
  72.  
  73.     if (num_rows <= 0 || num_rows > h)
  74.     num_rows = h;
  75.  
  76.     /* Update the physical screen if possible.                  */
  77.  
  78.     if (   b_pcurwin->where_shown.dev != MONO
  79.     && b_pcurwin->where_shown.dev != COLOR)
  80.     {                      /* Not shown anywhere.          */
  81.     b_pcurwin->internals.dirty = 1;
  82.     }
  83.     else if (b_pcurwin->options.hidden)
  84.     {
  85.                       /* Do nothing if hidden.          */
  86.     }
  87.     else if (    b_pcurwin->options.delayed
  88.          || b_pcurwin->internals.frozen)
  89.     {                      /* Displayed, but can't be      */
  90.     b_pcurwin->internals.dirty = 1;          /* written to.   */
  91.     }
  92.     else
  93.     {                      /* Actually do the write.       */
  94.  
  95.     wnupdate(b_pcurwin);          /* Flush pending output.          */
  96.  
  97.                       /* Update the window.          */
  98.     gvscroll(num_rows,
  99.          attr,
  100.          b_pcurwin->where_shown.corner.row,
  101.          b_pcurwin->where_shown.corner.col,
  102.          b_pcurwin->where_shown.corner.row + h - 1,
  103.          b_pcurwin->where_shown.corner.col + w - 1,
  104.          dir);
  105.     }
  106.  
  107.     /* Update the memory copy of the window's data area.              */
  108.  
  109.     if (num_rows < h)
  110.     {                      /* Copy rows of the window      */
  111.                       /* upward or downward.          */
  112.     if (dir == SCR_UP)
  113.     {
  114.         pfrom = b_pcurwin->img.pdata + (w * num_rows);
  115.         pto   = b_pcurwin->img.pdata;
  116.     }
  117.     else
  118.     {
  119.         pfrom = b_pcurwin->img.pdata;
  120.         pto   = b_pcurwin->img.pdata + (w * num_rows);
  121.     }
  122.  
  123.     memcpy((char *)       pto,
  124.            (char *)       pfrom,
  125.            (unsigned int) (w * (h - num_rows) * sizeof(CELL)));
  126.     }
  127.  
  128.     /* Finally fill the new lines with blanks.                  */
  129.  
  130.     if (dir == SCR_UP)
  131.     {                      /* Fill bottom of window.       */
  132.     pto = b_pcurwin->img.pdata + (w * (h - num_rows));
  133.     }
  134.     else
  135.     {                      /* Fill top of window.          */
  136.     pto = b_pcurwin->img.pdata;
  137.     }
  138.  
  139.     limit = num_rows * w;
  140.     for (i = 0; i < limit; i++)
  141.     {
  142.     pto[i].ch   = ' ';
  143.     pto[i].attr = (char) attr;
  144.     }
  145.  
  146.     return b_pcurwin;              /* Success.              */
  147. }
  148.