Commit | Line | Data |
---|---|---|
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 | * XMenuAddSelection - Adds a selection to an XMenu object. | |
10 | * | |
11 | * Author: Tony Della Fera, DEC | |
12 | * August, 1985 | |
13 | * | |
14 | */ | |
15 | ||
16 | #include <config.h> | |
17 | #include "XMenuInt.h" | |
18 | ||
19 | int | |
55660072 PE |
20 | XMenuAddSelection(Display *display, register XMenu *menu, register int p_num, char *data, char *label, int active, char const *help) |
21 | ||
b782e2d7 DN |
22 | /* Menu object to be modified. */ |
23 | /* Pane number to be modified. */ | |
24 | /* Data value. */ | |
25 | /* Selection label. */ | |
26 | /* Make selection active? */ | |
27 | /* Help string */ | |
e745ede7 DL |
28 | { |
29 | register XMPane *pane; /* Pane containing the new selection. */ | |
55660072 | 30 | register XMSelect *sel; /* Newly created selection. */ |
e745ede7 DL |
31 | |
32 | ||
53964682 | 33 | int label_length; /* Label length in characters. */ |
e745ede7 | 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 | * Find the right pane. | |
45 | */ | |
46 | pane = _XMGetPanePtr(menu, p_num); | |
47 | if (pane == NULL) return(XM_FAILURE); | |
48 | ||
49 | /* | |
50 | * Calloc the XMSelect structure. | |
51 | */ | |
55660072 PE |
52 | sel = (XMSelect *)calloc(1, sizeof(XMSelect)); |
53 | if (sel == NULL) { | |
e745ede7 DL |
54 | _XMErrorCode = XME_CALLOC; |
55 | return(XM_FAILURE); | |
56 | } | |
57 | /* | |
58 | * Determine label size. | |
59 | */ | |
60 | label_length = strlen(label); | |
61 | label_width = XTextWidth(menu->s_fnt_info, label, label_length); | |
177c0ea7 | 62 | |
e745ede7 DL |
63 | /* |
64 | * Fill the XMSelect structure. | |
65 | */ | |
66 | if (!strcmp (label, "--") || !strcmp (label, "---")) | |
67 | { | |
55660072 PE |
68 | sel->type = SEPARATOR; |
69 | sel->active = 0; | |
e745ede7 DL |
70 | } |
71 | else | |
72 | { | |
55660072 PE |
73 | sel->type = SELECTION; |
74 | sel->active = active; | |
e745ede7 DL |
75 | } |
76 | ||
55660072 PE |
77 | sel->serial = -1; |
78 | sel->label = label; | |
79 | sel->label_width = label_width; | |
80 | sel->label_length = label_length; | |
81 | sel->data = data; | |
82 | sel->parent_p = pane; | |
83 | sel->help_string = help; | |
177c0ea7 | 84 | |
e745ede7 DL |
85 | /* |
86 | * Insert the selection at the end of the selection list. | |
87 | */ | |
55660072 | 88 | emacs_insque(sel, pane->s_list->prev); |
e745ede7 DL |
89 | |
90 | /* | |
91 | * Update the selection count. | |
92 | */ | |
93 | pane->s_count++; | |
94 | ||
95 | /* | |
96 | * Schedule a recompute. | |
97 | */ | |
98 | menu->recompute = 1; | |
99 | ||
100 | /* | |
101 | * Return the selection number just added. | |
102 | */ | |
103 | _XMErrorCode = XME_NO_ERROR; | |
104 | return((pane->s_count - 1)); | |
105 | } |