qiu@inf.ethz.ch (Yonggang Qiu) (12/15/89)
I want to get users' input from several string text widgets in Xaw. So I try to make XtGetValues call on the XtNstring and the XtNselection. I don't know why I can't get correct texts. Making XtGetValues call on the XtNstring can only obtain text from last active one of text widgets. Making XtGetValues call on the XtNselection can't read texts at all. Moreover, it changes text in text widgets ( for example, "asd gfddgfdg" -->" asd g^@dg@d ") sometimes. The following is the program. Can anyone tell me how to obtain texts from several string text widgets of Xaw? Thanx in advance! Wish you Merry Christamas and Happy New Year! ---- Yonggang ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Yonggang Qiu Institute for Information-system | e-mail: qiu@inf.ethz.ch ETH-Zentrum | phone: (41-1) 254 7223 CH-8092 Zurich,Switzerland | fax: (41-1) 262 3973 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ======================================= X#include <stdio.h> X#include <strings.h> X#include <ctype.h> X#include <X11/Intrinsic.h> X#include <X11/Command.h> X#include <X11/Xlib.h> X#include <X11/StringDefs.h> X#include <X11/Shell.h> X#include <X11/Form.h> X#include <X11/Text.h> X#include <X11/Box.h> X#include <X11/AsciiText.h> X#define WIDTH 500 X#define HEIGHT 50 Widget toplevel; /* top widget */ Widget formw; Widget topboxwidget; Widget boxwidget[3]; Widget textwidget[3]; Widget test1widget; Widget test2widget; Arg args[20]; Cardinal i; static XrmOptionDescRec options[] = { {"-lable","*button.lable",XrmoptionSepArg, NULL} }; /********************************************************************** inf_text(textstr, parent ) -- Create string text widget to display string : textstr, return the widget **********************************************************************/ Widget inf_text(textstr, parent) /* display information in string text widget */ char *textstr; Widget parent; {Widget tw; i = 0; XtSetArg( args[i], XtNwidth,WIDTH); i++; XtSetArg( args[i],XtNheight,HEIGHT); i++; XtSetArg( args[i],XtNlength, 2000); i++; XtSetArg( args[i],XtNstring,textstr); i++; XtSetArg( args[i],XtNtextSource, NULL); i++; XtSetArg( args[i],XtNtextSink, NULL); i++; XtSetArg( args[i],XtNeditType, XttextEdit); i++; XtSetArg( args[i],XtNtextOptions, editable | scrollVertical | wordBreak); i++; tw = XtCreateManagedWidget("text",asciiStringWidgetClass,parent,args,i); return(tw); } /* end of inf_text() */ /********************************************************************** +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test1() --- GET TEXTS FROM SEVERAL TEXT WIDGET make XtGetValues call on XtNstring +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ **********************************************************************/ void test1(w,client_data, call_data) Widget w; caddr_t client_data; caddr_t call_data; { int j; char *str; for( j=0; j<3; j++) { XtSetArg( args[0], XtNstring, &str); XtGetValues(textwidget[j], args, 1 ); printf(" text string = %s\n",str); } } /* end of test1() */ /********************************************************************** +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test2() --- GET TEXTS FROM SEVERAL TEXT WIDGET make XtGetValues call on XtNselection +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ **********************************************************************/ void test2(w,client_data, call_data) Widget w; caddr_t client_data; caddr_t call_data; { int j; XtTextBlock text; XtTextSelectType selectall = { XtselectAll,XtselectNull }; for( j=0; j<3; j++) { XtSetArg( args[0], XtNselectTypes, selectall ); XtSetValues( textwidget[j], args, 1 ); XtSetArg( args[0], XtNselection, &text); XtGetValues(textwidget[j], args, 1 ); printf("text string= %s\n",text.ptr); XtTextUnsetSelection(textwidget[j]); } } /* end of test2() */ /********************************************************************** main(argc,argv) -- Creates widgets Events handing **********************************************************************/ void main(argc,argv) unsigned int argc; char **argv; { int row; toplevel = XtInitialize("main","Demo",options,XtNumber(options), &argc,argv); formw = XtCreateManagedWidget("FormW",formWidgetClass,toplevel,args,0); test1widget = XtCreateManagedWidget("XtNstring",commandWidgetClass,formw,args,0); XtAddCallback(testwidget, XtNcallback,test1,NULL); XtSetArg( args[0], XtNfromHoriz, test1widget); test2widget = XtCreateManagedWidget("XtNselection",commandWidgetClass,formw,args,1); XtAddCallback(testwidget, XtNcallback,test2,NULL); i = 0; XtSetArg( args[i], XtNwidth, WIDTH); i++; XtSetArg( args[i], XtNfromVert, test1widget); i++; topboxwidget = XtCreateManagedWidget("Box",boxWidgetClass,formw,args,i); for ( row=0; row<3; row++) boxwidget[row] = XtCreateManagedWidget("Box",boxWidgetClass,topboxwidget,args,0); textwidget[0] = inf_text("text 0",boxwidget[0] ); textwidget[1] = inf_text("text 1",boxwidget[1] ); textwidget[2] = inf_text("text 2",boxwidget[2] ); XtRealizeWidget(toplevel); /* Realize widgets */ XtMainLoop(); /* event handing */ } /* end of main() */ ===================================================