AddPane.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Copyright Massachusetts Institute of Technology 1985 */
  2. #include "copyright.h"
  3. /*
  4. * XMenu: MIT Project Athena, X Window system menu package
  5. *
  6. * XMenuAddPane - Adds a pane to an XMenu object.
  7. *
  8. * Author: Tony Della Fera, DEC
  9. * August, 1985
  10. *
  11. */
  12. #include "XMenuInt.h"
  13. int
  14. XMenuAddPane(Display *display, register XMenu *menu, register char const *label, int active)
  15. /* Menu object to be modified. */
  16. /* Selection label. */
  17. /* Make selection active? */
  18. {
  19. register XMPane *pane; /* Newly created pane. */
  20. register XMSelect *sel; /* Initial selection for the new pane. */
  21. int label_length; /* Label length in characters. */
  22. int label_width; /* Label width in pixels. */
  23. /*
  24. * Check for NULL pointers!
  25. */
  26. if (label == NULL) {
  27. _XMErrorCode = XME_ARG_BOUNDS;
  28. return(XM_FAILURE);
  29. }
  30. /*
  31. * Calloc the XMPane structure and the initial XMSelect.
  32. */
  33. pane = (XMPane *)calloc(1, sizeof(XMPane));
  34. if (pane == NULL) {
  35. _XMErrorCode = XME_CALLOC;
  36. return(XM_FAILURE);
  37. }
  38. sel = (XMSelect *)calloc(1, sizeof(XMSelect));
  39. if (sel == NULL) {
  40. _XMErrorCode = XME_CALLOC;
  41. return(XM_FAILURE);
  42. }
  43. /*
  44. * Determine label size.
  45. */
  46. label_length = strlen(label);
  47. label_width = XTextWidth(menu->p_fnt_info,
  48. label,
  49. label_length);
  50. /*
  51. * Set up the initial selection.
  52. * Values not explicitly set are zeroed by calloc.
  53. */
  54. sel->next = sel;
  55. sel->prev = sel;
  56. sel->type = SL_HEADER;
  57. sel->serial = -1;
  58. sel->parent_p = pane;
  59. /*
  60. * Fill the XMPane structure.
  61. * X and Y position are set to 0 since a recompute will follow.
  62. */
  63. pane->type = PANE;
  64. pane->active = active;
  65. pane->serial = -1;
  66. pane->label = label;
  67. pane->label_width = label_width;
  68. pane->label_length = label_length;
  69. pane->s_list = sel;
  70. /*
  71. * Insert the pane at the end of the pane list.
  72. */
  73. emacs_insque(pane, menu->p_list->prev);
  74. /*
  75. * Update the pane count.
  76. */
  77. menu->p_count++;
  78. /*
  79. * Schedule a recompute.
  80. */
  81. menu->recompute = 1;
  82. /*
  83. * Return the pane number just added.
  84. */
  85. _XMErrorCode = XME_NO_ERROR;
  86. return((menu->p_count - 1));
  87. }