ChgSel.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Copyright Massachusetts Institute of Technology 1985 */
  2. #include "copyright.h"
  3. /*
  4. * XMenu: MIT Project Athena, X Window system menu package
  5. *
  6. * XMenuChangeSelection - Change a menu selection.
  7. *
  8. * Author: Tony Della Fera, DEC
  9. * December 19, 1985
  10. *
  11. */
  12. #include <config.h>
  13. #include "XMenuInt.h"
  14. int
  15. XMenuChangeSelection(Display *display, register XMenu *menu, register int p_num, register int s_num, char *data, int data_sw, char *label, int label_sw)
  16. /* previously opened display. */
  17. /* Menu object to be modified. */
  18. /* Pane number to be modified. */
  19. /* Selection number to modified. */
  20. /* Data value. */
  21. /* Change to new data value? */
  22. /* Selection label. */
  23. /* Change to new label? */
  24. {
  25. register XMPane *p_ptr; /* XMPane pointer. */
  26. register XMSelect *s_ptr; /* XMSelect pointer. */
  27. int label_length; /* Label length in characters. */
  28. int label_width; /* Label width in pixels. */
  29. /*
  30. * Check for NULL pointers!
  31. */
  32. if (label == NULL) {
  33. _XMErrorCode = XME_ARG_BOUNDS;
  34. return(XM_FAILURE);
  35. }
  36. /*
  37. * Find the right pane.
  38. */
  39. p_ptr = _XMGetPanePtr(menu, p_num);
  40. if (p_ptr == NULL) return(XM_FAILURE);
  41. /*
  42. * Find the right selection.
  43. */
  44. s_ptr = _XMGetSelectionPtr(p_ptr, s_num);
  45. if (s_ptr == NULL) return(XM_FAILURE);
  46. /*
  47. * Reset the label?
  48. */
  49. if (label_sw) {
  50. /*
  51. * Determine label size.
  52. */
  53. label_length = strlen(label);
  54. label_width = XTextWidth(menu->s_fnt_info, label, label_length);
  55. /*
  56. * Change the selection data.
  57. */
  58. s_ptr->label = label;
  59. s_ptr->label_width = label_width;
  60. s_ptr->label_length = label_length;
  61. /*
  62. * Schedule a recompute.
  63. */
  64. menu->recompute = 1;
  65. }
  66. /*
  67. * Reset the data?
  68. */
  69. if (data_sw) s_ptr->data = data;
  70. /*
  71. * Return successfully.
  72. */
  73. _XMErrorCode = XME_NO_ERROR;
  74. return(s_num);
  75. }