1: #include <X/mit-copyright.h>
2:
3: /* $Header: XMenuInsSel.c,v 10.9 86/02/01 16:15:07 tony Rel $ */
4: /* Copyright Massachusetts Institute of Technology 1985 */
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 "XMenuInternal.h"
17:
18:
19: XMenuInsertSelection(menu, p_num, s_num, data, label, active)
20: register XMenu *menu; /* Menu object to be modified. */
21: register int p_num; /* Pane number to be modified. */
22: register int s_num; /* Selection number of new selection. */
23: char *data; /* Data value. */
24: char *label; /* Selection label. */
25: int active; /* Make selection active? */
26: {
27: register XMPane *p_ptr; /* XMPane pointer. */
28: register XMSelect *s_ptr; /* XMSelect pointer. */
29:
30: register int i; /* Loop index. */
31:
32: XMSelect *select; /* Newly created selection. */
33:
34: int label_length; /* Label lenght in characters. */
35: int label_width; /* Label width in pixels. */
36:
37: /*
38: * Check for NULL pointers!
39: */
40: if (label == NULL) {
41: _XMErrorCode = XME_ARG_BOUNDS;
42: return(XM_FAILURE);
43: }
44:
45: /*
46: * Find the right pane.
47: */
48: p_ptr = _XMGetPanePtr(menu, p_num);
49: if (p_ptr == NULL) return(XM_FAILURE);
50:
51: /*
52: * Find the selection number one less than the one specified since that
53: * is the selection after which the insertion will occur.
54: */
55: s_ptr = _XMGetSelectionPtr(p_ptr, (s_num - 1));
56: if (s_ptr == NULL) return(XM_FAILURE);
57:
58: /*
59: * Calloc the XMSelect structure.
60: */
61: select = (XMSelect *)calloc(1, sizeof(XMSelect));
62: if (select == NULL) {
63: _XMErrorCode = XME_CALLOC;
64: return(XM_FAILURE);
65: }
66:
67: /*
68: * Determine label size.
69: */
70: label_length = strlen(label);
71: label_width = XQueryWidth(label, menu->s_fnt_info->id);
72:
73: /*
74: * Fill the XMSelect structure.
75: */
76: select->type = SELECTION;
77: select->active = active;
78: select->serial = -1;
79: select->label = label;
80: select->label_width = label_width;
81: select->label_length = label_length;
82: select->data = data;
83: select->parent_p = p_ptr;
84:
85: /*
86: * Insert the selection after the selection with the selection
87: * number one less than the desired number for the new selection.
88: */
89: insque(select, s_ptr);
90:
91: /*
92: * Update the selection count.
93: */
94: p_ptr->s_count++;
95:
96: /*
97: * Schedule a recompute.
98: */
99: menu->recompute = 1;
100:
101: /*
102: * Return the selection number just inserted.
103: */
104: _XMErrorCode = XME_NO_ERROR;
105: return(s_num);
106: }
Defined functions
defined in line
18; used 2 times