[comp.windows.x] Ask for the problem of X Toolkit

jwkim@sorak.kaist.ac.kr (JangWook Kim) (09/20/88)

Dear,

In the X Toolkit(X11R2), XtNx(XtNy)-the one of the resources of 
argument list of the Widget Class- for the x(y) coordinate doesn't work.
Sample program(Goodbye.c, as described below) of displaying 
a window with a label and a command button also doesn't work.

What's wrong with the line 31,32,37, and 38(that don't work) 
of the program below?

I expect your reply.


#include <X11/Intrinsic.h>
#include <X11/Atoms.h>
#include <X11/Form.h>
#include <X11/Label.h>
#include <X11/Command.h>
#include <X11/StringDefs.h>
#include <X11/Xatom.h>
#include <X11/Shell.h>

void Callback(widget,clientData,callData)
Widget widget;
caddr_t clientData,callData;
{
	(void) printf("Goodbye, cruel world\n");
	exit(0);
}

int main(argc,argv)
unsigned int argc;
char **argv;
{
	Widget toplevel,box,label,command;
	Arg arg[25];
	unsigned int n;

	toplevel = XtInitialize("goodbye","Goodbye",NULL,0,&argc,argv);

	box = XtCreateManagedWidget("box",formWidgetClass,toplevel,(Arg*)NULL,0);

	n = 0;
	XtSetArg(arg[n],XtNx,10);		n++;
	XtSetArg(arg[n],XtNy,10);		n++;
	XtSetArg(arg[n],XtNlabel,"Goodbye, world");		n++;
	label = XtCreateManagedWidget("label",labelWidgetClass,box,arg,n);

	n = 0;
	XtSetArg(arg[n],XtNx,10);		n++;
	XtSetArg(arg[n],XtNy,40);		n++;
	XtSetArg(arg[n],XtNlabel,"Click and die");		n++;
	command = XtCreateManagedWidget("command",commandWidgetClass,box,arg,n);
	XtAddCallback(command,XtNcallback,Callback,NULL);

	XtRealizeWidget(toplevel);
	XtMainLoop();
}

Yours truly,

Jangwook Kim.
(jwkim@cosmos.kaist.ac.kr)

swick@ATHENA.MIT.EDU (Ralph R. Swick) (09/20/88)

> What's wrong with the line 31,32,37, and 38(that don't work) 
> of the program below?

You have used the FormWidget as the parent.  Form ignores the
positions of it's children and moves them to what it considers
an appropriate position, based upon the constraints attached
to each of the children.  In your case, the default values for
the constraints cause each child to be positioned 4 pixels from
the left and top edges of the Form; i.e. both are at (4,4).

If you replace XtNx with XtNhorizDistance and XtNy with
XtNvertDistance you will see something closer to what you
probably expect (though this wouldn't necessarily be the best
way to specify your particular form).