AddSel.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 *display, register XMenu *menu, register int p_num, char *data, char *label, int active, char const *help)
  16. /* Menu object to be modified. */
  17. /* Pane number to be modified. */
  18. /* Data value. */
  19. /* Selection label. */
  20. /* Make selection active? */
  21. /* Help string */
  22. {
  23. register XMPane *pane; /* Pane containing the new selection. */
  24. register XMSelect *sel; /* Newly created selection. */
  25. int label_length; /* Label length in characters. */
  26. int label_width; /* Label width in pixels. */
  27. /*
  28. * Check for NULL pointers!
  29. */
  30. if (label == NULL) {
  31. _XMErrorCode = XME_ARG_BOUNDS;
  32. return(XM_FAILURE);
  33. }
  34. /*
  35. * Find the right pane.
  36. */
  37. pane = _XMGetPanePtr(menu, p_num);
  38. if (pane == NULL) return(XM_FAILURE);
  39. /*
  40. * Calloc the XMSelect structure.
  41. */
  42. sel = (XMSelect *)calloc(1, sizeof(XMSelect));
  43. if (sel == NULL) {
  44. _XMErrorCode = XME_CALLOC;
  45. return(XM_FAILURE);
  46. }
  47. /*
  48. * Determine label size.
  49. */
  50. label_length = strlen(label);
  51. label_width = XTextWidth(menu->s_fnt_info, label, label_length);
  52. /*
  53. * Fill the XMSelect structure.
  54. */
  55. if (!strcmp (label, "--") || !strcmp (label, "---"))
  56. {
  57. sel->type = SEPARATOR;
  58. sel->active = 0;
  59. }
  60. else
  61. {
  62. sel->type = SELECTION;
  63. sel->active = active;
  64. }
  65. sel->serial = -1;
  66. sel->label = label;
  67. sel->label_width = label_width;
  68. sel->label_length = label_length;
  69. sel->data = data;
  70. sel->parent_p = pane;
  71. sel->help_string = help;
  72. /*
  73. * Insert the selection at the end of the selection list.
  74. */
  75. emacs_insque(sel, pane->s_list->prev);
  76. /*
  77. * Update the selection count.
  78. */
  79. pane->s_count++;
  80. /*
  81. * Schedule a recompute.
  82. */
  83. menu->recompute = 1;
  84. /*
  85. * Return the selection number just added.
  86. */
  87. _XMErrorCode = XME_NO_ERROR;
  88. return((pane->s_count - 1));
  89. }