[comp.windows.x] XmLabel question

argv@turnpike.Eng.Sun.COM (Dan Heller) (09/06/90)

In article <6265@adobe.UUCP> asente@adobe.com (Paul Asente) writes:
> >    *label string.labelString: another label
> >
> >This means: all widgets that have the name "label string" should use a
> >label string that says: "another label".
>   This bit, however, isn't quite right.  Space is not a legal character
> in a resource specification, so the above line is not a valid resource
> specification.

As someone else pointed out, "it seems to work" and it always has.
I must confess, I didn't think it would work, so I tested it and it
did.  so, I thought that the MIT documentation was wrong.. My error.

Something else occured to me that I figured I should mention.  This
is something that I do frequently.

Consider the problem of the desire to set all buttons a of particular
type to "red".  However, you don't want to do:

    *PushButton.foreground: red

because you don't want to set *all* pushbuttons, just those of a
particular type.  For example, you might want to set the color of
all the *default* buttons (those in an action area, for example)
to red, but all the other pushbuttons in the group should be blue.

Remember that widgets need not have *unique* names.  By creating
widgets with identical names, you can set resources for the entire
lot using one resource:

    *default_button.foreground: red
    *other_button.foreground: blue

The coresponding code might be:

    ok_str = XmStringCreateSimple(parent, "Ok");
    XtVaCreateManagedWidget("default_button", xmPushButtonWidgetClass, parent,
	XmNlabelString, ok_str,
	NULL);
    XmStringFree(ok_str);

    cancel_str = XmStringCreateSimple(parent, "Cancel");
    XtVaCreateManagedWidget("other_button", xmPushButtonWidgetClass, parent,
	XmNlabelString, cancel_str,
	NULL);
    XmStringFree(cancel_str);

    help_str = XmStringCreateSimple(parent, "Help");
    XtVaCreateManagedWidget("other_button", xmPushButtonWidgetClass, parent,
	XmNlabelString, help_str,
	NULL);
    XmStringFree(help_str);

Notice that the cancel and help pushbuttons have the same "name", but
have different labelstrings.  This allows the resources to work as I
described.  Note: you can set the name of a widget to the emptry string
(""), but you can't set resources on it.
--
dan
----------------------------------------------------
O'Reilly && Associates   argv@sun.com / argv@ora.com
Opinions expressed reflect those of the author only.