InsPane.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Copyright Massachusetts Institute of Technology 1985 */
  2. #include "copyright.h"
  3. /*
  4. * XMenu: MIT Project Athena, X Window system menu package
  5. *
  6. * XMenuInsertPane - Inserts a pane into an XMenu object in
  7. * a particular position.
  8. *
  9. * Author: Tony Della Fera, DEC
  10. * 20-Nov-85
  11. *
  12. */
  13. #include <config.h>
  14. #include "XMenuInt.h"
  15. int
  16. XMenuInsertPane(register XMenu *menu, register int p_num, char *label, int active)
  17. /* Menu object to be modified. */
  18. /* Pane number of new pane. */
  19. /* Selection label. */
  20. /* Make selection active? */
  21. {
  22. register XMPane *p_ptr; /* XMPane pointer. */
  23. register XMPane *pane; /* Newly created pane. */
  24. register XMSelect *sel; /* Initial selection for the new pane. */
  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 pane number one less than the one specified since that
  36. * is the pane after which the insertion will occur.
  37. */
  38. p_ptr = _XMGetPanePtr(menu, (p_num - 1));
  39. if (p_ptr == NULL) return(XM_FAILURE);
  40. /*
  41. * Calloc the XMPane structure and the initial XMSelect.
  42. */
  43. pane = (XMPane *)calloc(1, sizeof(XMPane));
  44. if (pane == NULL) {
  45. _XMErrorCode = XME_CALLOC;
  46. return(XM_FAILURE);
  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->p_fnt_info, label, label_length);
  58. /*
  59. * Set up the initial selection.
  60. * Values not explicitly set are zeroed by calloc.
  61. */
  62. sel->next = sel;
  63. sel->prev = sel;
  64. sel->type = SL_HEADER;
  65. sel->serial = -1;
  66. sel->parent_p = pane;
  67. /*
  68. * Fill the XMPane structure.
  69. */
  70. pane->type = PANE;
  71. pane->active = active;
  72. pane->serial = -1;
  73. pane->label = label;
  74. pane->label_width = label_width;
  75. pane->label_length = label_length;
  76. pane->s_list = sel;
  77. /*
  78. * Insert the pane after the pane with the pane
  79. * number one less than the desired number for the
  80. * new pane.
  81. */
  82. emacs_insque(pane, p_ptr);
  83. /*
  84. * Update the pane count.
  85. */
  86. menu->p_count++;
  87. /*
  88. * Schedule a recompute.
  89. */
  90. menu->recompute = 1;
  91. /*
  92. * Return the number of the pane just added.
  93. */
  94. _XMErrorCode = XME_NO_ERROR;
  95. return(p_num);
  96. }