home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_Geom.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  4KB  |  102 lines

  1. /* $XConsortium: Geom.c,v 1.9 94/04/17 20:19:29 rws Exp $ */
  2.  
  3. /*
  4.  
  5. Copyright (c) 1985  X Consortium
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining
  8. a copy of this software and associated documentation files (the
  9. "Software"), to deal in the Software without restriction, including
  10. without limitation the rights to use, copy, modify, merge, publish,
  11. distribute, sublicense, and/or sell copies of the Software, and to
  12. permit persons to whom the Software is furnished to do so, subject to
  13. the following conditions:
  14.  
  15. The above copyright notice and this permission notice shall be included
  16. in all copies or substantial portions of the Software.
  17.  
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. OTHER DEALINGS IN THE SOFTWARE.
  25.  
  26. Except as contained in this notice, the name of the X Consortium shall
  27. not be used in advertising or otherwise to promote the sale, use or
  28. other dealings in this Software without prior written authorization
  29. from the X Consortium.
  30.  
  31. */
  32.  
  33. #include "Xlib_private.h"
  34. #include "Xutil.h"
  35.  
  36. /*
  37.  * This routine given a user supplied positional argument and a default
  38.  * argument (fully qualified) will return the position the window should take
  39.  * returns 0 if there was some problem, else the position bitmask.
  40.  */
  41.  
  42. #if NeedFunctionPrototypes
  43. int XGeometry (
  44.      Display *dpy,            /* user's display connection */
  45.      int screen,            /* screen on which to do computation */
  46.      _Xconst char *pos,            /* user provided geometry spec */
  47.      _Xconst char *def,            /* default geometry spec for window */
  48.      unsigned int bwidth,        /* border width */
  49.      unsigned int fwidth,        /* size of position units */
  50.      unsigned int fheight,
  51.      int xadd,                /* any additional interior space */
  52.      int yadd,
  53.      register int *x,            /* always set on successful RETURN */
  54.      register int *y,            /* always set on successful RETURN */
  55.      register int *width,        /* always set on successful RETURN */
  56.      register int *height)        /* always set on successful RETURN */
  57. #else
  58. int XGeometry (dpy, screen, pos, def, bwidth, fwidth, fheight, xadd, yadd, x, y, width, height)
  59.      Display *dpy;            /* user's display connection */
  60.      int screen;            /* screen on which to do computation */
  61.      char *pos;                /* user provided geometry spec */
  62.      char *def;                /* default geometry spec for window */
  63.      unsigned int bwidth;        /* border width */
  64.      unsigned int fwidth, fheight;    /* size of position units */
  65.      int xadd, yadd;            /* any additional interior space */
  66.      register int *x, *y, *width, *height;/* always set on successful RETURN */
  67. #endif
  68. {
  69.     DBUG_ENTER("XGeometry")
  70.     int px, py;            /* returned values from parse */
  71.     unsigned int pwidth, pheight;    /* returned values from parse */
  72.     int dx, dy;            /* default values from parse */
  73.     unsigned int dwidth, dheight;    /* default values from parse */
  74.     int pmask, dmask;        /* values back from parse */
  75.  
  76.     pmask = XParseGeometry(pos, &px, &py, &pwidth, &pheight);
  77.     dmask = XParseGeometry(def, &dx, &dy, &dwidth, &dheight);
  78.  
  79.     /* set default values */
  80.     *x = (dmask & XNegative) ? 
  81.         DisplayWidth(dpy, screen)  + dx - dwidth * fwidth - 
  82.             2 * bwidth - xadd : dx;
  83.     *y = (dmask & YNegative) ? 
  84.         DisplayHeight(dpy, screen) + dy - dheight * fheight - 
  85.             2 * bwidth - yadd : dy;
  86.     *width  = dwidth;
  87.     *height = dheight;
  88.  
  89.     if (pmask & WidthValue)  *width  = pwidth;
  90.     if (pmask & HeightValue) *height = pheight;
  91.  
  92.     if (pmask & XValue)
  93.         *x = (pmask & XNegative) ?
  94.           DisplayWidth(dpy, screen) + px - *width * fwidth - 
  95.           2 * bwidth - xadd : px;
  96.     if (pmask & YValue)
  97.         *y = (pmask & YNegative) ?
  98.           DisplayHeight(dpy, screen) + py - *height * fheight - 
  99.           2 * bwidth - yadd : py;
  100.     DBUG_RETURN(pmask);
  101. }
  102.