[comp.windows.x] PROBLEM WITH X TOOLKIT EXAMPLE

mlp@ardent.UUCP (Mark Patrick) (07/12/88)

The following example taken from the paper "Using the X Toolkit or How to
Write a Widget" by Joel McCormack and Paul Asente appears to have a problem
on the X toolkit implementations (including the sun) which we have access to.
The program is given below:

#include <X11/Intrinsic.h>
#include <X11/Atoms.h>
#include <X11/Form.h>
#include <X11/Label.h>
#include <X11/Command.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);

    n = 0;
    box = XtCreateManagedWidget("box", formWidgetClass, toplevel, arg, n);

    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], XtNfromVert, label); n++;
    XtSetArg(arg[n], XtNlabel, "Click and die");n++;
    command = XtCreateManagedWidget("command", commandWidgetClass, box, arg, n);
    XtAddCallback(command, XtNcallback, Callback, NULL);

    XtRealizeWidget(toplevel);
    XtMainLoop();
}


The line which reads:

	XtSetArg(arg[n], XtNfromVert, label); n++;

appears to be essential for the command widget to be displayed.  Does anyone
know if this line really should be there of if there is a problem with the
X toolkit

Mark Patrick
Ardent Computer
uunet!ardent!mlp

fanning@3d.DEC.COM (07/12/88)

	
>From: 3d::decwrl::ardent!mlp@uunet.uu.net (Mark Patrick  11-Jul-88 1454 PDT)
 
>The following example taken from the paper "Using the X Toolkit or How to
>Write a Widget" by Joel McCormack and Paul Asente appears to have a problem
>on the X toolkit implementations (including the sun) which we have access to.
>The program is given below:
	.
	.
	.
	.
>The line which reads:
>
>	XtSetArg(arg[n], XtNfromVert, label); n++;
>
>appears to be essential for the command widget to be displayed.  Does anyone
>know if this line really should be there of if there is a problem with the
>X toolkit
 
 
The command widget is displayed with or without that line.  If, however,
the XtNfromVert argument is left equal to its default value (NULL), then
the form widget which parents both the label and command widgets tries to
put them both XtNvertDistance (XtDefaultDistance) from its top.  This results 
in the widgets overlapping one another. 
 
The reason that the first widget created (not the first widget managed)
overlaps the second traces back to the following two facts : 
	
	o	The insert_child procedure for the form widget by
		default places a newly created child on the end
		of its array or queue of children.
 
	o	XtRealizeWidget calls RealizeWidget, which traverses
		the children of a composite widget in postfix order,
		meaning that the last child in the queue is realized
		first and the first is realized last (pretty biblical, huh?).
		In other words, a composite widget's array of children
		is realized and displayed from the last created to the 
		first created.
 
 
 
Blaise Fanning
Digital Equipment Corporation
Workstation Graphics
Marlboro, MA
 
 

asente@WSL.DEC.COM (07/12/88)

The problem is that when the paper was written we thought that release
2 would countain a different version of the form widget from what was
actually released.  If you have access to it, see the published version
of the paper in the Summer Usenix proceedings; at any rate some small
tweaks are necessary to make the example program work with the release 2 form.

	-paul

diane@drao.nrc.ca (Diane Parchomchuk) (02/14/91)

I am working my way through the Douglas Young book, 'The X Window System...'
OSF/Motif edition.

PROBLEM: Chapter 10 examples fractal.c and fractal2.c.
Both compiled, no problem but on trying to run them I got a 
	FIXEDUP UNALIGNED DATA ACCESS FOR pid 17269(fractal2) at pc0x404684

Our system person told me that this error was due to RISC architecture, we are
running ULTRIX, 4.0, on a DecStation 3100. 

Consulting with the Dec people, they maintain it is due to sloppy programming
habits brought on by exposure to non-picky compilers.  Where is it written in
standard C that parameters HAVE to be passed in order of size?  Also in all of
X TOOLKIT you are working with predefined structures that are beyond your
control.  Are they all aligned so they will run on RISC machines?

I tried to rearrange the order of variables in the structure image_data to put
the type complex and float first.  Didn't help.

Any comments or fixes? 

Sorry if this is a bonehead gripe but I am running into too many brick walls!

Diane Parchomchuk
diane@drao.nrc.ca

ps. The Makefile tries to make Chapter 8 programs, there aren't any in the
tar file I got from expo - did I goof or did someone forget about poor ol'
ch8.

D_GONZALEZ@upr1.upr.cun.EDU (02/15/91)

In a recent mail, "diane@dao.nrc.ca" mentions having problems running the
fractal examples on her "risc" system and not working.

	I guess this is not a problem of all risc architectures since I am
running those examples on an IBM RS6000 system using X11R4/OSF/MOTIF from
IBM (AIXWINDOWS) and the fractal program works fine.

David Gonzalez		Internet:  D_GONZALEZ@upr1.upr.clu.edu
University of Puerto Rico
Mayaguez Campus -- Engineering School