1 /* Copyright Massachusetts Institute of Technology 1985 */ 2 3 /* 4 5 Copyright 1985, 1986, 1987 by the Massachusetts Institute of Technology 6 7 Permission to use, copy, modify, and distribute this 8 software and its documentation for any purpose and without 9 fee is hereby granted, provided that the above copyright 10 notice appear in all copies and that both that copyright 11 notice and this permission notice appear in supporting 12 documentation, and that the name of M.I.T. not be used in 13 advertising or publicity pertaining to distribution of the 14 software without specific, written prior permission. 15 M.I.T. makes no representations about the suitability of 16 this software for any purpose. It is provided "as is" 17 without express or implied warranty. 18 19 */ 20 21 22 23 24 /* 25 * XMenu: MIT Project Athena, X Window system menu package 26 * 27 * XMenuChangeSelection - Change a menu selection. 28 * 29 * Author: Tony Della Fera, DEC 30 * December 19, 1985 31 * 32 */ 33 34 #include "XMenuInt.h" 35 #include <string.h> 36 37 int 38 XMenuChangeSelection(Display *display, register XMenu *menu, register int p_num, register int s_num, char *data, int data_sw, char *label, int label_sw) 39 /* previously opened display. */ 40 /* Menu object to be modified. */ 41 /* Pane number to be modified. */ 42 /* Selection number to modified. */ 43 /* Data value. */ 44 /* Change to new data value? */ 45 /* Selection label. */ 46 /* Change to new label? */ 47 { 48 register XMPane *p_ptr; /* XMPane pointer. */ 49 register XMSelect *s_ptr; /* XMSelect pointer. */ 50 51 int label_length; /* Label length in characters. */ 52 int label_width; /* Label width in pixels. */ 53 54 /* 55 * Check for NULL pointers! 56 */ 57 if (label == NULL) { 58 _XMErrorCode = XME_ARG_BOUNDS; 59 return(XM_FAILURE); 60 } 61 62 /* 63 * Find the right pane. 64 */ 65 p_ptr = _XMGetPanePtr(menu, p_num); 66 if (p_ptr == NULL) return(XM_FAILURE); 67 68 /* 69 * Find the right selection. 70 */ 71 s_ptr = _XMGetSelectionPtr(p_ptr, s_num); 72 if (s_ptr == NULL) return(XM_FAILURE); 73 74 /* 75 * Reset the label? 76 */ 77 if (label_sw) { 78 /* 79 * Determine label size. 80 */ 81 label_length = strlen(label); 82 label_width = XTextWidth(menu->s_fnt_info, label, label_length); 83 84 /* 85 * Change the selection data. 86 */ 87 s_ptr->label = label; 88 s_ptr->label_width = label_width; 89 s_ptr->label_length = label_length; 90 91 /* 92 * Schedule a recompute. 93 */ 94 menu->recompute = 1; 95 } 96 97 /* 98 * Reset the data? 99 */ 100 if (data_sw) s_ptr->data = data; 101 102 /* 103 * Return successfully. 104 */ 105 _XMErrorCode = XME_NO_ERROR; 106 return(s_num); 107 }