Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!snorkelwacker!bloom-beacon!EXPO.LCS.MIT.EDU!kit From: kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) Newsgroups: comp.windows.x Subject: Re: Widget questions Message-ID: <9002212306.AA03914@expo.lcs.mit.edu> Date: 21 Feb 90 23:06:18 GMT References: <8037@pt.cs.cmu.edu> Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 65 > As a beginning of the Widget user, I am not sure how to use dialogWidgets. > What I need is to "gets" a string into a buffer when the string is typed > into the dialog window along with a carriage return (just like a regular > gets() does). I understand that I may be able to use > XtDialogGetValueString, but I don't know how the Xserver can inform the > dialog Widget that the string has been typed in. I tried to use the > client callback interface, but couldn't find the appropriate resourse in the > dialog resource database listed in the X11/R3 X Toolkit Athena Widgets > Manual (yes, I am still using X11/R3). You can certainly perform operations similar to gets() with widgets, the interface is a bit different, however, as well as the style of programming. To really do this in the X model you need to have an event driven interface. This to say rather than doing this: . . . printf("enter a value"); gets(string); PerformOperation(string); } You would do this: . . . PutUpDialogBox("enter a value"); return(); } PutUpDialogBox(string) { /* Create box, and bind function DialogReturn() to the action of the user saying that the string has been entered. */ } DialogReturn(dialog, ...) { string = XtDialogGetValueString(dialog); PreformOperation(string); } Basically it is the assumption that your application is just performing a bunch of operations, based on the actions of the user within the user interface. There is no longer a single line of obvious program flow control. Once you have bitten off this change in logic, using a dialog box to get a string from the user should be pretty simple. You simple create a dialog box with the proper prompt, and position it on the display. The you drop back into XtAppMainLoop() and wait until your callback routine that is bound to the "okay" button is called. When this happens you get the string from the dialog box's text entry field, pop down the dialog box, and off you go. To bind the action of carridge return in the dialog's text entry widget to the same action as the "okay" buttin you need to define a global application action and bind it to a keypress of carridge_return in that text widget, by modifying that widget's translation table. This is most easily accomplished using the resource database, and an app-defaults file. Take a look at the Xt Specification under XtAppAddActions(), and the Text widget's translation table.