AddSel.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright Massachusetts Institute of Technology 1985 */
  2. #include "copyright.h"
  3. /*
  4. * XMenu: MIT Project Athena, X Window system menu package
  5. *
  6. * XMenuAddSelection - Adds a selection to an XMenu object.
  7. *
  8. * Author: Tony Della Fera, DEC
  9. * August, 1985
  10. *
  11. */
  12. #include <config.h>
  13. #include "XMenuInt.h"
  14. int
  15. XMenuAddSelection(display, menu, p_num, data, label, active, help)
  16. Display *display;
  17. register XMenu *menu; /* Menu object to be modified. */
  18. register int p_num; /* Pane number to be modified. */
  19. char *data; /* Data value. */
  20. char *label; /* Selection label. */
  21. int active; /* Make selection active? */
  22. char *help; /* Help string */
  23. {
  24. register XMPane *pane; /* Pane containing the new selection. */
  25. register XMSelect *select; /* Newly created selection. */
  26. int label_length; /* Label lenght in characters. */
  27. int label_width; /* Label width in pixels. */
  28. /*
  29. * Check for NULL pointers!
  30. */
  31. if (label == NULL) {
  32. _XMErrorCode = XME_ARG_BOUNDS;
  33. return(XM_FAILURE);
  34. }
  35. /*
  36. * Find the right pane.
  37. */
  38. pane = _XMGetPanePtr(menu, p_num);
  39. if (pane == NULL) return(XM_FAILURE);
  40. /*
  41. * Calloc the XMSelect structure.
  42. */
  43. select = (XMSelect *)calloc(1, sizeof(XMSelect));
  44. if (select == NULL) {
  45. _XMErrorCode = XME_CALLOC;
  46. return(XM_FAILURE);
  47. }
  48. /*
  49. * Determine label size.
  50. */
  51. label_length = strlen(label);
  52. label_width = XTextWidth(menu->s_fnt_info, label, label_length);
  53. /*
  54. * Fill the XMSelect structure.
  55. */
  56. if (!strcmp (label, "--") || !strcmp (label, "---"))
  57. {
  58. select->type = SEPARATOR;
  59. select->active = 0;
  60. }
  61. else
  62. {
  63. select->type = SELECTION;
  64. select->active = active;
  65. }
  66. select->serial = -1;
  67. select->label = label;
  68. select->label_width = label_width;
  69. select->label_length = label_length;
  70. select->data = data;
  71. select->parent_p = pane;
  72. select->help_string = help;
  73. /*
  74. * Insert the selection at the end of the selection list.
  75. */
  76. emacs_insque(select, pane->s_list->prev);
  77. /*
  78. * Update the selection count.
  79. */
  80. pane->s_count++;
  81. /*
  82. * Schedule a recompute.
  83. */
  84. menu->recompute = 1;
  85. /*
  86. * Return the selection number just added.
  87. */
  88. _XMErrorCode = XME_NO_ERROR;
  89. return((pane->s_count - 1));
  90. }
  91. /* arch-tag: 0161f024-c739-440d-9498-050280c6c355
  92. (do not change this comment) */