Recomp.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Copyright Massachusetts Institute of Technology 1985 */
  2. #include "copyright.h"
  3. /*
  4. * XMenu: MIT Project Athena, X Window system menu package
  5. *
  6. * XMenuRecompute - Recompute XMenu object dependencies.
  7. *
  8. * Author: Tony Della Fera, DEC
  9. * September, 1985
  10. *
  11. */
  12. #include "XMenuInt.h"
  13. int
  14. XMenuRecompute(Display *display, register XMenu *menu)
  15. /* Menu object to be recomputed. */
  16. {
  17. register XMPane *p_ptr; /* Pane pointer. */
  18. register XMSelect *s_ptr; /* Selection pointer. */
  19. register int p_num; /* Pane serial number. */
  20. register int s_num; /* Selection serial number. */
  21. /*
  22. * If there are no panes in the menu then return failure
  23. * because the menu is not initialized.
  24. */
  25. if (menu->p_count == 0) {
  26. _XMErrorCode = XME_NOT_INIT;
  27. return(XM_FAILURE);
  28. }
  29. /*
  30. * Recompute menu wide global values: pane window size,
  31. * selection size and maximum selection count.
  32. */
  33. _XMRecomputeGlobals(display, menu);
  34. /*
  35. * For each pane in the menu...
  36. */
  37. p_num = 0;
  38. for (
  39. p_ptr = menu->p_list->next;
  40. p_ptr != menu->p_list;
  41. p_ptr = p_ptr->next
  42. ){
  43. /*
  44. * Recompute pane dependencies.
  45. */
  46. if (_XMRecomputePane(display, menu, p_ptr, p_num) == _FAILURE) {
  47. return(XM_FAILURE);
  48. }
  49. p_num++;
  50. /*
  51. * For each selection in the pane...
  52. */
  53. s_num = 0;
  54. for (
  55. s_ptr = p_ptr->s_list->next;
  56. s_ptr != p_ptr->s_list;
  57. s_ptr = s_ptr->next
  58. ) {
  59. /*
  60. * Recompute selection dependencies.
  61. */
  62. if (_XMRecomputeSelection(display, menu, s_ptr, s_num) == _FAILURE) {
  63. return(XM_FAILURE);
  64. }
  65. s_num++;
  66. }
  67. }
  68. /*
  69. * Recompute menu size.
  70. */
  71. if (menu->menu_style == CENTER) {
  72. menu->width = menu->p_width + (menu->p_bdr_width << 1);
  73. }
  74. else {
  75. menu->width = menu->p_width + (menu->p_bdr_width << 1) +
  76. ((menu->p_count - 1) * menu->p_x_off);
  77. }
  78. menu->height = menu->p_height + (menu->p_bdr_width << 1) +
  79. ((menu->p_count - 1) * menu->p_y_off);
  80. /*
  81. * Reset the recompute flag.
  82. */
  83. menu->recompute = 0;
  84. /*
  85. * Return successfully.
  86. */
  87. _XMErrorCode = XME_NO_ERROR;
  88. return(XM_SUCCESS);
  89. }