1 /* Copyright Massachusetts Institute of Technology 1985 */
7 * XMenu: MIT Project Athena, X Window system menu package
9 * XMenuInsertSelection - Inserts a selection into an XMenu object
11 * Author: Tony Della Fera, DEC
20 XMenuInsertSelection(menu
, p_num
, s_num
, data
, label
, active
)
21 register XMenu
*menu
; /* Menu object to be modified. */
22 register int p_num
; /* Pane number to be modified. */
23 register int s_num
; /* Selection number of new selection. */
24 char *data
; /* Data value. */
25 char *label
; /* Selection label. */
26 int active
; /* Make selection active? */
28 register XMPane
*p_ptr
; /* XMPane pointer. */
29 register XMSelect
*s_ptr
; /* XMSelect pointer. */
31 XMSelect
*select
; /* 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
;
45 * Find the right pane.
47 p_ptr
= _XMGetPanePtr(menu
, p_num
);
48 if (p_ptr
== NULL
) return(XM_FAILURE
);
51 * Find the selection number one less than the one specified since that
52 * is the selection after which the insertion will occur.
54 s_ptr
= _XMGetSelectionPtr(p_ptr
, (s_num
- 1));
55 if (s_ptr
== NULL
) return(XM_FAILURE
);
58 * Calloc the XMSelect structure.
60 select
= (XMSelect
*)calloc(1, sizeof(XMSelect
));
62 _XMErrorCode
= XME_CALLOC
;
67 * Determine label size.
69 label_length
= strlen(label
);
70 label_width
= XTextWidth(menu
->s_fnt_info
, label
, label_length
);
74 * Fill the XMSelect structure.
76 if (!strcmp (label
, "--") || !strcmp (label
, "---"))
78 select
->type
= SEPARATOR
;
83 select
->type
= SELECTION
;
84 select
->active
= active
;
87 select
->active
= active
;
89 select
->label
= label
;
90 select
->label_width
= label_width
;
91 select
->label_length
= label_length
;
93 select
->parent_p
= p_ptr
;
96 * Insert the selection after the selection with the selection
97 * number one less than the desired number for the new selection.
99 emacs_insque(select
, s_ptr
);
102 * Update the selection count.
107 * Schedule a recompute.
112 * Return the selection number just inserted.
114 _XMErrorCode
= XME_NO_ERROR
;
118 /* arch-tag: 8398626f-81cb-4e13-8ebc-aac1b9237663
119 (do not change this comment) */