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

  1. /**
  2. *
  3. * Name        MNLITEM -- Add, change, or delete an item in a
  4. *               Lotus-style menu.
  5. *
  6. * Synopsis    presult = mnlitem (pmenu, row, col, option,
  7. *                   pstring, lrow, lcol, plstring);
  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. *        int    row,    Row and column (relative to menu's
  13. *               col    window data area) at which to place
  14. *                the item.
  15. *        int    option    The bitwise OR-ing of the following values:
  16. *                    MN_PROTECT
  17. *                    Item is protected.
  18. *                    MN_NOPROTECT
  19. *                    Item is not protected.
  20. *                    MN_CHAR_ATTR
  21. *                    PSTRING contains character/attribute
  22. *                    pairs, terminated by a '\0' in a
  23. *                    character cell.
  24. *                    MN_CHARS_ONLY
  25. *                    PSTRING contains a normal '\0'
  26. *                    terminated string.
  27. *        const char *pstring
  28. *                Text of the item.
  29. *        int    lrow,    Row and column (relative to menu's
  30. *               lcol    window data area) at which to place
  31. *                the item's description.
  32. *        const char *plstring
  33. *                Text of the long description of the item.
  34. *
  35. * Description    This function writes a Lotus-style item to a menu.
  36. *        An example is probably best here:
  37. *
  38. *        The call:
  39. *            presult = mnlitem (pmenu, 5, 2, MN_NOPROTECT, "Close",
  40. *                       7, 1, "Close the currently-open file");
  41. *
  42. *        Will add the text "Close" to the menu at (5,2).  The
  43. *        item will be in the normal-text attribute, because
  44. *        "option" is MN_NOPROTECT.  It will also add the text
  45. *        "Close the currently-open file" to the item data
  46. *        structure.  If the menu is read with MNLREAD, when the
  47. *        highlight bar is on "Close," the long description text
  48. *        will appear at (7,1) in the longattr attribute given at
  49. *        MNCREATE time.
  50. *
  51. *        An error occurs if row or col or lrow or lcol exceeds
  52. *        the menu's window dimensions.
  53. *
  54. * Returns    presult         Pointer to changed menu, or
  55. *                    NIL if failure.
  56. *        b_wnerr     Possible values:
  57. *                (No change)    Success.
  58. *                MN_BAD_MENU    Pmenu is invalid.
  59. *                MN_BAD_ITEM    An item in pmenu is bad.
  60. *                WN_BAD_WIN    Pmenu's window is invalid.
  61. *                WN_NO_MEMORY    Insufficient memory.
  62. *                WN_ILL_DIM    Row or col out of range
  63. *
  64. * Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  65. *
  66. **/
  67.  
  68.  
  69. #include <string.h>
  70.  
  71. #include <bmenu.h>
  72.  
  73.  
  74. BMENU *mnlitem (pmenu, row, col, option, pstring, lrow, lcol, plstring)
  75. BMENU *pmenu;
  76. int    row, col, option;
  77. const char *pstring;
  78. int    lrow, lcol;
  79. const char *plstring;
  80. {
  81.     BITEM *pitem;
  82.     int    code;
  83.     int    lasterr;
  84.  
  85.         /* Add the standard text item to the menu.        */
  86.     if (NIL == mnitem (pmenu, row, col, option, pstring))
  87.     return (NIL);
  88.  
  89.         /* Get a pointer to the item so we can add special  */
  90.         /* "Lotus"-style information; if we cannot get a    */
  91.         /* pointer, the above MNITEM call was a deletion.   */
  92.     if ((pitem = mnmchitm (pmenu, NIL, row, col, 1, &code)) != NIL)
  93.     {
  94.         /* Add the information.                 */
  95.     pitem->lrow    = lrow;
  96.     pitem->lcol    = lcol;
  97.     pitem->llen = mntrunc (pmenu, strlen(plstring), lcol);
  98.     if ((pitem->plstring = malloc(pitem->llen + 1)) == NIL)
  99.     {
  100.         /* Error allocating memory for copy of Lotus string.*/
  101.         lasterr = b_wnerr;
  102.         mnitem(pmenu, row, col, option, NIL);
  103.         b_wnerr = lasterr;
  104.         return(NIL);
  105.     }
  106.     strncpy(pitem->plstring, plstring, pitem->llen);
  107.     pitem->plstring[pitem->llen] = '\0';
  108.     }
  109.  
  110.     if (code != WN_NO_ERROR)
  111.     return (NIL);
  112.     else
  113.     return (pmenu);
  114. }
  115.