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

  1. /**
  2. *
  3. * Name        MNITMKEY -- Add both an item and a key binding
  4. *                to a menu.
  5. *
  6. * Synopsis    presult = mnitmkey (pmenu, row, col, option, pstring,
  7. *                    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. *        const char *pkeys
  31. *                List of keys that should bind to this
  32. *                item.
  33. *        int    action    The action which should be taken
  34. *                when one of the keys in *pkeys is
  35. *                pressed:
  36. *                   The bitwise OR-ing of the
  37. *                   following:
  38. *                       MN_TRANSMIT, MN_BEEP,
  39. *                       MN_DISABLE, and
  40. *                       MN_ABORT.
  41. *
  42. * Description    This function writes an item to a menu, and also binds
  43. *        keys to the item.  An example is probably best here:
  44. *
  45. *        The call:
  46. *            presult = mnitmkey (pmenu, 0, 0, MN_NOPROTECT, "Open",
  47. *                    "Oo", MN_BEEP);
  48. *
  49. *        Will add the text "Open" to the menu at (0,0), and
  50. *        bind both the upper case and lower case "O" to select
  51. *        the item and beep.
  52. *
  53. *        The "key binding" means that when MNREAD is being
  54. *        used and the user types an "o" or an "O", the
  55. *        selection bar will move to the "Open" item and
  56. *        beep.
  57. *
  58. *        An error occurs if row or col exceeds the menu's
  59. *        window dimensions.
  60. *
  61. * Returns    presult         Pointer to changed menu, or
  62. *                    NIL if failure.
  63. *        b_wnerr         Possible values:
  64. *                (No change)     Success.
  65. *                MN_BAD_MENU     pmenu is invalid.
  66. *                WN_BAD_WIN     pmenu's window is invalid.
  67. *                WN_ILL_DIM     row or col out of range
  68. *
  69. * Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  70. *
  71. **/
  72.  
  73.  
  74. #include <bkeybrd.h>
  75. #include <bmenu.h>
  76.  
  77. #define NUL '\0'
  78.  
  79.  
  80. BMENU *mnitmkey (pmenu, row, col, option, pstring, pkeys, action)
  81. BMENU *pmenu;
  82. int    row, col, option;
  83. const char *pstring, *pkeys;
  84. int    action;
  85. {
  86.     char c;
  87.     int  err;
  88.  
  89.         /* Add item to menu.                    */
  90.     if (NIL == mnitem (pmenu, row, col, option, pstring))
  91.     return (NIL);
  92.  
  93.         /* Add all of the characters pointed to by *pkeys   */
  94.         /* into the menu's key binding list.                */
  95.     while ((c = *pkeys++) != NUL)
  96.     if (NIL == mnkey (pmenu, row, col,
  97.               kbcharof (c), kbscanof (c),
  98.         /* Make sure the movement portion of the action is  */
  99.         /* MN_SELECT.                        */
  100.               (action & ~MN_MOVE_MASK) | MN_SELECT, MN_ADD))
  101.         {
  102.         err = b_wnerr;
  103.         mnitem (pmenu, row, col, option, NIL);
  104.         wnreterr (err);
  105.         }
  106.  
  107.     return (pmenu);
  108. }
  109.