[comp.windows.x] need help creating a widget with a Widget field

uejio@lll-crg.llnl.gov (Jeremy Y. Uejio) (08/18/89)

I've just started creating my own widgets and was wondering if someone
could help me with the following problem creating a widget with a
Widget field.

Basically, I want a widget where one of the fields is a Label widget.
To do this I first created my .h and P.h by simply copying the
Template example.  I call my widget test so my TestP.h file looks
partly like:

typedef struct {
    /* resources */
	Widget label;
    /* private state */
} TestPart;

In my Test.c file I have an Initialize and a Realize function:

static void Initialize (request,new)
     Widget request;
     Widget new;
{
	Arg args[2];
	TestWidget test = (TestWidget)new;

	/* width and height are not initialized by core */
	if (test->core.width == 0)
	  test->core.width = 200;
	if (test->core.height <= 20)
	  test->core.height = 200;
	XtSetArg(args[0],XtNwidth,100);
	XtSetArg(args[1],XtNlabel,"Hello");
	test->test.label = XtCreateWidget("label",labelWidgetClass,
					  test,args,2);
}

static void Realize( w, valueMask, attributes )
     Widget w;
     Mask *valueMask;
     XSetWindowAttributes *attributes;
{
	TestWidget c = (TestWidget)w;
	XtRealizeWidget(c->test.label);
}

I compile, link, and run with a simple main.c and get the following error:

X Protocol error:  not a valid window ID
  Major opcode of failed request:  1 (X_CreateWindow)
  Minor opcode of failed request:  0
  Resource id in failed request:  0x0
  Serial number of failed request:  22
  Current serial number in output stream:  24

What's the problem here?  What am I doing wrong?


				Thanks in advance,
				jeremy


Jeremy Uejio (pronounced 'oo-ay-joe')    uejio@lll-crg.llnl.gov
Jeremy Uejio (pronounced 'oo-ay-joe')    uejio@lll-crg.llnl.gov
uucp:  {gatech,pyramid,rutgers}!lll-crg!uejio
other things to try:  uejio%lll-crg.llnl.gov@relay.cs.net

swick@ATHENA.MIT.EDU (Ralph R. Swick) (08/18/89)

> static void Realize( w, valueMask, attributes )
>      Widget w;
>      Mask *valueMask;
>      XSetWindowAttributes *attributes;
> {
> 	TestWidget c = (TestWidget)w;
> 	XtRealizeWidget(c->test.label);
> }


The realize procedure has to actually create the window for
the widget.  In this case, it also has to make sure to create
the window _before_ attempting to realize the child (since the
child will be a subwindow).  The most-frequently-correct action
is to call your superclass realize from within your own
realize;

	TestWidget c = (TestWidget)w;
	*(testWidgetClass->core_class.superclass->
	    core_class.realize) ( w, valueMask, attributes )
	XtRealizeWidget(c->test.label);

[Note that you can't use XtSuperclass(w), as things will get
fouled up if someone ever tries to subclass TestWidget.  I have
gotten into the habit of defining a macro, "superclass", for
thisWidgetClass->core_class.superclass so that the 3 or 4
typical references in the widget.c file are uniform.]

uejio@LLL-CRG.LLNL.GOV ("Jeremy Y. Uejio") (08/19/89)

Thank you for your very prompt response.  I tried what you suggested
and it works fine.  Do you have any examples for creating widgets
which contain other widgets?  I want to have a VPaned Widget within my
Widget and any child widgets will be inserted into the Vpaned Widget.
I'm getting really confused about how to access the
composite_class.insert_child routine of the Vpaned widget so that I
don't have to write my own insert child but simply change the parent
of the incoming widget to my widgets vpaned widget and then call the
insert_child routine of the vpaned widget.  ???

Anyway, I've looked thru the sources for the Athena widgets and can't
seem to find any examples of this kind of thing.  Are there any more
examples somewhere on the net?


				thanks for your help,
				jeremy

swick@ATHENA.MIT.EDU (Ralph R. Swick) (08/19/89)

>  I want to have a VPaned Widget within my
> Widget and any child widgets will be inserted into the Vpaned Widget.

Who is creating the children?  If your widget is creating them, then
it should specify the VPaned as the parent; if an external source is
creating them, then you'll have to be really careful trying to
splice the VPaned into the hierarchy.  It's not impossible, but
it's also not necessarily encouraged.

There are no examples in Xaw of a widget which splices the hierarchy.
The Dialog widget both creates some children automatically and
handles children created by the application; you might learn something
from it.

uejio@LLL-CRG.LLNL.GOV ("Jeremy Y. Uejio") (08/19/89)

> Who is creating the children?  If your widget is creating them, then
> it should specify the VPaned as the parent; if an external source is
> creating them, then you'll have to be really careful trying to
> splice the VPaned into the hierarchy.  It's not impossible, but
> it's also not necessarily encouraged.

I guess what I really want to do is add some fields and routines to
the VPaned widget.  So all I need to do is create a new widget which
is a sub class of the VPaned widget.  Simple, huh?  I think I won't
have any problems with doing this. Sorry for all the confusion. 

Well, it's the end of the week...


				jeremy