home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / MNHILIT0.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  4.7 KB  |  163 lines

  1. /**
  2. *
  3. * Name        MNHILIT0 -- Move or remove menu highlight bar
  4. *                or item description.
  5. *
  6. * Synopsis    presult = mnhilit0(pmenu,pitem,option);
  7. *
  8. *        BMENU *presult    Pointer to newly-changed BMENU
  9. *                structure, or NIL if failure.
  10. *        BITEM *pitem    Address of menu item to highlight.
  11. *                If NIL then no item is highlighted.
  12. *                Ignored if MN_UNHIGHLIGHT specified.
  13. *        int option    Option bits:
  14. *                  MN_HIGHLIGHT
  15. *                  MN_UNHIGHLIGHT (ignores row and col)
  16. *                  MN_USE_DESCRIPTION
  17. *                  WN_UPDATE or WN_NO_UPDATE
  18. *
  19. * Description    This function highlights a menu item or removes the
  20. *        highlight bar.    It optionally adds or removes the item's
  21. *        Lotus-style description string.
  22. *
  23. *        This function can work on protected menu items.
  24. *
  25. * Returns    presult       Pointer to newly-changed BMENU
  26. *                  structure, or NIL if failure.
  27. *        b_wnerr       Possible values:
  28. *                  (No change)       Success.
  29. *                  WN_BAD_OPT       Unknown option.
  30. *                  MN_BAD_MENU       pmenu is invalid.
  31. *                  WN_BAD_WIN       pmenu->pwin is invalid.
  32. *                  MN_BAD_ITEM       pitem is invalid.
  33. *
  34. *                  WN_NOT_SHOWN       Internal error.
  35. *                  WN_BAD_DEV       Internal error.
  36. *                  WN_ILL_DIM       Internal error.
  37. *                  WN_NULL_PTR       Internal error.
  38. *
  39. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  40. *
  41. **/
  42.  
  43. #include <bmenu.h>
  44.  
  45. BMENU *mnhilit0(pmenu,pitem,option)
  46. BMENU *pmenu;
  47. BITEM *pitem;
  48. int    option;
  49. {
  50.     int remove        = (   (pitem == NIL)
  51.                || (MN_UNHIGHLIGHT ==
  52.                 (option & (MN_HIGHLIGHT | MN_UNHIGHLIGHT))));
  53.     int desc        = (option & MN_USE_DESCRIPTION);
  54.  
  55.     REGION strip;              /* Region to force into viewport*/
  56.     LOC    begin_strip,end_strip;     /* Points to force into viewport*/
  57.  
  58.  
  59.     mnvalidm(pmenu)              /* Validate menu.           */
  60.  
  61.     if (pmenu->pbar_item != NIL)
  62.     {                      /* A bar is currently shown.    */
  63.  
  64.     if (pmenu->internals.desc_shown)      /* If description shown */
  65.     {                      /* and if           */
  66.         if (   remove              /*   no bar wanted      */
  67.         || !desc              /*   or no description  */
  68.                           /*      wanted          */
  69.         || pmenu->pbar_item != pitem) /*   or bar moved       */
  70.         {
  71.                       /* then remove description.     */
  72.         if (pmenu->pbar_item->llen &&
  73.             NIL == wnscrblk(pmenu->pwin,
  74.                     pmenu->pbar_item->lrow,
  75.                     pmenu->pbar_item->lcol,
  76.                     pmenu->pbar_item->lrow,
  77.                     (pmenu->pbar_item->lcol
  78.                       + pmenu->pbar_item->llen) - 1,
  79.                     utlonyb(pmenu->pwin->attr),
  80.                     uthinyb(pmenu->pwin->attr),
  81.                     WNSCR_LEFT,0,WN_NO_UPDATE))
  82.             return NIL;
  83.         pmenu->internals.desc_shown = 0;
  84.         }
  85.     }
  86.     if (   remove               /* If removing bar          */
  87.         || pmenu->pbar_item != pitem)  /* or bar moved          */
  88.     {
  89.                       /* remove old highlight bar.    */
  90.         if (NIL == mnatr(pmenu,pmenu->pbar_item,MN_UNHIGHLIGHT))
  91.         return NIL;
  92.         pmenu->pbar_prev = pmenu->pbar_item;
  93.         pmenu->pbar_item = NIL;
  94.     }
  95.     }
  96.  
  97.     if (!remove)
  98.     {
  99.     if (pmenu->pbar_item != pitem)
  100.     {                  /* Light new highlight bar.     */
  101.         if (NIL == mnatr(pmenu,pitem,MN_HIGHLIGHT))
  102.         return NIL;
  103.         if (pmenu->pbar_item != NIL)
  104.         pmenu->pbar_prev = pmenu->pbar_item;
  105.         pmenu->pbar_item = pitem;
  106.     }
  107.  
  108.     if (   desc
  109.         && pitem->llen
  110.         && !pmenu->internals.desc_shown)
  111.     {                  /* Show description.          */
  112.         if (NIL == wnwrrect(pmenu->pwin,
  113.                 pitem->lrow,pitem->lcol,
  114.                 pitem->lrow,pitem->lrow + pitem->llen - 1,
  115.                 pitem->plstring,
  116.                 utlonyb(pmenu->longattr),
  117.                 uthinyb(pmenu->longattr),
  118.                 CHARS_ONLY | WN_NO_UPDATE))
  119.         return NIL;
  120.         pmenu->internals.desc_shown = 1;
  121.  
  122.                   /* Force description into viewport.     */
  123.         strip.ul.row    = pitem->lrow;
  124.         begin_strip.row = pitem->lrow;
  125.         strip.lr.row    = pitem->lrow;
  126.         end_strip.row   = pitem->lrow;
  127.  
  128.         strip.ul.col    = pitem->lcol;
  129.         begin_strip.col = pitem->lcol;
  130.         strip.lr.col    = pitem->lcol + pitem->llen - 1;
  131.         end_strip.col   = pitem->lcol + pitem->llen - 1;
  132.  
  133.         if (NIL == wnshoblk(pmenu->pwin,
  134.                 &strip,&begin_strip,&end_strip,
  135.                 WN_NO_UPDATE))
  136.         return NIL;
  137.     }
  138.  
  139.                   /* Force item into viewport.          */
  140.     strip.ul.row    = pitem->row;
  141.     begin_strip.row = pitem->row;
  142.     strip.lr.row    = pitem->row;
  143.     end_strip.row    = pitem->row;
  144.  
  145.     strip.ul.col    = pitem->col;
  146.     begin_strip.col = pitem->col;
  147.     strip.lr.col    = pitem->col + pitem->len - 1;
  148.     end_strip.col    = pitem->col + pitem->len - 1;
  149.  
  150.     if (NIL == wnshoblk(pmenu->pwin,
  151.                 &strip,&begin_strip,&end_strip,
  152.                 WN_NO_UPDATE))
  153.         return NIL;
  154.     }
  155.  
  156.     if (   WN_UPDATE == (option & (WN_UPDATE | WN_NO_UPDATE))
  157.     && !pmenu->pwin->options.delayed)
  158.     if (NIL == wnupdate(pmenu->pwin))
  159.         return NIL;
  160.  
  161.     return pmenu;              /* Success.              */
  162. }
  163.