From: cs435141@umbc8.umbc.edu (cs435141)
Subject: Problems with Form widget
Summary: Doesn't work as expected
Keywords: Form Widget Problems
Organization: University of Maryland, Baltimore County Campus
Date: Thu, 19 Nov 1992 04:29:37 GMT

I have been programming Motif for several weeks now (I consider myself a
novice) and I have come up against a problem no one arround here can
solve.  I am trying to arrange four pushButtons inside a Form widget
in the following organization.  (Actually, this is a much simplified
case of what I really want, but I still can't get it to work.)

+-------+
|+-+ +-+|
||A| |B||
|+-+ +-+|
|+-+ +-+|
||C| |D||
|+-+ +-+|
+-------+

But this is what I get when I run the program below:

+-------+
|+-+ +-+|
||A| |B||
|+-+ +-+|
+-------+

PushButton widgets C and D are located at (0,0) within the form widget.
I've used the Form widget several times before, and from what I know
about the Form widget so far, the code below *should* work.

I know I could use the BulletinBoard widget and place the buttons at
absolute x,y coordinates, but that does not solve my lack of understanding
regarding the Form widget.

Any help would be much appreciated.  I'm running Motif version 1.1.4
on an SGI Indigo running X11R4.  Please Email responses to:
cs435141@umbc8.umbc.edu.  I'll post a summary to the net if there is
sufficient interest.

Thanks in advance,
Peter Johansson.

/*-----------------snip-----------snip-------------snip------------------------
| Test program
|----------------------------------------------------------------------------*/

#include <stdio.h>

#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>

#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>

int main (argc, argv)
    int argc;
    char *argv[];
{
    Widget
	top,
	box,
	button_a,
	button_b,
	button_c,
	button_d;

    Arg
	wargs[10];

    int
	n;

    XmString
	xmstr;

    Dimension
	x, y;

    /* Initialize Xt Intrinsics and Motif */
    top = XtInitialize ("paint", argv[0], NULL, 0, &argc, argv);

    /* Create Form widget for icons */
    box = XtCreateManagedWidget ("box", xmFormWidgetClass,
				 top, NULL, 0);

    xmstr = XmStringCreate ("A", XmSTRING_DEFAULT_CHARSET);
    n = 0;
    XtSetArg (wargs[n], XmNlabelString,      xmstr); n++;
    XtSetArg (wargs[n], XmNtopAttachment,    XmATTACH_FORM); n++;
    XtSetArg (wargs[n], XmNleftAttachment,   XmATTACH_FORM); n++;    
    button_a = XtCreateManagedWidget ("buttonA", xmPushButtonWidgetClass,
				      box, wargs, n);

    xmstr = XmStringCreate ("B", XmSTRING_DEFAULT_CHARSET);
    n = 0;
    XtSetArg (wargs[n], XmNlabelString,      xmstr); n++;
    XtSetArg (wargs[n], XmNtopAttachment,    XmATTACH_FORM); n++;
    XtSetArg (wargs[n], XmNleftAttachment,   XmATTACH_WIDGET); n++;    
    XtSetArg (wargs[n], XmNleftWidget,       button_a); n++;    
    button_b = XtCreateManagedWidget ("buttonB", xmPushButtonWidgetClass,
				      box, wargs, n);

    xmstr = XmStringCreate ("C", XmSTRING_DEFAULT_CHARSET);
    n = 0;
    XtSetArg (wargs[n], XmNlabelString,      xmstr); n++;
    XtSetArg (wargs[n], XmNtopAttachment,    XmATTACH_WIDGET); n++;
    XtSetArg (wargs[n], XmNtopWidget,        button_a);
    XtSetArg (wargs[n], XmNleftAttachment,   XmATTACH_FORM); n++;    
    button_c = XtCreateManagedWidget ("buttonC", xmPushButtonWidgetClass,
				      box, wargs, n);
    
    xmstr = XmStringCreate ("D", XmSTRING_DEFAULT_CHARSET);
    n = 0;
    XtSetArg (wargs[n], XmNlabelString,      xmstr); n++;
    XtSetArg (wargs[n], XmNtopAttachment,    XmATTACH_WIDGET); n++;
    XtSetArg (wargs[n], XmNtopWidget,        button_b);
    XtSetArg (wargs[n], XmNleftAttachment,   XmATTACH_WIDGET); n++;    
    XtSetArg (wargs[n], XmNleftWidget,       button_c);
    button_d = XtCreateManagedWidget ("buttonD", xmPushButtonWidgetClass,
				      box, wargs, n);

    /* Realize widgets */
    XtRealizeWidget(top);

    n = 0;
    XtSetArg (wargs[n], XmNx, &x); n++;
    XtSetArg (wargs[n], XmNy, &y); n++;
    XtGetValues (button_a, wargs, n);
    printf ("button A: (%d,%d)\n", x, y);
    XtGetValues (button_b, wargs, n);
    printf ("button B: (%d,%d)\n", x, y);
    XtGetValues (button_c, wargs, n);
    printf ("button C: (%d,%d)\n", x, y);
    XtGetValues (button_d, wargs, n);
    printf ("button D: (%d,%d)\n", x, y);

    XtMainLoop();
}
/* end of main */
Newsgroups: comp.windows.x.motif