Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!caen!zaphod.mps.ohio-state.edu!wuarchive!emory!wrdis01!mips!pacbell.com!pacbell!sactoh0!csusac!unify!Unify.com!grp From: grp@Unify.com (Greg Pasquariello) Newsgroups: comp.windows.x Subject: Re: X/OLIT question Message-ID: <1991Mar5.093828@Unify.com> Date: 5 Mar 91 17:38:28 GMT References: Sender: news@Unify.Com (news admin) Reply-To: grp@Unify.com (Greg Pasquariello) Organization: Unify Corporation, Sacramento, CA, USA Lines: 110 In article , fm@neptune.iex.com (Mohammad Faroog) writes: > > 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. Your problem is that you are installing the event handler on the wrong widget. The TextField widget is made up of a sub-widget called the TextEdit widget. You need to get the id of that sub-widget, and install the event handler on it. The id of the sub-widget can be had by getting the resource XtNtextEditWidget on the TextField. I have modified your example slightly to demonstrate. The modifications are marked with comments. > > 1- I used XtAddEventHandler() > > 1- I modified widget's translation table. > > Method - 1 code example : > > #include > #include > > #include > #include > > #include > #include > #include > #include > #include > > myhandler() > { > fprintf(stderr,"hello world"); > } > > void main(argc, argv) > unsigned int argc; > char *argv[]; > { > Arg warg; /* MODIFICATION */ Widget subWid; /* MODIFICATION */ > 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 > ); XtSetArg(wargs, XtNtextEditWidget, &subWid); /* MODIFICATION */ XtGetValues(w_text, warg, 1); /* MODIFICATION */ XtAddEventHandler(subWid, KeyPressMask, /* MODIFICATION */ FALSE, myhandler, NULL); > > XtManageChild(w_form); > (void) XtRealizeWidget(w_toplevel); > > (void) XtMainLoop(); > } > > Mohammad Farooq. > > address: fm@iex.com -- --- Greg Pasquariello grp@unify.com Unify Corporation Be good and never poison people