BUG in lesstif - does not size text widget properly,
forcing a call to its resize intrinsic fixes things.

Test program scrollTextBug.c shows this...
see attachment.

Clicking on Popup creates a popup dialog
shell --> form --> scrolled text widget combo
               --> push button gadget "Done"
Notice that the text is not sized properly.
However resizing (click and drag) of the dialog gives correct appearance.

Invoke program with argument "hack"
e.g. scrollTextBug hack
Notice that the text has correct appearance.
This hack works by managing the form,
getting the dimensions of the scroll window
and modifying them so it's resize intrinsic
(and it's childrens') are called.
NOTE: both width and height must change to force resize in both dimensions.

Also note that similar appearance is exhibited by
lesstif-0.92.40/test/Xm/text/test14.c

I assume that somehow during widget initialization the width and
height are not being propagated correctly, or the resize intrinsic
is not doing it's job.  I don't know enough about the internals to
trace down the error.  But hopefully this work around hack will give
some knowledgeable person a hint at the solution.

Thanks,

-------------------------------------------------------------------------------
Dale M. Walker      FlightSafety International| RA: Liz Little   __o --o
[EMAIL PROTECTED] 5695 Campus Parkway       |         Walker _-\<.-\<,
314-551-8594        St. Louis MO 63042        | '94 Sovereign (*)-%--% (*)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <Xm/Xm.h>
#include <Xm/DialogS.h>
#include <Xm/MenuShell.h>
#include <Xm/Text.h>
#include <Xm/PushBG.h>
#include <Xm/Form.h>
#include <Xm/ScrolledW.h>
#include <Xm/PanedW.h>
#include <Xm/MainW.h>
#include <Xm/RowColumn.h>
#include <Xm/CascadeB.h>

static XtAppContext     app_context;
static Widget           topLevel, dialog, textw;

static int              hack;


static void popdown(Widget w, XtPointer cd, XtPointer cb)
{
    XtUnmanageChild(XtParent(w));
}

static void create_textDialog(void)
{
    Widget      w, sw;
    Arg         args[8];

    w = XtVaCreatePopupShell( "dialogShell",
                    xmDialogShellWidgetClass, topLevel,
                    NULL );

    /* Motif groups the shell with it's child, both are managed
    ** via the shell's child
    */
    dialog = XtVaCreateWidget( "dialog",
                    xmFormWidgetClass, w,
                    NULL );

    w = XtVaCreateManagedWidget("Done",
                xmPushButtonGadgetClass, dialog,
                XmNleftAttachment, XmATTACH_FORM,
                XmNrightAttachment, XmATTACH_FORM,
                XmNbottomAttachment, XmATTACH_FORM,
                NULL);
    XtAddCallback(w, XmNactivateCallback, popdown, NULL);

    XtSetArg(args[0], XmNheight, 300);
    XtSetArg(args[1], XmNcolumns, 80);
    XtSetArg(args[2], XmNeditable, False);
    XtSetArg(args[3], XmNeditMode, XmMULTI_LINE_EDIT);
    XtSetArg(args[4], XmNwordWrap, True);
    XtSetArg(args[5], XmNscrollVertical, True);
    XtSetArg(args[6], XmNscrollHorizontal, False);
    XtSetArg(args[7], XmNcursorPositionVisible, False);
    textw = XmCreateScrolledText(dialog, "dialogText", args, 8);

    XtVaSetValues(XtParent(textw),
                XmNtopAttachment, XmATTACH_FORM,
                XmNleftAttachment, XmATTACH_FORM,
                XmNrightAttachment, XmATTACH_FORM,
                XmNbottomAttachment, XmATTACH_WIDGET,
                XmNbottomWidget, w,
                NULL);

    XtManageChild(textw);

    if (hack)
    {
        /* BUG in lesstif - does not size text widget properly
        ** forcing a call to its resize intrinsic fixes things.
        ** This hack works by managing the form,
        ** getting the dimensions of the scroll window
        ** and modifying them so it's resize intrinsic
        ** (and it's childrens') are called.
        ** NOTE: both width and height must change to force resize in
        ** both dimensions.
        */
        Dimension       width, height;

        XtManageChild(dialog);

        XtVaGetValues(XtParent(textw),
                        XmNheight, &height,
                        XmNwidth, &width,
                        NULL);
        XtVaSetValues(XtParent(textw),
                        XmNheight, height+1,
                        XmNwidth, width+1,
                        NULL);
    }
}


static void callback(Widget w, XtPointer cd, XtPointer cb)
{
    char        *text = "This is just a bit of text to display...\n"
"The Gettysberg Address\n"
"Abraham Lincoln\n"
"November 19, 1863\n"
"Gettysburg, Pennsylvania\n"
"\n"
"Four score and seven years ago our fathers brought forth on this continent, "
"a new nation, conceived in Liberty, and dedicated to the proposition that "
"all men are created equal.\n"
"Now we are engaged in a great civil war, testing whether that nation, or "
"any nation so conceived and so dedicated, can long endure. We are met on "
"a great battle-field of that war. We have come to dedicate a portion of "
"that field, as a final resting place for those who here gave their lives "
"that that nation might live. It is altogether fitting and proper that we "
"should do this.\n"
"But in a larger sense, we can not dedicate -- we can not consecrate -- "
"we can not hallow -- this ground. The brave men, living and dead, who "
"struggled here, have consecrated it, far above our poor power to add or "
"detract. The world will little note, nor long remember, what we say here, "
"but it can never forget what they did here. It is for us the living, "
"rather, to be dedicated here to the unfinished work which they who "
"fought here have thus far so nobly advanced. It is rather for us to be "
"here dedicated to the great task remaining before us -- that from these "
"honored dead we may take increased devotion to that cause for which they "
"gave the last full measure of devotion -- that we here highly resolve "
"that these dead shall not have died in vain -- that this nation, under "
"God, shall have a new birth of freedom -- and that government of the "
"people, by the people, for the people, shall not perish from the earth.";

    if (dialog == NULL) create_textDialog();
    XtManageChild(dialog);

    XtUnmanageChild(textw);
    XmTextSetString(textw, text);
    XtManageChild(textw);
}



int main(int argc, char *argv[])
{
    Widget      mainW, popup, push;

    if (argc > 1 && strcmp("hack", argv[1]) == 0) hack = 1;

    topLevel = XtAppInitialize( &app_context, "textTest", NULL, 0,
                                &argc, argv, NULL, NULL, 0 );

    mainW = XmCreateMainWindow(topLevel, "mainW", NULL, 0 );

    popup = XmCreateMenuBar( mainW, "menuBar", NULL, 0 );
    XtManageChild( popup );

    push = XmCreateCascadeButton( popup, "Popup", NULL, 0 );
    XtManageChild( push );
    XtAddCallback( push, XmNactivateCallback, callback, NULL);

    XtManageChild( mainW );
    XtRealizeWidget( topLevel );
    XtAppMainLoop( app_context );
    return 0;
}

Reply via email to