home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / fontutils-0.6-base.tgz / fontutils-0.6-base.tar / fsf / fontutils / widgets / Form.c < prev    next >
C/C++ Source or Header  |  1992-08-19  |  21KB  |  647 lines

  1. /* Form.c: implementation of the Athena Form widget.  The geometry
  2.    manager has been modified from the distributed version.
  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 <X11/IntrinsicP.h>
  28. #include <X11/StringDefs.h>
  29. #include <X11/Xmu/Converters.h>
  30. #include <X11/Xmu/CharSet.h>
  31. #include <X11/Xaw/XawInit.h>
  32.  
  33. #include <X11/Xaw/FormP.h>
  34.  
  35. /* Private Definitions */
  36.  
  37. static int default_value = -99999;
  38.  
  39. #define Offset(field) XtOffset(FormWidget, form.field)
  40. static XtResource resources[] = {
  41.     {XtNdefaultDistance, XtCThickness, XtRInt, sizeof(int),
  42.     Offset(default_spacing), XtRImmediate, (caddr_t)4}
  43. };
  44. #undef Offset
  45.  
  46. static XtEdgeType defEdge = XtRubber;
  47.  
  48. #define Offset(field) XtOffset(FormConstraints, form.field)
  49. static XtResource formConstraintResources[] = {
  50.     {XtNtop, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  51.     Offset(top), XtREdgeType, (XtPointer)&defEdge},
  52.     {XtNbottom, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  53.     Offset(bottom), XtREdgeType, (XtPointer)&defEdge},
  54.     {XtNleft, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  55.     Offset(left), XtREdgeType, (XtPointer)&defEdge},
  56.     {XtNright, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  57.     Offset(right), XtREdgeType, (XtPointer)&defEdge},
  58.     {XtNhorizDistance, XtCThickness, XtRInt, sizeof(int),
  59.     Offset(dx), XtRInt, (XtPointer) &default_value},
  60.     {XtNfromHoriz, XtCWidget, XtRWidget, sizeof(Widget),
  61.     Offset(horiz_base), XtRWidget, (XtPointer)NULL},
  62.     {XtNvertDistance, XtCThickness, XtRInt, sizeof(int),
  63.     Offset(dy), XtRInt, (XtPointer) &default_value},
  64.     {XtNfromVert, XtCWidget, XtRWidget, sizeof(Widget),
  65.     Offset(vert_base), XtRWidget, (XtPointer)NULL},
  66.     {XtNresizable, XtCBoolean, XtRBoolean, sizeof(Boolean),
  67.     Offset(allow_resize), XtRImmediate, (XtPointer) FALSE},
  68. };
  69. #undef Offset
  70.  
  71. static void ClassInitialize(), ClassPartInitialize(), Initialize(), Resize();
  72. static void ConstraintInitialize();
  73. static Boolean SetValues(), ConstraintSetValues();
  74. static XtGeometryResult GeometryManager(), PreferredGeometry();
  75. static void ChangeManaged();
  76. static Boolean Layout();
  77.  
  78. FormClassRec formClassRec = {
  79.   { /* core_class fields */
  80.     /* superclass         */    (WidgetClass) &constraintClassRec,
  81.     /* class_name         */    "Form",
  82.     /* widget_size        */    sizeof(FormRec),
  83.     /* class_initialize   */    ClassInitialize,
  84.     /* class_part_init    */    ClassPartInitialize,
  85.     /* class_inited       */    FALSE,
  86.     /* initialize         */    Initialize,
  87.     /* initialize_hook    */    NULL,
  88.     /* realize            */    XtInheritRealize,
  89.     /* actions            */    NULL,
  90.     /* num_actions        */    0,
  91.     /* resources          */    resources,
  92.     /* num_resources      */    XtNumber(resources),
  93.     /* xrm_class          */    NULLQUARK,
  94.     /* compress_motion    */    TRUE,
  95.     /* compress_exposure  */    TRUE,
  96.     /* compress_enterleave*/    TRUE,
  97.     /* visible_interest   */    FALSE,
  98.     /* destroy            */    NULL,
  99.     /* resize             */    Resize,
  100.     /* expose             */    XtInheritExpose,
  101.     /* set_values         */    SetValues,
  102.     /* set_values_hook    */    NULL,
  103.     /* set_values_almost  */    XtInheritSetValuesAlmost,
  104.     /* get_values_hook    */    NULL,
  105.     /* accept_focus       */    NULL,
  106.     /* version            */    XtVersion,
  107.     /* callback_private   */    NULL,
  108.     /* tm_table           */    NULL,
  109.     /* query_geometry     */    PreferredGeometry,
  110.     /* display_accelerator*/    XtInheritDisplayAccelerator,
  111.     /* extension          */    NULL
  112.   },
  113.   { /* composite_class fields */
  114.     /* geometry_manager   */   GeometryManager,
  115.     /* change_managed     */   ChangeManaged,
  116.     /* insert_child       */   XtInheritInsertChild,
  117.     /* delete_child       */   XtInheritDeleteChild,
  118.     /* extension          */   NULL
  119.   },
  120.   { /* constraint_class fields */
  121.     /* subresourses       */   formConstraintResources,
  122.     /* subresource_count  */   XtNumber(formConstraintResources),
  123.     /* constraint_size    */   sizeof(FormConstraintsRec),
  124.     /* initialize         */   ConstraintInitialize,
  125.     /* destroy            */   NULL,
  126.     /* set_values         */   ConstraintSetValues,
  127.     /* extension          */   NULL
  128.   },
  129.   { /* form_class fields */
  130.     /* layout             */   Layout
  131.   }
  132. };
  133.  
  134. WidgetClass formWidgetClass = (WidgetClass)&formClassRec;
  135.  
  136. /****************************************************************
  137.  *
  138.  * Private Procedures
  139.  *
  140.  ****************************************************************/
  141.  
  142.  
  143. static XrmQuark    XtQChainLeft, XtQChainRight, XtQChainTop,
  144.         XtQChainBottom, XtQRubber;
  145.  
  146. #define    done(address, type) \
  147.     { toVal->size = sizeof(type); \
  148.       toVal->addr = (caddr_t) address; \
  149.       return; \
  150.     }
  151.  
  152. /* ARGSUSED */
  153. static void _CvtStringToEdgeType(args, num_args, fromVal, toVal)
  154.     XrmValuePtr args;        /* unused */
  155.     Cardinal    *num_args;      /* unused */
  156.     XrmValuePtr fromVal;
  157.     XrmValuePtr toVal;
  158. {
  159.     static XtEdgeType edgeType;
  160.     XrmQuark q;
  161.     char lowerName[1000];
  162.  
  163.     XmuCopyISOLatin1Lowered (lowerName, (char*)fromVal->addr);
  164.     q = XrmStringToQuark(lowerName);
  165.     if (q == XtQChainLeft) {
  166.     edgeType = XtChainLeft;
  167.     done(&edgeType, XtEdgeType);
  168.     }
  169.     if (q == XtQChainRight) {
  170.     edgeType = XtChainRight;
  171.     done(&edgeType, XtEdgeType);
  172.     }
  173.     if (q == XtQChainTop) {
  174.     edgeType = XtChainTop;
  175.     done(&edgeType, XtEdgeType);
  176.     }
  177.     if (q == XtQChainBottom) {
  178.     edgeType = XtChainBottom;
  179.     done(&edgeType, XtEdgeType);
  180.     }
  181.     if (q == XtQRubber) {
  182.     edgeType = XtRubber;
  183.     done(&edgeType, XtEdgeType);
  184.     }
  185.  
  186.     XtStringConversionWarning(fromVal->addr, "edgeType");
  187.     toVal->addr = NULL;
  188.     toVal->size = 0;
  189. }
  190.  
  191. static void ClassInitialize()
  192. {
  193.     static XtConvertArgRec parentCvtArgs[] = {
  194.     {XtBaseOffset, (caddr_t)XtOffset(Widget, core.parent), sizeof(Widget)}
  195.     };
  196.     XawInitializeWidgetSet();
  197.     XtQChainLeft   = XrmStringToQuark("chainleft");
  198.     XtQChainRight  = XrmStringToQuark("chainright");
  199.     XtQChainTop    = XrmStringToQuark("chaintop");
  200.     XtQChainBottom = XrmStringToQuark("chainbottom");
  201.     XtQRubber      = XrmStringToQuark("rubber");
  202.  
  203.     XtAddConverter( XtRString, XtREdgeType, _CvtStringToEdgeType, NULL, 0 );
  204.     XtAddConverter( XtRString, XtRWidget, XmuCvtStringToWidget,
  205.             parentCvtArgs, XtNumber(parentCvtArgs) );
  206. }
  207.  
  208. static void ClassPartInitialize(class)
  209.     WidgetClass class;
  210. {
  211.     register FormWidgetClass c = (FormWidgetClass)class;
  212.  
  213.     if (c->form_class.layout == XtInheritLayout)
  214.     c->form_class.layout = Layout;
  215. }
  216.  
  217.  
  218. /* ARGSUSED */
  219. static void Initialize(request, new)
  220.     Widget request, new;
  221. {
  222.     FormWidget fw = (FormWidget)new;
  223.  
  224.     fw->form.old_width = fw->core.width;
  225.     fw->form.old_height = fw->core.height;
  226.     fw->form.no_refigure = False;
  227.     fw->form.needs_relayout = False;
  228.     fw->form.resize_in_layout = True;
  229. }
  230.  
  231.  
  232. static void RefigureLocations(w)
  233.     FormWidget w;
  234. {
  235.     if (w->form.no_refigure) {
  236.     w->form.needs_relayout = True;
  237.     }
  238.     else {
  239.     (*((FormWidgetClass)w->core.widget_class)->form_class.layout)
  240.         ( w, w->core.width, w->core.height );
  241.     w->form.needs_relayout = False;
  242.     }
  243. }
  244.  
  245. /* ARGSUSED */
  246. static Boolean Layout(fw, width, height)
  247.     FormWidget fw;
  248.     Dimension width, height;
  249. {
  250.     int num_children = fw->composite.num_children;
  251.     WidgetList children = fw->composite.children;
  252.     Widget *childP;
  253.     Position maxx, maxy;
  254.     static void LayoutChild();
  255.     Boolean ret_val;
  256.  
  257.     for (childP = children; childP - children < num_children; childP++) {
  258.     FormConstraints form = (FormConstraints)(*childP)->core.constraints;
  259.     form->form.layout_state = LayoutPending;
  260.     }
  261.  
  262.     maxx = maxy = 1;
  263.  
  264. #define CHILD_BORDER_WIDTH(childP) ((*childP)->core.border_width << 1)
  265. #define CHILD_RIGHT_EDGE(childP) ((*childP)->core.x \
  266.     + (*childP)->core.width + CHILD_BORDER_WIDTH (childP))
  267. #define CHILD_BOTTOM_EDGE(childp) ((*childP)->core.y \
  268.     + (*childP)->core.height + CHILD_BORDER_WIDTH (childP))
  269.  
  270.     for (childP = children; childP - children < num_children; childP++) {
  271.     if (XtIsManaged(*childP)) {
  272.         Position x, y;
  273.         LayoutChild(*childP);
  274.         x = CHILD_RIGHT_EDGE (childP);
  275.         y = CHILD_BOTTOM_EDGE (childP);
  276.         if (maxx < x) maxx = x;
  277.         if (maxy < y) maxy = y;
  278.     }
  279.     }
  280.  
  281.     fw->form.preferred_width = (maxx += fw->form.default_spacing);
  282.     fw->form.preferred_height = (maxy += fw->form.default_spacing);
  283.  
  284.     if (fw->form.resize_in_layout
  285.     && ((Dimension) maxx != fw->core.width
  286.             || (Dimension) maxy != fw->core.height)) {
  287.     XtGeometryResult result;
  288.     result = XtMakeResizeRequest( (Widget) fw,
  289.                                       (Dimension)maxx, (Dimension)maxy,
  290.                       (Dimension*)&maxx, (Dimension*)&maxy );
  291.     if (result == XtGeometryAlmost)
  292.         result = XtMakeResizeRequest( (Widget) fw,
  293.                                           (Dimension)maxx, (Dimension)maxy,
  294.                       NULL, NULL );
  295.         else if (result == XtGeometryNo) {
  296.             /* Resize the children, since at least one of them doesn't
  297.                fit within our current borders.  */
  298.             for (childP = children; childP - children < num_children;
  299.                  childP++) {
  300.                 if (XtIsManaged(*childP)) {
  301.                     Dimension w
  302.                       = CHILD_RIGHT_EDGE (childP) > fw->core.width
  303.                         ? fw->core.width - (*childP)->core.x
  304.                           - CHILD_BORDER_WIDTH (childP)
  305.                         : (*childP)->core.width;
  306.                     Dimension h
  307.                       = CHILD_BOTTOM_EDGE (childP) > fw->core.height
  308.                         ? fw->core.height - (*childP)->core.y
  309.                           - CHILD_BORDER_WIDTH (childP)
  310.                         : (*childP)->core.height;
  311.                     XtResizeWidget(*childP, w, h, (*childP)->core.border_width);
  312.                 }
  313.             }
  314.         }
  315.         
  316.     fw->form.old_width  = fw->core.width;
  317.     fw->form.old_height = fw->core.height;
  318.     ret_val = (result == XtGeometryYes);
  319.     } else ret_val = False;
  320.  
  321.     return ret_val;
  322. }
  323.  
  324.  
  325. static void LayoutChild(w)
  326.     Widget w;
  327. {
  328.     FormConstraints form = (FormConstraints)w->core.constraints;
  329.     Position x, y;
  330.     Widget ref;
  331.  
  332.     switch (form->form.layout_state) {
  333.  
  334.       case LayoutPending:
  335.     form->form.layout_state = LayoutInProgress;
  336.     break;
  337.  
  338.       case LayoutDone:
  339.     return;
  340.  
  341.       case LayoutInProgress:
  342.     {
  343.     String subs[2];
  344.     Cardinal num_subs = 2;
  345.     subs[0] = w->core.name;
  346.     subs[1] = w->core.parent->core.name;
  347.     XtAppWarningMsg(XtWidgetToApplicationContext(w),
  348.             "constraintLoop","xawFormLayout","XawToolkitError",
  349.    "constraint loop detected while laying out child '%s' in FormWidget '%s'",
  350.             subs, &num_subs);
  351.     return;
  352.     }
  353.     }
  354.     x = form->form.dx;
  355.     y = form->form.dy;
  356.     if ((ref = form->form.horiz_base) != (Widget)NULL) {
  357.     LayoutChild(ref);
  358.     x += ref->core.x + ref->core.width + (ref->core.border_width << 1);
  359.     }
  360.     if ((ref = form->form.vert_base) != (Widget)NULL) {
  361.     LayoutChild(ref);
  362.     y += ref->core.y + ref->core.height + (ref->core.border_width << 1);
  363.     }
  364.     XtMoveWidget( w, x, y );
  365.     form->form.layout_state = LayoutDone;
  366. }
  367.  
  368.  
  369. static Position TransformCoord(loc, old, new, type)
  370.     register Position loc;
  371.     Dimension old, new;
  372.     XtEdgeType type;
  373. {
  374.     if (type == XtRubber) {
  375.         if ( ((int) old) > 0)
  376.         loc = (loc * new) / old;
  377.     }
  378.     else if (type == XtChainBottom || type == XtChainRight)
  379.       loc += (Position)new - (Position)old;
  380.  
  381.     /* I don't see any problem with returning values less than zero. */
  382.  
  383.     return (loc);
  384. }
  385.  
  386.  
  387. static void Resize(w)
  388.     Widget w;
  389. {
  390.     FormWidget fw = (FormWidget)w;
  391.     WidgetList children = fw->composite.children;
  392.     int num_children = fw->composite.num_children;
  393.     Widget *childP;
  394.     Position x, y;
  395.     Dimension width, height;
  396.  
  397.     for (childP = children; childP - children < num_children; childP++) {
  398.     FormConstraints form = (FormConstraints)(*childP)->core.constraints;
  399.     if (!XtIsManaged(*childP)) continue;
  400.     x = TransformCoord( (*childP)->core.x, fw->form.old_width,
  401.                 fw->core.width, form->form.left );
  402.     y = TransformCoord( (*childP)->core.y, fw->form.old_height,
  403.                 fw->core.height, form->form.top );
  404.  
  405.     form->form.virtual_width =
  406.       TransformCoord((Position)((*childP)->core.x
  407.                     + form->form.virtual_width
  408.                     + 2 * (*childP)->core.border_width),
  409.              fw->form.old_width, fw->core.width,
  410.              form->form.right )
  411.         - (x + 2 * (*childP)->core.border_width);
  412.  
  413.     form->form.virtual_height =
  414.       TransformCoord((Position)((*childP)->core.y
  415.                     + form->form.virtual_height
  416.                     + 2 * (*childP)->core.border_width),
  417.              fw->form.old_height, fw->core.height,
  418.              form->form.bottom ) 
  419.         - ( y + 2 * (*childP)->core.border_width);
  420.     
  421.     width = (Dimension) 
  422.            (form->form.virtual_width < 1) ? 1 : form->form.virtual_width;
  423.     height = (Dimension)
  424.            (form->form.virtual_height < 1) ? 1 : form->form.virtual_height;
  425.  
  426.     XtConfigureWidget( *childP, x, y, (Dimension)width, (Dimension)height,
  427.               (*childP)->core.border_width );
  428.     }
  429.  
  430.     fw->form.old_width = fw->core.width;
  431.     fw->form.old_height = fw->core.height;
  432. }
  433.  
  434.  
  435. /* ARGSUSED */
  436. static XtGeometryResult GeometryManager(w, request, reply)
  437.     Widget w;
  438.     XtWidgetGeometry *request;
  439.     XtWidgetGeometry *reply;    /* RETURN */
  440. {
  441.     XtWidgetGeometry allowed, parent_request;
  442.     Boolean parent_no = False, parent_almost = False;
  443.     Boolean querying = request->request_mode & XtCWQueryOnly;
  444.     Boolean requesting_width = request->request_mode & CWWidth;
  445.     Boolean requesting_height = request->request_mode & CWHeight;
  446.     FormWidget fw = (FormWidget) w->core.parent;
  447.     FormConstraints fc = (FormConstraints)w->core.constraints;
  448.  
  449.     /* Only allow width and height changes (unless just querying).  */
  450.     if ((request->request_mode & ~(XtCWQueryOnly | CWWidth | CWHeight))
  451.         || !fc->form.allow_resize)
  452.     return XtGeometryNo;
  453.  
  454.     /* If the size of the child is the same as it was before, we don't
  455.        need to do anything.  */
  456.     if ((!requesting_width || request->width == w->core.width)
  457.         && (!requesting_height || request->height == w->core.height))
  458.     return XtGeometryYes;
  459.  
  460. #define REQUESTED_RIGHT_EDGE (w->core.x + request->width \
  461.     + (w->core.border_width << 1))
  462. #define REQUESTED_BOTTOM_EDGE (w->core.y + request->height \
  463.     + (w->core.border_width << 1))
  464.  
  465.     /* Check if the child wants to go outside our current borders.  */
  466.     parent_request.request_mode = 0;
  467.  
  468.     if (requesting_width) {
  469.        if (REQUESTED_RIGHT_EDGE > fw->core.width) {
  470.            parent_request.request_mode |= CWWidth;
  471.            parent_request.width = request->width;
  472.        } else
  473.            /* Else the new size fits already, or is smaller.  */
  474.            allowed.width = request->width;
  475.     } else
  476.        allowed.width = w->core.width; /* Don't change it.  */
  477.  
  478.     if (requesting_height) {
  479.         if (REQUESTED_BOTTOM_EDGE > fw->core.height) {
  480.             parent_request.request_mode |= CWHeight;
  481.             parent_request.height = request->height;
  482.         } else
  483.             allowed.height = request->height;
  484.     } else
  485.         allowed.height = w->core.height;
  486.  
  487.     /* If necessary, ask our parent if we can grow.  */
  488.     if (parent_request.request_mode != 0) {
  489.         XtGeometryResult result;
  490.         XtWidgetGeometry parent_return;
  491.         
  492.         if (querying)
  493.           parent_request.request_mode |= XtCWQueryOnly;
  494.         result = XtMakeGeometryRequest ((Widget) fw, &parent_request,
  495.                                         &parent_return);
  496.         if (result == XtGeometryNo)
  497.             parent_no = True;
  498.         else if (result == XtGeometryAlmost) {
  499.             XtMakeGeometryRequest ((Widget) fw, &parent_return, NULL);
  500.             parent_almost = True;
  501.         }
  502.         if (parent_request.request_mode & CWWidth)
  503.             allowed.width = fw->core.width - w->core.x
  504.                             - (w->core.border_width << 1);
  505.         if (parent_request.request_mode & CWHeight)
  506.             allowed.height = fw->core.height - w->core.y
  507.                             - (w->core.border_width << 1);
  508.     }
  509.  
  510.     /* If we needed to grow, and the parent didn't let us, we couldn't
  511.        satisfy the request.  Say that we'll let the widget go right up to
  512.        our edge, and return XtGeometryAlmost.  */
  513.     if (parent_no || parent_almost) {
  514.         if (reply != NULL) {
  515.             reply->request_mode = CWWidth | CWHeight;
  516.             reply->width = allowed.width;
  517.             reply->height = allowed.height;
  518.         }
  519.         return XtGeometryAlmost;
  520.     } else if (!querying) {
  521.         /* We were able to satisfy everything, so reset the virtual width
  522.            and height.  */
  523.           fc->form.virtual_width = w->core.width = allowed.width;
  524.     fc->form.virtual_height = w->core.height = allowed.height;
  525.     RefigureLocations(fw);
  526.     }
  527.     
  528.     /* This return only applies to the last else clause, but putting it
  529.        here keeps the warnings away.  */
  530.     return XtGeometryYes;
  531. }
  532.  
  533.  
  534.  
  535. /* ARGSUSED */
  536. static Boolean SetValues(current, request, new)
  537.     Widget current, request, new;
  538. {
  539.     return( FALSE );
  540. }
  541.  
  542.  
  543. /* ARGSUSED */
  544. static void ConstraintInitialize(request, new)
  545.     Widget request, new;
  546. {
  547.     FormConstraints form = (FormConstraints)new->core.constraints;
  548.     FormWidget fw = (FormWidget)new->core.parent;
  549.  
  550.     form->form.virtual_width = (int) new->core.width;
  551.     form->form.virtual_height = (int) new->core.height;
  552.  
  553.     if (form->form.dx == default_value)
  554.         form->form.dx = fw->form.default_spacing;
  555.  
  556.     if (form->form.dy == default_value)
  557.         form->form.dy = fw->form.default_spacing;
  558. }
  559.  
  560. /* ARGSUSED */
  561. static Boolean ConstraintSetValues(current, request, new)
  562.     Widget current, request, new;
  563. {
  564.     return( FALSE );
  565. }
  566.  
  567. static void ChangeManaged(w)
  568.     Widget w;
  569. {
  570.   FormWidget fw = (FormWidget)w;
  571.   FormConstraints form;
  572.   WidgetList children, childP;
  573.   int num_children = fw->composite.num_children;
  574.   Widget child;
  575.   
  576.   /*
  577.    * Reset virtual width and height for all children.
  578.    */
  579.   
  580.   for (children = childP = fw->composite.children ;
  581.        childP - children < num_children; childP++) {
  582.     child = *childP;
  583.     if (XtIsManaged(child)) {
  584.       form = (FormConstraints)child->core.constraints;
  585.  
  586. /*
  587.  * If the size is one (1) then we must not change the virtual sizes, as
  588.  * they contain useful information.  If someone actually wants a widget of
  589.  * width or height one (1) in a form widget he will lose, can't win them all.
  590.  *
  591.  * Chris D. Peterson 2/9/89.
  592.  */
  593.      
  594.  
  595.       if ( child->core.width != 1)
  596.     form->form.virtual_width = (int) child->core.width;
  597.       if ( child->core.height != 1)
  598.     form->form.virtual_height = (int) child->core.height;
  599.     }
  600.   }
  601.   RefigureLocations( (FormWidget)w );
  602. }
  603.  
  604.  
  605. static XtGeometryResult PreferredGeometry( widget, request, reply  )
  606.     Widget widget;
  607.     XtWidgetGeometry *request, *reply;
  608. {
  609.     FormWidget w = (FormWidget)widget;
  610.     
  611.     reply->width = w->form.preferred_width;
  612.     reply->height = w->form.preferred_height;
  613.     reply->request_mode = CWWidth | CWHeight;
  614.     if (  request->request_mode & (CWWidth | CWHeight) ==
  615.         reply->request_mode & (CWWidth | CWHeight)
  616.       && request->width == reply->width
  617.       && request->height == reply->height)
  618.     return XtGeometryYes;
  619.     else if (reply->width == w->core.width && reply->height == w->core.height)
  620.     return XtGeometryNo;
  621.     else
  622.     return XtGeometryAlmost;
  623. }
  624.  
  625.  
  626. /**********************************************************************
  627.  *
  628.  * Public routines
  629.  *
  630.  **********************************************************************/
  631.  
  632. /* 
  633.  * Set or reset figuring (ignored if not realized)
  634.  */
  635.  
  636. void XawFormDoLayout(w, doit)
  637. Widget w;
  638. Boolean doit;
  639. {
  640.     register FormWidget fw = (FormWidget)w;
  641.  
  642.     fw->form.no_refigure = !doit;
  643.  
  644.     if ( XtIsRealized(w) && fw->form.needs_relayout )
  645.         RefigureLocations( fw );
  646. }
  647.