[comp.windows.open-look] X Question

fm@neptune.iex.com (Mohammad Faroog) (03/01/91)

I have just started programming in X. I came accross a couple of problems. 
Is there anyone who can explain me why it is not doing what I think it suppose
to do.

I am using textfield widget of openlook intrinsics toolkit. What I want to do
when ever pointer is in the field and if user presses any key widget should call
application supplied function. As you know textfield widget doesn't offer 
any call back of that kind. So I tried to solve this problem by to different
methods. 

1- I used XtAddEventHandler()

1- I modified widget's translation table.

Method - 1 code example :

#include <stdio.h>
#include <errno.h>

#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>

#include <Xol/OpenLook.h>
#include <Xol/ControlAre.h>
#include <Xol/TextField.h>
#include <Xol/Form.h>
#include <Xol/Caption.h>

myhandler()
{
	fprintf(stderr,"hello world");
}

void main(argc, argv)
unsigned int argc;
char *argv[];
{

	Widget w_toplevel, w_form, w_text, w_caption;

	w_toplevel = OlInitialize(
		NULL, 				/* app name - filled by Xt */
		"Event", 			/* app class */
		NULL,				/* option list */
		0,					/* # of options */
		&argc, 				/* addr of main argc */
		argv				/* main argv */
	);

	w_form = XtVaCreateWidget(	/* create form widget */
		"form",
		formWidgetClass,
		w_toplevel,
		XtNxResizable,FALSE, XtNyResizable, FALSE, NULL
	);

	w_caption = XtVaCreateManagedWidget(
       "fieldLabel",
       captionWidgetClass,
       w_form,
       XtNlabel,   "File Name:", 0
    );

	w_text = XtVaCreateManagedWidget(
		"textfield",
		textFieldWidgetClass,
		w_caption, 
		XtNwidth,    200,
		NULL
     );
	XtAddEventHandler(w_text,KeyPressMask,FALSE,myhandler,NULL);

	XtManageChild(w_form); 
	(void) XtRealizeWidget(w_toplevel);

	(void) XtMainLoop();
}

What I expected, while pointer is in the text field, when user presses any key
myhandler() will be called. Somehow it does not do anything like that. But If I
change KeyPressMask to StructureNotifyMask then it calls myhandler().

Method - 2 example code:

#include <stdio.h>
#include <errno.h>

#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>

#include <Xol/OpenLook.h>
#include <Xol/TextField.h>
#include <Xol/Form.h>
#include <Xol/Caption.h>

XtActionProc Myfunc()
{
	fprintf(stderr,"hello world");
}

void main(argc, argv)
unsigned int argc;
char *argv[];
{
	static XtActionsRec new_actions[] = {
		{"myfunc",(XtActionProc) Myfunc}
		};
	Widget w_form, w_caption, w_text;

	XtAppContext app_context;
	Widget w_toplevel;

	w_toplevel = OlInitialize(
		NULL, 				/* app name - filled by Xt */
		"Trans",	 		/* app class */
		NULL,				/* option list */
		0,					/* # of options */
		&argc, 				/* addr of main argc */
		argv				/* main argv */
	);

	app_context = XtWidgetToApplicationContext(w_toplevel);
	XtAppAddActions(app_context,new_actions,XtNumber(new_actions));

	w_form = XtVaCreateWidget(	/* create form widget */
		"form",
		formWidgetClass,
		w_toplevel,
		XtNxResizable,FALSE, XtNyResizable, FALSE, NULL
	);

	w_caption = XtVaCreateWidget(
       "fieldLabel",
       captionWidgetClass,
       w_form,
	   NULL
    );

	w_text = XtVaCreateManagedWidget(
		"textfield",
		textFieldWidgetClass,
		w_caption, 
		XtNwidth,    200,
		NULL
     );

	XtManageChild(w_caption); 
	XtManageChild(w_form); 
	(void) XtRealizeWidget(w_toplevel);

	(void) XtMainLoop();
}

Resource table for 2nd method:

*label:File Name: 
*textfield.translations: #override\n\
<Key>:myfunc()

Every time I press any key I can see the text in the field, but myfunc() is 
never called. Am I missing something? I was reading openlook GUI RM it says 
in the core widget's resources that application should not change 
XtNtranslations. One thing surprise me that unlike motif, openlook toolkit 
documentation does not provide info. about the default translation table of
its wiget set. Does it mean we should not modify wigdet's translation table?
I will appreciate if you point me to the right direction.

Mohammad Farooq.