[comp.windows.x] Automatic relayout/resize of Athena Form Widget

battle@alphard.cs.utk.edu (David Battle) (05/17/89)

I am having trouble with the athena form widget.  The form widget
in question is inside a viewport widget.  It contains several subordinate
form widgets layed out vertically (one below the other).  This layout
is achieved by using the XtNfromVert argument when creating each of the
subordinate form widgets and specifying the previously created widget.
Each of the subordinate widgets in turn contain a command button and
three text widgets layed out horizontally (using XtNfromHoriz).
The viewport widget mentioned earlier has vertical scrolling enabled.
This allows vertical scrolling through the collection of subordiante
forms.  So far, everything works quite nicely.

Now comes the problem.  When I delete one of the subordinate form widgets
with XtDestroyWidget, the parent form widget resizes itself smaller.  This
is to be expected, I suppose, except that it seems to over do it.  It then
proceeds to reduce the vertical size of each of the remaining subordinate
form widgets.  This continues happening each time I destroy a subordinate
form widget until some minimum vertical size for each subform is aparently
reached.  At this point, it is impossible to read the text inside the text
widgets because they are so short.

I haven't tried it, but I could probably stop this behavior by specifying
a height for the subordinate form widgets, but for other reasons, I do
not want to do this.

Can anyone shed any light on this problem?

					-David L. Battle
					 battle@esddlb.esd.ornl.gov
					 battle@utkcs2.cs.utk.edu

battle@alphard.cs.utk.edu (David Battle) (05/20/89)

In article <885@utkcs2.cs.utk.edu> I wrote:

>Now comes the problem.  When I delete one of the subordinate ... widgets
>with XtDestroyWidget, the parent form widget resizes itself smaller.  This
>is to be expected, I suppose, except that it seems to over do it.  It then
>proceeds to reduce the ... size of each of the remaining subordinate
>... widgets.  This continues happening each time I destroy a subordinate
>... widget until some minimum ... size for each sub[widget] is aparently
>reached.  At this point, it is impossible to read the text inside the ...
>widgets because they are so [small].

(Some adjectives which don't apply in the general case were removed. )

Here is a program which illustrates the problem I described in my
previous article.  Just compile with the command:

	cc -o resize resize.c -lXaw -lXmu -lXt -lX11

I can't imagine the behavior this program exhibits being "correct".
(The viewport widget and it's contents shrink away to nothing.)  Try it,
I think you will find it very frustrating.  You will get different
results by pressing the buttons in a different order.

Once again, can anyone shed any light on this problem?

				-David L. Battle
				 battle@utkcs2.cs.utk.edu
				 battle@esddlb.esd.ornl.gov

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/Command.h>
#include <X11/Form.h>
#include <X11/Box.h>
#include <X11/Viewport.h>
#include <X11/StringDefs.h>

#define TEN 10

void DeleteMe(w, client_data, call_data)
Widget w;
caddr_t client_data, call_data;
{
    static int count = 0;

    XtDestroyWidget(w);
    count++;
    if(count >= TEN)
        exit(1);
}

main(argc,argv)
char **argv;
{
    Widget toplevel, box, view, form, commands[TEN];
    int i;
    static Arg view_args[] = {
        { XtNallowVert, (XtArgVal) True },
        { XtNheight, (XtArgVal)50 },
        { XtNwidth, (XtArgVal)150 }, 
    };
    static XtCallbackRec callbacks[] = {
        { DeleteMe, NULL },
        { NULL, NULL },
    };
    static Arg command_args[] = {
        { XtNfromVert, (XtArgVal) NULL },
        { XtNcallback, (XtArgVal)callbacks },
    };


    toplevel=XtInitialize("resize","Resize", 0, 0, &argc, argv);
    box = XtCreateManagedWidget("box", boxWidgetClass, toplevel, 0, 0);
    view = XtCreateManagedWidget("view", viewportWidgetClass,
      box, view_args, XtNumber(view_args));
    form = XtCreateManagedWidget("form", formWidgetClass, view, 0, 0);
    for(i = 0; i < TEN; i++) {
        commands[i] = XtCreateManagedWidget("Delete",commandWidgetClass,form,
          command_args, XtNumber(command_args));
        command_args[0].value = (XtArgVal)commands[i];
    }
    XtRealizeWidget(toplevel);
    XtMainLoop();
}

envbvs@epb2.lbl.gov (Brian V. Smith) (05/20/89)

In article <889@utkcs2.cs.utk.edu>, battle@alphard.cs.utk.edu (David Battle) writes:

> >Now comes the problem.  When I delete one of the subordinate ... widgets
> >with XtDestroyWidget, the parent form widget resizes itself smaller.  This
> >is to be expected, I suppose, except that it seems to over do it.  It then
> >proceeds to reduce the ... size of each of the remaining subordinate
> >... widgets.  This continues happening each time I destroy a subordinate
> >... widget until some minimum ... size for each sub[widget] is aparently
> >reached.  At this point, it is impossible to read the text inside the ...
> >widgets because they are so [small].
> 

  [ program follows to demonstrate the shrinking widget ]

I have found that in working with widgets one must "chain" them to the
parent widget, or they get hosed when sizes change.  I added the following
arguments to command_args[] and it works pretty well (when you destroy
the subwidgets the parent doesn't get any smaller, which is what was happening
before adding these constraints). 

I confess that there may be a more appropriate way to do this, but this seems
to work.

    static Arg command_args[] = {
        { XtNfromVert, (XtArgVal) NULL },
        { XtNcallback, (XtArgVal)callbacks },
        { XtNwidth, (XtArgVal)130 },
        { XtNtop, (XtArgVal)XtChainTop},
        { XtNbottom, (XtArgVal)XtChainTop},
        { XtNleft, (XtArgVal)XtChainLeft },
        { XtNright, (XtArgVal)XtChainLeft },
     };
_____________________________________
Brian V. Smith    (bvsmith@lbl.gov)
Lawrence Berkeley Laboratory
We don't need no signatures!