|
|
1.1 ! root 1: #include <X/mit-copyright.h> ! 2: ! 3: /* $Header: XMenuAddSel.c,v 10.8 86/02/12 16:18:33 tony Rel $ */ ! 4: /* Copyright Massachusetts Institute of Technology 1985 */ ! 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 "XMenuInternal.h" ! 17: ! 18: int ! 19: XMenuAddSelection(menu, p_num, data, label, active) ! 20: register XMenu *menu; /* Menu object to be modified. */ ! 21: register int p_num; /* Pane number to be modified. */ ! 22: char *data; /* Data value. */ ! 23: char *label; /* Selection label. */ ! 24: int active; /* Make selection active? */ ! 25: { ! 26: register XMPane *pane; /* Pane containing the new selection. */ ! 27: register XMSelect *select; /* Newly created selection. */ ! 28: ! 29: register int i; /* Loop index. */ ! 30: ! 31: int label_length; /* Label lenght in characters. */ ! 32: int label_width; /* Label width in pixels. */ ! 33: ! 34: /* ! 35: * Check for NULL pointers! ! 36: */ ! 37: if (label == NULL) { ! 38: _XMErrorCode = XME_ARG_BOUNDS; ! 39: return(XM_FAILURE); ! 40: } ! 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: */ ! 51: select = (XMSelect *)calloc(1, sizeof(XMSelect)); ! 52: if (select == NULL) { ! 53: _XMErrorCode = XME_CALLOC; ! 54: return(XM_FAILURE); ! 55: } ! 56: ! 57: /* ! 58: * Determine label size. ! 59: */ ! 60: label_length = strlen(label); ! 61: label_width = XQueryWidth(label, menu->s_fnt_info->id); ! 62: ! 63: /* ! 64: * Fill the XMSelect structure. ! 65: */ ! 66: select->type = SELECTION; ! 67: select->active = active; ! 68: select->serial = -1; ! 69: select->label = label; ! 70: select->label_width = label_width; ! 71: select->label_length = label_length; ! 72: select->data = data; ! 73: select->parent_p = pane; ! 74: ! 75: /* ! 76: * Insert the selection at the end of the selection list. ! 77: */ ! 78: insque(select, pane->s_list->prev); ! 79: ! 80: /* ! 81: * Update the selection count. ! 82: */ ! 83: pane->s_count++; ! 84: ! 85: /* ! 86: * Schedule a recompute. ! 87: */ ! 88: menu->recompute = 1; ! 89: ! 90: /* ! 91: * Return the selection number just added. ! 92: */ ! 93: _XMErrorCode = XME_NO_ERROR; ! 94: return((pane->s_count - 1)); ! 95: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.