Locate.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Copyright Massachusetts Institute of Technology 1985 */
  2. #include "copyright.h"
  3. /*
  4. * XMenu: MIT Project Athena, X Window system menu package
  5. *
  6. * XMenuLocate - Return data necessary to position and locate
  7. * a menu on the screen.
  8. *
  9. * Author: Tony Della Fera, DEC
  10. * January 11, 1985
  11. *
  12. */
  13. #include "XMenuInt.h"
  14. int
  15. XMenuLocate(register Display *display, register XMenu *menu, int p_num, int s_num, int x_pos, int y_pos, int *ul_x, int *ul_y, int *width, int *height)
  16. /* Previously opened display. */
  17. /* Menu object being located. */
  18. /* Active pane number. */
  19. /* Active selection number. */
  20. /* X coordinate of mouse active position. */
  21. /* Y coordinate of mouse active position. */
  22. /* Returned upper left menu X coordinate. */
  23. /* Returned upper left menu Y coordinate. */
  24. /* Returned menu width. */
  25. /* Returned menu height. */
  26. {
  27. register XMPane *p_ptr; /* XMPane pointer. */
  28. register XMSelect *s_ptr; /* XMSelect pointer. */
  29. /*
  30. * Are the position arguments positive?
  31. */
  32. if ((x_pos <= 0) || (y_pos <= 0)) {
  33. _XMErrorCode = XME_ARG_BOUNDS;
  34. return(XM_FAILURE);
  35. }
  36. /*
  37. * Find the right pane.
  38. */
  39. p_ptr = _XMGetPanePtr(menu, p_num);
  40. if (p_ptr == NULL) return(XM_FAILURE);
  41. /*
  42. * Find the right selection.
  43. */
  44. s_ptr = _XMGetSelectionPtr(p_ptr, s_num);
  45. /*
  46. * Check to see that the menu's dependencies have been
  47. * recomputed and are up to date. If not, do it now.
  48. */
  49. if (menu->recompute) XMenuRecompute(display, menu);
  50. /*
  51. * Compute the new menu origin such that the active point lies
  52. * in the center of the desired active pane and selection.
  53. * This sets the values of ul_x and ul_y.
  54. */
  55. _XMTransToOrigin(display, menu, p_ptr, s_ptr, x_pos, y_pos, ul_x, ul_y);
  56. /*
  57. * Set remaining return argument values.
  58. */
  59. *width = menu->width;
  60. *height = menu->height;
  61. /*
  62. * Return successfully.
  63. */
  64. _XMErrorCode = XME_NO_ERROR;
  65. return(XM_SUCCESS);
  66. }