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