| 1 | /* Copyright Massachusetts Institute of Technology 1985 */ |
| 2 | |
| 3 | #include "copyright.h" |
| 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 | |
| 15 | #include "XMenuInt.h" |
| 16 | |
| 17 | int |
| 18 | XMenuAddPane(Display *display, register XMenu *menu, register char const *label, int active) |
| 19 | |
| 20 | /* Menu object to be modified. */ |
| 21 | /* Selection label. */ |
| 22 | /* Make selection active? */ |
| 23 | { |
| 24 | register XMPane *pane; /* Newly created pane. */ |
| 25 | register XMSelect *sel; /* Initial selection for the new pane. */ |
| 26 | |
| 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 | } |
| 46 | sel = (XMSelect *)calloc(1, sizeof(XMSelect)); |
| 47 | if (sel == NULL) { |
| 48 | _XMErrorCode = XME_CALLOC; |
| 49 | return(XM_FAILURE); |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Determine label size. |
| 54 | */ |
| 55 | label_length = strlen(label); |
| 56 | label_width = XTextWidth(menu->p_fnt_info, |
| 57 | label, |
| 58 | label_length); |
| 59 | |
| 60 | /* |
| 61 | * Set up the initial selection. |
| 62 | * Values not explicitly set are zeroed by calloc. |
| 63 | */ |
| 64 | sel->next = sel; |
| 65 | sel->prev = sel; |
| 66 | sel->type = SL_HEADER; |
| 67 | sel->serial = -1; |
| 68 | sel->parent_p = pane; |
| 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; |
| 80 | pane->s_list = sel; |
| 81 | |
| 82 | /* |
| 83 | * Insert the pane at the end of the pane list. |
| 84 | */ |
| 85 | emacs_insque(pane, menu->p_list->prev); |
| 86 | |
| 87 | /* |
| 88 | * Update the pane count. |
| 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 | } |