[comp.windows.x.motif] XmText: Change Font Smoothly?

alan@metasoft.UUCP (Alan Epstein) (04/17/91)

I've got a text widget which I move around when an edit window
is required. Each invocation may require a new font also.

What I do is create a font list (XmFontListCreate), and run XtSetValues
to set it. However, the widget normally tries to resize itself to the
new font size, so I call XtSetValues again with the original width/height
to bring it back to size.

Then I reparent the text widget via its parent (XReparentWindow), to insure
that the scrolled window and scrolled bars get moved, and finally I call
XMapRaised and XFlush so I can see the thing.

This all works as expected with one major drawback: each time the widget
comes up, it generates multiple exposures, and flashes very noticeably
in different sizes before it settles down.

If I use only one XtSetValues call for the font list and W/H, the
font list is ignored some of the time.

Is this a known problem, and is there a way around this unpleasantry?

I include code below for inquiring minds.

Thanks in advance.

-----------------------------
Alan Epstein
Meta Software Corp                   UUCP:  ...bbn!metasoft!alan
150 Cambridgepark Dr        Internet/ARPA:  alan%metasoft@bbn.com
Cambridge, MA 02140  USA
-----------------------------


/*	... init:   */
    n = 0;
    XtSetArg(args[n], XmNx, 0); n++;
    XtSetArg(args[n], XmNy, 0); n++;
    XtSetArg(args[n], XmNwidth, 100); n++;
    XtSetArg(args[n], XmNheight, 100); n++;
    XtSetArg(args[n], XmNborderWidth, 0); n++;
    XtSetArg(args[n], XmNscrollingPolicy, XmAPPLICATION_DEFINED); n++;
    XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
    XtSetArg(args[n], XmNscrollHorizontal, False); n++;
    XtSetArg(args[n], XmNscrollVertical, True); n++;
    XtSetArg(args[n], XmNwordWrap, True); n++;
    XtSetArg(args[n], XmNforeground, Text_ForeGround); n++;
    XtSetArg(args[n], XmNbackground, Text_BackGround); n++;
    XtSetArg(args[n], XmNmarginHeight, 0); n++;
    XtSetArg(args[n], XmNmarginWidth, 0); n++;
    MotifText = (Widget)XmCreateScrolledText(PopupShell, "text", args, n);
    XtManageChild(MotifText);

    XtRealizeWidget(PopupShell);
/* 	end of init ... */

-------------------------------------------------------------------------

/*	updater ... */

    tmpFontList = XmFontListCreate(&fontStruct, XmSTRING_DEFAULT_CHARSET);

    /* Set the dimensions and font of the Motif text widget */
    if (Local_XFontList != tmpFontList)
    {
	n = 0;
	XtSetArg(args[n], XmNfontList, tmpFontList); n++;
	XtSetValues(MotifText,args,n);
	if (Local_XFontList)
	{
	    XmFontListFree(Local_XFontList);
	}
	Local_XFontList = tmpFontList;
    }

    n = 0;
    XtSetArg(args[n], XmNwidth, W); n++;
    XtSetArg(args[n], XmNheight,H); n++;
    XtSetValues(MotifText,args,n);

    /* Make the text widget a child of the current page */
    XReparentWindow(XDisplay, XtWindow(XtParent(MotifText)),
		    XtWindow((Widget)win), X, Y);

    XMapRaised(XDisplay, XtWindow(XtParent(MotifText)));

    XFlush(XDisplay);

/*  end of updater ... */