[comp.windows.x] Does the Athena Form widget work under X11/R3

joe@retina.anatomy.upenn.edu (Joe Panico) (08/23/90)

Have been yet unable to coerce the Athena Form widget into properly
placing its children relative to
one another. A simple representative example of the problem follows:

---------begin xt source -----------------
/*
 * Copyright 1989 O'Reilly and Associates, Inc.
 * See ../Copyright for complete rights and liability information.
 */


/* 
 *  xform.c - simple button form
 */
/*
 *  So that we can use fprintf:
 */
#include <stdio.h>

/* 
 * Standard Toolkit include files:
 */
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/XawMisc.h>

/*
 * Public include files for widgets used in this file.
 */
#include <X11/Command.h>
#include <X11/Form.h>
/*
 * quit button callback function
 */
/*ARGSUSED*/
void Quit(w, client_data, call_data)
Widget w;
caddr_t client_data, call_data;
{ 
	exit(0); 
}

/*
 * "Press me!" button callback function
 */
/*ARGSUSED*/
void PressMe(w, client_data, call_data)
Widget w;
caddr_t client_data, call_data;
{ 
	fprintf(stderr, "Thankyou!\n"); 
}

main(argc, argv)
int argc;
char **argv;
{
	Widget form, quit, pressme, topLevel;

	topLevel = XtInitialize(
		argv[0], 	/* application name */
		"XBox2", 	/* application class name */
		NULL, 	/* application resources (not used) */
		0, 	/* application resource count */
		&argc, 	/* command line argument count */
		argv);	/* command-line string */

	form = XtCreateManagedWidget(
		"form", 	/* widget name */
		formWidgetClass,	/* widget class */
		topLevel,	/* parent widget*/
		NULL,	/* argument list*/
		0	/* arglist size */
		);

	pressme = XtCreateManagedWidget(
		"pressme",	/* widget name	 */
		commandWidgetClass,	/* widget class */
		form,	/* parent widget*/
		NULL,	/* argument list*/
		0	/* arglist size */
		);

	quit = XtCreateManagedWidget(
		"quit",	/* widget name */
		commandWidgetClass,	/* widget class */
		form,	/* parent widget*/
		NULL,	/* argument list*/
		0	/* arglist size */
		);

	XtAddCallback(quit, XtNcallback, Quit, 0);
	XtAddCallback(pressme, XtNcallback, PressMe, 0);

	XtRealizeWidget(topLevel);

	XtMainLoop();
}

---------------------end xt source-----------------
---------------------begin app-defaults-----------------

*pressme*label:	Press Me
*quit*label:	Quit
*Command*background:	orange
*pressme*fromHoriz:	quit
!*quit*fromHoriz:	pressme
---------------------end app-defaults-----------------

This is the error message above program produces:

X Toolkit Warning: Cannot convert string "quit" to type Widget

Would be eternally gratefull for any insights into this problem.

        -JP


  Communism is the long hard road between capitalism and capitalism.
                             - Contemporary Polish diplomat

converse@EXPO.LCS.MIT.EDU (08/23/90)

> Have been yet unable to coerce the Athena Form widget into properly
> placing its children relative to one another.
> This is the error message above program produces:
> 
> X Toolkit Warning: Cannot convert string "quit" to type Widget

With this resource specification:

	*pressme*fromHoriz:	quit

the Form widget tries to find the widget named "quit" at the time that
it is creating (not realizing) the widget named "pressme".  That is 
the problem.  This is considered a bug in the Athena Form widget, and
this behavior persists in R4.  To accomodate this bug, you must make
sure that any widgets referenced on the right hand side of these
constraint resource specifications have already been created at the 
time that the resource is read.  The resource is read at the time of
widget creation.  In this case, create the "quit" widget before the 
"pressme" widget.


Donna Converse

steve@wattres.UUCP (Steve Watt) (08/23/90)

The Athena form widget does not work well, but this problem is easy...

In article <28738@netnews.upenn.edu> you write:
>Have been yet unable to coerce the Athena Form widget into properly
>placing its children relative to
>one another. A simple representative example of the problem follows:
[ app-defaults moved up here... ]

>*pressme*label:	Press Me
>*quit*label:	Quit
>*Command*background:	orange
>*pressme*fromHoriz:	quit
>!*quit*fromHoriz:	pressme

[ some source deleted ]

>	pressme = XtCreateManagedWidget(
>		"pressme",	/* widget name	 */
>		commandWidgetClass,	/* widget class */
>		form,	/* parent widget*/
>		NULL,	/* argument list*/
>		0	/* arglist size */
>		);
>
>	quit = XtCreateManagedWidget(
>		"quit",	/* widget name */
>		commandWidgetClass,	/* widget class */
>		form,	/* parent widget*/
>		NULL,	/* argument list*/
>		0	/* arglist size */
>		);

[ some more source deleted ]

The problem is that when the X toolkit goes to look up resources for creating
the "pressme" widget, the "quit" widget does not exist.

If you rearrange the creates so it looks like:

  quit = XtCreateManagedWidget("quit", commandWidgetClass, form, NULL, 0);
  pressme = XtCreateManagedWidget("pressme, commandWidgetClass, form, NULL, 0);

It should work better (but still not well, the Athena form widget is generally
quite stupid.)


N.B.:   If you do not actually need the widget IDs for quit and pressme, it
          is probably better to declare an XtCallbackRec, and point the argument
          list at it.

For example:
{ ...
  XtCallbackRec cback[] = {
    { NULL, NULL }, { NULL, NULL }
  };
  Arg arg[1];

  cback[0].callback = quit;
  XtSetArg(arg[1], XtNcallback, cback);
  XtCreateManagedWidget("quit", commandWidgetClass, form, arg, 1);

  cback[0].callback = pressme;
  XtCreateManagedWidget("pressme", commandWidgetClass, form, arg, 1);
...
}
-- 
Steve Watt
...!claris!wattres!steve		wattres!steve@claris.com also works
Don't let your schooling get in the way of your education.

gjf00@duts.ccc.amdahl.com (Gordon Freedman) (08/25/90)

In article <28738@netnews.upenn.edu> joe@retina.anatomy.upenn.edu (Joe Panico) writes:
>Have been yet unable to coerce the Athena Form widget into properly
>placing its children relative to
>one another. A simple representative example of the problem follows:
>
>-------- some source code delete
>
>	pressme = XtCreateManagedWidget(
>		"pressme",	/* widget name	 */
>		commandWidgetClass,	/* widget class */
>		form,	/* parent widget*/
>		NULL,	/* argument list*/
>		0	/* arglist size */
>		);
>
>	quit = XtCreateManagedWidget(
>		"quit",	/* widget name */
>		commandWidgetClass,	/* widget class */
>		form,	/* parent widget*/
>		NULL,	/* argument list*/
>		0	/* arglist size */
>		);
>
>	XtAddCallback(quit, XtNcallback, Quit, 0);
>	XtAddCallback(pressme, XtNcallback, PressMe, 0);
>
>	XtRealizeWidget(topLevel);
>
>	XtMainLoop();
>}
>
>---------------------end xt source-----------------
>---------------------begin app-defaults-----------------
>
>*pressme*label:	Press Me
>*quit*label:	Quit
>*Command*background:	orange
>*pressme*fromHoriz:	quit
>!*quit*fromHoriz:	pressme
>---------------------end app-defaults-----------------
>
>This is the error message above program produces:
>
>X Toolkit Warning: Cannot convert string "quit" to type Widget
>

The problem is you haven't created the "quit" widget before you create the
"pressme" widget. As part of the XtCreateManagedWidget call for "pressme",
something somewhere goes out and looks for "pressme"'s resources. The
"*pressme*fromHoriz: quit" wants to place "pressme" next to the "quit"
widget, only there isn't any "quit" widget at this point.

Call XtCreateManagedWidget for "quit" before "pressme". I'm not sure but
it looks like there can be lots of "catch-22" situations with respect to
widget creation and resources. I think I've always been able to find a
way to do it by the order of widget creation.
--
Gordon Freedman: gjf00@duts.ccc.amdahl.com
Disclaimer: My opinions! Not my employers!