1 /* Copyright Massachusetts Institute of Technology 1985 */
2
3 /*
4
5 Copyright 1985, 1986, 1987 by the Massachusetts Institute of Technology
6
7 Permission to use, copy, modify, and distribute this
8 software and its documentation for any purpose and without
9 fee is hereby granted, provided that the above copyright
10 notice appear in all copies and that both that copyright
11 notice and this permission notice appear in supporting
12 documentation, and that the name of M.I.T. not be used in
13 advertising or publicity pertaining to distribution of the
14 software without specific, written prior permission.
15 M.I.T. makes no representations about the suitability of
16 this software for any purpose. It is provided "as is"
17 without express or implied warranty.
18
19 */
20
21
22
23
24 /*
25 * XMenu: MIT Project Athena, X Window system menu package
26 *
27 * XMenuInsertPane - Inserts a pane into an XMenu object in
28 * a particular position.
29 *
30 * Author: Tony Della Fera, DEC
31 * 20-Nov-85
32 *
33 */
34
35 #include "XMenuInt.h"
36 #include <string.h>
37
38 int
39 XMenuInsertPane(register XMenu *menu, register int p_num, char *label, int active)
40 /* Menu object to be modified. */
41 /* Pane number of new pane. */
42 /* Selection label. */
43 /* Make selection active? */
44 {
45 register XMPane *p_ptr; /* XMPane pointer. */
46 register XMPane *pane; /* Newly created pane. */
47 register XMSelect *sel; /* Initial selection for the new pane. */
48
49 int label_length; /* Label length in characters. */
50 int label_width; /* Label width in pixels. */
51
52 /*
53 * Check for NULL pointers!
54 */
55 if (label == NULL) {
56 _XMErrorCode = XME_ARG_BOUNDS;
57 return(XM_FAILURE);
58 }
59
60 /*
61 * Find the pane number one less than the one specified since that
62 * is the pane after which the insertion will occur.
63 */
64 p_ptr = _XMGetPanePtr(menu, (p_num - 1));
65 if (p_ptr == NULL) return(XM_FAILURE);
66
67 /*
68 * Calloc the XMPane structure and the initial XMSelect.
69 */
70 pane = (XMPane *)calloc(1, sizeof(XMPane));
71 if (pane == NULL) {
72 _XMErrorCode = XME_CALLOC;
73 return(XM_FAILURE);
74 }
75 sel = (XMSelect *)calloc(1, sizeof(XMSelect));
76 if (sel == NULL) {
77 _XMErrorCode = XME_CALLOC;
78 return(XM_FAILURE);
79 }
80
81 /*
82 * Determine label size.
83 */
84 label_length = strlen(label);
85 label_width = XTextWidth(menu->p_fnt_info, label, label_length);
86
87 /*
88 * Set up the initial selection.
89 * Values not explicitly set are zeroed by calloc.
90 */
91 sel->next = sel;
92 sel->prev = sel;
93 sel->type = SL_HEADER;
94 sel->serial = -1;
95 sel->parent_p = pane;
96
97 /*
98 * Fill the XMPane structure.
99 */
100 pane->type = PANE;
101 pane->active = active;
102 pane->serial = -1;
103 pane->label = label;
104 pane->label_width = label_width;
105 pane->label_length = label_length;
106 pane->s_list = sel;
107
108 /*
109 * Insert the pane after the pane with the pane
110 * number one less than the desired number for the
111 * new pane.
112 */
113 emacs_insque(pane, p_ptr);
114
115 /*
116 * Update the pane count.
117 */
118 menu->p_count++;
119
120 /*
121 * Schedule a recompute.
122 */
123 menu->recompute = 1;
124
125 /*
126 * Return the number of the pane just added.
127 */
128 _XMErrorCode = XME_NO_ERROR;
129 return(p_num);
130 }