[comp.windows.x] Losing chars to a pop-up

de@comp.lancs.ac.uk (David England) (03/06/89)

I writing a graph editor and want to have editable text labels.
At the moment I pop up a text widget when the user clicks the mouse 
in the parent window and then starts typing. The first letter pops up
the asciiStringWidget. However any text typed after the first character
and before the widget appears is lost. I've tried buffering up
these characters and adding them to the text source but there's
always a delay between setting the text source and the appearance
of the widget. Does anyone have any better ideas e.g. using selection
buffers and pasting that in ? (Don't know how to do that)
Here's my current attempt;

char *
pop_up_text(ch, textX, textY)
int ch;
int textX;
int textY;
{
    static Arg popup_args[]={
        {XtNx, (XtArgVal)0},
        {XtNy, (XtArgVal)0} };
    int new_x, new_y;
    char buffer[2];
    Window tempchild;

    if (isalpha(ch)) {
            sprintf(buffer,"%c",ch);
	     sprintf(textBuffer,"%s",buffer);
            fprintf(debug_fp,"text buffer before %s\n",textBuffer);
    }


    textLabel = makeStringBox(textBox, textBuffer, 120,1);

    XtTextSetInsertionPoint(textLabel, 1);

    XtSetKeyboardFocus(textBox, textLabel);
    XTranslateCoordinates(display, XtWindow(editCanvas), root, textX, textY,
                         &new_x, &new_y, &tempchild);

    popup_args[0].value = (XtArgVal)new_x;
    popup_args[1].value = (XtArgVal)new_y;

    /* pop_up via Xtk routines @ new_x, new_y*/
    XtSetValues(textPopup, popup_args, XtNumber(popup_args));

    XtPopup(textPopup, XtGrabNone);

    return (textBuffer);
}

appendToken(ch)
int ch;
{
    char buffer[2];

    if (isalpha(ch)) {
            sprintf(buffer,"%c",ch);
            strcat(textBuffer,buffer);
            fprintf(debug_fp,"text buffer before %s\n",textBuffer);
    }
}
-- 
uucp:   ...!mcvax!ukc!dcl-cs!de or: ...!uunet!comp.lancs.ac.uk!de
arpa/janet: de@comp.lancs.ac.uk 
"The Bluebird of happiness long absent from his life,
Ned is visited by the chicken of depression"

swick@ATHENA.MIT.EDU (Ralph R Swick) (03/08/89)

Can't tell from your code extract what the instance hierarchy is
between textBox, textPopup and textLabel but you want to make
sure that the keyboard focus for the _child_ of the popup shell
is appropriately set before calling XtPopup.