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

  1. /**
  2. *
  3. * Name        MNLITKEY -- Add both an item and a key binding
  4. *                to a Lotus-style menu.
  5. *
  6. * Synopsis    presult = mnlitkey (pmenu, row, col, option, pstring,
  7. *                    lrow, lcol, plstring, pkeys, action);
  8. *
  9. *        BMENU *presult    Pointer to menu which item and key(s)
  10. *                were just added to, or NIL for failure.
  11. *        BMENU *pmenu    Pointer to menu to which to add item
  12. *                and key(s).
  13. *        int    row,    Row and column (relative to menu's
  14. *               col    window data area) at which to both
  15. *                place the item, and bind the key(s).
  16. *        int    option    The bitwise OR-ing of the following values:
  17. *                    MN_PROTECT
  18. *                    Item is protected.
  19. *                    MN_NOPROTECT
  20. *                    Item is not protected.
  21. *                    MN_CHAR_ATTR
  22. *                    PSTRING contains character/attribute
  23. *                    pairs, terminated by a '\0' in a
  24. *                    character cell.
  25. *                    MN_CHARS_ONLY
  26. *                    PSTRING contains a normal '\0'
  27. *                    terminated string.
  28. *        const char *pstring
  29. *                Text of the item.
  30. *        int    lrow,    Row and column (relative to menu's
  31. *               lcol    window data area) at which to place
  32. *                the item's description.
  33. *        const char *plstring
  34. *                Text of the long description of the item.
  35. *        const char *pkeys
  36. *                List of keys that should bind to this
  37. *                item.
  38. *        int    action    The action which should be taken
  39. *                when one of the keys in *pkeys is
  40. *                pressed:
  41. *                   The bitwise OR-ing of the
  42. *                   following:
  43. *                       MN_TRANSMIT, MN_BEEP,
  44. *                       MN_DISABLE, and
  45. *                       MN_ABORT.
  46. *
  47. * Description    This function writes an item to a menu, adds a long
  48. *        description to the item, and also binds keys to
  49. *        the item.  An example is probably best here:
  50. *
  51. *        The call:
  52. *            presult = mnlitkey (pmenu, 0, 0, MN_NOPROTECT, "Open",
  53. *                    7, 0, "Open a file",
  54. *                    "Oo", MN_BEEP);
  55. *
  56. *        Will add the text "Open" to the menu at (0,0), and
  57. *        bind both the upper case and lower case "O" to select
  58. *        the item and beep.
  59. *
  60. *        It will also add "Open a file" to the menu data
  61. *        structure, and that string will appear at (7,0) when
  62. *        the highlight bar moves onto "Open" while using
  63. *        MNLREAD.
  64. *
  65. *        The "key binding" means that when MNREAD/MNLREAD is
  66. *        being used and the user types an "o" or an "O", the
  67. *        selection bar will move to the "Open" item and
  68. *        beep.
  69. *
  70. *        An error occurs if row or col or lrow or lcol exceeds
  71. *        the menu's window dimensions.
  72. *
  73. * Returns    presult         Pointer to changed menu, or
  74. *                    NIL if failure.
  75. *        b_wnerr         Possible values:
  76. *                (No change)     Success.
  77. *                MN_BAD_MENU     Pmenu is invalid.
  78. *                MN_NOT_FOUND     Internal error.
  79. *                WN_BAD_WIN     Pmenu's window is invalid.
  80. *                WN_ILL_DIM     Row or col out of range
  81. *
  82. * Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  83. *
  84. **/
  85.  
  86.  
  87. #include <bkeybrd.h>
  88. #include <bmenu.h>
  89.  
  90. #define NUL '\0'
  91.  
  92.  
  93. BMENU *mnlitkey (pmenu,
  94.          row, col, option, pstring,
  95.          lrow, lcol, plstring,
  96.          pkeys, action)
  97. BMENU *pmenu;
  98. int    row, col, option;
  99. const char *pstring;
  100. int    lrow, lcol;
  101. const char *plstring;
  102. const char *pkeys;
  103. int    action;
  104. {
  105.     char c;
  106.     int  err;
  107.  
  108.         /* Add the item to the menu.                */
  109.     if (NIL == mnlitem (pmenu, row, col, option, pstring,
  110.             lrow, lcol, plstring))
  111.     return (NIL);
  112.  
  113.         /* Add all of the characters pointed to by *pkeys   */
  114.         /* into the menu's key binding list.                */
  115.     while ((c = *pkeys++) != NUL)
  116.     if (NIL == mnkey (pmenu, row, col,
  117.               kbcharof (c), kbscanof (c),
  118.         /* Make sure the movement portion of the action is  */
  119.         /* MN_SELECT.                        */
  120.               (action & ~MN_MOVE_MASK) | MN_SELECT, MN_ADD))
  121.         {
  122.         err = b_wnerr;
  123.         mnitem (pmenu, row, col, option, NIL);
  124.         wnreterr (err);
  125.         }
  126.  
  127.     return (pmenu);
  128. }
  129.