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

  1. /**
  2. *
  3. * Name        wngetopt -- Retrieve window option or status
  4. *
  5. * Synopsis    presult = wngetopt(pwin,item,pvalue);
  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 data item
  11. *                  to return.
  12. *        int *pvalue      Pointer to variable to receive data
  13. *                  value.
  14. *
  15. * Description    This function retrieves one item of information about a
  16. *        window's characteristics or status.
  17. *
  18. *        For certain items, an error may occur if the window is
  19. *        not attached to a screen location.  (That is, the window
  20. *        must have been displayed with WNDSPLAY.  It is okay if
  21. *        the window has been hidden with WNHIDE, but not if it
  22. *        has been removed with WNREMOVE.)
  23. *
  24. *        An error also occurs if the item requested is unknown or
  25. *        if pwin does not point to a valid window.
  26. *
  27. * Returns    presult       Pointer to window, or NIL if
  28. *                  failure.
  29. *        *pvalue       Data value (unless error).
  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_BAD_OPT       Unknown item.
  37. *
  38. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  39. *
  40. **/
  41.  
  42. #include <bwindow.h>
  43.  
  44.     /* Macro to build a case statement which does a simple lookup or  */
  45.     /* calculation.                              */
  46.  
  47. #define easycase(item_num,data)             \
  48.         case (item_num):                \
  49.         *pvalue = (data);            \
  50.         presult = pwin;             \
  51.         break;
  52.  
  53.     /* Macro to build a case statement whose success depends on the   */
  54.     /* window being currently displayed (although perhaps hidden).    */
  55.     /* (This is a stub version to allow easy future installation of   */
  56.     /* case-by-case data checking.)                      */
  57.  
  58. #define dispcase(item_num,data)  easycase(item_num,data)
  59.  
  60. BWINDOW *wngetopt(pwin,item,pvalue)
  61. BWINDOW *pwin;
  62. int    item,*pvalue;
  63. {
  64.     BWINDOW *presult;
  65.  
  66.     if (wnvalwin(pwin) == NIL)          /* Validate window structure.   */
  67.     {
  68.     wnerror(WN_BAD_WIN);
  69.     return NIL;
  70.     }
  71.  
  72.     if (item < 0)              /* This kind of item is          */
  73.     {                      /* meaningless unless window is */
  74.                       /* displayed.              */
  75.     if (   pwin->where_shown.dev != MONO
  76.         && pwin->where_shown.dev != COLOR)
  77.     {
  78.         wnerror(WN_NOT_SHOWN);
  79.         return NIL;
  80.     }
  81.     }
  82.  
  83.     switch (item)
  84.     {
  85.                       /* Dimensions of data area      */
  86.     easycase( WN_ROWS,     pwin->img.dim.h)
  87.     easycase( WN_COLS,     pwin->img.dim.w)
  88.  
  89.                       /* Where the window is displayed*/
  90.     easycase( WN_DEVICE,     pwin->where_shown.dev)
  91.     dispcase( WN_PAGE,     pwin->where_shown.page)
  92.     dispcase( WN_ROW_CORNER, pwin->where_shown.corner.row)
  93.     dispcase( WN_COL_CORNER, pwin->where_shown.corner.col)
  94.                       /* Area covered by window       */
  95.                       /* & border              */
  96.     dispcase( WN_ROW_OVERALL,pwin->where_prev.corner.row)
  97.     dispcase( WN_COL_OVERALL,pwin->where_prev.corner.col)
  98.     dispcase( WN_HT_OVERALL, pwin->prev.dim.h)
  99.     dispcase( WN_WID_OVERALL,pwin->prev.dim.w)
  100.  
  101.                       /* Whether it's hidden.         */
  102.     dispcase( WN_HIDDEN,     pwin->options.hidden)
  103.  
  104.                       /* Cursor on/off state & scan   */
  105.                       /* lines                  */
  106.     easycase( WN_CUR_OFF,     pwin->options.cur_off)
  107.     easycase( WN_CUR_HIGH,     pwin->cur_type.high)    /* Upper line */
  108.     easycase( WN_CUR_LOW,     pwin->cur_type.low)    /* Lower line */
  109.  
  110.                       /* User-controllable options    */
  111.     easycase( WN_DELAYED,     pwin->options.delayed)
  112.     easycase( WN_REMOVABLE,  pwin->options.removable)
  113.  
  114.                       /* Internal effects of          */
  115.                       /* displaying windows          */
  116.     easycase( WN_FROZEN,     pwin->internals.frozen)
  117.     easycase( WN_DIRTY,     pwin->internals.dirty)
  118.     easycase( WN_ANY_DATA_COVERED, pwin->internals.any_data_covered)
  119.  
  120.                       /* Cursor location          */
  121.     easycase( WN_ROW_REL,     pwin->cur_loc.row)    /* Relative to */
  122.     easycase( WN_COL_REL,     pwin->cur_loc.col)    /*   data area */
  123.  
  124.                       /* Absolute cursor location on  */
  125.                       /* screen               */
  126. #define ABS_LOC(type) (  pwin->where_shown.corner.type      \
  127.                + pwin->cur_loc         .type)
  128.  
  129.     dispcase( WN_ROW_ABS,     ABS_LOC(row))
  130.     dispcase( WN_COL_ABS,     ABS_LOC(col))
  131.  
  132.                       /* Default attributes          */
  133.     easycase( WN_ATTR,     pwin->attr)
  134.  
  135.                       /* Border               */
  136.     easycase( WN_BOR_TYPE,           pwin->bord.type)
  137.     easycase( WN_BOR_CHAR,     (int) pwin->bord.ch)
  138.     easycase( WN_BOR_ATTR,           pwin->bord.attr)
  139.  
  140.                       /* Whether this is the current  */
  141.                       /* window               */
  142.     easycase( WN_IS_CURRENT, (pwin == b_pcurwin))
  143.  
  144.                       /* Whether this window (among   */
  145.                       /* all the windows displayed on */
  146.                       /* its page) is the one whose   */
  147.                       /* cursor is active.          */
  148.  
  149. #define PNode (b_pactnode[pwin->where_shown.dev][pwin->where_shown.page])
  150.  
  151.     dispcase( WN_ACTIVE_CUR,(pwin->pnode==PNode && pwin==PNode->pwin))
  152.  
  153.     default:
  154.         wnerror(WN_BAD_OPT);      /* Unknown item requested.      */
  155.         presult = NIL;
  156.         break;
  157.     }
  158.  
  159.     return presult;
  160. }
  161.