AddPane.c 2.3 KB

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