home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name MNLITEM -- Add, change, or delete an item in a
- * Lotus-style menu.
- *
- * Synopsis presult = mnlitem (pmenu, row, col, option,
- * pstring, lrow, lcol, plstring);
- *
- * BMENU *presult Pointer to menu which item and key(s)
- * were just added to, or NIL for failure.
- * BMENU *pmenu Pointer to menu to which to add item.
- * int row, Row and column (relative to menu's
- * col window data area) at which to place
- * the item.
- * int option The bitwise OR-ing of the following values:
- * MN_PROTECT
- * Item is protected.
- * MN_NOPROTECT
- * Item is not protected.
- * MN_CHAR_ATTR
- * PSTRING contains character/attribute
- * pairs, terminated by a '\0' in a
- * character cell.
- * MN_CHARS_ONLY
- * PSTRING contains a normal '\0'
- * terminated string.
- * const char *pstring
- * Text of the item.
- * int lrow, Row and column (relative to menu's
- * lcol window data area) at which to place
- * the item's description.
- * const char *plstring
- * Text of the long description of the item.
- *
- * Description This function writes a Lotus-style item to a menu.
- * An example is probably best here:
- *
- * The call:
- * presult = mnlitem (pmenu, 5, 2, MN_NOPROTECT, "Close",
- * 7, 1, "Close the currently-open file");
- *
- * Will add the text "Close" to the menu at (5,2). The
- * item will be in the normal-text attribute, because
- * "option" is MN_NOPROTECT. It will also add the text
- * "Close the currently-open file" to the item data
- * structure. If the menu is read with MNLREAD, when the
- * highlight bar is on "Close," the long description text
- * will appear at (7,1) in the longattr attribute given at
- * MNCREATE time.
- *
- * An error occurs if row or col or lrow or lcol exceeds
- * the menu's window dimensions.
- *
- * Returns presult Pointer to changed menu, or
- * NIL if failure.
- * b_wnerr Possible values:
- * (No change) Success.
- * MN_BAD_MENU Pmenu is invalid.
- * MN_BAD_ITEM An item in pmenu is bad.
- * WN_BAD_WIN Pmenu's window is invalid.
- * WN_NO_MEMORY Insufficient memory.
- * WN_ILL_DIM Row or col out of range
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1987,1989
- *
- **/
-
-
- #include <string.h>
-
- #include <bmenu.h>
-
-
- BMENU *mnlitem (pmenu, row, col, option, pstring, lrow, lcol, plstring)
- BMENU *pmenu;
- int row, col, option;
- const char *pstring;
- int lrow, lcol;
- const char *plstring;
- {
- BITEM *pitem;
- int code;
- int lasterr;
-
- /* Add the standard text item to the menu. */
- if (NIL == mnitem (pmenu, row, col, option, pstring))
- return (NIL);
-
- /* Get a pointer to the item so we can add special */
- /* "Lotus"-style information; if we cannot get a */
- /* pointer, the above MNITEM call was a deletion. */
- if ((pitem = mnmchitm (pmenu, NIL, row, col, 1, &code)) != NIL)
- {
- /* Add the information. */
- pitem->lrow = lrow;
- pitem->lcol = lcol;
- pitem->llen = mntrunc (pmenu, strlen(plstring), lcol);
- if ((pitem->plstring = malloc(pitem->llen + 1)) == NIL)
- {
- /* Error allocating memory for copy of Lotus string.*/
- lasterr = b_wnerr;
- mnitem(pmenu, row, col, option, NIL);
- b_wnerr = lasterr;
- return(NIL);
- }
- strncpy(pitem->plstring, plstring, pitem->llen);
- pitem->plstring[pitem->llen] = '\0';
- }
-
- if (code != WN_NO_ERROR)
- return (NIL);
- else
- return (pmenu);
- }