*** empty log message ***
[emacs.git] / oldXMenu / AddSel.c
blob7807fb665183d65d3fcf8314c9bb56ef45137380
1 #include "copyright.h"
3 /* $Header: /cvs/emacs/oldXMenu/AddSel.c,v 1.2 2000/01/27 15:30:18 gerd Exp $ */
4 /* Copyright Massachusetts Institute of Technology 1985 */
6 /*
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
12 * August, 1985
16 #include <config.h>
17 #include "XMenuInt.h"
19 int
20 XMenuAddSelection(display, menu, p_num, data, label, active, help)
21 Display *display;
22 register XMenu *menu; /* Menu object to be modified. */
23 register int p_num; /* Pane number to be modified. */
24 char *data; /* Data value. */
25 char *label; /* Selection label. */
26 int active; /* Make selection active? */
27 char *help; /* Help string */
29 register XMPane *pane; /* Pane containing the new selection. */
30 register XMSelect *select; /* Newly created selection. */
33 int label_length; /* Label lenght in characters. */
34 int label_width; /* Label width in pixels. */
37 * Check for NULL pointers!
39 if (label == NULL) {
40 _XMErrorCode = XME_ARG_BOUNDS;
41 return(XM_FAILURE);
44 * Find the right pane.
46 pane = _XMGetPanePtr(menu, p_num);
47 if (pane == NULL) return(XM_FAILURE);
50 * Calloc the XMSelect structure.
52 select = (XMSelect *)calloc(1, sizeof(XMSelect));
53 if (select == NULL) {
54 _XMErrorCode = XME_CALLOC;
55 return(XM_FAILURE);
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 select->type = SEPARATOR;
69 select->active = 0;
71 else
73 select->type = SELECTION;
74 select->active = active;
77 select->serial = -1;
78 select->label = label;
79 select->label_width = label_width;
80 select->label_length = label_length;
81 select->data = data;
82 select->parent_p = pane;
83 select->help_string = help;
86 * Insert the selection at the end of the selection list.
88 emacs_insque(select, pane->s_list->prev);
91 * Update the selection count.
93 pane->s_count++;
96 * Schedule a recompute.
98 menu->recompute = 1;
101 * Return the selection number just added.
103 _XMErrorCode = XME_NO_ERROR;
104 return((pane->s_count - 1));