home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / WNHORIZ.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  2.9 KB  |  119 lines

  1. /**
  2. *
  3. * Name        wnhoriz -- Horizontally scroll the current window.
  4. *
  5. * Synopsis    presult = wnhoriz(num_cols,fore,back,dir);
  6. *
  7. *        BWINDOW *presult  Pointer to newly-scrolled BWINDOW
  8. *                  structure, or NIL if failure.
  9. *        int num_cols      Number of columns to scroll.    A value
  10. *                  of 0 clears the window.
  11. *        int fore,back      Foreground and background attributes of
  12. *                  new blank columns.  (-1 specifies
  13. *                  window's native attributes.)
  14. *        int dir       Scrolling direction (SCR_LEFT or
  15. *                  SCR_RIGHT).
  16. *
  17. * Description    This function moves columns of characters (with their
  18. *        attributes) to the left or right within the current
  19. *        window.  The vacant columns are filled with blanks and a
  20. *        specified attribute.
  21. *
  22. *        An error occurs if no window is current.
  23. *
  24. * Returns    presult       Pointer to newly-scrolled BWINDOW
  25. *                  structure, or NIL if failure.
  26. *        b_wnerr       Possible values:
  27. *                  (No change)       Success.
  28. *                  WN_BAD_WIN       b_pcurwin is invalid.
  29. *                  WN_NOT_SHOWN       Internal error.
  30. *                  WN_BAD_DEV       Internal error.
  31. *                  WN_ILL_DIM       Internal error.
  32. *                  WN_NULL_PTR       Internal error.
  33. *
  34. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  35. *
  36. **/
  37.  
  38. #include <bwindow.h>
  39.  
  40. #if MSC300
  41. #include <memory.h>
  42. #else
  43. #include <stdlib.h>
  44. #endif
  45.  
  46. BWINDOW *wnhoriz(num_cols,fore,back,dir)
  47. int num_cols,fore,back,dir;
  48. {
  49.     char attr;
  50.     int  h,w,i,j;
  51.     CELL *pto,*pfrom;
  52.  
  53.     if (wnvalwin(b_pcurwin) == NIL)
  54.     {
  55.     wnerror(WN_BAD_WIN);
  56.     return NIL;
  57.     }
  58.  
  59.     if (fore == -1)
  60.     fore = utlonyb(b_pcurwin->attr);
  61.     if (back == -1)
  62.     back = uthinyb(b_pcurwin->attr);
  63.     attr = (char) utnybbyt(back,fore);
  64.  
  65.     h = b_pcurwin->img.dim.h;          /* Height and width of data area*/
  66.     w = b_pcurwin->img.dim.w;
  67.  
  68.     if (num_cols <= 0 || num_cols > w)
  69.     num_cols = w;
  70.  
  71.                       /* Update the memory image      */
  72.     if (num_cols < w)
  73.     {
  74.     if (dir == SCR_RIGHT)
  75.     {
  76.         pfrom = b_pcurwin->img.pdata;
  77.         pto   = b_pcurwin->img.pdata + num_cols;
  78.     }
  79.     else
  80.     {
  81.         pfrom = b_pcurwin->img.pdata + num_cols;
  82.         pto   = b_pcurwin->img.pdata;
  83.     }
  84.  
  85.     for (i = 0; i < h; i++)       /* Shift each row left or right */
  86.     {
  87.         memcpy((char *)      pto,
  88.            (char *)      pfrom,
  89.            (unsigned int) ((w - num_cols) * sizeof(CELL)));
  90.         pto   += w;           /* Next row.              */
  91.         pfrom += w;
  92.     }
  93.     }
  94.  
  95.     if (dir == SCR_RIGHT)
  96.     pto = b_pcurwin->img.pdata;
  97.     else
  98.     pto = b_pcurwin->img.pdata + (w - num_cols);
  99.  
  100.     for (i = 0; i < h; i++)          /* Fill the blank columns.      */
  101.     {
  102.     for (j = 0; j < num_cols; j++)
  103.     {
  104.         pto[j].ch    = ' ';
  105.         pto[j].attr = attr;
  106.     }
  107.     pto += w;              /* Next row.              */
  108.     }
  109.  
  110.     b_pcurwin->internals.dirty = 1;
  111.  
  112.                       /* Write whole window unless    */
  113.                       /* delayed or not shown.          */
  114.     return (   b_pcurwin->options.delayed
  115.         || b_pcurwin->where_shown.dev == ABSENT)
  116.                       ? b_pcurwin
  117.                       : wnupdate(b_pcurwin);
  118. }
  119.