[comp.windows.x] Form Widget question

hrp@snoid.cray.COM (Hal Peterson) (12/16/88)

I am trying to make a Form widget with three daughter widgets like
this:

	+------+------+
	|    Label    |
	+------+------+
	|      |      |
	| Form | Form |
	|______|______|

but I keep winding up with this:

	+------++-----+
	| Label |     |
	+------++-----+
	|      |      |
	| Form | Form |
	|______|______|

I can't find any way, short of setting the initial size of the Label
widget to some large value, to center the Label in the enclosing Form.
I have tried setting
	XtNright <- XtChainRight
	XtNleft <- XtChainLeft
in the Label widget, with no change in behavior, and I think that
makes sense, but it still doesn't solve my problem.

--
Hal Peterson / Cray Research / 1440 Northland Dr. / Mendota Hts, MN  55120
hrp@cray.com			uunet!cray!hrp		    (612) 681-3145

hrp@snoid.cray.COM (Hal Peterson) (12/16/88)

Are there any plans to add an XtNorientation resource to the Dialog
widget?  It would be handy to be able to specify a Dialog like

	+-------+------+
	| Label | Text |
	+-------+------+

or like

	+-------+
	| Label |
	+-------+
	| Text  |
	+-------+

without resorting to a Form.

--
Hal Peterson / Cray Research / 1440 Northland Dr. / Mendota Hts, MN  55120
hrp@cray.com			uunet!cray!hrp		    (612) 681-3145

jack@hpcvlx.HP.COM (Jack Peterson) (12/17/88)

/ hpcvlx:comp.windows.x / hrp@snoid.cray.COM (Hal Peterson) / 11:34 am  Dec 15, 1988 /
I am trying to make a Form widget with three daughter widgets like
this:

	+------+------+
	|    Label    |
	+------+------+
	|      |      |
	| Form | Form |
	|______|______|

but I keep winding up with this:

	+------++-----+
	| Label |     |
	+------++-----+
	|      |      |
	| Form | Form |
	|______|______|

I can't find any way, short of setting the initial size of the Label
widget to some large value, to center the Label in the enclosing Form.
I have tried setting
	XtNright <- XtChainRight
	XtNleft <- XtChainLeft
in the Label widget, with no change in behavior, and I think that
makes sense, but it still doesn't solve my problem.

--
Hal Peterson / Cray Research / 1440 Northland Dr. / Mendota Hts, MN  55120
hrp@cray.com			uunet!cray!hrp		    (612) 681-3145
----------

With the HP Widget set, in order to span the width of a form, the constraint 
resources XtNxAttachRight and XtNxResizable must both be set to TRUE.

Jack Peterson
HP Corvallis Workstation Operation
Support and Training

kit@ATHENA.MIT.EDU (Chris D. Peterson) (12/17/88)

> From hrp@snoid.cray.com (Hal Peterson)
> 
> [picture deleted, basically trying to get a label widget to be the 
>  titlebar over two forms, so that it extends across both of the daughter 
>  forms.]
>
> I can't find any way, short of setting the initial size of the Label
> widget to some large value, to center the Label in the enclosing Form.
> I have tried setting
> 	XtNright <- XtChainRight
> 	XtNleft <- XtChainLeft
> in the Label widget, with no change in behavior, and I think that
> makes sense, but it still doesn't solve my problem.

The form widget is a slippery character and is difficult to describe and
understand, we are looking into getting something better, but for a while
for doing general widget layout the form is it.  So to let people use it more
effectively I will try to give a better explanation of its use.

The form has two distinct methods of laying itself out.  Method 1 never
resizes the children of the form, and just attempts to place them in next
to each other like building blocks, according to the resources shown below.
The FromVert resource is used to place this widget directly below one of its
siblings.  The fromHoriz resource is used to place this widget directly to the
right of one of its siblings.  This method is used when managing and unmanaging
children, and processing childrens geometry requests.

Method 2 may resize children if the XtNresizable constraint resouce is set
for that child.  This method takes each edge of each child, and moves it 
appropriately, for instance in the above example you may want to 
chain both the top and bottom edges of the lable widget to the top of the
form.  This will of course keep it from changing size, and both edges are
fixed to the top of the form.  For really strange behavior you can chain the
top of a widget to the bottom of the form, and the bottom of a widget to the 
top of the form.  This method is only used when the form is told to resize
itself by its parent.

Resources for each method of laying out the form widgets children.

Method 1				Method 2
--------------------------------------------------------------
XtNfromVert				XtNbottom
XtNfromHoriz				XtNtop
XtNhorizDistance			XtNleft
XtNvertDistance				XtNright
					XtNresizeable

Back to the specific question:

The only what to get the label widget to go all the way across the form 
like you are asking is to size it appropriately.  This can be done by querying
the daughter form widgets of their sizes (a call to XtFormDoLayout may be
necessary) and the label widget of its XtNhorizDistance resource, and adding
them all together as the correct size of the label widget.

						Chris D. Peterson     
						MIT X Consortium /
						Project Athena 

Net:	kit@athena.mit.edu		
Phone: (617) 253 - 1326			
USMail: MIT - Room E40-342C		
	77 Massachusetts Ave.		
	Cambridge, MA 02139		

sundar@WHEATIES.AI.MIT.EDU (Sundar Narasimhan) (12/19/88)

If you are using the athena form widget equalizing widths horizontally and
heights vertically may be a problem depending on how you create the widgets
initially.

My solution was to have a equalize_geometry(widget_list, XtNwidth)
procedure that just resizes the widgets to be of equal widths once
they have been created.

-Sundar

ps. here's that piece of code

xt_equalize_geometry(direction, list)
char *direction;			/* XtNwidth/XtNheight */
xt_widget_list list;
{
    xt_widget_list l;
    Arg args[W_MAXARGS];
    int i = 0;
    Dimension width, height, borderwidth;
    int maxvalue = 0;
    int widflag = 0;

    xt_set_args(args, &i, W_MAXARGS, 
		XtNwidth, &width,
		XtNheight, &height,
		XtNborderWidth, &borderwidth,
		NULL);
    if(strcmp(direction, XtNwidth) == 0) 
      widflag = 1;

    for(l = list; l != NULL; l = l->next) {
	XtGetValues(l->widget, args, i);
	if(widflag) {
	    if (maxvalue < width) maxvalue = width;
	} else
	  if(maxvalue < height) maxvalue = height;
    }

    for(l = list; l != NULL; l = l->next) {
	XtGetValues(l->widget, args, i);
	XtResizeWidget(l->widget, (widflag == 1) ? maxvalue : width,
		       (widflag == 1) ? height : maxvalue,
		       borderwidth);
    }
    return(maxvalue);
}

Sherman.Uitzetter@MAPS.CS.CMU.EDU (07/14/89)

   I am using X11R3 and have a Form Widget with (let's say) two buttons in it.
How can I stick a third button between the first two? I tried the obvious -
set XtNfromHoriz for the new button to the first (left) button and XtNfromHoriz
for the second (right) button to the new button and then realized the Form.
What happened was - the new button ends up under the first button (upper left
of the Form) and the right button ends up to the right of the new button and,
thus, obscured by the first button. Basically, the middle button doesn't end
up in the middle but underneath the button at the left.

Thanks in advance for any response.

-Sherman.

converse@EXPO.LCS.MIT.EDU (Donna Converse) (07/14/89)

>    I am using X11R3 and have a Form Widget with (let's say) two buttons in it.
> How can I stick a third button between the first two? 

The following resources presuppose the order of widget creation to be
leftButton, middleButton, rightButton.

Demo.form.middleButton.fromHoriz:	leftButton
Demo.form.rightButton.fromHoriz:	middleButton

At the time that the right button is created, the Athena form widget 
converts middleButton to a widget ID.  So, the middle button must be
created before the right button.

If the order of widget creation is leftButton, rightButton, middleButton,
write the resources so that the placement of buttons depend only on
existing buttons.

Demo.form.middleButton.fromHoriz:	leftButton
Demo.form.rightButton.fromHoriz:	leftButton
Demo.form.rightButton.horizDistance:	60

Not very elegant, is it?

Donna Converse
converse@expo.lcs.mit.edu