[comp.windows.x] More widget size strangeness

battle@alphard.cs.utk.edu (David Battle) (05/30/89)

I am having more troubles with widget sizing.  This time apparently as a
result of a slightly untimely XtSetValues().  The problem is this: I have
a program which (for reasons I will attempt to get away without explaning)
needs to change the label on some command widgets between the time they are
created and the time they are realized.  This has the unfortunate (and
to my knowledge undocumented) side effect of causing the widget to ignore
its defaults for width and height.  The following program illustrates.

The relevant resources in effect at the time of the invocation of this program
are:

Broken*dunno.borderColor:     blue
Broken*dunno.height:    200
Broken*dunno.width:     200

This program may be invoked in three different modes.

csh> broken &
csh> broken before &
csh> broken after &

With no arguments, the program does not attempt to change the command button's
label at all.  This results in a correctly sized and colored widget
(according to the defaults).  The label is, of course, unchanged (it is
still "dunno").

With the single argument "before" it attempts to change the command button's
label before it is realized.  This results in the widget of the same size it
would have been had the defaults not been present (this is the problem).
The borderColor, however, is correct.

With the single argument "after" it attempts to change the command button's
label after it is realized.  This works fine, resulting in a correctly
sized, labeled, and colored widget.  As I explained before, however, I
sometimes need to change the label before realization.  I don't think this
is an unreaonable thing to want to do.

In all cases the label is changed (or not) as it should be.  The problem
is the side effects.

XtChain doesn't seem to be strong enough to keep this widget from misbehaving.
Perhaps we need to add XtStock for use on really *tough* customers like this
one.

                                                David Lane Battle
                                                battle@utkcs2.cs.utk.edu
                                                battle@esddlb.esd.ornl.gov

---cut here---

/*
    broken.c

    compile with:

    cc broken.c -o broken -lXaw -lXt -lXmu -lX11
*/

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/Command.h>
#include <X11/Form.h>
#include <X11/StringDefs.h>

void quit()
{
    exit(0);
}

main(argc,argv)
char **argv;
{
    Widget toplevel, form, command;
    static XtCallbackRec callback[] = {
        { quit, NULL },
        { NULL, NULL },
    };
    static Arg args[] = {
        { XtNcallback, (XtArgVal) callback },
        { XtNtop, (XtArgVal) XtChainTop },
        { XtNbottom, (XtArgVal) XtChainTop },
        { XtNleft, (XtArgVal) XtChainLeft },
        { XtNright, (XtArgVal) XtChainLeft },
    };
    static Arg commandlabel_args[] = {
        { XtNlabel, (XtArgVal) "cyanide" },
    };
    int before = 0, after = 0;
    int i;


    toplevel=XtInitialize("broken", "Broken", 0, 0, &argc, argv);
    if(argc > 1 && !strcmp(argv[1], "before"))
        before = 1;
    if(argc > 1 && !strcmp(argv[1], "after"))
        after = 1;
    form = XtCreateManagedWidget("form", formWidgetClass, toplevel, 0, 0);
    command = XtCreateManagedWidget("dunno",commandWidgetClass, form, args, 1);
    if(before)
        XtSetValues(command, commandlabel_args, XtNumber(commandlabel_args));
    XtRealizeWidget(toplevel);
    if(after)
        XtSetValues(command, commandlabel_args, XtNumber(commandlabel_args));
    XtMainLoop();
}