#include #include #include #include #include #include #include #include #include #include #include XtAppContext app; Widget linetext; /* pass the Widget to be toggled as the client data */ void togglefunc(Widget w, XtPointer client, XtPointer call) { if (XtIsManaged(client)) XtUnmanageChild(client); else XtManageChild(client); } void quitfunc(Widget w, XtPointer client, XtPointer call) { XtAppSetExitFlag(app); } void linetextfunc(Widget w, XtPointer client, XtPointer call) { static int busy = 0; if (busy) return; busy = 1; Widget bigsink = (Widget)client; XawTextBlock tb; tb.firstPos = 0; tb.format = XawFmt8Bit; char *s; size_t len; XtVaGetValues(w, XtNstring, &s, NULL); len = strlen(s); if (len == 0) return; else if (len == 1 && s[0] == '\n') { //XtVaSetValues(w, XtNstring, "", NULL); tb.length = 0; tb.ptr = ""; XawTextReplace(linetext, 0, 1, &tb); } else if (s[len - 1] == '\n') { printf("'%s'\n", s); XtVaSetValues(w, XtNstring, "", NULL); //XtVaSetValues(bigsink, XtNstring, s, NULL); tb.length = len; tb.ptr = s; Widget sink; char *t; size_t end; XtVaGetValues(bigsink, XtNtextSource, &sink, NULL); XtVaGetValues(sink, XtNstring, &t, NULL); end = strlen(t); int r = XawTextReplace(bigsink, end, end, &tb); printf("Replace returned %d\n", r); } XawAsciiSourceFreeString(w); busy = 0; } int main(int argc, char **argv) { Widget w, box, quit, command, label, bigtext, bigsink, linesource; Arg args[10]; int n; w = XtVaOpenApplication(&app, "BEN-TEST", NULL, 0, &argc, argv, NULL, sessionShellWidgetClass, NULL); box = XtCreateManagedWidget("box", boxWidgetClass, w, NULL, 0); n = 0; XtSetArg(args[n], XtNlabel, "Quit"); n++; quit = XtCreateManagedWidget("command", commandWidgetClass, box, args, n); XtAddCallback(quit, XtNcallback, quitfunc, NULL); n = 0; XtSetArg(args[n], XtNlabel, "Hello World!"); n++; label = XtCreateManagedWidget("label", labelWidgetClass, box, args, n); n = 0; XtSetArg(args[n], XtNlabel, "press me"); n++; XtSetArg(args[n], XtNheight, 100); n++; XtSetArg(args[n], XtNwidth, 200); n++; command = XtCreateManagedWidget("command", commandWidgetClass, box, args, n); XtAddCallback(command, XtNcallback, togglefunc, label); n = 0; XtSetArg(args[n], XtNeditType, XawtextAppend); n++; XtSetArg(args[n], XtNscrollHorizontal, XawtextScrollWhenNeeded); n++; XtSetArg(args[n], XtNscrollVertical, XawtextScrollWhenNeeded); n++; XtSetArg(args[n], XtNheight, 300); n++; XtSetArg(args[n], XtNwidth, 300); n++; XtSetArg(args[n], XtNtype, XawAsciiString); n++; XtSetArg(args[n], XtNstring, "text here\n"); n++; bigtext = XtCreateManagedWidget("text", asciiTextWidgetClass, box, args, n); XtVaGetValues(bigtext, XtNtextSource, &bigsink, NULL); //XtAddCallback(bigsource, XtNcallback, textfunc, NULL); n = 0; XtSetArg(args[n], XtNeditType, XawtextEdit); n++; XtSetArg(args[n], XtNscrollHorizontal, XawtextScrollWhenNeeded); n++; XtSetArg(args[n], XtNscrollVertical, XawtextScrollWhenNeeded); n++; //XtSetArg(args[n], XtNheight, 300); n++; XtSetArg(args[n], XtNwidth, 300); n++; XtSetArg(args[n], XtNtype, XawAsciiString); n++; XtSetArg(args[n], XtNstring, "type here: "); n++; linetext = XtCreateManagedWidget("text", asciiTextWidgetClass, box, args, n); XtVaGetValues(linetext, XtNtextSource, &linesource, NULL); XtAddCallback(linesource, XtNcallback, linetextfunc, bigtext); XtRealizeWidget(w); XtAppMainLoop(app); XtDestroyWidget(w); return 0; }