Parent document is top of "Motif FAQ (Part 9 of 9)"
Previous document is "331) Can I write a multi-threaded Motif application?"
Next document is "333) How do I convert my xpm file into a Pixmap? (The xpm file is"
332) How can I dump my widget instance tree in a way that reflects
the hierarchy?
[Last modified: July 97]
Answer: Jeremy Jameson (jameson@drmail.dr.att.com) posted this code to
c.w.x.m in 5/95.
[Note: this code does not consider popup children, which are not listed in
the XmNchildren array. To find those, you have to peek at the popup_list in
core widget record. - K.Lee 7/97]
/*******************************************************************************
* dumpWidgetTree( Widget w )
*
* This function will recursively descend throught the Widget tree
* and print the children and their pointer addresses.
*
* Jeremy Jameson 5/17/95
*
*******************************************************************************/
static void dumpWidgetTree( Widget w )
{
WidgetList list = NULL;
Cardinal num_children = 0;
int i;
static int n = 0;
Widget child;
static char* indent =
"-----------------------------------------------------------------------------";
char tmp[256];
*tmp = ' ';
if ( n >= strlen( indent ) +1 )
{
printf(
"ERROR:Widget tree is too deep, not enough indent string ( < %d )!\n",
n );
n = 0;
return;
}
strncpy( tmp, indent, n );
tmp[n] = ' ';
printf( "%s> Dumping widget tree of %s - %#x \n", tmp, XtName( w ), w );
if ( ! XtIsComposite( w ) )
{
printf(
"%s> %s is not a subclass of Composite and therefore has no children\n",
tmp, XtName( w ) );
return;
}
XtVaGetValues( w,
XmNchildren, &list,
XmNnumChildren, &num_children,
NULL );
printf( "%s> %s has %d %s\n", tmp, XtName( w ),
num_children, num_children == 1 ? "child" : "children" );
for ( i = 1; i <= num_children; i++ )
{
child = list[i-1];
printf( "%s> child %2d %20s \t (%#x)\n", tmp, i, XtName( child ), child );
}
printf( "\n" );
for ( i = 1; i <= num_children; i++ )
{
child = list[i-1];
n += 3;
dumpWidgetTree( child );
n -= 3;
}
printf( "\n" );
}
Parent document is top of "Motif FAQ (Part 9 of 9)"
Previous document is "331) Can I write a multi-threaded Motif application?"
Next document is "333) How do I convert my xpm file into a Pixmap? (The xpm file is"