[comp.windows.x] accessing list of children

randy@erik.UUCP (Randy Brown) (07/13/90)

Sometimes I'm incredibly slow, but I can't find any way to get a list of
a widget's children except by accessing the fields of the widget instance
record.  I know it's simple, but I would prefer my callbacks to use 
something more like XtParent()--I can write it, I just can't find it.
Does it exist? ... uunet!erik!rbrown

swick@ATHENA.MIT.EDU (Ralph Swick) (07/14/90)

    Sometimes I'm incredibly slow, but I can't find any way to get a list of
    a widget's children except by accessing the fields of the widget instance

As of X11R4, you can use XtGetValues on the XtNchildren and XtNnumChildren
resources.  (Don't try to set 'em; you're supposed to treat them as
read-only.)

west@gsrc.dec.com (Jim West (Stealth Contractor)) (07/17/90)

In article <9007130024.AA06843@uunet.uu.net>, randy@erik.UUCP (Randy Brown) writes...
-Sometimes I'm incredibly slow, but I can't find any way to get a list of
-a widget's children except by accessing the fields of the widget instance
-record.  I know it's simple, but I would prefer my callbacks to use 
-something more like XtParent()--I can write it, I just can't find it.
-Does it exist? ... uunet!erik!rbrown

  From DECwindows there is DwtChildren and DwtNumberChildren.  I think these
are macros that do what you described you were doing.

----------------------------------------------------------------------
 Jim West                      |  The Schainker Converse
 west@gsrc.dec.com             |  to Hoare's Law :
                               |
 These are my opinions.        |   Inside every small problem
 Digital has no idea           |     is a larger problem struggling
 what I'm  saying.             |       to get out.
----------------------------------------------------------------------

rlh2@ukc.ac.uk (Richard Hesketh) (07/18/90)

In article <1435@shodha.dec.com> west@gsrc.dec.com (Jim West (Stealth Contractor)) writes:
>
>In article <9007130024.AA06843@uunet.uu.net>, randy@erik.UUCP (Randy Brown) writes...
>-Sometimes I'm incredibly slow, but I can't find any way to get a list of
>-a widget's children except by accessing the fields of the widget instance
>-record.  I know it's simple, but I would prefer my callbacks to use 
>-something more like XtParent()--I can write it, I just can't find it.
>-Does it exist? ... uunet!erik!rbrown
>
>  From DECwindows there is DwtChildren and DwtNumberChildren.  I think these
>are macros that do what you described you were doing.

Using the MIT Xt Toolkit you could use the following...

	WidgetList children;
	Cardinal num_children;

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

Which returns the children as a widget list and of course the number of
children on that list.  This is for X11R4 .. its been a long time since I
have used R3 so my memory fades on that one.  These resources are documented
in section 1.4.2 of the R4 Xt Intrinsics manual.

If you can, try not to access any of the members of the different structures
that make up a widget (unless you are writing a widget class), the ..

	XtName(), XtClass(), XtParent(), XtWindow(), XtDisplay() ... etc

macros and functions provide quick and easy methods of access to useful
resources.  For almost all resources (I can't think of any that don't)
their current values can be got through the GetValues interface.  This
doesn't break the information hiding aspect of object oriented toolkits.
Also the varargs versions of these interface routines can make
programming a lot easier.

I think what would be very useful for R5 would be a tutorial of how to
write neat and correct Xt based programs.  What I would envisage is things
like ... how to use the Widget Creation Library, how not to get tied up
in knots by the geometry management handlers ("how can I get my form to
resize when it is in a box, another form and a shell??"),  why its
bad to hard-wire in resources at creation time,  how to use the varargs
interface to do neat tricks (such as setting colours or fonts using strings)
and a quick and easy guide to widget class creation.

I think the last point is very important, Chapter 7 of the Athena Widget Set
gives a good start, but we need lots more examples!!  Perhaps someone
has created a useful script that takes an existing widget class and generates
a new subclass by munging the names and putting in new class and instance
parts in the structures?? (offers anyone?).  Xt was designed so that
subclassing would be easy but how many people actually do it?  It is still
a daunting task to the uninitiated and even us ol' timers 8-)

Anyway, user interface builders are on the way; all being well it won't be long
(a couple of months) before a publically available and *free* user interface
builder/design tool (call it what you will) will be posted to comp.sources.x.
Speaking of which I would like to hear from anyone who can tell me the best
way of distributing 1 Meg of source code?  Can I drop it in to expo for
ftp access, is it too much for comp.sources.x??

Richard Hesketh   :   @nsfnet-relay.ac.uk:rlh2@ukc.ac.uk
		  :   rlh2@ukc.ac.uk    ..!mcsun!ukc!rlh2
---                                               
Computing Lab., University of Kent at Canterbury,
Canterbury, Kent, CT2 7NF, United Kingdom.    Tel: +44 227 764000 ext 7620/3682