1 /* Copyright Massachusetts Institute of Technology 1985 */
7 * XMenu: MIT Project Athena, X Window system menu package
9 * XMenuAddSelection - Adds a selection to an XMenu object.
11 * Author: Tony Della Fera, DEC
20 XMenuAddSelection(Display
*display
, register XMenu
*menu
, register int p_num
, char *data
, char *label
, int active
, char const *help
)
22 /* Menu object to be modified. */
23 /* Pane number to be modified. */
25 /* Selection label. */
26 /* Make selection active? */
29 register XMPane
*pane
; /* Pane containing the new selection. */
30 register XMSelect
*sel
; /* Newly created selection. */
33 int label_length
; /* Label length in characters. */
34 int label_width
; /* Label width in pixels. */
37 * Check for NULL pointers!
40 _XMErrorCode
= XME_ARG_BOUNDS
;
44 * Find the right pane.
46 pane
= _XMGetPanePtr(menu
, p_num
);
47 if (pane
== NULL
) return(XM_FAILURE
);
50 * Calloc the XMSelect structure.
52 sel
= (XMSelect
*)calloc(1, sizeof(XMSelect
));
54 _XMErrorCode
= XME_CALLOC
;
58 * Determine label size.
60 label_length
= strlen(label
);
61 label_width
= XTextWidth(menu
->s_fnt_info
, label
, label_length
);
64 * Fill the XMSelect structure.
66 if (!strcmp (label
, "--") || !strcmp (label
, "---"))
68 sel
->type
= SEPARATOR
;
73 sel
->type
= SELECTION
;
79 sel
->label_width
= label_width
;
80 sel
->label_length
= label_length
;
83 sel
->help_string
= help
;
86 * Insert the selection at the end of the selection list.
88 emacs_insque(sel
, pane
->s_list
->prev
);
91 * Update the selection count.
96 * Schedule a recompute.
101 * Return the selection number just added.
103 _XMErrorCode
= XME_NO_ERROR
;
104 return((pane
->s_count
- 1));