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

  1. /* $XConsortium: WMGeom.c,v 1.5 94/04/17 20:21:28 rws Exp $ */
  2. /*
  3.  
  4. Copyright (c) 1989  X Consortium
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  19. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  
  23. Except as contained in this notice, the name of the X Consortium shall not be
  24. used in advertising or otherwise to promote the sale, use or other dealings
  25. in this Software without prior written authorization from the X Consortium.
  26.  
  27. */
  28.  
  29. #include "Xlib_private.h"
  30. #include "X11/Xutil.h"
  31.  
  32. static int _GeometryMaskToGravity();
  33.  
  34.  
  35. /*
  36.  * This routine given a user supplied positional argument and a default
  37.  * argument (fully qualified) will return the position the window should take
  38.  * as well as the gravity to be set in the WM_NORMAL_HINTS size hints.
  39.  * Always sets all return values and returns a mask describing which fields
  40.  * were set by the user or'ed with whether or not the x and y values should
  41.  * be considered "negative".
  42.  */
  43.  
  44. #if NeedFunctionPrototypes
  45. int XWMGeometry (
  46.     Display *dpy,            /* user's display connection */
  47.     int screen,                /* screen on which to do computation */
  48.     _Xconst char *user_geom,        /* user provided geometry spec */
  49.     _Xconst char *def_geom,        /* default geometry spec for window */
  50.     unsigned int bwidth,        /* border width */
  51.     XSizeHints *hints,            /* usually WM_NORMAL_HINTS */
  52.     int *x_return,            /* location of window */
  53.     int *y_return,            /* location of window */
  54.     int *width_return,            /* size of window */
  55.     int *height_return,            /* size of window */
  56.     int *gravity_return)        /* gravity of window */
  57. #else
  58. int XWMGeometry (dpy, screen, user_geom, def_geom, bwidth, hints,
  59.          x_return, y_return, width_return, height_return, 
  60.          gravity_return)
  61.     Display *dpy;            /* user's display connection */
  62.     int screen;                /* screen on which to do computation */
  63.     char *user_geom;            /* user provided geometry spec */
  64.     char *def_geom;            /* default geometry spec for window */
  65.     unsigned int bwidth;        /* border width */
  66.     XSizeHints *hints;            /* usually WM_NORMAL_HINTS */
  67.     int *x_return, *y_return;        /* location of window */
  68.     int *width_return, *height_return;    /* size of window */
  69.     int *gravity_return;        /* gravity of window */
  70. #endif
  71. {
  72.     DBUG_ENTER("XWMGeometry")
  73.     int ux, uy;                /* returned values from parse */
  74.     unsigned int uwidth, uheight;    /* returned values from parse */
  75.     int umask;                /* parse mask of returned values */
  76.     int dx, dy;                /* default values from parse */
  77.     unsigned int dwidth, dheight;    /* default values from parse */
  78.     int dmask;                /* parse mask of returned values */
  79.     int base_width, base_height;    /* valid amounts */
  80.     int min_width, min_height;        /* valid amounts */
  81.     int width_inc, height_inc;        /* valid amounts */
  82.     int rx, ry, rwidth, rheight;    /* return values */
  83.     int rmask;                /* return mask */
  84.  
  85.     /*
  86.      * Get the base sizes and increments.  Section 4.1.2.3 of the ICCCM
  87.      * states that the base and minimum sizes are defaults for each other.
  88.      * If neither is given, then the base sizes should be 0.  These parameters
  89.      * control the sets of sizes that window managers should allow for the 
  90.      * window according to the following formulae:
  91.      *
  92.      *          width = base_width  + (i * width_inc)
  93.      *         height = base_height + (j * height_inc)
  94.      */
  95.     base_width =  ((hints->flags & PBaseSize) ? hints->base_width : 
  96.            ((hints->flags & PMinSize) ? hints->min_width : 0));
  97.     base_height = ((hints->flags & PBaseSize) ? hints->base_height :
  98.            ((hints->flags & PMinSize) ? hints->min_height : 0));
  99.     min_width = ((hints->flags & PMinSize) ? hints->min_width : base_width);
  100.     min_height = ((hints->flags & PMinSize) ? hints->min_height : base_height);
  101.     width_inc = (hints->flags & PResizeInc) ? hints->width_inc : 1;
  102.     height_inc = (hints->flags & PResizeInc) ? hints->height_inc : 1;
  103.  
  104.  
  105.     /*
  106.      * parse the two geometry masks
  107.      */
  108.     rmask = umask = XParseGeometry (user_geom, &ux, &uy, &uwidth, &uheight);
  109.     dmask = XParseGeometry (def_geom, &dx, &dy, &dwidth, &dheight);
  110.  
  111.  
  112.     /*
  113.      * get the width and height:
  114.      *     1.  if user-specified, then take that value
  115.      *     2.  else, if program-specified, then take that value
  116.      *     3.  else, take 1
  117.      *     4.  multiply by the size increment
  118.      *     5.  and add to the base size
  119.      */
  120.     rwidth = ((((umask & WidthValue) ? uwidth : 
  121.         ((dmask & WidthValue) ? dwidth : 1)) * width_inc) +
  122.           base_width);
  123.     rheight = ((((umask & HeightValue) ? uheight : 
  124.          ((dmask & HeightValue) ? dheight : 1)) * height_inc) + 
  125.            base_height);
  126.  
  127.     /*
  128.      * Make sure computed size is within limits.  Note that we always do the
  129.      * lower bounds check since the base size (which defaults to 0) should
  130.      * be used if a minimum size isn't specified.
  131.      */
  132.     if (rwidth < min_width) rwidth = min_width;
  133.     if (rheight < min_height) rheight = min_height;
  134.  
  135.     if (hints->flags & PMaxSize) {
  136.     if (rwidth > hints->max_width) rwidth = hints->max_width;
  137.     if (rheight > hints->max_height) rheight = hints->max_height;
  138.     }
  139.  
  140.  
  141.     /*
  142.      * Compute the location.  Set the negative flags in the return mask
  143.      * (and watch out for borders), if necessary.
  144.      */
  145.     if (umask & XValue) {
  146.     rx = ((umask & XNegative) ?
  147.           (DisplayWidth (dpy, screen) + ux - rwidth - 2 * bwidth) : ux);
  148.     } else if (dmask & XValue) {
  149.     if (dmask & XNegative) {
  150.         rx = (DisplayWidth (dpy, screen) + dx - rwidth - 2 * bwidth);
  151.         rmask |= XNegative;
  152.     } else 
  153.       rx = dx;
  154.     } else {
  155.     rx = 0;                /* gotta choose something... */
  156.     }
  157.  
  158.     if (umask & YValue) {
  159.     ry = ((umask & YNegative) ?
  160.           (DisplayHeight(dpy, screen) + uy - rheight - 2 * bwidth) : uy);
  161.     } else if (dmask & YValue) {
  162.     if (dmask & YNegative) {
  163.         ry = (DisplayHeight(dpy, screen) + dy - rheight - 2 * bwidth);
  164.         rmask |= YNegative;
  165.     } else 
  166.       ry = dy;
  167.     } else {
  168.     ry = 0;                /* gotta choose something... */
  169.     }
  170.  
  171.  
  172.     /*
  173.      * All finished, so set the return variables.
  174.      */
  175.     *x_return = rx;
  176.     *y_return = ry;
  177.     *width_return = rwidth;
  178.     *height_return = rheight;
  179.     *gravity_return = _GeometryMaskToGravity (rmask);
  180.     DBUG_RETURN(rmask);
  181. }
  182.  
  183.  
  184. static int _GeometryMaskToGravity (mask)
  185.     int mask;
  186. {
  187.     DBUG_ENTER("_GeometryMaskToGravity")
  188.     switch (mask & (XNegative|YNegative)) {
  189.       case 0:
  190.         DBUG_RETURN(NorthWestGravity);
  191.       case XNegative:
  192.         DBUG_RETURN(NorthEastGravity);
  193.       case YNegative:
  194.         DBUG_RETURN(SouthWestGravity);
  195.       default:
  196.         DBUG_RETURN(SouthEastGravity);
  197.     }
  198. }
  199.