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