/* $Id: util.c,v 10.1 92/10/06 23:03:38 ca Exp $ */ /* * MaRS Maryland Routing Simulator * Copyright (c) 1991 University of Maryland * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of U.M. not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. U.M. makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: Eric Bull * Systems Design and Analysis Group * Department of Computer Science * University of Maryland at College Park. */ #include #include #include #include #include #include #include #include #include #include "xm-util.h" #include "simx.h" #include "comptypes.h" /* This file contains miscellaneous utility routines that don't belong anywhere else. */ /********************************************************************************************************************************************/ /* This is set on the popupCallback list of dialog shell widgets to set their position just before they pop up. */ void SetShellPosition(Widget w, CoordinatePair *pos) { XtVaSetValues(w, XmNx, pos->x, XmNy, pos->y, NULL); } /********************************************************************************************************************************************/ /* Translate (w1x,w1y) in widget w1 to the corresponding position in widget w2 (Assuming the widgets overlap). */ void WWTranslateCoords(Widget w1,Widget w2,Position w1x,Position w1y,Position *w2x,Position *w2y) { Position r1x,r1y,r2x,r2y; XtTranslateCoords(w1,w1x,w1y,&r1x,&r1y); XtTranslateCoords(w2,(Position)0,(Position)0,&r2x,&r2y); *w2x=(Position)(r1x-r2x); *w2y=(Position)(r1y-r2y); } /* Translate root-relative coordinates to widget relative-coordinates. */ void RWTranslateCoords(Position x, Position y, Widget w, Position *wx, Position *wy) { Position rx,ry; XtTranslateCoords(w,(Position)0,(Position)0,&rx,&ry); *wx=(Position)x-rx; *wy=(Position)y-ry; } /********************************************************************************************************************************************/ int which_string(String key, String *strings, int nstrings) { int i; for (i=0;i