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

  1. /**
  2. *
  3. * Name        wnattr -- Change attributes on current window
  4. *
  5. * Synopsis    presult = wnattr(fore,back);
  6. *
  7. *        BWINDOW *presult  Pointer to newly-changed BWINDOW
  8. *                  structure, or NIL if failure.
  9. *        int fore      New foreground attribute (-1 if
  10. *                  foreground to be unchanged).
  11. *        int back      New background attribute (-1 if
  12. *                  background to be unchanged).
  13. *
  14. * Description    This function fills the data area of the current window
  15. *        with a given attribute without affecting the characters
  16. *        already displayed there.  The cursor is not moved.
  17. *
  18. *        If fore or back is -1, then foreground or background
  19. *        attributes are left unchanged, respectively.
  20. *
  21. *        This function does not affect the window's default
  22. *        attributes.  Use WNSETOPT for that purpose.
  23. *
  24. *        An error occurs if no window is current.
  25. *
  26. * Returns    presult       Pointer to newly-changed BWINDOW
  27. *                  structure, or NIL if failure.
  28. *        b_wnerr       Possible values:
  29. *                  (No change)       Success.
  30. *                  WN_BAD_WIN       b_pcurwin is invalid.
  31. *                  WN_NOT_SHOWN       Internal error.
  32. *                  WN_BAD_DEV       Internal error.
  33. *                  WN_ILL_DIM       Internal error.
  34. *                  WN_NULL_PTR       Internal error.
  35. *
  36. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  37. *
  38. **/
  39.  
  40. #include <bwindow.h>
  41.  
  42. BWINDOW *wnattr(fore,back)
  43. int fore,back;
  44. {
  45.     int  i,area;
  46.     CELL *pdata;
  47.     char oldmask,attr;
  48.  
  49.     if (wnvalwin(b_pcurwin) == NIL)
  50.     {
  51.     wnerror(WN_BAD_WIN);
  52.     return NIL;
  53.     }
  54.  
  55.     if (fore == -1)              /* "oldmask" will help us       */
  56.     oldmask  = 0x0f;          /* extract the portions of the  */
  57.     else                  /* existing attributes that we  */
  58.     oldmask  = 0x00;          /* want to keep.              */
  59.     if (back == -1)
  60.     oldmask |= 0xf0;
  61.  
  62.     attr = (char) (utnybbyt(back,fore) & ~oldmask);
  63.  
  64.     area  = b_pcurwin->img.dim.h * b_pcurwin->img.dim.w;
  65.     pdata = b_pcurwin->img.pdata;
  66.  
  67.     for (i = 0; i < area; i++)
  68.     pdata[i].attr = (pdata[i].attr & oldmask) | attr;
  69.  
  70.     b_pcurwin->internals.dirty = 1;
  71.  
  72.                       /* Write whole window unless    */
  73.                       /* delayed or not shown.          */
  74.     return (   b_pcurwin->options.delayed
  75.         || b_pcurwin->where_shown.dev == ABSENT)
  76.                       ? b_pcurwin
  77.                       : wnupdate(b_pcurwin);
  78. }
  79.