Commit | Line | Data |
---|---|---|
e745ede7 | 1 | /* Copyright Massachusetts Institute of Technology 1985 */ |
2cd3138f GM |
2 | |
3 | #include "copyright.h" | |
e745ede7 DL |
4 | |
5 | /* | |
6 | * XMenu: MIT Project Athena, X Window system menu package | |
7 | * | |
8 | * XMenuAddPane - Adds a pane to an XMenu object. | |
9 | * | |
10 | * Author: Tony Della Fera, DEC | |
11 | * August, 1985 | |
12 | * | |
13 | */ | |
14 | ||
e745ede7 DL |
15 | #include "XMenuInt.h" |
16 | ||
17 | int | |
55660072 PE |
18 | XMenuAddPane(Display *display, register XMenu *menu, register char const *label, int active) |
19 | ||
b782e2d7 DN |
20 | /* Menu object to be modified. */ |
21 | /* Selection label. */ | |
22 | /* Make selection active? */ | |
e745ede7 DL |
23 | { |
24 | register XMPane *pane; /* Newly created pane. */ | |
55660072 | 25 | register XMSelect *sel; /* Initial selection for the new pane. */ |
177c0ea7 | 26 | |
e745ede7 DL |
27 | int label_length; /* Label length in characters. */ |
28 | int label_width; /* Label width in pixels. */ | |
29 | ||
30 | /* | |
31 | * Check for NULL pointers! | |
32 | */ | |
33 | if (label == NULL) { | |
34 | _XMErrorCode = XME_ARG_BOUNDS; | |
35 | return(XM_FAILURE); | |
36 | } | |
37 | ||
38 | /* | |
39 | * Calloc the XMPane structure and the initial XMSelect. | |
40 | */ | |
41 | pane = (XMPane *)calloc(1, sizeof(XMPane)); | |
42 | if (pane == NULL) { | |
43 | _XMErrorCode = XME_CALLOC; | |
44 | return(XM_FAILURE); | |
45 | } | |
55660072 PE |
46 | sel = (XMSelect *)calloc(1, sizeof(XMSelect)); |
47 | if (sel == NULL) { | |
e745ede7 DL |
48 | _XMErrorCode = XME_CALLOC; |
49 | return(XM_FAILURE); | |
50 | } | |
177c0ea7 | 51 | |
e745ede7 DL |
52 | /* |
53 | * Determine label size. | |
54 | */ | |
55 | label_length = strlen(label); | |
56 | label_width = XTextWidth(menu->p_fnt_info, | |
57 | label, | |
58 | label_length); | |
177c0ea7 | 59 | |
e745ede7 DL |
60 | /* |
61 | * Set up the initial selection. | |
62 | * Values not explicitly set are zeroed by calloc. | |
63 | */ | |
55660072 PE |
64 | sel->next = sel; |
65 | sel->prev = sel; | |
66 | sel->type = SL_HEADER; | |
67 | sel->serial = -1; | |
68 | sel->parent_p = pane; | |
e745ede7 DL |
69 | |
70 | /* | |
71 | * Fill the XMPane structure. | |
72 | * X and Y position are set to 0 since a recompute will follow. | |
73 | */ | |
74 | pane->type = PANE; | |
75 | pane->active = active; | |
76 | pane->serial = -1; | |
77 | pane->label = label; | |
78 | pane->label_width = label_width; | |
79 | pane->label_length = label_length; | |
55660072 | 80 | pane->s_list = sel; |
e745ede7 DL |
81 | |
82 | /* | |
83 | * Insert the pane at the end of the pane list. | |
84 | */ | |
85 | emacs_insque(pane, menu->p_list->prev); | |
86 | ||
87 | /* | |
177c0ea7 | 88 | * Update the pane count. |
e745ede7 DL |
89 | */ |
90 | menu->p_count++; | |
91 | ||
92 | /* | |
93 | * Schedule a recompute. | |
94 | */ | |
95 | menu->recompute = 1; | |
96 | ||
97 | /* | |
98 | * Return the pane number just added. | |
99 | */ | |
100 | _XMErrorCode = XME_NO_ERROR; | |
101 | return((menu->p_count - 1)); | |
102 | } |