InsSel.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright Massachusetts Institute of Technology 1985 */
  2. #include "copyright.h"
  3. /*
  4. * XMenu: MIT Project Athena, X Window system menu package
  5. *
  6. * XMenuInsertSelection - Inserts a selection into an XMenu object
  7. *
  8. * Author: Tony Della Fera, DEC
  9. * 20-Nov-85
  10. *
  11. */
  12. #include <config.h>
  13. #include "XMenuInt.h"
  14. int
  15. XMenuInsertSelection(register XMenu *menu, register int p_num, register int s_num, char *data, char *label, int active)
  16. /* Menu object to be modified. */
  17. /* Pane number to be modified. */
  18. /* Selection number of new selection. */
  19. /* Data value. */
  20. /* Selection label. */
  21. /* Make selection active? */
  22. {
  23. register XMPane *p_ptr; /* XMPane pointer. */
  24. register XMSelect *s_ptr; /* XMSelect pointer. */
  25. XMSelect *sel; /* Newly created selection. */
  26. int label_length; /* Label length 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. p_ptr = _XMGetPanePtr(menu, p_num);
  39. if (p_ptr == NULL) return(XM_FAILURE);
  40. /*
  41. * Find the selection number one less than the one specified since that
  42. * is the selection after which the insertion will occur.
  43. */
  44. s_ptr = _XMGetSelectionPtr(p_ptr, (s_num - 1));
  45. if (s_ptr == NULL) return(XM_FAILURE);
  46. /*
  47. * Calloc the XMSelect structure.
  48. */
  49. sel = (XMSelect *)calloc(1, sizeof(XMSelect));
  50. if (sel == NULL) {
  51. _XMErrorCode = XME_CALLOC;
  52. return(XM_FAILURE);
  53. }
  54. /*
  55. * Determine label size.
  56. */
  57. label_length = strlen(label);
  58. label_width = XTextWidth(menu->s_fnt_info, label, label_length);
  59. /*
  60. * Fill the XMSelect structure.
  61. */
  62. if (!strcmp (label, "--") || !strcmp (label, "---"))
  63. {
  64. sel->type = SEPARATOR;
  65. sel->active = 0;
  66. }
  67. else
  68. {
  69. sel->type = SELECTION;
  70. sel->active = active;
  71. }
  72. sel->active = active;
  73. sel->serial = -1;
  74. sel->label = label;
  75. sel->label_width = label_width;
  76. sel->label_length = label_length;
  77. sel->data = data;
  78. sel->parent_p = p_ptr;
  79. /*
  80. * Insert the selection after the selection with the selection
  81. * number one less than the desired number for the new selection.
  82. */
  83. emacs_insque(sel, s_ptr);
  84. /*
  85. * Update the selection count.
  86. */
  87. p_ptr->s_count++;
  88. /*
  89. * Schedule a recompute.
  90. */
  91. menu->recompute = 1;
  92. /*
  93. * Return the selection number just inserted.
  94. */
  95. _XMErrorCode = XME_NO_ERROR;
  96. return(s_num);
  97. }