1 /* Copyright Massachusetts Institute of Technology 1985 */ 2 3 /* 4 5 Copyright 1985, 1986, 1987 by the Massachusetts Institute of Technology 6 7 Permission to use, copy, modify, and distribute this 8 software and its documentation for any purpose and without 9 fee is hereby granted, provided that the above copyright 10 notice appear in all copies and that both that copyright 11 notice and this permission notice appear in supporting 12 documentation, and that the name of M.I.T. not be used in 13 advertising or publicity pertaining to distribution of the 14 software without specific, written prior permission. 15 M.I.T. makes no representations about the suitability of 16 this software for any purpose. It is provided "as is" 17 without express or implied warranty. 18 19 */ 20 21 22 23 24 /* 25 * XMenu: MIT Project Athena, X Window system menu package 26 * 27 * XMenuLocate - Return data necessary to position and locate 28 * a menu on the screen. 29 * 30 * Author: Tony Della Fera, DEC 31 * January 11, 1985 32 * 33 */ 34 35 #include "XMenuInt.h" 36 37 int 38 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) 39 /* Previously opened display. */ 40 /* Menu object being located. */ 41 /* Active pane number. */ 42 /* Active selection number. */ 43 /* X coordinate of mouse active position. */ 44 /* Y coordinate of mouse active position. */ 45 /* Returned upper left menu X coordinate. */ 46 /* Returned upper left menu Y coordinate. */ 47 /* Returned menu width. */ 48 /* Returned menu height. */ 49 { 50 register XMPane *p_ptr; /* XMPane pointer. */ 51 register XMSelect *s_ptr; /* XMSelect pointer. */ 52 53 /* 54 * Are the position arguments positive? 55 */ 56 if ((x_pos <= 0) || (y_pos <= 0)) { 57 _XMErrorCode = XME_ARG_BOUNDS; 58 return(XM_FAILURE); 59 } 60 61 /* 62 * Find the right pane. 63 */ 64 p_ptr = _XMGetPanePtr(menu, p_num); 65 if (p_ptr == NULL) return(XM_FAILURE); 66 67 /* 68 * Find the right selection. 69 */ 70 s_ptr = _XMGetSelectionPtr(p_ptr, s_num); 71 72 /* 73 * Check to see that the menu's dependencies have been 74 * recomputed and are up to date. If not, do it now. 75 */ 76 if (menu->recompute) XMenuRecompute(display, menu); 77 78 /* 79 * Compute the new menu origin such that the active point lies 80 * in the center of the desired active pane and selection. 81 * This sets the values of ul_x and ul_y. 82 */ 83 _XMTransToOrigin(display, menu, p_ptr, s_ptr, x_pos, y_pos, ul_x, ul_y); 84 85 /* 86 * Set remaining return argument values. 87 */ 88 *width = menu->width; 89 *height = menu->height; 90 91 /* 92 * Return successfully. 93 */ 94 _XMErrorCode = XME_NO_ERROR; 95 return(XM_SUCCESS); 96 } 97