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

  1. /**
  2. *
  3. * Name        wnsetopt -- Set window option
  4. *
  5. * Synopsis    presult = wnsetopt(pwin,item,value);
  6. *
  7. *        BWINDOW *presult  Pointer to window, or NIL if
  8. *                  failure.
  9. *        BWINDOW *pwin      Pointer to window.
  10. *        int item      Identifying code number of option to
  11. *                  set.
  12. *        int value      Data value.
  13. *
  14. * Description    This function modifies one of a window's
  15. *        characteristics.
  16. *
  17. *        Depending on the item requested, an error may occur if
  18. *        the window is not attached to a screen location.  (That
  19. *        is, the window must have been displayed with WNDSPLAY,
  20. *        although it may be hidden.)
  21. *
  22. *        An error also occurs if the item requested is unknown or
  23. *        cannot be changed or if pwin does not point to a valid
  24. *        window.
  25. *
  26. * Returns    presult       Pointer to window, or NIL if
  27. *                  failure.
  28. *        *pwin          Window structure values perhaps
  29. *                  altered.
  30. *        b_wnerr       Possible values:
  31. *                  (No change)       Success.
  32. *                  WN_BAD_WIN       *pwin is invalid.
  33. *                  WN_NOT_SHOWN       *pwin not currently
  34. *                           attached to screen
  35. *                           location.
  36. *                  WN_HARD       Item can't be changed
  37. *                           via this routine.
  38. *                  WN_ILL_VALUE       Illegal value for this
  39. *                           item.
  40. *
  41. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  42. *
  43. **/
  44.  
  45. #include <bwindow.h>
  46.  
  47. #if MSC300
  48. #include <malloc.h>
  49. #else
  50. #include <stdlib.h>
  51. #endif
  52.  
  53. #define FALSE    0
  54. #define TRUE    (!FALSE)
  55.  
  56.     /* Macro to build a case statement which tests the new value and  */
  57.     /* performs the assignment if the value meets the specified       */
  58.     /* condition.                              */
  59.  
  60. #define easycase(item_num,cond,data,calc)            \
  61.         case (item_num):                    \
  62.         if (cond)                    \
  63.         {                        \
  64.             (data)  = (calc);                \
  65.             presult = pwin;                \
  66.         }                        \
  67.         else                        \
  68.         {                        \
  69.             wnerror(WN_ILL_VALUE);            \
  70.             presult = NIL;                \
  71.         }                        \
  72.         break;
  73.  
  74.     /* Macro to build a case which tests and assigns a value for a    */
  75.     /* bitfield.                              */
  76.  
  77. #define bitcase(item_num,data,calc)                \
  78.         easycase(item_num,(value==0||value==1),data,calc)
  79.  
  80.     /* Macro to build a case which assigns the new value without      */
  81.     /* testing its validity.                          */
  82.  
  83. #define anycase(item_num,data,calc)                \
  84.         case (item_num):                    \
  85.         (data)    = (calc);                \
  86.         presult = pwin;                 \
  87.         break;
  88.  
  89. BWINDOW *wnsetopt(pwin,item,value)
  90. BWINDOW *pwin;
  91. int    item,value;
  92. {
  93.     int     dev;
  94.     BWINDOW *presult;
  95.  
  96.     if (wnvalwin(pwin) == NIL)          /* Validate window structure.   */
  97.     {
  98.     wnerror(WN_BAD_WIN);
  99.     return NIL;
  100.     }
  101.  
  102.     dev = pwin->where_shown.dev;
  103.     if (item < 0)              /* This kind of item is          */
  104.     {                      /* meaningless unless window is */
  105.                       /* displayed.              */
  106.     if (dev != MONO && dev != COLOR)
  107.     {
  108.         wnerror(WN_NOT_SHOWN);
  109.         return NIL;
  110.     }
  111.     }
  112.  
  113.     switch (item)
  114.     {
  115.                       /* Cursor on/off state          */
  116.     bitcase(  WN_CUR_OFF,  pwin->options.cur_off,
  117.                    value)
  118.  
  119.                       /* Cursor scan lines          */
  120.     easycase( WN_CUR_HIGH, (value >= 0 && value <= 13),
  121.                    pwin->cur_type.high,
  122.                    value)
  123.     easycase( WN_CUR_LOW,  (value >= 0 && value <= 13),
  124.                    pwin->cur_type.low,
  125.                    value)
  126.  
  127.                       /* User-controllable options    */
  128.     bitcase(  WN_DELAYED,  pwin->options.delayed,
  129.                    value)
  130.  
  131.                       /* Default attributes          */
  132.     anycase(  WN_ATTR,     pwin->attr,
  133.                    value)
  134.  
  135.     case WN_REMOVABLE:
  136.         if (value == 0)
  137.         {                  /* Making non-removable.          */
  138.         if (pwin->options.removable)
  139.         {
  140.                       /* Discard copy of previous     */
  141.                       /* screen data.              */
  142.             if (pwin->prev.pdata != NIL)
  143.             {
  144.             free((char *) pwin->prev.pdata);
  145.             pwin->prev.pdata = NIL;
  146.             }
  147.             pwin->options.removable = value;
  148.         }
  149.         presult = pwin;
  150.         }
  151.         else if (value == 1)
  152.         {                  /* Making removable.          */
  153.         if (   (!pwin->options.removable)
  154.             && (dev == MONO || dev == COLOR))
  155.         {              /* Too late:  already displayed */
  156.                       /* and non-removable.          */
  157.             wnerror(WN_ILL_VALUE);
  158.             presult = NIL;
  159.         }
  160.         else
  161.         {              /* Easy to make it removable.   */
  162.             pwin->options.removable = value;
  163.             presult = pwin;
  164.         }
  165.         }
  166.         else
  167.         {
  168.         wnerror(WN_ILL_VALUE);
  169.         presult = NIL;
  170.         }
  171.         break;
  172.  
  173.     case WN_HIDDEN:
  174.  
  175.     case WN_ROW_REL:
  176.     case WN_COL_REL:
  177.     case WN_ROW_ABS:
  178.     case WN_COL_ABS:
  179.  
  180.     case WN_IS_CURRENT:
  181.     case WN_ACTIVE_CUR:
  182.  
  183.     case WN_BOR_TYPE:
  184.     case WN_BOR_CHAR:
  185.     case WN_BOR_ATTR:
  186.  
  187.     case WN_DEVICE:
  188.     case WN_PAGE:
  189.     case WN_ROW_CORNER:
  190.     case WN_COL_CORNER:
  191.     case WN_FROZEN:
  192.     case WN_DIRTY:
  193.     case WN_ANY_DATA_COVERED:
  194.     case WN_ROWS:
  195.     case WN_COLS:
  196.     case WN_ROW_OVERALL:
  197.     case WN_COL_OVERALL:
  198.     case WN_HT_OVERALL:
  199.     case WN_WID_OVERALL:
  200.         wnerror(WN_HARD);
  201.         presult = NIL;
  202.         break;
  203.  
  204.     default:
  205.         wnerror(WN_BAD_OPT);      /* Unknown item requested.      */
  206.         presult = NIL;
  207.         break;
  208.     }
  209.  
  210.     return presult;
  211. }
  212.