home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / l / libxtgeo.zip / libgeo17 / geoGeometry.c next >
C/C++ Source or Header  |  1992-10-06  |  21KB  |  689 lines

  1. /* $XConsortium: Geometry.c,v 1.55 92/02/11 17:13:18 converse Exp */
  2.  
  3. /***********************************************************
  4. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  5. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its 
  10. documentation for any purpose and without fee is hereby granted, 
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in 
  13. supporting documentation, and that the names of Digital or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.  
  16.  
  17. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. #include "IntrinsicI.h"
  28. #include "ShellP.h"
  29.  
  30. #include "geoTattler.h"
  31.  
  32. int ResizeStuff = 0 ;
  33.  
  34. static void ClearRectObjAreas(r, old)
  35.     RectObj r;
  36.     XWindowChanges* old;
  37. {
  38.     Widget pw = _XtWindowedAncestor((Widget)r);
  39.     int bw2;
  40.  
  41.     bw2 = old->border_width << 1;
  42.     XClearArea( XtDisplay(pw), XtWindow(pw),
  43.         old->x, old->y,
  44.         old->width + bw2, old->height + bw2,
  45.         TRUE );
  46.  
  47.     bw2 = r->rectangle.border_width << 1;
  48.     XClearArea( XtDisplay(pw), XtWindow(pw),
  49.         (int)r->rectangle.x, (int)r->rectangle.y,
  50.         (unsigned int)(r->rectangle.width + bw2),
  51.             (unsigned int)(r->rectangle.height + bw2),
  52.         TRUE );
  53. }
  54.  
  55. /*
  56.  * Internal function used by XtMakeGeometryRequest and XtSetValues.
  57.  * Returns more data than the public interface.  Does not convert
  58.  * XtGeometryDone to XtGeometryYes.
  59.  *
  60.  * clear_rect_obj - *** RETURNED ***  
  61.  *            TRUE if the rect obj has been cleared, false otherwise.
  62.  */
  63.  
  64. XtGeometryResult 
  65. _XtMakeGeometryRequest (widget, request, reply, clear_rect_obj)
  66.     Widget widget;
  67.     XtWidgetGeometry *request, *reply;
  68.     Boolean * clear_rect_obj;
  69. {
  70.     XtWidgetGeometry    junk;
  71.     XtGeometryHandler manager;
  72.     XtGeometryResult returnCode;
  73.     Widget parent = widget->core.parent;
  74.     XtGeometryMask    changeMask;
  75.     Boolean managed, parentRealized, rgm = False;
  76.     XWindowChanges changes;
  77.  
  78.     *clear_rect_obj = FALSE;
  79.  
  80.     _GeoPrintTrace(widget,
  81.     "\"%s\" is making a %sgeometry request to its parent \"%s\".\n",
  82.            XtName(widget),
  83.            ((GMode (request) & XtCWQueryOnly))? "query only ":"",
  84.            (XtParent(widget))?XtName(XtParent(widget)):"Root");
  85.     _GeoTabTrace();
  86.  
  87.     if (XtIsShell(widget)) {
  88.     ShellClassExtension ext;
  89.     for (ext = (ShellClassExtension)((ShellWidgetClass)XtClass(widget))
  90.            ->shell_class.extension;
  91.          ext != NULL && ext->record_type != NULLQUARK;
  92.          ext = (ShellClassExtension)ext->next_extension);
  93.  
  94.     if (ext != NULL) {
  95.         if (  ext->version == XtShellExtensionVersion
  96.           && ext->record_size == sizeof(ShellClassExtensionRec)) {
  97.  
  98.         manager = ext->root_geometry_manager;
  99.         rgm = True;
  100.         } else {
  101.         String params[1];
  102.         Cardinal num_params = 1;
  103.         params[0] = XtClass(widget)->core_class.class_name;
  104.         XtAppErrorMsg(XtWidgetToApplicationContext(widget),
  105.              "invalidExtension", "xtMakeGeometryRequest",
  106.              XtCXtToolkitError,
  107.              "widget class %s has invalid ShellClassExtension record",
  108.              params, &num_params);
  109.         }
  110.     } else {
  111.         XtAppErrorMsg(XtWidgetToApplicationContext(widget),
  112.               "internalError", "xtMakeGeometryRequest",
  113.               XtCXtToolkitError,
  114.               "internal error; ShellClassExtension is NULL",
  115.               NULL, NULL);
  116.     }
  117.     managed = True;
  118.     parentRealized = TRUE;
  119.     } else if (parent == NULL) {
  120.     XtAppErrorMsg(XtWidgetToApplicationContext(widget),
  121.               "invalidParent","xtMakeGeometryRequest",XtCXtToolkitError,
  122.               "non-shell has no parent in XtMakeGeometryRequest",
  123.               (String *)NULL, (Cardinal *)NULL);
  124.     } else /* not shell */ {
  125.     managed = XtIsManaged(widget);
  126.  
  127.     if (XtIsComposite(parent)) {
  128.         parentRealized = XtIsRealized(parent);
  129.         manager = ((CompositeWidgetClass) (parent->core.widget_class))
  130.             ->composite_class.geometry_manager;
  131.     } else if (managed) {
  132.         /* Should never happen - XtManageChildren should have checked */
  133.         XtAppErrorMsg(XtWidgetToApplicationContext(widget),
  134.               "invalidParent", "xtMakeGeometryRequest",
  135.               XtCXtToolkitError,
  136.               "XtMakeGeometryRequest - parent not composite",
  137.               (String *)NULL, (Cardinal *)NULL);
  138.     } else {
  139.         /* no need to waste time checking if parent is actually realized
  140.          * at this point; since the child is unmanaged we need to perform
  141.          * the configure iff the child is realized, so we dummy the
  142.          * parentRealized checks below.
  143.          */
  144.         parentRealized = TRUE;
  145.     }
  146.     }
  147.  
  148.     if (managed && manager == (XtGeometryHandler) NULL) {
  149.     XtErrorMsg("invalidGeometryManager","xtMakeGeometryRequest",
  150.                  XtCXtToolkitError,
  151.                  "XtMakeGeometryRequest - parent has no geometry manager",
  152.                   (String *)NULL, (Cardinal *)NULL);
  153.     }
  154.  
  155.     if (widget->core.being_destroyed) {
  156.     _GeoUnTabTrace();
  157.     _GeoPrintTrace(widget,
  158.                "It is being destroyed, just return XtGeometryNo.\n");
  159.     return XtGeometryNo;
  160.     }
  161.  
  162.     /* see if requesting anything to change */
  163.     changeMask = 0;
  164.     if (request->request_mode & CWStackMode
  165.     && request->stack_mode != XtSMDontChange) {
  166.         changeMask |= CWStackMode;
  167.         _GeoPrintTrace(widget,"Asking for a change in StackMode!\n");
  168.         if (request->request_mode & CWSibling) {
  169.         XtCheckSubclass(request->sibling, rectObjClass,
  170.                 "XtMakeGeometryRequest");
  171.         changeMask |= CWSibling;
  172.         }
  173.     }
  174.     if (request->request_mode & CWX
  175.     && widget->core.x != request->x) {
  176.     _GeoPrintTrace(widget,"Asking for a change in x: from %d to %d.\n",
  177.                widget->core.x, request->x);
  178.     changeMask |= CWX;
  179.     }
  180.     if (request->request_mode & CWY
  181.     && widget->core.y != request->y) {
  182.     _GeoPrintTrace(widget,"Asking for a change in y: from %d to %d.\n",
  183.                widget->core.y, request->y);
  184.     changeMask |= CWY;
  185.     }
  186.     if (request->request_mode & CWWidth
  187.     && widget->core.width != request->width) {
  188.     _GeoPrintTrace(widget,"Asking for a change in width: from %d to %d.\n",
  189.                widget->core.width, request->width);
  190.     changeMask |= CWWidth;
  191.     }
  192.     if (request->request_mode & CWHeight
  193.     && widget->core.height != request->height) {
  194.     _GeoPrintTrace(widget,"Asking for a change in height: from %d to %d.\n",
  195.                widget->core.height, request->height);
  196.     changeMask |= CWHeight;
  197.     }
  198.     if (request->request_mode & CWBorderWidth
  199.     && widget->core.border_width != request->border_width){
  200.     _GeoPrintTrace(widget,
  201.                "Asking for a change in border_width: from %d to %d.\n",
  202.                widget->core.border_width, request->border_width);
  203.     changeMask |= CWBorderWidth;
  204.     }
  205.     if (! changeMask) {
  206.     _GeoPrintTrace(widget,
  207.                "Asking for nothing new,\n");
  208.     _GeoUnTabTrace();
  209.     _GeoPrintTrace(widget,
  210.                "just return XtGeometryYes.\n");
  211.     return XtGeometryYes;
  212.     }
  213.  
  214.     changeMask |= (request->request_mode & XtCWQueryOnly);
  215.  
  216.     if ( !(changeMask & XtCWQueryOnly) && XtIsRealized(widget) ) {
  217.     /* keep record of the current geometry so we know what's changed */
  218.     changes.x = widget->core.x ;
  219.     changes.y = widget->core.y ;
  220.     changes.width = widget->core.width ;
  221.     changes.height = widget->core.height ;
  222.     changes.border_width = widget->core.border_width ;
  223.     }
  224.  
  225.     if (!managed || !parentRealized) {
  226.     if (!managed) {
  227.         _GeoPrintTrace(widget,"\"%s\" is not managed yet.\n",XtName(widget));
  228.     }
  229.     if (!parentRealized) {
  230.         _GeoPrintTrace(widget,"Parent \"%s\" is not realized yet.\n",
  231.                (XtParent(widget))?XtName(XtParent(widget)):"Root");
  232.     }
  233.     /* Don't get parent's manager involved--assume the answer is yes */
  234.     if (changeMask & XtCWQueryOnly) {
  235.         /* He was just asking, don't change anything, just tell him yes */
  236.         _GeoPrintTrace(widget,"QueryOnly request\n");
  237.         _GeoUnTabTrace();
  238.         _GeoPrintTrace(widget,"just return XtGeometryYes.\n");
  239.         return XtGeometryYes;
  240.     } else {
  241.         _GeoPrintTrace(widget,"Copy values from request to widget.\n");
  242.         /* copy values from request to widget */
  243.         if (request->request_mode & CWX)
  244.         widget->core.x = request->x;
  245.         if (request->request_mode & CWY)
  246.         widget->core.y = request->y;
  247.         if (request->request_mode & CWWidth)
  248.         widget->core.width = request->width;
  249.         if (request->request_mode & CWHeight)
  250.         widget->core.height = request->height;
  251.         if (request->request_mode & CWBorderWidth)
  252.         widget->core.border_width = request->border_width;
  253.         if (!parentRealized) {
  254.         _GeoUnTabTrace();
  255.         _GeoPrintTrace(widget,"and return XtGeometryYes.\n");
  256.         return XtGeometryYes;
  257.         }
  258.         else returnCode = XtGeometryYes;
  259.     }
  260.     } else {
  261.     /* go ask the widget's geometry manager */
  262.     _GeoPrintTrace(widget,"Go ask the parent geometry manager.\n");
  263.     if (reply == (XtWidgetGeometry *) NULL) {
  264.         returnCode = (*manager)(widget, request, &junk);
  265.     } else {
  266.         returnCode = (*manager)(widget, request, reply);
  267.     }
  268.     }
  269.  
  270.     /*
  271.      * If Unrealized, not a XtGeometryYes, or a query-only then we are done.
  272.      */
  273.  
  274.     if ((returnCode != XtGeometryYes) || 
  275.     (changeMask & XtCWQueryOnly) || !XtIsRealized(widget)) {
  276.  
  277.     switch(returnCode){
  278.     case XtGeometryNo:
  279.         _GeoUnTabTrace();
  280.         _GeoPrintTrace(widget,"\"%s\" returns XtGeometryNo.\n",
  281.                  (XtParent(widget))?XtName(XtParent(widget)):"Root");
  282.             /* check for no change */
  283.             break ;
  284.     case XtGeometryDone:
  285.         _GeoUnTabTrace();
  286.         _GeoPrintTrace(widget,"\"%s\" returns XtGeometryDone.\n",
  287.                  (XtParent(widget))?XtName(XtParent(widget)):"Root");
  288.             /* check for no change in queryonly */
  289.             break ;
  290.     case XtGeometryAlmost:
  291.         _GeoUnTabTrace();
  292.         _GeoPrintTrace(widget,"\"%s\" returns XtGeometryAlmost.\n",
  293.                  (XtParent(widget))?XtName(XtParent(widget)):"Root");
  294.         _GeoTabTrace();
  295.         _GeoPrintTrace(widget,"Proposal: width %d height %d.\n",
  296.                (reply)?reply->width:junk.width,
  297.                (reply)?reply->height:junk.height);
  298.         _GeoUnTabTrace();
  299.         
  300.             /* check for no change */
  301.             break ;
  302.     case XtGeometryYes:
  303.         if (changeMask & XtCWQueryOnly) {
  304.         _GeoPrintTrace(widget,"QueryOnly specified, no configuration.\n");
  305.         }
  306.             if (!XtIsRealized(widget)) {
  307.         _GeoPrintTrace(widget,"\"%s\" not realized, no configuration.\n",
  308.                  XtName(widget));
  309.         }
  310.         _GeoUnTabTrace();
  311.             _GeoPrintTrace(widget,"\"%s\" returns XtGeometryYes.\n",
  312.                  (XtParent(widget))?XtName(XtParent(widget)):"Root");
  313.         break ;
  314.     }
  315.  
  316.     return returnCode;
  317.     }
  318.  
  319.     _GeoUnTabTrace();
  320.     _GeoPrintTrace(widget,"\"%s\" returns XtGeometryYes.\n",
  321.            (XtParent(widget))?XtName(XtParent(widget)):"Root");
  322.  
  323.     
  324.     if (XtIsWidget(widget)) {    /* reconfigure the window (if needed) */
  325.  
  326.     if (rgm) return returnCode;    
  327.  
  328.     if (changes.x != widget->core.x) {
  329.          changeMask |= CWX;
  330.          changes.x = widget->core.x;
  331.      }
  332.      if (changes.y != widget->core.y) {
  333.          changeMask |= CWY;
  334.          changes.y = widget->core.y;
  335.      }
  336.      if (changes.width != widget->core.width) {
  337.          changeMask |= CWWidth;
  338.          changes.width = widget->core.width;
  339.      }
  340.      if (changes.height != widget->core.height) {
  341.          changeMask |= CWHeight;
  342.          changes.height = widget->core.height;
  343.      }
  344.      if (changes.border_width != widget->core.border_width) {
  345.          changeMask |= CWBorderWidth;
  346.          changes.border_width = widget->core.border_width;
  347.      }
  348.     if (changeMask & CWStackMode) {
  349.         changes.stack_mode = request->stack_mode;
  350.         if (changeMask & CWSibling)
  351.         changes.sibling = XtWindow(request->sibling);
  352.     }
  353.  
  354.         if (changeMask) {
  355.         _GeoPrintTrace(widget,"XConfigure \"%s\"'s window.\n",XtName(widget));
  356.     } else {
  357.         _GeoPrintTrace(widget,"No window configuration needed for \"%s\".\n",
  358.                  XtName(widget));
  359.     }
  360.  
  361.     XConfigureWindow(XtDisplay(widget), XtWindow(widget),
  362.              changeMask, &changes);
  363.     }
  364.     else {            /* RectObj child of realized Widget */
  365.     *clear_rect_obj = TRUE;
  366.  
  367.     _GeoPrintTrace(widget,"ClearRectObj on \"%s\".\n",XtName(widget));
  368.  
  369.     ClearRectObjAreas((RectObj)widget, &changes);
  370.     }
  371.  
  372.     return returnCode;
  373. } /* _XtMakeGeometryRequest */
  374.  
  375.  
  376. /* Public routines */
  377.  
  378. XtGeometryResult XtMakeGeometryRequest (widget, request, reply)
  379.     Widget         widget;
  380.     XtWidgetGeometry *request, *reply;
  381. {
  382.     Boolean junk;
  383.     XtGeometryResult returnCode;
  384.  
  385.     returnCode = _XtMakeGeometryRequest(widget, request, reply, &junk);
  386.  
  387.     return ((returnCode == XtGeometryDone) ? XtGeometryYes : returnCode);
  388. }
  389.  
  390. #if NeedFunctionPrototypes
  391. XtGeometryResult XtMakeResizeRequest(
  392.     Widget    widget,
  393.     _XtDimension width,
  394.     _XtDimension height,
  395.     Dimension    *replyWidth,
  396.     Dimension    *replyHeight
  397.     )
  398. #else
  399. XtGeometryResult XtMakeResizeRequest
  400.     (widget, width, height, replyWidth, replyHeight)
  401.     Widget    widget;
  402.     Dimension    width, height;
  403.     Dimension    *replyWidth, *replyHeight;
  404. #endif
  405. {
  406.     XtWidgetGeometry request, reply;
  407.     XtGeometryResult r;
  408.  
  409.     request.request_mode = CWWidth | CWHeight;
  410.     request.width = width;
  411.     request.height = height;
  412.     r = XtMakeGeometryRequest(widget, &request, &reply);
  413.     if (replyWidth != NULL)
  414.     if (r == XtGeometryAlmost && reply.request_mode & CWWidth)
  415.         *replyWidth = reply.width;
  416.     else
  417.         *replyWidth = width;
  418.     if (replyHeight != NULL)
  419.     if (r == XtGeometryAlmost && reply.request_mode & CWHeight)
  420.         *replyHeight = reply.height;
  421.     else
  422.         *replyHeight = height;
  423.     return r;
  424. } /* XtMakeResizeRequest */
  425.  
  426. void XtResizeWindow(w)
  427.     Widget w;
  428. {
  429.     if (XtIsRealized(w)) {
  430.     XWindowChanges changes;
  431.     changes.width = w->core.width;
  432.     changes.height = w->core.height;
  433.     changes.border_width = w->core.border_width;
  434.     XConfigureWindow(XtDisplay(w), XtWindow(w),
  435.         (unsigned) CWWidth | CWHeight | CWBorderWidth, &changes);
  436.     }
  437. } /* XtResizeWindow */
  438.  
  439.  
  440. #if NeedFunctionPrototypes
  441. void XtConfigureWidget(
  442.     Widget w,
  443.     _XtPosition x,
  444.     _XtPosition y,
  445.     _XtDimension width,
  446.     _XtDimension height,
  447.     _XtDimension borderWidth
  448.     )
  449. #else
  450. void XtConfigureWidget(w, x, y, width, height, borderWidth)
  451.     Widget w;
  452.     Position x, y;
  453.     Dimension width, height, borderWidth;
  454. #endif
  455. {
  456.     XWindowChanges changes, old;
  457.     Cardinal mask = 0;
  458.  
  459.     _GeoPrintTrace(w,"\"%s\" is being configured by its parent \"%s\"\n",
  460.         XtName(w), XtName(XtParent(w)));
  461.     _GeoTabTrace();
  462.     
  463.     if ((old.x = w->core.x) != x) {
  464.     _GeoPrintTrace(w,"x move from %d to %d\n",w->core.x, x);
  465.     changes.x = w->core.x = x;
  466.     mask |= CWX;
  467.     }
  468.  
  469.     if ((old.y = w->core.y) != y) {
  470.     _GeoPrintTrace(w,"y move from %d to %d\n",w->core.y, y);
  471.     changes.y = w->core.y = y;
  472.     mask |= CWY;
  473.     }
  474.  
  475.     if ((old.width = w->core.width) != width) {
  476.     _GeoPrintTrace(w,"width move from %d to %d\n",w->core.width, width);
  477.     changes.width = w->core.width = width;
  478.     mask |= CWWidth;
  479.     }
  480.  
  481.     if ((old.height = w->core.height) != height) {
  482.     _GeoPrintTrace(w,"height move from %d to %d\n",w->core.height, height);
  483.     changes.height = w->core.height = height;
  484.     mask |= CWHeight;
  485.     }
  486.  
  487.     if ((old.border_width = w->core.border_width) != borderWidth) {
  488.     _GeoPrintTrace(w,"border_width move from %d to %d\n",
  489.             w->core.border_width,borderWidth );
  490.     changes.border_width = w->core.border_width = borderWidth;
  491.     mask |= CWBorderWidth;
  492.     }
  493.  
  494.     if (mask != 0) {
  495.     if (XtIsRealized(w)) {
  496.         if (XtIsWidget(w)) {
  497.         _GeoPrintTrace(w,"XConfigure \"%s\"'s window\n",XtName(w));
  498.         XConfigureWindow(XtDisplay(w), XtWindow(w), mask, &changes);
  499.         }
  500.         else {
  501.         _GeoPrintTrace(w,"ClearRectObj called on \"%s\"\n",XtName(w));
  502.         ClearRectObjAreas((RectObj)w, &old);
  503.         }
  504.     } else {
  505.         _GeoPrintTrace(w,"\"%s\" not Realized\n",XtName(w));
  506.     }
  507.  
  508.     if ((mask & (CWWidth | CWHeight)) &&
  509.           XtClass(w)->core_class.resize != (XtWidgetProc) NULL) {
  510.  
  511.         _GeoPrintTrace(w,"Resize proc is called.\n");
  512.  
  513.         if (ResizeStuff == (int)w) ResizeStuff = 0;
  514.  
  515.         (*(w->core.widget_class->core_class.resize))(w);
  516.     } else {
  517.         _GeoPrintTrace(w,"Resize proc is not called.\n");
  518.     }
  519.         
  520.     } else {
  521.     _GeoPrintTrace(w,"No change in configuration\n");
  522.     }
  523.  
  524.     _GeoUnTabTrace();
  525.  
  526. } /* XtConfigureWidget */
  527.  
  528.  
  529. #if NeedFunctionPrototypes
  530. void XtResizeWidget(
  531.     Widget w,
  532.     _XtDimension width,
  533.     _XtDimension height,
  534.     _XtDimension borderWidth
  535.     )
  536. #else
  537. void XtResizeWidget(w, width, height, borderWidth)
  538.     Widget w;
  539.     Dimension width, height, borderWidth;
  540. #endif
  541. {
  542.     XtConfigureWidget(w, w->core.x, w->core.y, width, height, borderWidth);
  543.     
  544. } /* XtResizeWidget */
  545.  
  546.  
  547. #if NeedFunctionPrototypes
  548. void XtMoveWidget(
  549.     Widget w,
  550.     _XtPosition x,
  551.     _XtPosition y
  552.     )
  553. #else
  554. void XtMoveWidget(w, x, y)
  555.     Widget w;
  556.     Position x, y;
  557. #endif
  558. {
  559.     XtConfigureWidget(w, x, y, w->core.width, w->core.height,
  560.               w->core.border_width);
  561.     
  562. } /* XtMoveWidget */
  563.  
  564. #if NeedFunctionPrototypes
  565. void XtTranslateCoords(
  566.     register Widget w,
  567.     _XtPosition x,
  568.     _XtPosition y,
  569.     register Position *rootx,    /* return */
  570.     register Position *rooty    /* return */
  571.     )
  572. #else
  573. void XtTranslateCoords(w, x, y, rootx, rooty)
  574.     register Widget w;
  575.     Position x, y;
  576.     register Position *rootx, *rooty;    /* return */
  577. #endif
  578. {
  579.     Position garbagex, garbagey;
  580.     Widget passed = w;
  581.  
  582.     if (rootx == NULL) rootx = &garbagex;
  583.     if (rooty == NULL) rooty = &garbagey;
  584.  
  585.     *rootx = x;
  586.     *rooty = y;
  587.  
  588.     for (; w != NULL && ! XtIsShell(w); w = w->core.parent) {
  589.     *rootx += w->core.x + w->core.border_width;
  590.     *rooty += w->core.y + w->core.border_width;
  591.     }
  592.  
  593.     if (w == NULL)
  594.         XtAppWarningMsg(XtWidgetToApplicationContext(passed),
  595.         "invalidShell","xtTranslateCoords",XtCXtToolkitError,
  596.                 "Widget has no shell ancestor",
  597.         (String *)NULL, (Cardinal *)NULL);
  598.     else {
  599.     Position x, y;
  600.     extern void _XtShellGetCoordinates();
  601.     _XtShellGetCoordinates( w, &x, &y );
  602.     *rootx += x + w->core.border_width;
  603.     *rooty += y + w->core.border_width;
  604.     }
  605. }
  606.  
  607. XtGeometryResult XtQueryGeometry(widget, intended, reply)
  608.     Widget widget;
  609.     register XtWidgetGeometry *intended; /* parent's changes; may be NULL */
  610.     XtWidgetGeometry *reply;    /* child's preferred geometry; never NULL */
  611. {
  612.     XtWidgetGeometry null_intended;
  613.     XtGeometryHandler query = XtClass(widget)->core_class.query_geometry;
  614.     XtGeometryResult result;
  615.  
  616.     _GeoPrintTrace(widget,"\"%s\" is asking its preferred geometry to \"%s\".\n",
  617.              (XtParent(widget))?XtName(XtParent(widget)):"Root",
  618.              XtName(widget));
  619.     _GeoTabTrace();
  620.  
  621.     reply->request_mode = 0;
  622.     if (query != NULL) {
  623.     if (intended == NULL) {
  624.         null_intended.request_mode = 0;
  625.         intended = &null_intended;
  626.  
  627.         _GeoPrintTrace(widget,"without any constraint.\n");
  628.         
  629.     } else {
  630.         _GeoPrintTrace(widget,"with the following constraints:\n");
  631.  
  632.         if (intended->request_mode & CWX) {
  633.         _GeoPrintTrace(widget," x = %d\n",intended->x);
  634.         }
  635.         if (intended->request_mode & CWY) {
  636.         _GeoPrintTrace(widget," y = %d\n",intended->y);
  637.         }
  638.         if (intended->request_mode & CWWidth) {
  639.         _GeoPrintTrace(widget," width = %d\n",intended->width);
  640.         }
  641.         if (intended->request_mode & CWHeight) {
  642.         _GeoPrintTrace(widget," height = %d\n",intended->height);
  643.         }
  644.         if (intended->request_mode & CWBorderWidth) {
  645.         _GeoPrintTrace(widget," border_width = %d\n",intended->border_width);
  646.         }
  647.  
  648.     }
  649.  
  650.     result = (*query) (widget, intended, reply);
  651.     }
  652.     else {
  653.     _GeoPrintTrace(widget,"\"%s\" has no QueryGeometry proc, return the current state\n",XtName(widget));
  654.  
  655.     result = XtGeometryYes;
  656.     }
  657.  
  658. #define FillIn(mask, field) \
  659.     if (!(reply->request_mode & mask)) {\
  660.           reply->field = widget->core.field;\
  661.           _GeoPrintTrace(widget," using core %s = %d.\n","field",\
  662.                                            widget->core.field);\
  663.     } else {\
  664.           _GeoPrintTrace(widget," replied %s = %d\n","field",\
  665.                                        reply->field);\
  666.     } 
  667.  
  668.     FillIn(CWX, x);
  669.     FillIn(CWY, y);
  670.     FillIn(CWWidth, width);
  671.     FillIn(CWHeight, height);
  672.     FillIn(CWBorderWidth, border_width);
  673.  
  674.     _GeoUnTabTrace();
  675.  
  676. #undef FillIn
  677.  
  678.     if (!reply->request_mode & CWStackMode) reply->stack_mode = XtSMDontChange;
  679.  
  680.     _GeoPrintTrace(widget,"\"%s\" returns %s to \"%s\".\n",
  681.              XtName(widget),
  682.              (result == XtGeometryYes)?"XtGeometryYes":
  683.              ((result == XtGeometryNo)?"XtGeometryNo":
  684.               "XtGeometryAlmost"),
  685.              (XtParent(widget))?XtName(XtParent(widget)):"Root");
  686.              
  687.     return result;
  688.   }
  689.