home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xaw / Form.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-22  |  24.5 KB  |  829 lines

  1. /* $XConsortium: Form.c,v 1.48 91/07/22 18:08:25 ackerman 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 <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. #include <X11/Xaw/FormP.h>
  33.  
  34. /* Private Definitions */
  35.  
  36. static int default_value = -99999;
  37.  
  38. #define Offset(field) XtOffsetOf(FormRec, form.field)
  39. static XtResource resources[] = {
  40.     {XtNdefaultDistance, XtCThickness, XtRInt, sizeof(int),
  41.     Offset(default_spacing), XtRImmediate, (XtPointer)4}
  42. };
  43. #undef Offset
  44.  
  45. static XtEdgeType defEdge = XtRubber;
  46.  
  47. #define Offset(field) XtOffsetOf(FormConstraintsRec, form.field)
  48. static XtResource formConstraintResources[] = {
  49.     {XtNtop, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  50.     Offset(top), XtREdgeType, (XtPointer)&defEdge},
  51.     {XtNbottom, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  52.     Offset(bottom), XtREdgeType, (XtPointer)&defEdge},
  53.     {XtNleft, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  54.     Offset(left), XtREdgeType, (XtPointer)&defEdge},
  55.     {XtNright, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  56.     Offset(right), XtREdgeType, (XtPointer)&defEdge},
  57.     {XtNhorizDistance, XtCThickness, XtRInt, sizeof(int),
  58.     Offset(dx), XtRInt, (XtPointer) &default_value},
  59.     {XtNfromHoriz, XtCWidget, XtRWidget, sizeof(Widget),
  60.     Offset(horiz_base), XtRWidget, (XtPointer)NULL},
  61.     {XtNvertDistance, XtCThickness, XtRInt, sizeof(int),
  62.     Offset(dy), XtRInt, (XtPointer) &default_value},
  63.     {XtNfromVert, XtCWidget, XtRWidget, sizeof(Widget),
  64.     Offset(vert_base), XtRWidget, (XtPointer)NULL},
  65.     {XtNresizable, XtCBoolean, XtRBoolean, sizeof(Boolean),
  66.     Offset(allow_resize), XtRImmediate, (XtPointer) FALSE},
  67. };
  68. #undef Offset
  69.  
  70. static void ClassInitialize(), ClassPartInitialize(), Initialize(), Resize();
  71. static void ConstraintInitialize();
  72. static Boolean SetValues(), ConstraintSetValues();
  73. static XtGeometryResult GeometryManager(), PreferredGeometry();
  74. static void ChangeManaged();
  75. static Boolean Layout();
  76.  
  77. static void LayoutChild(), ResizeChildren();
  78.  
  79. FormClassRec formClassRec = {
  80.   { /* core_class fields */
  81.     /* superclass         */    (WidgetClass) &constraintClassRec,
  82.     /* class_name         */    "Form",
  83.     /* widget_size        */    sizeof(FormRec),
  84.     /* class_initialize   */    ClassInitialize,
  85.     /* class_part_init    */    ClassPartInitialize,
  86.     /* class_inited       */    FALSE,
  87.     /* initialize         */    Initialize,
  88.     /* initialize_hook    */    NULL,
  89.     /* realize            */    XtInheritRealize,
  90.     /* actions            */    NULL,
  91.     /* num_actions        */    0,
  92.     /* resources          */    resources,
  93.     /* num_resources      */    XtNumber(resources),
  94.     /* xrm_class          */    NULLQUARK,
  95.     /* compress_motion    */    TRUE,
  96.     /* compress_exposure  */    TRUE,
  97.     /* compress_enterleave*/    TRUE,
  98.     /* visible_interest   */    FALSE,
  99.     /* destroy            */    NULL,
  100.     /* resize             */    Resize,
  101.     /* expose             */    XtInheritExpose,
  102.     /* set_values         */    SetValues,
  103.     /* set_values_hook    */    NULL,
  104.     /* set_values_almost  */    XtInheritSetValuesAlmost,
  105.     /* get_values_hook    */    NULL,
  106.     /* accept_focus       */    NULL,
  107.     /* version            */    XtVersion,
  108.     /* callback_private   */    NULL,
  109.     /* tm_table           */    NULL,
  110.     /* query_geometry     */    PreferredGeometry,
  111.     /* display_accelerator*/    XtInheritDisplayAccelerator,
  112.     /* extension          */    NULL
  113.   },
  114.   { /* composite_class fields */
  115.     /* geometry_manager   */   GeometryManager,
  116.     /* change_managed     */   ChangeManaged,
  117.     /* insert_child       */   XtInheritInsertChild,
  118.     /* delete_child       */   XtInheritDeleteChild,
  119.     /* extension          */   NULL
  120.   },
  121.   { /* constraint_class fields */
  122.     /* subresourses       */   formConstraintResources,
  123.     /* subresource_count  */   XtNumber(formConstraintResources),
  124.     /* constraint_size    */   sizeof(FormConstraintsRec),
  125.     /* initialize         */   ConstraintInitialize,
  126.     /* destroy            */   NULL,
  127.     /* set_values         */   ConstraintSetValues,
  128.     /* extension          */   NULL
  129.   },
  130.   { /* form_class fields */
  131.     /* layout             */   Layout
  132.   }
  133. };
  134.  
  135. WidgetClass formWidgetClass = (WidgetClass)&formClassRec;
  136.  
  137. /****************************************************************
  138.  *
  139.  * Private Procedures
  140.  *
  141.  ****************************************************************/
  142.  
  143.  
  144. static XrmQuark    XtQChainLeft, XtQChainRight, XtQChainTop,
  145.         XtQChainBottom, XtQRubber;
  146.  
  147. #define    done(address, type) \
  148.     { toVal->size = sizeof(type); \
  149.       toVal->addr = (caddr_t) address; \
  150.       return; \
  151.     }
  152.  
  153. /* ARGSUSED */
  154. static void _CvtStringToEdgeType(args, num_args, fromVal, toVal)
  155.     XrmValuePtr args;        /* unused */
  156.     Cardinal    *num_args;      /* unused */
  157.     XrmValuePtr fromVal;
  158.     XrmValuePtr toVal;
  159. {
  160.     static XtEdgeType edgeType;
  161.     XrmQuark q;
  162.     char lowerName[1000];
  163.  
  164.     XmuCopyISOLatin1Lowered (lowerName, (char*)fromVal->addr);
  165.     q = XrmStringToQuark(lowerName);
  166.     if (q == XtQChainLeft) {
  167.     edgeType = XtChainLeft;
  168.     done(&edgeType, XtEdgeType);
  169.     }
  170.     if (q == XtQChainRight) {
  171.     edgeType = XtChainRight;
  172.     done(&edgeType, XtEdgeType);
  173.     }
  174.     if (q == XtQChainTop) {
  175.     edgeType = XtChainTop;
  176.     done(&edgeType, XtEdgeType);
  177.     }
  178.     if (q == XtQChainBottom) {
  179.     edgeType = XtChainBottom;
  180.     done(&edgeType, XtEdgeType);
  181.     }
  182.     if (q == XtQRubber) {
  183.     edgeType = XtRubber;
  184.     done(&edgeType, XtEdgeType);
  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, (XtPointer)XtOffsetOf(WidgetRec, core.parent),
  195.          sizeof(Widget)}
  196.     };
  197.     XawInitializeWidgetSet();
  198.     XtQChainLeft   = XrmPermStringToQuark("chainleft");
  199.     XtQChainRight  = XrmPermStringToQuark("chainright");
  200.     XtQChainTop    = XrmPermStringToQuark("chaintop");
  201.     XtQChainBottom = XrmPermStringToQuark("chainbottom");
  202.     XtQRubber      = XrmPermStringToQuark("rubber");
  203.  
  204.     XtAddConverter( XtRString, XtREdgeType, _CvtStringToEdgeType, NULL, 0 );
  205.     XtSetTypeConverter (XtRString, XtRWidget, XmuNewCvtStringToWidget,
  206.             parentCvtArgs, XtNumber(parentCvtArgs), XtCacheNone,
  207.             NULL);
  208. }
  209.  
  210. static void ClassPartInitialize(class)
  211.     WidgetClass class;
  212. {
  213.     register FormWidgetClass c = (FormWidgetClass)class;
  214.     register FormWidgetClass super = (FormWidgetClass) 
  215.     c->core_class.superclass;
  216.  
  217.     if (c->form_class.layout == XtInheritLayout)
  218.     c->form_class.layout = super->form_class.layout;
  219. }
  220.  
  221. /* ARGSUSED */
  222. static void Initialize(request, new)
  223.     Widget request, new;
  224. {
  225.     FormWidget fw = (FormWidget)new;
  226.  
  227.     fw->form.old_width = fw->core.width;
  228.     fw->form.old_height = fw->core.height;
  229.     fw->form.no_refigure = False;
  230.     fw->form.needs_relayout = False;
  231.     fw->form.resize_in_layout = True;
  232.     fw->form.resize_is_no_op = False;
  233. }
  234.  
  235. /*    Function Name: ChangeFormGeometry
  236.  *    Description: Ask the parent to change the form widget's geometry.
  237.  *    Arguments: w - the Form widget.
  238.  *                 query_only - TRUE if this is only a query.
  239.  *                 width, height - the new width and height.
  240.  *                 ret_width, ret_height - the actual size the form is allowed
  241.  *                                         to resize to.
  242.  *    Returns: TRUE of children may always be resized.
  243.  */
  244.  
  245. static Boolean
  246. ChangeFormGeometry(w, query_only, width, height, ret_width, ret_height)
  247. Widget w;
  248. Boolean query_only;
  249. Dimension width, height;
  250. Dimension *ret_width, *ret_height;
  251. {
  252.     FormWidget fw = (FormWidget) w;
  253.     Boolean always_resize_children;
  254.     XtGeometryResult result;
  255.     XtWidgetGeometry request, return_request;
  256.  
  257.     /*
  258.      * If we are already at the desired size then there is no need
  259.      * to ask our parent of we can change size.
  260.      */
  261.  
  262.     if ( (width == fw->core.width) && (height == fw->core.height) )
  263.     return(TRUE);
  264.  
  265.     request.width = width;
  266.     request.height = height;
  267.     request.request_mode = CWWidth | CWHeight;
  268.     if (query_only)
  269.     request.request_mode |= XtCWQueryOnly;
  270.  
  271.     /*
  272.      * Do no invoke the resize rules if our size changes here.
  273.      */
  274.  
  275.     fw->form.resize_is_no_op = TRUE;
  276.  
  277.     result = XtMakeGeometryRequest(w, &request, &return_request);
  278.     if (result == XtGeometryAlmost) {
  279.     request = return_request;
  280.     (void) XtMakeGeometryRequest(w, &request, &return_request);
  281.     always_resize_children = FALSE;
  282.     }
  283.     else
  284.     always_resize_children = (result == XtGeometryYes);
  285.  
  286.     fw->form.resize_is_no_op = FALSE;
  287.  
  288.     if (ret_width != NULL)
  289.     *ret_width = request.width;
  290.     if (ret_height != NULL)
  291.     *ret_height = request.height;
  292.  
  293.     return(always_resize_children);
  294. }
  295.  
  296. /*    Function Name: Layout
  297.  *    Description: Moves all the children around.
  298.  *    Arguments: fw - the Form widget.
  299.  *                 width, height - ** UNUSED **.
  300.  *                 force_relayout - will force the children to be
  301.  *                                 moved, even if some go past the edge
  302.  *                                 of the form.
  303.  *    Returns: True if the children are allowed to move from their
  304.  *               current locations to the new ones.
  305.  */
  306.  
  307. /* ARGSUSED */
  308. static Boolean Layout(fw, width, height, force_relayout)
  309.     FormWidget fw;
  310.     Dimension width, height;
  311.     Boolean force_relayout;
  312. {
  313.     int num_children = fw->composite.num_children;
  314.     WidgetList children = fw->composite.children;
  315.     Widget *childP;
  316.     Dimension maxx, maxy;
  317.     Boolean ret_val;
  318.  
  319.     for (childP = children; childP - children < num_children; childP++) {
  320.     FormConstraints form = (FormConstraints)(*childP)->core.constraints;
  321.     form->form.layout_state = LayoutPending;
  322.     }
  323.  
  324.     maxx = maxy = 1;
  325.     for (childP = children; childP - children < num_children; childP++) {
  326.     if (XtIsManaged(*childP)) {
  327.         register FormConstraints form;
  328.         register Position x, y;
  329.  
  330.         form = (FormConstraints)(*childP)->core.constraints;
  331.  
  332.         LayoutChild(*childP);
  333.  
  334.         x = form->form.new_x + (*childP)->core.width + 
  335.         ((*childP)->core.border_width << 1);
  336.         if (x > (int)maxx)
  337.         maxx = x;
  338.  
  339.         y = form->form.new_y + (*childP)->core.height +
  340.         ((*childP)->core.border_width << 1);
  341.         if (y > (int)maxy)
  342.         maxy = y;
  343.     }
  344.     }
  345.  
  346.     fw->form.preferred_width = (maxx += fw->form.default_spacing);
  347.     fw->form.preferred_height = (maxy += fw->form.default_spacing);
  348.  
  349.     if (fw->form.resize_in_layout) {
  350.     Boolean always_resize_children;
  351.  
  352.     always_resize_children = ChangeFormGeometry( (Widget) fw, FALSE,
  353.                             maxx, maxy, NULL, NULL);
  354.  
  355.     fw->form.old_width  = fw->core.width;
  356.     fw->form.old_height = fw->core.height;
  357.  
  358.     ret_val = (always_resize_children || ( (fw->core.width >= maxx) &&
  359.                           (fw->core.height >= maxy)));
  360.  
  361.     if (force_relayout)
  362.         ret_val = TRUE;
  363.  
  364.     if (ret_val)
  365.         ResizeChildren((Widget) fw);
  366.     }
  367.     else
  368.     ret_val = False;
  369.  
  370.     fw->form.needs_relayout = False;
  371.     return ret_val;
  372. }
  373.  
  374. /*    Function Name: ResizeChildren
  375.  *    Description: Resizes all children to new_x and new_y.
  376.  *    Arguments: w - the form widget.
  377.  *    Returns: none.
  378.  */
  379.  
  380. static void ResizeChildren(w) 
  381. Widget w;
  382. {
  383.     FormWidget fw = (FormWidget) w;
  384.     int num_children = fw->composite.num_children;
  385.     WidgetList children = fw->composite.children;
  386.     Widget *childP;
  387.  
  388.     for (childP = children; childP - children < num_children; childP++) {
  389.     FormConstraints form;
  390.  
  391.     if (!XtIsManaged(*childP)) 
  392.         continue;
  393.  
  394.     form = (FormConstraints)(*childP)->core.constraints;
  395.     if (fw->form.no_refigure) {
  396. /* 
  397.  * I am changing the widget wrapper w/o modifing the window.  This is
  398.  * risky, but I can get away with it since I am the parent of this
  399.  * widget, and he must ask me for any geometry changes.
  400.  *
  401.  * The window will be updated when no_refigure is set back to False.
  402.  */    
  403.         (*childP)->core.x = form->form.new_x;
  404.         (*childP)->core.y = form->form.new_y;
  405.     }
  406.     else
  407.         XtMoveWidget(*childP, form->form.new_x, form->form.new_y);
  408.     }
  409. }
  410.  
  411.  
  412. static void LayoutChild(w)
  413.     Widget w;
  414. {
  415.     FormConstraints form = (FormConstraints)w->core.constraints;
  416.     Widget ref;
  417.  
  418.     switch (form->form.layout_state) {
  419.  
  420.       case LayoutPending:
  421.     form->form.layout_state = LayoutInProgress;
  422.     break;
  423.  
  424.       case LayoutDone:
  425.     return;
  426.  
  427.       case LayoutInProgress:
  428.     {
  429.     String subs[2];
  430.     Cardinal num_subs = 2;
  431.     subs[0] = w->core.name;
  432.     subs[1] = w->core.parent->core.name;
  433.     XtAppWarningMsg(XtWidgetToApplicationContext(w),
  434.             "constraintLoop","xawFormLayout","XawToolkitError",
  435.    "constraint loop detected while laying out child '%s' in FormWidget '%s'",
  436.             subs, &num_subs);
  437.     return;
  438.     }
  439.     }
  440.  
  441.     form->form.new_x = form->form.dx;
  442.     form->form.new_y = form->form.dy;
  443.     if ((ref = form->form.horiz_base) != (Widget)NULL) {
  444.     FormConstraints ref_form = (FormConstraints) ref->core.constraints;
  445.  
  446.     LayoutChild(ref);
  447.     form->form.new_x += (ref_form->form.new_x + 
  448.                  ref->core.width + (ref->core.border_width << 1));
  449.     }
  450.     if ((ref = form->form.vert_base) != (Widget)NULL) {
  451.     FormConstraints ref_form = (FormConstraints) ref->core.constraints;
  452.  
  453.     LayoutChild(ref);
  454.     form->form.new_y += (ref_form->form.new_y + 
  455.                  ref->core.height + (ref->core.border_width << 1));
  456.     }
  457.  
  458.     form->form.layout_state = LayoutDone;
  459. }
  460.  
  461.  
  462. static Position TransformCoord(loc, old, new, type)
  463.     register Position loc;
  464.     Dimension old, new;
  465.     XtEdgeType type;
  466. {
  467.     if (type == XtRubber) {
  468.         if ( ((int) old) > 0)
  469.         loc = (int)(loc * new) / (int)old;
  470.     }
  471.     else if (type == XtChainBottom || type == XtChainRight)
  472.       loc += (Position)new - (Position)old;
  473.  
  474.     /* I don't see any problem with returning values less than zero. */
  475.  
  476.     return (loc);
  477. }
  478.  
  479. static void Resize(w)
  480.     Widget w;
  481. {
  482.     FormWidget fw = (FormWidget)w;
  483.     WidgetList children = fw->composite.children;
  484.     int num_children = fw->composite.num_children;
  485.     Widget *childP;
  486.     Position x, y;
  487.     Dimension width, height;
  488.  
  489.     if (!fw->form.resize_is_no_op)
  490.     for (childP = children; childP - children < num_children; childP++) {
  491.         FormConstraints form= (FormConstraints)(*childP)->core.constraints;
  492.         if (!XtIsManaged(*childP)) continue;
  493.         x = TransformCoord( (*childP)->core.x, fw->form.old_width,
  494.                    fw->core.width, form->form.left );
  495.         y = TransformCoord( (*childP)->core.y, fw->form.old_height,
  496.                    fw->core.height, form->form.top );
  497.         
  498.         form->form.virtual_width =
  499.         TransformCoord((Position)((*childP)->core.x
  500.                       + form->form.virtual_width
  501.                       + 2 * (*childP)->core.border_width),
  502.                    fw->form.old_width, fw->core.width,
  503.                    form->form.right )
  504.             - (x + 2 * (*childP)->core.border_width);
  505.         
  506.         form->form.virtual_height =
  507.         TransformCoord((Position)((*childP)->core.y
  508.                       + form->form.virtual_height
  509.                       + 2 * (*childP)->core.border_width),
  510.                    fw->form.old_height, fw->core.height,
  511.                    form->form.bottom ) 
  512.             - ( y + 2 * (*childP)->core.border_width);
  513.         
  514.         width = (Dimension) 
  515.         (form->form.virtual_width < 1) ? 1 : form->form.virtual_width;
  516.         height = (Dimension)
  517.            (form->form.virtual_height < 1) ? 1 : form->form.virtual_height;
  518.         
  519.         XtConfigureWidget(*childP,x,y, (Dimension)width, (Dimension)height,
  520.                   (*childP)->core.border_width );
  521.     }
  522.  
  523.     fw->form.old_width = fw->core.width;
  524.     fw->form.old_height = fw->core.height;
  525. }
  526.  
  527. /*
  528.  * I don't want to even think about what ``Almost'' would mean - Chris.
  529.  */
  530.  
  531. /* ARGSUSED */
  532. static XtGeometryResult GeometryManager(w, request, reply)
  533.     Widget w;
  534.     XtWidgetGeometry *request;
  535.     XtWidgetGeometry *reply;    /* RETURN */
  536. {
  537.     Dimension old_width, old_height;
  538.     FormWidget fw = (FormWidget) XtParent(w);
  539.     FormConstraints form = (FormConstraints) w->core.constraints;
  540.     XtWidgetGeometry allowed;
  541.     XtGeometryResult ret_val;
  542.  
  543.     if ((request->request_mode & ~(XtCWQueryOnly | CWWidth | CWHeight)) ||
  544.     !form->form.allow_resize) {
  545.  
  546.     /* If GeometryManager is invoked during a SetValues call on a child
  547.          * then it is necessary to compute a new layout if ConstraintSetValues
  548.          * allowed any constraint changes. */
  549.  
  550.     if (fw->form.needs_relayout) 
  551.         (*((FormWidgetClass)fw->core.widget_class)->form_class.layout)
  552.         (fw, 0, 0, True);
  553.     return(XtGeometryNo);
  554.     }
  555.  
  556.     if (request->request_mode & CWWidth)
  557.     allowed.width = request->width;
  558.     else
  559.     allowed.width = w->core.width;
  560.  
  561.     if (request->request_mode & CWHeight)
  562.     allowed.height = request->height;
  563.     else
  564.     allowed.height = w->core.height;
  565.  
  566.     if (allowed.width == w->core.width && allowed.height == w->core.height) {
  567.  
  568.     /* If GeometryManager is invoked during a SetValues call on a child
  569.          * then it is necessary to compute a new layout if ConstraintSetValues
  570.          * allowed any constraint changes. */
  571.  
  572.     if (fw->form.needs_relayout) 
  573.         (*((FormWidgetClass)fw->core.widget_class)->form_class.layout)
  574.         (fw, 0, 0, True);
  575.     return(XtGeometryNo);
  576.     }
  577.  
  578.     /*
  579.      * Remember the old size, and then set the size to the requested size.
  580.      */
  581.  
  582.     old_width = w->core.width;
  583.     old_height = w->core.height;
  584.     w->core.width = allowed.width;
  585.     w->core.height = allowed.height;
  586.  
  587.     if (request->request_mode & XtCWQueryOnly) {
  588.     Boolean always_resize_children;
  589.     Dimension ret_width, ret_height;
  590.  
  591.     fw->form.resize_in_layout = FALSE;
  592.  
  593.     (*((FormWidgetClass)fw->core.widget_class)->form_class.layout)
  594.                                        ( fw, w->core.width, w->core.height,
  595.                        FALSE );
  596.  
  597.     /*
  598.      * Reset the size of this child back to what it used to be.
  599.      */
  600.  
  601.     w->core.width = old_width;
  602.     w->core.height = old_height;
  603.  
  604.     fw->form.resize_in_layout = TRUE;
  605.  
  606.     always_resize_children = ChangeFormGeometry(w, TRUE, 
  607.                    fw->form.preferred_width,
  608.                    fw->form.preferred_height,
  609.                    &ret_width, &ret_height);
  610.  
  611.     if (always_resize_children || 
  612.         ((ret_width >= fw->form.preferred_width) &&
  613.          (ret_height >= fw->form.preferred_height)))
  614.     {
  615.         ret_val = XtGeometryYes;
  616.     }
  617.     else
  618.         ret_val = XtGeometryNo;
  619.     }
  620.     else {
  621.     if ((*((FormWidgetClass)fw->core.widget_class)->form_class.layout)
  622.                                       ( fw, w->core.width, w->core.height,
  623.                         FALSE))
  624.     {
  625.         form->form.virtual_width = w->core.width;   /* reset virtual */
  626.         form->form.virtual_height = w->core.height; /* width and height. */
  627.         if (fw->form.no_refigure) {
  628. /* 
  629.  * I am changing the widget wrapper w/o modifing the window.  This is
  630.  * risky, but I can get away with it since I am the parent of this
  631.  * widget, and he must ask me for any geometry changes.
  632.  *
  633.  * The window will be updated when no_refigure is set back to False.
  634.  */    
  635.         form->form.deferred_resize = True;
  636.         ret_val = XtGeometryDone;
  637.         }
  638.         else 
  639.         ret_val = XtGeometryYes;
  640.     }
  641.     else {
  642.         w->core.width = old_width;
  643.         w->core.height = old_height;
  644.         ret_val = XtGeometryNo;
  645.     }
  646.     }
  647.  
  648.     return(ret_val);
  649. }
  650.  
  651.  
  652. /* ARGSUSED */
  653. static Boolean SetValues(current, request, new)
  654.     Widget current, request, new;
  655. {
  656.     return( FALSE );
  657. }
  658.  
  659.  
  660. /* ARGSUSED */
  661. static void ConstraintInitialize(request, new)
  662.     Widget request, new;
  663. {
  664.     FormConstraints form = (FormConstraints)new->core.constraints;
  665.     FormWidget fw = (FormWidget)new->core.parent;
  666.  
  667.     form->form.virtual_width = (int) new->core.width;
  668.     form->form.virtual_height = (int) new->core.height;
  669.  
  670.     if (form->form.dx == default_value)
  671.         form->form.dx = fw->form.default_spacing;
  672.  
  673.     if (form->form.dy == default_value)
  674.         form->form.dy = fw->form.default_spacing;
  675.  
  676.     form->form.deferred_resize = False;
  677. }
  678.  
  679. /*ARGSUSED*/
  680. static Boolean ConstraintSetValues(current, request, new, args, num_args)
  681.     Widget current, request, new;
  682.     ArgList args;
  683.     Cardinal *num_args;
  684. {
  685.   register FormConstraints cfc = (FormConstraints) current->core.constraints;
  686.   register FormConstraints nfc = (FormConstraints) new->core.constraints;
  687.   
  688.   if (cfc->form.top          != nfc->form.top         ||
  689.       cfc->form.bottom       != nfc->form.bottom      ||
  690.       cfc->form.left         != nfc->form.left        ||
  691.       cfc->form.right        != nfc->form.right       ||
  692.       cfc->form.dx           != nfc->form.dx          ||
  693.       cfc->form.dy           != nfc->form.dy          ||
  694.       cfc->form.horiz_base   != nfc->form.horiz_base  ||
  695.       cfc->form.vert_base    != nfc->form.vert_base) {
  696.  
  697.       FormWidget fp = (FormWidget) XtParent(new);
  698.  
  699.     /* If there are no subclass ConstraintSetValues procedures remaining
  700.      * to be invoked, and if there is no geometry request about to be
  701.      * made, then invoke the new layout now; else defer it. */
  702.  
  703.     if (XtClass(XtParent(new))  == formWidgetClass    &&
  704.     current->core.x        == new->core.x        &&
  705.     current->core.y        == new->core.y        &&
  706.     current->core.width    == new->core.width    &&
  707.     current->core.height    == new->core.height    &&
  708.     current->core.border_width == new->core.border_width)
  709.     Layout(fp, 0, 0, True);
  710.     else fp->form.needs_relayout = True;
  711.   }
  712.   return( FALSE );
  713. }
  714.  
  715. static void ChangeManaged(w)
  716.     Widget w;
  717. {
  718.   FormWidget fw = (FormWidget)w;
  719.   FormConstraints form;
  720.   WidgetList children, childP;
  721.   int num_children = fw->composite.num_children;
  722.   Widget child;
  723.  
  724.   /*
  725.    * Reset virtual width and height for all children.
  726.    */
  727.   
  728.   for (children = childP = fw->composite.children ;
  729.        childP - children < num_children; childP++) {
  730.     child = *childP;
  731.     if (XtIsManaged(child)) {
  732.       form = (FormConstraints)child->core.constraints;
  733.  
  734. /*
  735.  * If the size is one (1) then we must not change the virtual sizes, as
  736.  * they contain useful information.  If someone actually wants a widget of
  737.  * width or height one (1) in a form widget he will lose, can't win them all.
  738.  *
  739.  * Chris D. Peterson 2/9/89.
  740.  */
  741.      
  742.       if ( child->core.width != 1)
  743.     form->form.virtual_width = (int) child->core.width;
  744.       if ( child->core.height != 1)
  745.     form->form.virtual_height = (int) child->core.height;
  746.     }
  747.   }
  748.   (*((FormWidgetClass)w->core.widget_class)->form_class.layout)
  749.                                        ((FormWidget) w, w->core.width, 
  750.                       w->core.height, TRUE);
  751. }
  752.  
  753.  
  754. static XtGeometryResult PreferredGeometry( widget, request, reply  )
  755.     Widget widget;
  756.     XtWidgetGeometry *request, *reply;
  757. {
  758.     FormWidget w = (FormWidget)widget;
  759.     
  760.     reply->width = w->form.preferred_width;
  761.     reply->height = w->form.preferred_height;
  762.     reply->request_mode = CWWidth | CWHeight;
  763.     if (  request->request_mode & (CWWidth | CWHeight) ==
  764.         (CWWidth | CWHeight)
  765.       && request->width == reply->width
  766.       && request->height == reply->height)
  767.     return XtGeometryYes;
  768.     else if (reply->width == w->core.width && reply->height == w->core.height)
  769.     return XtGeometryNo;
  770.     else
  771.     return XtGeometryAlmost;
  772. }
  773.  
  774.  
  775. /**********************************************************************
  776.  *
  777.  * Public routines
  778.  *
  779.  **********************************************************************/
  780.  
  781. /* 
  782.  * Set or reset figuring (ignored if not realized)
  783.  */
  784.  
  785. void
  786. #if NeedFunctionPrototypes
  787. XawFormDoLayout(Widget w,
  788. #if NeedWidePrototypes
  789.         int doit)
  790. #else
  791.         Boolean doit)
  792. #endif
  793. #else
  794. XawFormDoLayout(w, doit)
  795. Widget w;
  796. Boolean doit;
  797. #endif
  798. {
  799.     register Widget *childP;
  800.     register FormWidget fw = (FormWidget)w;
  801.     register int num_children = fw->composite.num_children;
  802.     register WidgetList children = fw->composite.children;
  803.  
  804.     if ( ((fw->form.no_refigure = !doit) == TRUE) || !XtIsRealized(w) )
  805.     return;
  806.  
  807.     for (childP = children; childP - children < num_children; childP++) {
  808.     register Widget w = *childP;
  809.     if (XtIsManaged(w)) {
  810.         FormConstraints form = (FormConstraints)w->core.constraints;
  811.  
  812.         /*
  813.          * Xt Configure widget is too smart, and optimizes out
  814.          * my changes.
  815.          */
  816.  
  817.         XMoveResizeWindow(XtDisplay(w), XtWindow(w),
  818.                   w->core.x, w->core.y, 
  819.                   w->core.width, w->core.height);
  820.  
  821.         if (form->form.deferred_resize &&
  822.         XtClass(w)->core_class.resize != (XtWidgetProc) NULL) {
  823.         (*(XtClass(w)->core_class.resize))(w);
  824.         form->form.deferred_resize = False;
  825.         }
  826.     }
  827.     }
  828. }
  829.