serge@optigfx.com (Serge Issakov) (12/18/90)
GENERAL:
I have a simple user-defined widget which captures keyboard input
via default translations using the "Keypress" translation. This
widget is a child of a Motif XmForm widget. The action proc simply
does a printf("got a key\n"). My problem is that the Escape,
Return and Enter keys are ignored. Pressing any other keys results
in the "got a key" message getting printed.
If I don't use the XmForm widget, but just make my widget
a direct child of the toplevel widget, then everything
works fine.
Has anyone run into this? What is special about the Escape, Return,
and Enter keys that would cause them to be treated differently?
ENVIRONMENT: Sparc, SunOS 4.1, X11R4, Motif 1.1
DETAILS:
To recreate this problem in a simple program, I modified the dial
widget example from section 12.2 of Douglas A. Young's, "The X
Window System Programming and Applications with Xt" (Motif
edition).
I added "KeyPress" to the defaultTranslations array:
static char defaultTranslations[] =
"<Btn1Down>: select()\n<KeyPress>: Input()";
And I added a new action proc:
static XtActionsRec actionsList[] = {
{ "select", (XtActionProc) select_dial},
{ "Input", Input }, /* NEW */
};
static void
Input(w, event, args, n_args)
XsDialWidget w;
XEvent *event;
char *args[];
int n_args;
{
printf("Input: got a key\n");
}
With just these changes, the program works as expected: pressing
any key while the pointer is in the dial results in the "got a key"
message.
But, if I also put a Motif form widget in between the top level
widget and the dial widget, pressing the Escape, Return and Enter keys
no longer results in the message being printed (but all other keys still
work).
The following code shows how I add in the form widget:
-----------------------------------
main(argc, argv)
char **argv;
{
Widget toplevel, dial;
#ifdef DONT_USE_FORM
/* this works */
toplevel = XtInitialize(argv[0], "DialTest", NULL,
0, &argc, argv);
dial = XtCreateManagedWidget("dial", XsdialWidgetClass,
toplevel, NULL, 0);
#else
/* this doesn't (for Return, Escape and Enter) */
Widget form;
toplevel = XtInitialize(argv[0], "DialTest", NULL,
0, &argc, argv);
form = XmCreateForm(toplevel, "form", NULL, 0);
XtManageChild(form);
dial = XtCreateManagedWidget("dial", XsdialWidgetClass,
form, NULL, 0);
#endif
XtAddCallback(dial, XtNselectCallback,
select_callback, NULL);
XtRealizeWidget(toplevel);
XtMainLoop();
} /* main */
-----------------------------------
How can the form widget be affecting keyboard input like this?
Thanks in advance...
-----------------------------------------------------------------------------
Serge Issakov serge@optigfx.COM
Optigraphics Corp. uunet!optigfx!serge
San Diego CA 619-292-6060