InsSel.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 "XMenuInt.h"
  13. int
  14. XMenuInsertSelection(register XMenu *menu, register int p_num, register int s_num, char *data, char *label, int active)
  15. /* Menu object to be modified. */
  16. /* Pane number to be modified. */
  17. /* Selection number of new selection. */
  18. /* Data value. */
  19. /* Selection label. */
  20. /* Make selection active? */
  21. {
  22. register XMPane *p_ptr; /* XMPane pointer. */
  23. register XMSelect *s_ptr; /* XMSelect pointer. */
  24. 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. p_ptr = _XMGetPanePtr(menu, p_num);
  38. if (p_ptr == NULL) return(XM_FAILURE);
  39. /*
  40. * Find the selection number one less than the one specified since that
  41. * is the selection after which the insertion will occur.
  42. */
  43. s_ptr = _XMGetSelectionPtr(p_ptr, (s_num - 1));
  44. if (s_ptr == NULL) return(XM_FAILURE);
  45. /*
  46. * Calloc the XMSelect structure.
  47. */
  48. sel = (XMSelect *)calloc(1, sizeof(XMSelect));
  49. if (sel == NULL) {
  50. _XMErrorCode = XME_CALLOC;
  51. return(XM_FAILURE);
  52. }
  53. /*
  54. * Determine label size.
  55. */
  56. label_length = strlen(label);
  57. label_width = XTextWidth(menu->s_fnt_info, label, label_length);
  58. /*
  59. * Fill the XMSelect structure.
  60. */
  61. if (!strcmp (label, "--") || !strcmp (label, "---"))
  62. {
  63. sel->type = SEPARATOR;
  64. sel->active = 0;
  65. }
  66. else
  67. {
  68. sel->type = SELECTION;
  69. sel->active = active;
  70. }
  71. sel->active = active;
  72. sel->serial = -1;
  73. sel->label = label;
  74. sel->label_width = label_width;
  75. sel->label_length = label_length;
  76. sel->data = data;
  77. sel->parent_p = p_ptr;
  78. /*
  79. * Insert the selection after the selection with the selection
  80. * number one less than the desired number for the new selection.
  81. */
  82. emacs_insque(sel, s_ptr);
  83. /*
  84. * Update the selection count.
  85. */
  86. p_ptr->s_count++;
  87. /*
  88. * Schedule a recompute.
  89. */
  90. menu->recompute = 1;
  91. /*
  92. * Return the selection number just inserted.
  93. */
  94. _XMErrorCode = XME_NO_ERROR;
  95. return(s_num);
  96. }