Merge from emacs-24; up to 2012-05-02T07:12:52Z!rgm@gnu.org.
[bpt/emacs.git] / oldXMenu / InsSel.c
CommitLineData
2cd3138f
GM
1/* Copyright Massachusetts Institute of Technology 1985 */
2
e745ede7
DL
3#include "copyright.h"
4
e745ede7
DL
5
6/*
7 * XMenu: MIT Project Athena, X Window system menu package
8 *
9 * XMenuInsertSelection - Inserts a selection into an XMenu object
10 *
11 * Author: Tony Della Fera, DEC
12 * 20-Nov-85
13 *
14 */
15
16#include <config.h>
17#include "XMenuInt.h"
18
19int
b782e2d7
DN
20XMenuInsertSelection(register XMenu *menu, register int p_num, register int s_num, char *data, char *label, int active)
21 /* Menu object to be modified. */
22 /* Pane number to be modified. */
23 /* Selection number of new selection. */
24 /* Data value. */
25 /* Selection label. */
26 /* Make selection active? */
e745ede7
DL
27{
28 register XMPane *p_ptr; /* XMPane pointer. */
29 register XMSelect *s_ptr; /* XMSelect pointer. */
30
55660072 31 XMSelect *sel; /* Newly created selection. */
e745ede7
DL
32
33 int label_length; /* Label length in characters. */
34 int label_width; /* Label width in pixels. */
177c0ea7 35
e745ede7
DL
36 /*
37 * Check for NULL pointers!
38 */
39 if (label == NULL) {
40 _XMErrorCode = XME_ARG_BOUNDS;
41 return(XM_FAILURE);
42 }
43
44 /*
45 * Find the right pane.
46 */
47 p_ptr = _XMGetPanePtr(menu, p_num);
48 if (p_ptr == NULL) return(XM_FAILURE);
49
50 /*
51 * Find the selection number one less than the one specified since that
52 * is the selection after which the insertion will occur.
53 */
54 s_ptr = _XMGetSelectionPtr(p_ptr, (s_num - 1));
55 if (s_ptr == NULL) return(XM_FAILURE);
56
57 /*
58 * Calloc the XMSelect structure.
59 */
55660072
PE
60 sel = (XMSelect *)calloc(1, sizeof(XMSelect));
61 if (sel == NULL) {
e745ede7
DL
62 _XMErrorCode = XME_CALLOC;
63 return(XM_FAILURE);
64 }
65
66 /*
67 * Determine label size.
68 */
69 label_length = strlen(label);
70 label_width = XTextWidth(menu->s_fnt_info, label, label_length);
71
72
73 /*
74 * Fill the XMSelect structure.
75 */
76 if (!strcmp (label, "--") || !strcmp (label, "---"))
77 {
55660072
PE
78 sel->type = SEPARATOR;
79 sel->active = 0;
e745ede7
DL
80 }
81 else
82 {
55660072
PE
83 sel->type = SELECTION;
84 sel->active = active;
e745ede7
DL
85 }
86
55660072
PE
87 sel->active = active;
88 sel->serial = -1;
89 sel->label = label;
90 sel->label_width = label_width;
91 sel->label_length = label_length;
92 sel->data = data;
93 sel->parent_p = p_ptr;
e745ede7
DL
94
95 /*
96 * Insert the selection after the selection with the selection
97 * number one less than the desired number for the new selection.
98 */
55660072 99 emacs_insque(sel, s_ptr);
e745ede7
DL
100
101 /*
102 * Update the selection count.
103 */
104 p_ptr->s_count++;
105
106 /*
107 * Schedule a recompute.
108 */
109 menu->recompute = 1;
110
111 /*
112 * Return the selection number just inserted.
113 */
114 _XMErrorCode = XME_NO_ERROR;
115 return(s_num);
116}