[comp.windows.x.motif] pointer on children of a widget.

cambon@mimosa.unice.fr (Thierry Cambon) (06/10/91)

Can someone tell me how to get a pointer on the children
of a given widget ? I know the toolkit macro XtParent(w)
to get the parent id. Is there a similar funtion to get
the children id. ?

  Thanks.

achan@sparkle.tdd.sj.nec.com (Amy Chan) (06/11/91)

In article <234@taloa.unice.fr> cambon@mimosa.unice.fr (Thierry Cambon) writes:
>Can someone tell me how to get a pointer on the children
>of a given widget ? I know the toolkit macro XtParent(w)
>to get the parent id. Is there a similar funtion to get
>the children id. ?
>
>  Thanks.

For X11R4, you can use the following:

    WidgetList children;
    Cardinal num_children;

    XtVaGetValues(parent, XtNchildren, &children,
                XtNnumChildren, &num_children, NULL);

which will return the children as a widget list and the number of children
on that list.


Amy Chan
--
Amy Chan                 | E-Mail:
NEC America              |  INET: achan@tdd.sj.nec.com
110 Rio Robles           |  UUCP: ...{decwrl,oliveb}!necsun!achan
San Jose, CA 95134       |

pete@IRIS49.BIOSYM.COM (Pete Ware) (06/11/91)

Just as a rough, off the cuff answer, cuff answer, try the following.
Beware that you should not modify the list of children.  Also, it does
not return the children's children, etc.

#include <Xm/Xm.h>
#include <Xm/DialogS.h>

void
GetChildren (shell, num_children, children)
Widget		shell;
Cardinal	*num_children;
Widget		**children;
{
	Arg		args[10];
	Cardinal	cnt;

	*num_children = 0;
	*children = NULL;
	if (!XtIsComposite (shell))
		return;

	cnt = 0;
	XtSetArg (args[cnt], XmNnumChildren, &num_children); ++cnt;
	XtSetArg (args[cnt], XmNchildren, &children); ++cnt;
	XtGetValues (gw, args, cnt);
}

--pete
Pete Ware / Biosym / San Diego CA / (619) 546-5532
     email: pete@biosym.com