From: young@borris.eece.unm.edu (Mark Young)
Subject: Re: Printing resource values
Date: Thu, 05 Nov 92 12:30:02 GMT
Organization: University of New Mexico, Albuquerque


Hi,

In article <1992Nov5.010656.25306@news2.cis.umn.edu> ianhogg@milli.cs.umn.edu (Ian J. Hogg) writes:
>I'm writing a function to print the resource values of an arbitrary widget.  My
>first cut is to simply print out the names of the resources and the widget 
>classes that actually define them.
>
>The code looks like this and may not be perfect some I'm recreating from memory
>from home.  Oh yeah, I'm unfortunately using X11R4 on an RS6000.

[old code deleted]

Actually the easiest way to get your code would probably use the Xt utility
XtGetResourceList().  This takes your widget class and converts the compiled
resource structure back into it's original form.  The traversal up the
superclass is not really needed since it should be included in the widget
class's resource list.

void PrintWidget(Widget w)
{
    WidgetClass widgetClass = XtClass(w);
    XtResourceList resources;
    Cardinal num_resources;

    fprintf(stderr,"resources from widget class %s\n", 
                widgetClass->core_class.class_name);
    XtGetResourceList(widget_class, &resources, &num_resources);
    PrintResources(resources, num_resources);
}

>When I call PrintWidget on an XmBulletinBoard it appears to walk the class
>hierarchy correctly because the class names print correctly.  However the
>resource list doesn't appear to be what I expect. I was expecting the resources
>and num_resource to be the same arrays used to initialize the widgets class 
>structure.  However, for the XmBulletinBoard it is giving num_resources as 54
>(I think) when the bulletin board only has 19 (I think) new resources.  The
>resource list appears to be anything but an array of XtResource's.

It is acutally the compiled resource list.  When the class is initialized
it turns all strings into quarks (which are unique numbers given a string).
This greatly speeds up the resource manipulation since it can then do a
simply compare rather than a costly string compare.  As for the reason why
there are 54 rather than 19 is that the compiled list includes the widget
class resources, but also includes all of the resource thru the superclass
hierarchy.

    while (widgetClass) {
        PrintResources(widgetClass->core_class.resources,
                       widgetClass->core_class.num_resources);
        widgetClass = widgetClass->core_class.superclass;
    }

Therefore your traversal thru the superclass hierarchy shouldn't be necessary
since this has already been done for you.

>
>What format are the resource & num_resources in after a widget of a given class
>has been created?

They are compiled resources or XrmResource list, which is defined in the
<IntrinsicP.h>.  Note that it's pretty much the same as the resource
structure, but uses XrmQuark instead of String.

typedef struct {
    XrmQuark	xrm_name;	  /* Resource name quark		*/
    XrmQuark	xrm_class;	  /* Resource class quark		*/
    XrmQuark	xrm_type;	  /* Resource representation type quark */
    Cardinal	xrm_size;	  /* Size in bytes of representation	*/
    long int	xrm_offset;	  /* -offset-1				*/
    XrmQuark	xrm_default_type; /* Default representation type quark	*/
    XtPointer	xrm_default_addr; /* Default resource address		*/
} XrmResource, *XrmResourceList;

>
>Thanks for any help.
>--
>===============================================================================
>Ian Hogg						ianhogg@cs.umn.edu
>                                                        (612) 424-6332

void PrintWidget(Widget w)
{
    int i;
    WidgetClass widgetClass = XtClass(w);

    for (i=0; i<widgetClass->core_class.num_resources;i++) {
	fprintf(stderr,"%s\n", XrmQuarkToString((XrmQuark)
		widgetClass->core_class.resources[i]->resource_name);
}

Anyway, you may want to play around with the above which is really all
you should need to print the widget resources.  Note that rather than calling
XtGetResourceList() you can use XrmQuarkToString() to convert a quark back
into a string.  I haven't tried this since i'm at home, but it may give
you a place to start.

			hope this helps,
				Mark

-----------------------------------------------------------------------------
Mark Young                         young@chama.eece.unm.edu
 
Khoros Group                       (505) 277-6563  (work)
University of New Mexico           Albuquerque,    NM 87131
-----------------------------------------------------------------------------
Xref: sparky comp.windows.x.intrinsics:503 comp.windows.x:18932