XawtextRead The user can't change any of the text in the text widget XawtextAppend The user can only add text to the end of the text buffer and modify the entered text, the user cannot modify the original contents of the buffer XawtextEdit The user can freely modify any of the text that is in the buffer, no restriction are placed on modification
XawtextScrollNever Never use a scrollbar in this direction XawtextScrollAlways Always use a scrollbar in this direction XawtextScrollWhenNeeded Only place a scrollbar on the widget when the complete contents of the text buffer can't be displayed in the window
/******************************************************************* * * text1 * * Simple test program to show of the text widget * *****************************************************************/ #include < X11/StringDefs.h > #include < X11/Intrinsic.h > #include < X11/Xaw/Form.h > #include < X11/Xaw/AsciiText.h > #include "../lib/lib.h" main(argc,argv) int argc; char **argv; { Widget toplevel; Widget form; Widget quit; Widget text; int n; Arg wargs[10]; toplevel = XtInitialize(argv[0],"text",NULL,0, &argc,argv); if(argc != 2) { printf("usage: text1 [ x options ] filename\n"); exit(1); } form = XtCreateManagedWidget("form", formWidgetClass, toplevel, NULL, 0); quit = quit_button(form); n = 0; XtSetArg(wargs[n], XtNfromVert, quit); n++; XtSetArg(wargs[n], XtNtype, XawAsciiFile); n++; XtSetArg(wargs[n], XtNstring, argv[1]); n++; XtSetArg(wargs[n], XtNwidth, 400); n++; XtSetArg(wargs[n], XtNheight, 500); n++; XtSetArg(wargs[n], XtNscrollHorizontal, XawtextScrollWhenNeeded); n++; XtSetArg(wargs[n], XtNscrollVertical, XawtextScrollAlways); n++; text = XtCreateManagedWidget("text", asciiTextWidgetClass, form, wargs, n); XtRealizeWidget(toplevel); XtMainLoop(); }
XawTextSetSelection(w, left, right) Widget w; long left; long right;
XawTextUnsetSelection(w) Widget w;
XawTextGetSelectionPos(w, begin, end) Widget w; long *begin; long *end;
int XawTextReplace(w, start, end, text) Widget w; long start; long end; XawTextBlock *text;
typedef struct { int firstPos; int length; char *ptr; unsigned long format; } XawTextBlock, *XawTextBlockPtr;
XawEditDone the text replacement was successful XawPositionError in append mode the start position is not the last character in the buffer XawEditError the source is read only, or the range to be deleted is larger than the text buffer
XawAsciiSave(w) Widget w; XawAsciiSaveAsFile(w, name) Widget w; char *name;
/******************************************************************* * * text2 * * Simple test program to show of the text widget * *****************************************************************/ #include < X11/StringDefs.h > #include < X11/Intrinsic.h > #include < X11/Xaw/Command.h > #include < X11/Xaw/Form.h > #include < X11/Xaw/AsciiText.h > #include "../lib/lib.h" char filename[] = "filename: "; char no_file_message[] = " ***** no file selected **** "; Widget fname; Widget quit; Widget text; Widget form; void text_call(w, client, call) Widget w; XtPointer client; XtPointer call; { static Widget source = 0; int len; char *name; char *string; int n; Arg wargs[5]; XawTextBlock block; static int busy = 0; if(busy) return; busy = 1; if(source == 0) { n = 0; XtSetArg(wargs[n], XtNtextSource, &source); n++; XtGetValues(fname, wargs, n); } n = 0; XtSetArg(wargs[n], XtNstring, &string); n++; XtGetValues(source, wargs, n); len = strlen(string); if(string[len-1] == '0) { name = (char *) malloc(len-9); strcpy(name,string+10); name[len-11] = 0; block.firstPos = 0; block.length = 0; XawTextReplace(fname, 10, len+1, &block); n = 0; XtSetArg(wargs[n],XtNinsertPosition, 10); n++; XtSetArg(wargs[n],XtNdisplayPosition, 0); n++; XtSetValues(fname, wargs, n); n = 0; XtSetArg(wargs[n], XtNtype, XawAsciiFile); n++; XtSetArg(wargs[n], XtNstring, name); n++; XtSetValues(text, wargs, n); } busy = 0; } void open_command(w, client, call) Widget w; XtPointer client; XtPointer call; { Widget source; int n; Arg wargs[10]; char *string; int len; char *name; XawTextBlock block; n = 0; XtSetArg(wargs[n], XtNtextSource>
name, wargs, n); n = 0; XtSetArg(wargs[n], XtNstring, &string); n++; XtGetValues(source, wargs, n); len = strlen(string); name = (char *) malloc(len-9); strcpy(name,string+10); block.firstPos = 0; block.length = 0; XawTextReplace(fname, 10, len, &block); n = 0; XtSetArg(wargs[n],XtNinsertPosition, 10); n++; XtSetArg(wargs[n], XtNdisplayPosition, 0); n++; XtSetValues(fname, wargs, n); n = 0; XtSetArg(wargs[n], XtNtype, XawAsciiFile); n++; XtSetArg(wargs[n], XtNstring, name); n++; XtSetValues(text, wargs, n); } main(argc,argv) int argc; char **argv; { Widget toplevel; Widget source; Widget command; int n; Arg wargs[10]; toplevel = XtInitialize(argv[0],"text",NULL,0, &argc,argv); form = XtCreateManagedWidget("form", formWidgetClass, toplevel, NULL, 0); quit = quit_button(form); n = 0; XtSetArg(wargs[n], XtNfromVert, quit); n++; XtSetArg(wargs[n], XtNtype, XawAsciiString); n++; XtSetArg(wargs[n], XtNwidth, 400); n++; XtSetArg(wargs[n], XtNheight, 500); n++; XtSetArg(wargs[n], XtNstring, no_file_message); n++; XtSetArg(wargs[n], XtNscrollHorizontal, XawtextScrollWhenNeeded); n++; XtSetArg(wargs[n], XtNscrollVertical, XawtextScrollAlways); n++; text = XtCreateManagedWidget("text", asciiTextWidgetClass, form, wargs, n); command = XtCreateManagedWidget("open",commandWidgetClass, form, NULL, 0); n = 0; XtSetArg(wargs[n], XtNfromHoriz, quit); n++; XtSetValues(command, wargs, n); XtAddCallback(command, XtNcallback, open_command, 0); n = 0; XtSetArg(wargs[n], XtNfromHoriz, command); n++; XtSetArg(wargs[n], XtNtype, XawAsciiString); n++; XtSetArg(wargs[n], XtNstring, filename); n++; XtSetArg(wargs[n], XtNwidth, 200); n++; XtSetArg(wargs[n], XtNeditType, XawtextEdit); n++; XtSetArg(wargs[n], XtNinsertPosition, 10); n++; fname = XtCreateManagedWidget("filename",asciiTextWidgetClass, form, wargs, n); n = 0; XtSetArg(wargs[n], XtNtextSource, &source); n++; XtGetValues(fname, wargs, n); n = 0; XtSetArg(wargs[n], XtNdataCompression, FALSE); n++; XtSetValues(source, wargs, n); XtAddCallback(source, XtNcallback, text_call, NULL); XtRealizeWidget(toplevel); XtMainLoop(); }