AddSel.c 2.3 KB

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