InsPane.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "XMenuInt.h"
  14. int
  15. XMenuInsertPane(register XMenu *menu, register int p_num, char *label, int active)
  16. /* Menu object to be modified. */
  17. /* Pane number of new pane. */
  18. /* Selection label. */
  19. /* Make selection active? */
  20. {
  21. register XMPane *p_ptr; /* XMPane pointer. */
  22. register XMPane *pane; /* Newly created pane. */
  23. register XMSelect *sel; /* Initial selection for the new pane. */
  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 pane number one less than the one specified since that
  35. * is the pane after which the insertion will occur.
  36. */
  37. p_ptr = _XMGetPanePtr(menu, (p_num - 1));
  38. if (p_ptr == NULL) return(XM_FAILURE);
  39. /*
  40. * Calloc the XMPane structure and the initial XMSelect.
  41. */
  42. pane = (XMPane *)calloc(1, sizeof(XMPane));
  43. if (pane == NULL) {
  44. _XMErrorCode = XME_CALLOC;
  45. return(XM_FAILURE);
  46. }
  47. sel = (XMSelect *)calloc(1, sizeof(XMSelect));
  48. if (sel == NULL) {
  49. _XMErrorCode = XME_CALLOC;
  50. return(XM_FAILURE);
  51. }
  52. /*
  53. * Determine label size.
  54. */
  55. label_length = strlen(label);
  56. label_width = XTextWidth(menu->p_fnt_info, label, label_length);
  57. /*
  58. * Set up the initial selection.
  59. * Values not explicitly set are zeroed by calloc.
  60. */
  61. sel->next = sel;
  62. sel->prev = sel;
  63. sel->type = SL_HEADER;
  64. sel->serial = -1;
  65. sel->parent_p = pane;
  66. /*
  67. * Fill the XMPane structure.
  68. */
  69. pane->type = PANE;
  70. pane->active = active;
  71. pane->serial = -1;
  72. pane->label = label;
  73. pane->label_width = label_width;
  74. pane->label_length = label_length;
  75. pane->s_list = sel;
  76. /*
  77. * Insert the pane after the pane with the pane
  78. * number one less than the desired number for the
  79. * new pane.
  80. */
  81. emacs_insque(pane, p_ptr);
  82. /*
  83. * Update the pane count.
  84. */
  85. menu->p_count++;
  86. /*
  87. * Schedule a recompute.
  88. */
  89. menu->recompute = 1;
  90. /*
  91. * Return the number of the pane just added.
  92. */
  93. _XMErrorCode = XME_NO_ERROR;
  94. return(p_num);
  95. }